Esempio n. 1
0
        public void Display(EditorWindow context)
        {
            if (EditorApplication.isUpdating || EditorApplication.isCompiling)
            {
                EditorGUILayout.LabelField("Wait for it...");
                return;
            }

            if (string.IsNullOrEmpty(currentProject))
            {
                EditorGUILayout.LabelField("You dont have a MVCC project setup yet.");
                return;
            }

            if (!EditorApplication.isCompiling)
            {
                if (!string.IsNullOrEmpty(_currentAsset))
                {
                    ScriptableObjectUtility.CreateAsset(_currentAsset, "Assets/" + currentProject + "/Scripts/Controllers/" + _currentAsset + ".asset");
                    _currentAsset = string.Empty;
                }
            }

            if (_doAddControllerToObject)
            {
                _doAddControllerToObject = false;
                AssetDatabase.Refresh();
                var temp = Selection.activeGameObject;

                var asm = EditorUtil.GetProjectAssembly();

                var newType = asm.GetType(currentProject + ".Controller." + _newViewNavName);
                var src     = temp.AddComponent(newType);
                (src as MVCC.AppMonoController).controllerType = CONTROLLER_TYPE.NAV;
                var r = (temp.transform as RectTransform);
                r.anchorMin     = Vector2.zero;
                r.anchorMax     = Vector2.one;
                r.sizeDelta     = Vector2.zero;
                temp.name       = _newViewNavName;
                _newViewNavName = string.Empty;
                return;
            }

            if (_doAddMonoControllerToObject)
            {
                _doAddMonoControllerToObject = false;
                AssetDatabase.Refresh();
                var temp = Selection.activeGameObject;
                var asm  = EditorUtil.GetProjectAssembly();
                MVCCLog.Log(currentProject + ".Controller." + _newViewName);
                var newType = asm.GetType(currentProject + ".Controller." + _newViewName);
                var src     = temp.AddComponent(newType);
                (src as MVCC.AppMonoController).controllerType = CONTROLLER_TYPE.ALL;
                _newViewName = string.Empty;
                return;
            }
            GUILayout.Space(20);

            EditorGUILayout.LabelField("View Controller:");
            GUILayout.Space(10);
            _addControllerToObject = GUILayout.Toggle(_addControllerToObject, "Add to selected gameObject");
            _newViewNavName        = EditorGUILayout.TextField("New ViewController Name", _newViewNavName);
            if (GUILayout.Button("Generate New ViewController Script"))
            {
                string content = File.ReadAllText(pathSource + "ViewController.txt");
                content = content.Replace("%NAMESPACE%", currentProject);
                content = content.Replace("%VIEWCONTROLLER%", _newViewNavName);
                content = content.Replace("%EXTRANAMESPACE%", string.Empty);
                EditorUtil.WriteData(outputFolder + "Controllers/", _newViewNavName + ".cs", content);
                if (_addControllerToObject && Selection.activeGameObject != null)
                {
                    PlayerPrefs.SetString("MVCC_NEW_VIEWCONTROLLER", _newViewNavName);
                }
                AssetDatabase.Refresh();
            }
            EditorUtil.DrawUILine(Color.gray);
            GUILayout.Space(20);
            EditorGUILayout.LabelField("Mono Controller:");
            GUILayout.Space(10);
            _addViewToObject = GUILayout.Toggle(_addViewToObject, "Add to selected gameObject");
            _newViewName     = EditorGUILayout.TextField("New Controller Name", _newViewName);
            if (GUILayout.Button("Generate New Mono Controller Script"))
            {
                string content = File.ReadAllText(pathSource + "Controller.txt");
                content = content.Replace("%NAMESPACE%", currentProject);
                content = content.Replace("%CONTROLLER%", _newViewName);
                content = content.Replace("%EXTRANAMESPACE%", string.Empty);

                EditorUtil.WriteData(outputFolder + "Controllers/", _newViewName + ".cs", content);
                if (_addViewToObject && Selection.activeGameObject != null)
                {
                    PlayerPrefs.SetString("MVCC_NEW_CONTROLLER", _newViewName);
                }
                AssetDatabase.Refresh();
            }
            EditorUtil.DrawUILine(Color.gray);
            GUILayout.Space(20);
            EditorGUILayout.LabelField("SC Controller:");
            GUILayout.Space(10);
            _newSCName = EditorGUILayout.TextField("New SC Controller Name", _newSCName);
            if (GUILayout.Button("Generate New SC Controller Script and Asset"))
            {
                string content = File.ReadAllText(pathSource + "CSController.txt");
                content = content.Replace("%NAMESPACE%", currentProject);
                content = content.Replace("%CONTROLLER%", _newSCName);
                content = content.Replace("%EXTRANAMESPACE%", string.Empty);
                EditorUtil.WriteData(outputFolder + "Controllers/", _newSCName + ".cs", content);
                PlayerPrefs.SetString("MVCC_SCC", _newSCName);
                AssetDatabase.Refresh();
            }
        }
