void RefreshFiles() { NeedRefresh = false; string JsonRootFull = Path.Combine(Application.dataPath, JsonRoot); if (!Directory.Exists(JsonRootFull)) { Directory.CreateDirectory(JsonRootFull); } if (SelectedWorkspace == null) { DirectoryInfo di = new DirectoryInfo(JsonRootFull); WorkspaceDirectoryInfos = di.GetDirectories(); // PRDebug.TagLog (lt, lc, JsonConvert.SerializeObject (WorkspaceDirectoryInfos.Select (_ => _.Name).ToList ())); } else { string JsonWSFull = Path.Combine(JsonRootFull, SelectedWorkspace.Name); DirectoryInfo di = new DirectoryInfo(JsonWSFull); FileInfo[] fis = di.GetFiles("*.json"); List <JSONElement> je = new List <JSONElement> (fis.Length - 1); for (int i = 0; i < fis.Length; i++) { FileInfo fi = fis [i]; JSONElement e = new JSONElement(); e.FileInfo = fi; if (fi.Name == "_Common.json") { SelectedWorkspaceCommon = e; } else { je.Add(e); } } jElements = je.ToArray(); } // Common Manager if (CommonManager == null) { CommonManager = new PGFrameCommonManager(this); } if (NeedRefreshCommon) { NeedRefreshCommon = false; CommonManager.Load(); } }
public void OnDestroy() { if (jElement != null) { this.jElement = null; } this.TransitionsList = null; if (PGFrameWindow.Current != null) { PGFrameWindow.Current.SelectedJsonElement = null; } PGFrameWindow.AutoSelected.SelectedJsonFileName = string.Empty; PGFrameWindow.AutoSelected.Save(); }
public static void OpenContentMenu(JSONElement jsonElement) { string workspace = jsonElement.Workspace; string docType = jsonElement.DocType; string name = jsonElement.Name; Debug.LogFormat("OpenContentMenu: {0} | {1} | {2}", workspace, docType, name); GenericMenu menu = new GenericMenu(); if (docType == "Element") { JArray ja_views = jsonElement.jo ["Views"] as JArray; for (int i = 0; i < ja_views.Count; i++) { JObject jo_view = ja_views [i] as JObject; string viewName = jo_view ["Name"].Value <string> (); menu.AddItem(new GUIContent(string.Format("{0}.cs", viewName)), false, () => { string file = string.Format("Assets/_Main/{0}/_Scripts/View/{1}.cs", workspace, viewName); UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(file, 1); }); } menu.AddItem(new GUIContent(string.Format("{0}Controller.cs", name)), false, () => { string file = string.Format("Assets/_Main/{0}/_Scripts/Controller/{1}Controller.cs", workspace, name); UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(file, 1); }); menu.AddItem(new GUIContent(string.Format("{0}ViewModel.cs", name)), false, () => { string file = string.Format("Assets/_Main/{0}/_Scripts/ViewModel/{1}ViewModel.cs", workspace, name); UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(file, 1); }); } else if (docType == "SimpleClass") { menu.AddItem(new GUIContent(string.Format("{0}.cs", name)), false, () => { string file = string.Format("Assets/_Main/{0}/_Scripts/SimpleClass/{1}.cs", workspace, name); UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(file, 1); }); } else if (docType == "Enum") { menu.AddItem(new GUIContent(string.Format("{0}.cs", name)), false, () => { string file = string.Format("Assets/_Main/{0}/_Scripts/Enum/{1}.cs", workspace, name); UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(file, 1); }); } else if (docType == "FSM") { menu.AddItem(new GUIContent(string.Format("{0}.cs", name)), false, () => { string file = string.Format("Assets/_Main/{0}/_Scripts/FSM/{1}.cs", workspace, name); UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(file, 1); }); } menu.AddSeparator(""); menu.AddItem(new GUIContent(string.Format("{0}.{1}.{2}.json", workspace, docType, name)), false, () => { string file = string.Format("Assets/PGFrameDesign/JsonData/{0}/{0}.{1}.{2}.json", workspace, docType, name); UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(file, 1); }); menu.ShowAsContext(); }
void DesignList() { if (WorkspaceDirectoryInfos == null || CommonManager.CommonObjectDic == null) { NeedRefresh = true; return; } // string JsonRootFull = Path.Combine (Application.dataPath, JsonRoot); if (SelectedWorkspace == null) { GUILayout.Label("Root", EditorStyles.boldLabel); scrollViewPos = GUILayout.BeginScrollView(scrollViewPos); for (int i = 0; i < WorkspaceDirectoryInfos.Length; i++) { DirectoryInfo wdi = WorkspaceDirectoryInfos [i]; string ws_name = wdi.Name; StringBuilder sb_content = new StringBuilder(wdi.Name); if (CommonManager != null) { int file_count = CommonManager.CommonObjectDic [ws_name].ElementFiles.Count; sb_content.AppendFormat(" ({0} file{1})", file_count, file_count > 1 ? "s" : ""); // button_content += " (" + CommonManager.CommonObjectDic [ws_name].ElementFiles.Count + " file)"; } GUIContent button_content = new GUIContent(sb_content.ToString(), pgf_workspace_icon); if (GUILayout.Button(button_content, GUIStyleTemplate.ButtonStyleAlignmentLeft())) { AutoSelected.SelectedWorkspaceName = ws_name; AutoSelected.Save(); SelectedWorkspace = wdi; NeedRefresh = true; } } GUILayout.EndScrollView(); } else { GUILayout.BeginHorizontal(); if (GUILayout.Button("<<")) { SelectedWorkspace = null; NeedRefresh = true; WSJsonFilesList = null; SelectedWorkspaceCommon = null; AutoSelected.SelectedWorkspaceName = string.Empty; AutoSelected.Save(); return; } if (GUILayout.Button("Save")) { SaveCommonFile(); } GUILayout.EndHorizontal(); GUILayout.Label("Workspace:" + SelectedWorkspace.Name, EditorStyles.boldLabel); if (SelectedWorkspaceCommon != null) { // PRDebug.TagLog ("PGFrameWindow.Debug", Color.yellow, JsonConvert.SerializeObject (SelectedWorkspaceCommon)); if (WSJsonFilesList == null) { ResetReorderableList(); } JsonFilesScrollPos = GUILayout.BeginScrollView(JsonFilesScrollPos); WSJsonFilesList.DoLayoutList(); GUILayout.EndScrollView(); TryShowPopupWindowDoc(); } } }
void ResetReorderableList() { JArray ja_elements = SelectedWorkspaceCommon.jo ["ElementFiles"] as JArray; WSJsonFilesList = new ReorderableList(ja_elements, typeof(JToken)); WSJsonFilesList.drawHeaderCallback += (Rect rect) => { GUI.Label(rect, "ElementFiles"); }; float[] split = new float[] { 0f, 1f }; WSJsonFilesList.drawElementCallback += (Rect rect, int index, bool isActive, bool isFocused) => { Rect r = new Rect(rect); r.y -= 1; r.height -= 2; int split_idx = 0; r.x = (rect.width - 25f) * split [split_idx] + 25f; r.width = (rect.width - 25f) * (split [split_idx + 1] - split [split_idx]); JObject jo_element = ja_elements [index] as JObject; string jo_element_filename = jo_element ["File"].Value <string> (); DocType dt = (DocType)Enum.Parse(typeof(DocType), jo_element ["DocType"].Value <string> ()); Texture2D icon = null; switch (dt) { case DocType.Element: icon = pgf_element_icon; break; case DocType.SimpleClass: icon = pgf_simple_class_icon; break; case DocType.Enum: icon = pgf_enum_icon; break; case DocType.FSM: icon = pgf_fsm_icon; break; default: throw new ArgumentOutOfRangeException(); } GUIContent content = new GUIContent(jo_element_filename, icon); if (GUI.Button(r, content, GUIStyleTemplate.ButtonStyleAlignmentLeft())) { if (Event.current.button == 1) { JSONElement jsonElement = jElements.Single(je => je.FileName == jo_element_filename); PGFrameOpenFileTools.OpenContentMenu(jsonElement); } else { SelectedJsonElement = jElements.Single(je => je.FileName == jo_element_filename); if (dt == DocType.FSM) { FSMWindow.Init(); FSMWindow.Current.jElement = SelectedJsonElement; } AutoSelected.SelectedJsonFileName = jo_element_filename; AutoSelected.Save(); } } }; WSJsonFilesList.onAddCallback += (ReorderableList list) => { GenericMenu menu = new GenericMenu(); foreach (DocType dt in Enum.GetValues(typeof(DocType))) { menu.AddItem(new GUIContent(dt.ToString()), false, (object userData) => { NeedShowPopupWindowDocType = (DocType)userData; }, dt); } menu.ShowAsContext(); }; WSJsonFilesList.onRemoveCallback += (ReorderableList list) => { JObject jo = ja_elements [list.index] as JObject; string jsonName = jo ["File"].Value <string> (); if (EditorUtility.DisplayDialog("警告!", string.Format("确定删除框架中的{0}文件?", jo ["File"].Value <string> ()), "Yes", "No")) { ja_elements.RemoveAt(list.index); SelectedWorkspaceCommon.jo ["ElementFiles"] = ja_elements; SaveCommonFile(); DeleteElementJsonFile(jsonName, SelectedWorkspaceCommon.Workspace); NeedRefresh = true; } }; }
void OnGUI() { if (Current == null) { Current = this; Current.NeedRefresh = true; Current.NeedRefreshCommon = true; RefreshIcons(); } if (Event.current.type == EventType.Layout && (NeedRefresh || NeedRefreshCommon)) { RefreshFiles(); } if (Generator == null) { Generator = new PGCodeGenerator(); Generator.Init(); } GUILayout.BeginVertical(); GUILayout.Label("PGFrame", EditorStyles.boldLabel); if (GUILayout.Button("刷新")) { NeedRefresh = true; NeedRefreshCommon = true; RefreshFiles(); } ApplySelected(); if (NeedRefresh == false) { if (SelectedJsonElement == null) { if (GUILayout.Button("添加 Workspace")) { PopupWindow.Show(buttonRect, new TextFieldPopupDialog("请输入 Workspace 的名字:", (string value) => { JsonWorkspaceManager manager = new JsonWorkspaceManager(Path.Combine(Application.dataPath, JsonRoot)); manager.CreateWorkspace(value); CommonManager.Load(); AssetDatabase.Refresh(); NeedRefresh = true; return; })); if (Event.current.type == EventType.Repaint) { buttonRect = GUILayoutUtility.GetLastRect(); } } DesignList(); } else { switch ((DocType)Enum.Parse(typeof(DocType), SelectedJsonElement.DocType)) { case DocType.Element: DesignList_Element(); break; case DocType.SimpleClass: DesignList_SimpleClass(); break; case DocType.Enum: DesignList_Enum(); break; case DocType.FSM: DesignList(); break; default: throw new ArgumentOutOfRangeException(); } if (GUILayout.Button("打开相关文件...")) { PGFrameOpenFileTools.OpenContentMenu(SelectedJsonElement); } } } else { this.Repaint(); } GUILayout.FlexibleSpace(); if (SelectedWorkspace != null && jElements != null) { if (GUILayout.Button(string.Format("发布代码 ({0})", jElements.Length))) { for (int i = 0; i < jElements.Length; i++) { JSONElement xe = jElements [i]; Generator.GenerateCode(xe.jo); } AssetDatabase.Refresh(); } } if (SelectedWorkspace != null && jElements != null) { if (GUILayout.Button(string.Format("删除代码 ({0})", jElements.Length))) { if (EditorUtility.DisplayDialog("警告!", string.Format("确定删除整个Workspace:{0}的文件,包括非base层代码", SelectedWorkspace.Name), "确定删除", "取消操作")) { for (int i = 0; i < jElements.Length; i++) { JSONElement xe = jElements [i]; Generator.DeleteCode(xe.jo); } AssetDatabase.Refresh(); } } } GUILayout.EndVertical(); // if (Event.current.type == EventType.KeyDown && Event.current.) }