我弄了好久都不知道NGUI怎么把变量显示在Inspector面板上,所以就找了一下,下面就是我找到的关于NGUI怎么把变量显示在Inspector面板上的答案。
  1. //----------------------------------------------
  2. //            NGUI: Next-Gen UI kit
  3. // Copyright ? 2011-2014 Tasharen Entertainment
  4. //----------------------------------------------
  5. using UnityEngine;
  6. using UnityEditor;
  7. [CanEditMultipleObjects]
  8. [CustomEditor(typeof(UIScrollBar))]
  9. public class UIScrollBarEditor : UIProgressBarEditor
  10. {
  11. protected override void DrawLegacyFields ()
  12. {
  13. UIScrollBar sb = target as UIScrollBar;
  14. float val = EditorGUILayout.Slider("Value", sb.value, 0f, 1f);
  15. float size = EditorGUILayout.Slider("Size", sb.barSize, 0f, 1f);
  16. float alpha = EditorGUILayout.Slider("Alpha", sb.alpha, 0f, 1f);
  17. if (sb.value != val ||
  18. sb.barSize != size ||
  19. sb.alpha != alpha)
  20. {
  21. NGUIEditorTools.RegisterUndo("Scroll Bar Change", sb);
  22. sb.value = val;
  23. sb.barSize = size;
  24. sb.alpha = alpha;
  25. NGUITools.SetDirty(sb);
  26. for (int i = 0; i < UIScrollView.list.size; ++i)
  27. {
  28. UIScrollView sv = UIScrollView.list[i];
  29. if (sv.horizontalScrollBar == sb || sv.verticalScrollBar == sb)
  30. {
  31. NGUIEditorTools.RegisterUndo("Scroll Bar Change", sv);
  32. sv.UpdatePosition();
  33. }
  34. }
  35. }
  36. }
  37. }