Esempio n. 2
0
        public bool Display(EditorWindow context)
        {
            if (_iconLogo == null)
            {
                _iconLogo = Resources.Load("mvccicon") as Texture2D;
            }

            GUILayout.Box(_iconLogo, GUILayout.MaxWidth(500));

            if (EditorApplication.isUpdating || EditorApplication.isCompiling)
            {
                EditorGUILayout.LabelField("Wait for it...");
                return(false);
            }

            if (_instructionPage > 0)
            {
                EditorGUILayout.LabelField("New project create - Next Steps");
                GUILayout.Space(20);

                switch (_instructionPage)
                {
                case 3:
                    GUILayout.Label($"You have setup your MVCC project.\n\n Your project is inside folder {_currentProject}");
                    break;

                case 2:
                    GUILayout.Label("You have setup your MVCC project.\n\n Next Step: Create your scene and add mvcc prefab");
                    break;

                case 1:
                    GUILayout.Label("Next panel will let you create new Events");
                    break;
                }

                GUILayout.Space(20);

                if (GUILayout.Button((_instructionPage == 1) ? "Finish" : "Next"))
                {
                    _instructionPage--;
                }
                return(false);
            }

            _counterTest++;

            if (_counterTest > 50)
            {
                _counterTest = 0;
                _mvccValues  = EditorUtil.GetCurrentData();
                if (_mvccValues.GetKey() == "TRUE")
                {
                    _setupNewProjectAfterCompiling = true;
                    _mvccValues.SetKey(string.Empty);
                }
            }

            if (_setupNewProjectAfterCompiling)
            {
                _setupNewProjectAfterCompiling = false;
                AssetDatabase.Refresh();
                string outputFolder = Application.dataPath + "/" + _currentProject;

                var obj = new GameObject();
                obj.name = "MVCC - " + _currentProject;

                var asm     = EditorUtil.GetProjectAssembly();
                var newType = asm.GetType("MVCC.Controller.DefaultStart");
                var src     = obj.AddComponent(newType);
                (src as MVCC.AppMonoController).controllerType = MVCC.CONTROLLER_TYPE.ALL;
                obj.AddComponent <AudioSource>();                //default sound system
                PrefabUtility.SaveAsPrefabAssetAndConnect(obj, outputFolder + "/Resources/mvcc.prefab", InteractionMode.UserAction);

                MVCCLog.Log("<color=green>MVCC RX Project Setup Success...</color>");
                UnityEngine.Object.DestroyImmediate(obj);

                ScriptableObjectUtility.CreateAsset("SoundComponent", "Assets/" + _currentProject + "/Resources/SoundComponent.asset");

                _instructionPage = 3;
                return(false);
            }

            if (string.IsNullOrEmpty(_currentProject))
            {
                _newProject = EditorGUILayout.TextField("MVCC project name", _newProject);
                GUILayout.Space(10);
                _hasDefaultAnim = GUILayout.Toggle(_hasDefaultAnim, "Add Default Animation");
                GUILayout.Space(5);
                _hasDefaultHttp = GUILayout.Toggle(_hasDefaultHttp, "Add Default Http Service");
                GUILayout.Space(5);
                _startWithViewController = GUILayout.Toggle(_startWithViewController, "Start With ViewController");
                GUILayout.Space(5);

                if (_mvccValues == null)
                {
                    _mvccValues = EditorUtil.GetCurrentData();
                }

                //_selectedBuild = (BuildTargetGroup)EditorGUILayout.EnumPopup("Platform:" , _selectedBuild);
                //if (GUILayout.Button("Add Platform"))
                //{
                //    if (_selectedBuild != BuildTargetGroup.Unknown)
                //    {
                //        if (!_mvccValues.supportedPlatforms.Contains(_selectedBuild))
                //        {
                //            _mvccValues.supportedPlatforms.Add(_selectedBuild);
                //        }
                //    }
                //}
                //GUILayout.Space(10);
                //EditorGUILayout.LabelField("Selected Platforms");
                //GUILayout.Space(10);
                //_scrollPos = GUILayout.BeginScrollView(_scrollPos);

                //int deleteItem = -1;

                //for(int i = 0; i < _mvccValues.supportedPlatforms.Count; i++)
                //{
                //    if (GUILayout.Button(_mvccValues.supportedPlatforms[i].ToString()))
                //    {
                //        deleteItem = i;
                //    }
                //}

                //if (_mvccValues.supportedPlatforms.Count == 0)
                //{
                //    GUILayout.Space(10);
                //    EditorGUILayout.LabelField("No Platforms added");
                //    GUILayout.Space(10);
                //    GUILayout.EndScrollView();
                //    return false;
                //}

                //if (deleteItem > -1)
                //{
                //    _mvccValues.supportedPlatforms.RemoveAt(deleteItem);
                //}

                //GUILayout.EndScrollView();

                GUILayout.Space(10);
                if (GUILayout.Button("Generate MVCC Project"))
                {
                    string outputFolder = Application.dataPath + "/" + _newProject;

                    EditorUtil.CreateDir(outputFolder);
                    EditorUtil.CreateDir(outputFolder + "/Definitions");
                    EditorUtil.CreateDir(outputFolder + "/Resources");
                    EditorUtil.CreateDir(outputFolder + "/Scripts");
                    EditorUtil.CreateDir(outputFolder + "/Scripts/Controllers");
                    EditorUtil.CreateDir(outputFolder + "/Scripts/Views");
                    EditorUtil.CreateDir(outputFolder + "/Scripts/Models");

                    string pathSource = "Packages/com.mvcrx.main/MVCRX/MVCC Base/Editor/Setup/Source/";

                    string content = File.ReadAllText(pathSource + ((_startWithViewController) ? "AppView.txt" : "App.txt"));
                    content = content.Replace("%NAMESPACE%", _newProject);
                    if (_hasDefaultAnim)
                    {
                        EditorUtil.ReplaceNameSpace(pathSource + "Anim.txt", outputFolder + "/Definitions/DefaultAnim.cs", _newProject);
                        content = content.Replace("%ADDANIM%", "MVCCStart.RegisterAnim(new DefaultAnim());");
                    }
                    else
                    {
                        content = content.Replace("%ADDANIM%", string.Empty);
                    }
                    if (_hasDefaultHttp)
                    {
                        EditorUtil.ReplaceNameSpace(pathSource + "Http.txt", outputFolder + "/Definitions/DefaultHttpHelper.cs", _newProject);

                        content = content.Replace("%ADDHTTPHELPER%", "MVCCStart.RegisterHttpHelper(new DefaultHttpHelper());");
                    }
                    else
                    {
                        content = content.Replace("%ADDHTTPHELPER%", string.Empty);
                    }
                    File.WriteAllText(outputFolder + "/Definitions/DefaultStart.cs", content);
                    EditorUtil.ReplaceNameSpace(pathSource + "Constants.txt", outputFolder + "/Definitions/Constants.cs", _newProject);
                    if (_startWithViewController)
                    {
                        EditorUtil.ReplaceNameSpace(pathSource + "DefaultNavController.txt", outputFolder + "/Scripts/Controllers/DefaultNavController.cs", _newProject);
                    }
                    else
                    {
                        EditorUtil.ReplaceNameSpace(pathSource + "DefaultController.txt", outputFolder + "/Scripts/Controllers/DefaultController.cs", _newProject);
                    }
                    _currentProject = _newProject;
                    if (_mvccValues == null)
                    {
                        _mvccValues = EditorUtil.GetCurrentData();
                    }

                    _mvccValues.SetKey("TRUE");
                    _mvccValues.SetupNewProject(_currentProject);


                    AssetDatabase.Refresh();
                    return(true);
                }
                return(false);
            }

            // When we have the project
            EditorGUILayout.LabelField("MVCC Project", _currentProject);
            GUILayout.Space(10);

            EditorGUILayout.LabelField("Available Events");
            GUILayout.Space(5);
            _selected = EditorGUILayout.Popup("INotify", _selected, _options);
            GUILayout.Space(5);
            _selectedParam = EditorGUILayout.Popup("INotifyParam", _selectedParam, _paramOptions);
            GUILayout.Space(5);
            _selectedNamespace = EditorGUILayout.Popup("Namespaces", _selectedNamespace, _namespacesOptions);
            GUILayout.Space(10);

            EditorUtil.DrawUILine(Color.gray);
            GUILayout.Space(10);
            if (GUILayout.Button("Show instructions"))
            {
                _instructionPage = 3;
            }
            GUILayout.Space(10);
            EditorUtil.DrawUILine(Color.gray);

            context.Repaint();

            return(false);
        }