GeneralDataModificationWindow.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using UnityEngine;
  2. using UnityEditor;
  3. /// <summary>
  4. /// 通用数据修改窗体
  5. /// </summary>
  6. public class GeneralDataModificationWindow : EditorWindow
  7. {
  8. string m_Title;
  9. //object value;
  10. object modifi_Value;
  11. CallBackR<object, object> customDrawGUI;
  12. CallBack<object> modificationCompleteCallBack;
  13. CallBackR<bool, object> checkCanOkButtonCallBack;
  14. static GeneralDataModificationWindow win;
  15. public static GeneralDataModificationWindow GetInstance()
  16. {
  17. return win;
  18. }
  19. EditorWindow otherWindow;
  20. /// <summary>
  21. /// 用于储存其他要使用的参数
  22. /// </summary>
  23. public static object otherParameter;
  24. /// <summary>
  25. /// 打开窗口
  26. /// </summary>
  27. /// <param name="title">标题</param>
  28. /// <param name="value">希望修改的数据</param>
  29. /// <param name="customDrawGUI">自定义GUI绘制</param>
  30. /// <param name="checkCanOkButtonCallBack">检查是否能使用"OK"按钮</param>
  31. /// <param name="modificationCompleteCallBack">完成修改回调</param>
  32. public static void OpenWindow(EditorWindow otherWindow, string title,object value,CallBackR<object,object> customDrawGUI,CallBackR<bool,object> checkCanOkButtonCallBack, CallBack<object> modificationCompleteCallBack)
  33. {
  34. win = GetWindow<GeneralDataModificationWindow>();
  35. win.wantsMouseMove = true;
  36. win.autoRepaintOnSceneChange = true;
  37. win.otherWindow = otherWindow;
  38. FocusWindowIfItsOpen<GeneralDataModificationWindow>();
  39. win.m_Title = title;
  40. //win.value = value;
  41. win.modifi_Value = value;//.DeepCopySelf();
  42. win.customDrawGUI = customDrawGUI;
  43. win.modificationCompleteCallBack = modificationCompleteCallBack;
  44. win.checkCanOkButtonCallBack = checkCanOkButtonCallBack;
  45. }
  46. private void OnGUI()
  47. {
  48. if (modifi_Value == null)
  49. return;
  50. EditorDrawGUIUtil.DrawHorizontalCenter(() =>
  51. {
  52. GUILayout.Label(m_Title);
  53. });
  54. EditorDrawGUIUtil.DrawScrollView(modifi_Value, () =>
  55. {
  56. if (customDrawGUI != null)
  57. modifi_Value = customDrawGUI(modifi_Value);
  58. else
  59. {
  60. modifi_Value = EditorDrawGUIUtil.DrawBaseValue("Value", modifi_Value);
  61. }
  62. GUILayout.FlexibleSpace();
  63. });
  64. GUILayout.FlexibleSpace();
  65. bool isClose = false;
  66. EditorDrawGUIUtil.DrawHorizontalCenter(() =>
  67. {
  68. if (GUILayout.Button("OK",GUILayout.Width( position.width/4)))
  69. {
  70. if (checkCanOkButtonCallBack != null)
  71. {
  72. if (!checkCanOkButtonCallBack(modifi_Value))
  73. return;
  74. }
  75. if(modificationCompleteCallBack != null)
  76. {
  77. modificationCompleteCallBack(modifi_Value);
  78. }
  79. if (otherWindow)
  80. otherWindow.Repaint();
  81. isClose = true;
  82. }
  83. if (GUILayout.Button("Cancel", GUILayout.Width(position.width / 4)))
  84. {
  85. isClose = true;
  86. }
  87. });
  88. GUILayout.Space(6);
  89. if (isClose)
  90. Close();
  91. }
  92. }