using UnityEngine; using UnityEditor; /// /// 通用数据修改窗体 /// public class GeneralDataModificationWindow : EditorWindow { string m_Title; //object value; object modifi_Value; CallBackR customDrawGUI; CallBack modificationCompleteCallBack; CallBackR checkCanOkButtonCallBack; static GeneralDataModificationWindow win; public static GeneralDataModificationWindow GetInstance() { return win; } EditorWindow otherWindow; /// /// 用于储存其他要使用的参数 /// public static object otherParameter; /// /// 打开窗口 /// /// 标题 /// 希望修改的数据 /// 自定义GUI绘制 /// 检查是否能使用"OK"按钮 /// 完成修改回调 public static void OpenWindow(EditorWindow otherWindow, string title,object value,CallBackR customDrawGUI,CallBackR checkCanOkButtonCallBack, CallBack modificationCompleteCallBack) { win = GetWindow(); win.wantsMouseMove = true; win.autoRepaintOnSceneChange = true; win.otherWindow = otherWindow; FocusWindowIfItsOpen(); win.m_Title = title; //win.value = value; win.modifi_Value = value;//.DeepCopySelf(); win.customDrawGUI = customDrawGUI; win.modificationCompleteCallBack = modificationCompleteCallBack; win.checkCanOkButtonCallBack = checkCanOkButtonCallBack; } private void OnGUI() { if (modifi_Value == null) return; EditorDrawGUIUtil.DrawHorizontalCenter(() => { GUILayout.Label(m_Title); }); EditorDrawGUIUtil.DrawScrollView(modifi_Value, () => { if (customDrawGUI != null) modifi_Value = customDrawGUI(modifi_Value); else { modifi_Value = EditorDrawGUIUtil.DrawBaseValue("Value", modifi_Value); } GUILayout.FlexibleSpace(); }); GUILayout.FlexibleSpace(); bool isClose = false; EditorDrawGUIUtil.DrawHorizontalCenter(() => { if (GUILayout.Button("OK",GUILayout.Width( position.width/4))) { if (checkCanOkButtonCallBack != null) { if (!checkCanOkButtonCallBack(modifi_Value)) return; } if(modificationCompleteCallBack != null) { modificationCompleteCallBack(modifi_Value); } if (otherWindow) otherWindow.Repaint(); isClose = true; } if (GUILayout.Button("Cancel", GUILayout.Width(position.width / 4))) { isClose = true; } }); GUILayout.Space(6); if (isClose) Close(); } }