private void OnDestroy() { if (ECSConfig.IsModfy()) { if (EditorUtility.DisplayDialog("提示", "ECS有未保存的修改,是否保存?", "保存", "放弃")) { ECSConfig.SaveToFile(); } else { ECSConfig.ReloadFormFile(); } } //Undo.ClearUndo(ECSConfig.Instance); }
protected ECSConfig() { _instance = this; }
void OnGUI() { for (int i = 0; i < ECSConfig.Instance.Contexts.Count; ++i) { var context = ECSConfig.Instance.Contexts[i]; using (new EditorGUILayout.VerticalScope("Box")) { using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label(context.Name); GUILayout.FlexibleSpace(); if (GUILayout.Button("移除")) { ECSConfig.MakeModify("remove context"); ECSConfig.Instance.Contexts.RemoveAt(i); --i; continue; } } using (new EditorGUILayout.HorizontalScope()) { if (!string.IsNullOrEmpty(context.UpLevelContext)) { GUILayout.Label("上层Context: "); GUILayout.Label(context.UpLevelContext); } if (GUILayout.Button("选择上层Context")) { var names = ECSConfig.Instance.Contexts.Where(it => it.Name != context.Name && context.Name != it.UpLevelContext).Select(it => it.Name).ToArray(); if (names.Length > 0) { GenericMenu generic = new GenericMenu(); foreach (var name in names) { generic.AddItem(new GUIContent(name), name == context.UpLevelContext, () => { ECSConfig.MakeModify("set up level context"); context.UpLevelContext = name; }); } generic.ShowAsContext(); } } } GUILayout.Space(5); if (GUILayout.Button(context.DirectoryPath, EditorStyles.linkLabel)) { string selectPath = context.DirectoryPath; if (selectPath.EndsWith("/")) { selectPath = selectPath.Substring(0, selectPath.Length - 1); } var obj = AssetDatabase.LoadMainAssetAtPath(selectPath); EditorGUIUtility.PingObject(obj); Selection.activeObject = obj; } if (GUILayout.Button("重新生成ECS文件")) { context.GenECSFile(true); } } GUILayout.Space(10); } DrawCreate(); DrawAddExits(); if (ECSConfig.IsModfy() && GUILayout.Button("保存")) { ECSConfig.SaveToFile(); } }
public static void ReloadFormFile() { _instance = JsonUtility.FromJson <ECSConfig>(SaveFile); }