示例#1
0
        void CreateJson(string jsonFullName, string workspace, string elementName)
        {
            string targetFileFullPath = Path.Combine(Application.dataPath, PGFrameWindow.JsonRoot);

            targetFileFullPath = Path.Combine(targetFileFullPath, string.Format("{0}/{1}", workspace, jsonFullName));

            JObject jo = new JObject();

            jo.Add("Workspace", workspace);
            jo.Add("DocType", "Element");

            JObject jo_common = new JObject();

            jo_common.Add("Name", elementName);
            jo_common.Add("Desc", string.Empty);

            jo.Add("Common", jo_common);
            jo.Add("Member", new JArray());
            jo.Add("Views", new JArray());

            string json = JsonConvert.SerializeObject(jo, Formatting.Indented);

            File.WriteAllText(targetFileFullPath, json);

            AssetDatabase.Refresh();

            PRDebug.TagLog(PGFrameWindow.lt, PGFrameWindow.lc, targetFileFullPath + " (Created)");
        }
示例#2
0
        public void DeleteCode(JObject jo)
        {
            string workspaceName = jo ["Workspace"].Value <string> ();
            string elementName   = jo ["Common"] ["Name"].Value <string> ();

            List <string> targetPaths = new List <string> ();

            DocType dt = (DocType)Enum.Parse(typeof(DocType), jo ["DocType"].Value <string> ());

            switch (dt)
            {
            case DocType.Element:
                targetPaths.Add(Path.Combine(Application.dataPath, "_Main/" + workspaceName + "/_Scripts/Controller/" + string.Format("{0}Controller.cs", elementName)));
                targetPaths.Add(Path.Combine(Application.dataPath, "_Main/" + workspaceName + "/_Scripts/Controller/_Base/" + string.Format("{0}ControllerBase.cs", elementName)));
                targetPaths.Add(Path.Combine(Application.dataPath, "_Main/" + workspaceName + "/_Scripts/ViewModel/" + string.Format("{0}ViewModel.cs", elementName)));
                targetPaths.Add(Path.Combine(Application.dataPath, "_Main/" + workspaceName + "/_Scripts/ViewModel/_Base/" + string.Format("{0}ViewModelBase.cs", elementName)));
                targetPaths.Add(Path.Combine(Application.dataPath, "_Main/" + workspaceName + "/_Scripts/View/_Interface/" + string.Format("I{0}View.cs", elementName)));
                targetPaths.Add(Path.Combine(Application.dataPath, "_Main/" + workspaceName + "/_Scripts/Editor/" + string.Format("{0}ElementEditor.cs", elementName)));

                JArray ja_view = jo ["Views"] as JArray;
                for (int i = 0; i < ja_view.Count; i++)
                {
                    JObject jo_view   = ja_view [i] as JObject;
                    string  view_name = jo_view ["Name"].Value <string> ();
                    targetPaths.Add(Path.Combine(Application.dataPath, "_Main/" + workspaceName + "/_Scripts/View/" + string.Format("{0}.cs", view_name)));
                    targetPaths.Add(Path.Combine(Application.dataPath, "_Main/" + workspaceName + "/_Scripts/View/_Base/" + string.Format("{0}Base.cs", view_name)));
                    targetPaths.Add(Path.Combine(Application.dataPath, "_Main/" + workspaceName + "/_Scripts/Editor/" + string.Format("{0}Editor.cs", view_name)));
                }
                break;

            case DocType.SimpleClass:
                targetPaths.Add(Path.Combine(Application.dataPath, "_Main/" + workspaceName + "/_Scripts/SimpleClass/" + string.Format("{0}.cs", elementName)));
                targetPaths.Add(Path.Combine(Application.dataPath, "_Main/" + workspaceName + "/_Scripts/SimpleClass/_Base/" + string.Format("{0}Base.cs", elementName)));
                break;

            case DocType.Enum:
                targetPaths.Add(Path.Combine(Application.dataPath, "_Main/" + workspaceName + "/_Scripts/Enum/" + string.Format("{0}.cs", elementName)));
                break;

            case DocType.FSM:
                targetPaths.Add(Path.Combine(Application.dataPath, "_Main/" + workspaceName + "/_Scripts/FSM/" + string.Format("{0}.cs", elementName)));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            List <string> fileDeleted = new List <string> ();

            foreach (string s in targetPaths)
            {
                if (File.Exists(s))
                {
                    File.Delete(s);
                    fileDeleted.Add(s);
                }
            }

            PRDebug.TagLog(lt + ".DeleteCode", lc, JsonConvert.SerializeObject(fileDeleted, Formatting.Indented));
        }
示例#3
0
        public override void Create()
        {
            JArray ja_elements = FrameWindow.SelectedWorkspaceCommon.jo ["ElementFiles"] as JArray;

            if (FrameWindow.jElements.FirstOrDefault(_ => _.Name == Name) == null)
            {
                string jsonName = MakeJsonName();

                JObject jo = new JObject();
                jo.Add("DocType", "Element");
                jo.Add("Name", Name);
                jo.Add("File", jsonName);
                ja_elements.Add(jo);

                FrameWindow.SaveCommonFile();

                CreateJson(MakeJsonName(), FrameWindow.SelectedWorkspaceCommon.Workspace, Name);

                FrameWindow.NeedRefresh = true;
            }
            else
            {
                PRDebug.TagLog(PGFrameWindow.lt, PGFrameWindow.lc, "该工作空间中已经含有名字: " + Name);
            }
        }
示例#4
0
        public void RenameState()
        {
            JArray ja_states = jElement.jo ["State"] as JArray;

            if (ja_states.FirstOrDefault(_ => _ ["Name"].Value <string> () == in_state_rename_target_name) == null)
            {
                string ori_state_name = in_state_rename_jo_state ["Name"].Value <string> ();
                in_state_rename_jo_state ["Name"] = in_state_rename_target_name;

                for (int i = 0; i < ja_states.Count; i++)
                {
                    JObject jo_state             = ja_states [i] as JObject;
                    JArray  ja_state_transitions = jo_state ["Transitions"] as JArray;
                    for (int j = 0; j < ja_state_transitions.Count; j++)
                    {
                        JObject jo_state_transition = ja_state_transitions [j] as JObject;
                        if (jo_state_transition ["TargetState"].Value <string> () == ori_state_name)
                        {
                            jo_state_transition ["TargetState"] = in_state_rename_target_name;
                        }
                    }
                }
            }
            else
            {
                PRDebug.TagLog(lt, lcr, "输入的状态名字已经被占用");
            }

            StatesList = null;
        }
示例#5
0
        void DeleteElementJsonFile(string jsonFullName, string workspace)
        {
            string targetFileFullPath = Path.Combine(Application.dataPath, JsonRoot);

            targetFileFullPath = Path.Combine(targetFileFullPath, string.Format("{0}/{1}", workspace, jsonFullName));

            File.Delete(targetFileFullPath);
            AssetDatabase.Refresh();

            PRDebug.TagLog(lt, lc, targetFileFullPath + " (Deleted)");
        }
示例#6
0
        void TryShowPopupWindowDoc()
        {
            if (Event.current.type == EventType.Repaint && NeedShowPopupWindowDocType != null)
            {
                DocType selected = NeedShowPopupWindowDocType.Value;

                string tip = string.Format("请输入 {0} 的名字:", selected.ToString());

                NeedShowPopupWindowDocType = null;

                PopupWindow.Show(buttonRect, new TextFieldPopupDialog(tip, (string value) => {
                    if (string.IsNullOrEmpty(value) == false)
                    {
                        JsonFileCreater cjf = null;
                        switch (selected)
                        {
                        case DocType.Element:
                            cjf = new ElementJsonFileCreater(this, value);
                            break;

                        case DocType.SimpleClass:
                            cjf = new SimpleClassJsonFileCreater(this, value);
                            break;

                        case DocType.Enum:
                            cjf = new EnumJsonFileCreater(this, value);
                            break;

                        case DocType.FSM:
                            cjf = new FSMJsonFileCreater(this, value);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                        if (cjf != null)
                        {
                            cjf.Create();
                            WSJsonFilesList = null;
                        }
                    }
                    else
                    {
                        PRDebug.TagLog(lt, lcr, "请输入名字!");
                    }
                }));

                if (Event.current.type == EventType.Repaint)
                {
                    buttonRect = GUILayoutUtility.GetLastRect();
                }
            }
        }
 static void DoExportPackage()
 {
     PRDebug.Log("开始将资源重新打包");
     string[] contents = new string[] {
         Path.Combine("Assets", "PGFrame"),
         Path.Combine("Assets", "Plugins/UniRx"),
         Path.Combine("Assets", "VariousAssets/JsonDotNet"),
         Path.Combine("Assets", "VariousAssets/PogoRock")
     };
     Debug.Log(JsonConvert.SerializeObject(contents));
     Observable.NextFrame().Subscribe(_ => {
         AssetDatabase.ExportPackage(contents, string.Format("PGFrame_{0}.unitypackage", Application.version), ExportPackageOptions.Recurse);
         Debug.Log("打包结束");
     });
 }
示例#8
0
        void CreateJson(string jsonFullName, string workspace, string elementName)
        {
            string targetFileFullPath = Path.Combine(Application.dataPath, PGFrameWindow.JsonRoot);

            targetFileFullPath = Path.Combine(targetFileFullPath, string.Format("{0}/{1}", workspace, jsonFullName));

            JObject jo = new JObject();

            jo.Add("Workspace", workspace);
            jo.Add("DocType", "FSM");

            JObject jo_common = new JObject();

            jo_common.Add("Name", elementName);
            jo_common.Add("Desc", string.Empty);
            jo_common.Add("EntryState", "DefaultState");
            jo.Add("Common", jo_common);
            jo.Add("Transition", new JArray());

            JArray ja_states = new JArray();

            ja_states.Add(new JObject()
            {
                { "Name", "DefaultState" },
                { "Transitions", new JArray() },
                { "Rect", new JObject()
                  {
                      { "x", 150 }, { "y", 100 }, { "w", 100 }, { "h", 50 }
                  } }
            });
            jo.Add("State", ja_states);

            string json = JsonConvert.SerializeObject(jo, Formatting.Indented);

            File.WriteAllText(targetFileFullPath, json);

            AssetDatabase.Refresh();

            PRDebug.TagLog(PGFrameWindow.lt, PGFrameWindow.lc, targetFileFullPath + " (Created)");
        }
示例#9
0
 public override void GameStateChanged(GameCoreViewModel viewModel, GameCoreFSM.State newState, GameCoreFSM.State oldState)
 {
     base.GameStateChanged(viewModel, newState, oldState);
     PRDebug.TagLog("GameCoreController", Color.blue, string.Format("{0} -> {1}", oldState.ToString(), newState.ToString()));
 }
示例#10
0
        public override void OnPairChanged_GameState(Pair <GameCoreFSM.State> pair)
        {
            base.OnPairChanged_GameState(pair);

            PRDebug.TagLog("GameCoreView", Color.blue, string.Format("{0} -> {1}", pair.Previous.ToString(), pair.Current.ToString()));
        }
    public override void OnGUI(Rect rect)
    {
        scrollViewPos = EditorGUILayout.BeginScrollView(scrollViewPos);
        for (int i = 0; i < rc.Count; i++)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(i.ToString(), GUILayout.MaxWidth(30));
            T      e         = rc [i];
            string tempJson  = JsonConvert.SerializeObject(e);
            string tempJson2 = EditorGUILayout.DelayedTextField(tempJson);
            if (tempJson != tempJson2)
            {
                rc [i] = JsonConvert.DeserializeObject <T> (tempJson2);
                parent.VMCopyToJson();
            }
            if (GUILayout.Button("-", GUILayout.MaxWidth(20)))
            {
                rc.RemoveAt(i);
                parent.VMCopyToJson();
                break;
            }
            if (GUILayout.Button("+", GUILayout.MaxWidth(20)))
            {
                rc.Insert(i, PE);
                parent.VMCopyToJson();
                break;
            }
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("NEW", GUILayout.MaxWidth(30));
        string PEJson = JsonConvert.SerializeObject(PE);

        PEJson = EditorGUILayout.DelayedTextField(PEJson);
        PE     = JsonConvert.DeserializeObject <T> (PEJson);
        if (GUILayout.Button("+", GUILayout.MaxWidth(40)))
        {
            rc.Add(PE);
            (parent as IElementEditor).VMCopyToJson();
        }
        EditorGUILayout.EndHorizontal();

        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Json"))
        {
            PRDebug.TagLog("ReactiveDictionary", new Color(.2f, .2f, 1f), JsonConvert.SerializeObject(rc, Formatting.Indented));
        }
        if (GUILayout.Button("Clear"))
        {
            rc.Clear();
            this.editorWindow.Close();
            parent.VMCopyToJson();
            GUI.changed = true;
        }
        if (GUILayout.Button("Close"))
        {
            this.editorWindow.Close();
        }
        EditorGUILayout.EndScrollView();
    }
示例#12
0
    public override void OnGUI(Rect rect)
    {
        scrollViewPos = EditorGUILayout.BeginScrollView(scrollViewPos);
        foreach (T key in rd.Keys)
        {
            U value = rd [key];

            EditorGUILayout.BeginHorizontal();

            string tempkJson  = JsonConvert.SerializeObject(key);
            string tempkJson2 = EditorGUILayout.DelayedTextField(tempkJson);
            if (tempkJson != tempkJson2)
            {
                T newKey = JsonConvert.DeserializeObject <T> (tempkJson2);
                rd [newKey] = value;
                rd.Remove(key);
                parent.VMCopyToJson();
            }

            string tempvJson  = JsonConvert.SerializeObject(value);
            string tempvJson2 = EditorGUILayout.DelayedTextField(tempvJson);
            if (tempvJson != tempvJson2)
            {
                U newValue = JsonConvert.DeserializeObject <U> (tempvJson2);
                rd [key] = newValue;
                parent.VMCopyToJson();
            }

            if (GUILayout.Button("-", GUILayout.MaxWidth(20)))
            {
                rd.Remove(key);
                parent.VMCopyToJson();
                break;
            }

            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.BeginHorizontal();
        string PKJson = JsonConvert.SerializeObject(PK);

        PKJson = EditorGUILayout.DelayedTextField(PKJson);
        PK     = JsonConvert.DeserializeObject <T> (PKJson);

        string PVJson = JsonConvert.SerializeObject(PV);

        PVJson = EditorGUILayout.DelayedTextField(PVJson);
        PV     = JsonConvert.DeserializeObject <U> (PVJson);

        if (GUILayout.Button("+", GUILayout.MaxWidth(20)))
        {
            rd.Add(PK, PV);
            parent.VMCopyToJson();
        }
        EditorGUILayout.EndHorizontal();


        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Json"))
        {
            PRDebug.TagLog("ReactiveDictionary", new Color(.2f, .2f, 1f), JsonConvert.SerializeObject(rd, Formatting.Indented));
        }
        if (GUILayout.Button("Clear"))
        {
            rd.Clear();
            this.editorWindow.Close();
            parent.VMCopyToJson();
            GUI.changed = true;
        }
        if (GUILayout.Button("Close"))
        {
            this.editorWindow.Close();
        }
        EditorGUILayout.EndScrollView();
    }
示例#13
0
        public void GenerateCode(JObject jo)
        {
            IList <string> filesGenerated = new List <string> ();

            DocType dt = (DocType)Enum.Parse(typeof(DocType), jo ["DocType"].Value <string> ());

            switch (dt)
            {
            case DocType.Element:
                if (sg_ViewModelBase.CanGenerate(jo))
                {
                    sg_ViewModelBase.GenerateCode(jo, filesGenerated);
                }
                if (sg_ViewModel.CanGenerate(jo))
                {
                    sg_ViewModel.GenerateCode(jo, filesGenerated);
                }
                if (sg_ControllerBase.CanGenerate(jo))
                {
                    sg_ControllerBase.GenerateCode(jo, filesGenerated);
                }
                if (sg_Controller.CanGenerate(jo))
                {
                    sg_Controller.GenerateCode(jo, filesGenerated);
                }
                if (sg_ViewInterface.CanGenerate(jo))
                {
                    sg_ViewInterface.GenerateCode(jo, filesGenerated);
                }
                if (sg_ViewBase.CanGenerate(jo))
                {
                    sg_ViewBase.GenerateCode(jo, filesGenerated);
                }
                if (sg_View.CanGenerate(jo))
                {
                    sg_View.GenerateCode(jo, filesGenerated);
                }
                if (sg_ElementEditor.CanGenerate(jo))
                {
                    sg_ElementEditor.GenerateCode(jo, filesGenerated);
                }
                if (sg_ElementViewEditor.CanGenerate(jo))
                {
                    sg_ElementViewEditor.GenerateCode(jo, filesGenerated);
                }
                break;

            case DocType.SimpleClass:
                if (sg_SimpleClassBase.CanGenerate(jo))
                {
                    sg_SimpleClassBase.GenerateCode(jo, filesGenerated);
                }
                if (sg_SimpleClass.CanGenerate(jo))
                {
                    sg_SimpleClass.GenerateCode(jo, filesGenerated);
                }
                break;

            case DocType.Enum:
                if (sg_Enum.CanGenerate(jo))
                {
                    sg_Enum.GenerateCode(jo, filesGenerated);
                }
                break;

            case DocType.FSM:
                if (sg_FSM.CanGenerate(jo))
                {
                    sg_FSM.GenerateCode(jo, filesGenerated);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }


            PRDebug.TagLog(lt + ".GenerateCode", lc, JsonConvert.SerializeObject(filesGenerated, Formatting.Indented));
        }
示例#14
0
        private void OnGUI()
        {
            if (TransitionsList == null)
            {
                if (jElement == null)
                {
                    this.Close();
                    return;
                }
                ResetReorderableTransitionsList();
            }

            if (StatesList == null)
            {
                if (jElement == null)
                {
                    this.Close();
                    return;
                }
                ResetReorderableStatesList();
            }

            JObject jo_common = jElement.jo ["Common"] as JObject;


            GUILayout.BeginHorizontal();

            // tab
            GUILayout.BeginVertical(GUILayout.MaxWidth(tab_width));
            scrollStatesPosition = GUILayout.BeginScrollView(scrollStatesPosition);

            TransitionsList.DoLayoutList();
            EditorGUILayout.Space();
            StatesList.DoLayoutList();

            GUILayout.FlexibleSpace();

            GUILayout.EndScrollView();

            if (in_state_rename_jo_state != null)
            {
                GUILayout.BeginVertical("box");
                GUILayout.Label(string.Format("Rename State({0}) To:", in_state_rename_jo_state ["Name"].Value <string> ()));
                in_state_rename_target_name = GUILayout.TextField(in_state_rename_target_name);
                if (GUILayout.Button("Confirm Rename"))
                {
                    RenameState();
                    in_state_rename_jo_state    = null;
                    in_state_rename_target_name = "";
                }
                if (GUILayout.Button("Cancel Rename State"))
                {
                    in_state_rename_jo_state    = null;
                    in_state_rename_target_name = "";
                }
                GUILayout.EndVertical();
            }

            if (in_state_transition_target_selecting_jo_state_transition != null)
            {
                if (GUILayout.Button("Cancel Transition To"))
                {
                    in_state_transition_target_selecting_jo_state_transition = null;
                    in_state_transition_target_selecting_window_id           = -1;
                }
            }
            if (GUILayout.Button("Create New State"))
            {
                CreateNewState();
            }
            if (GUILayout.Button("JElement"))
            {
                PRDebug.TagLog(lt, lc, JsonConvert.SerializeObject(jElement, Formatting.Indented));
            }
            if (GUILayout.Button("Reset"))
            {
                TransitionsList = null;
                StatesList      = null;
                jElement.Load();
            }
            if (GUILayout.Button("Save"))
            {
                SaveJsonFile();
            }
            if (GUILayout.Button("Save & Generate"))
            {
                SaveJsonFile();
                PGFrameWindow.Current.Generator.GenerateCode(jElement.jo);
            }
            if (GUILayout.Button("Save & Close"))
            {
                SaveJsonFile();
                this.Close();
                return;
            }
            EditorGUILayout.Space();
            GUILayout.EndVertical();

            // title
            GUILayout.BeginVertical();
            GUILayout.Label(jo_common ["Name"].Value <string> (), GUIStyleTemplate.FSMTitleStyle());
            jo_common ["Desc"] = EditorGUILayout.TextArea(jo_common ["Desc"].Value <string> (), GUIStyleTemplate.GreenDescStyle());
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();

            DrawTransitionLines();

            BeginWindows();
            if (jElement != null)
            {
                JArray ja_states = jElement.jo ["State"] as JArray;

                for (int i = 0; i < ja_states.Count; i++)
                {
                    JObject jo_state   = ja_states [i] as JObject;
                    string  state_name = jo_state ["Name"].Value <string> ();
                    float   x          = jo_state ["Rect"] ["x"].Value <float> ();
                    float   y          = jo_state ["Rect"] ["y"].Value <float> ();
                    float   w          = jo_state ["Rect"] ["w"].Value <float> ();
                    float   h          = jo_state ["Rect"] ["h"].Value <float> ();

                    Rect rect = GUI.Window(i, new Rect(x, y, w, h), WindowFunction, state_name);

                    rect.x = Math.Max((int)tab_width, (int)rect.x);
                    rect.y = Math.Max(50, (int)rect.y);
                    rect   = SnapRect(rect);
                    jo_state ["Rect"] ["x"] = (int)rect.x;
                    jo_state ["Rect"] ["y"] = (int)rect.y;
                    jo_state ["Rect"] ["w"] = (int)rect.width;
                    jo_state ["Rect"] ["h"] = (int)rect.height;
                }
            }
            EndWindows();
        }