Exemplo n.º 1
0
        static void VerifyPlatformIsCorrect()
        {
            var info = ProjenyEditorUtil.GetCurrentProjectInfo();

            var expectedPlatform = ProjenyEditorUtil.FromPlatformDirStr(info.PlatformDirName);
            var currentPlatform  = EditorUserBuildSettings.activeBuildTarget;

            if ((expectedPlatform == BuildTarget.StandaloneWindows || expectedPlatform == BuildTarget.StandaloneWindows64) &&
                (currentPlatform == BuildTarget.StandaloneWindows || currentPlatform == BuildTarget.StandaloneWindows64))
            {
                return;
            }

            if (currentPlatform != expectedPlatform)
            {
                if (EditorUserBuildSettings.SwitchActiveBuildTarget(expectedPlatform))
                {
                    UnityEngine.Debug.LogError(
                        "Projeny has detected an unexpected platform change.\n\nPlatforms should only be changed through Projeny and never through Unity's normal Build Settings dialog.\n\nThis is necessary to allow Projeny to include platform specific packages, quick platform switching, etc.\n\nProjeny has switched the platform back to '" + expectedPlatform.ToString() + "'");
                }
                else
                {
                    UnityEngine.Debug.LogError("Projeny - Unknown error occurred when attempting to switch platform to '" + expectedPlatform.ToString() + "'");
                }
            }
        }
Exemplo n.º 2
0
        public bool HasProjectConfigChanged()
        {
            var configPath = ProjenyEditorUtil.GetProjectConfigPath(_view.ProjectConfigType);

            var currentConfig = GetProjectConfigFromLists();

            if (!File.Exists(configPath))
            {
                return(!currentConfig.AssetsFolder.IsEmpty() || !currentConfig.PluginsFolder.IsEmpty());
            }

            ProjectConfig savedConfig;

            try
            {
                savedConfig = DeserializeProjectConfig(configPath);
            }
            catch (Exception e)
            {
                Log.ErrorException(e);
                // This happens if we have serialization errors
                // Just log the error then assume that the file is different in this case so that the user
                // has the option to overwrite
                return(true);
            }

            if (savedConfig == null)
            {
                return(!currentConfig.AssetsFolder.IsEmpty() || !currentConfig.PluginsFolder.IsEmpty());
            }

            return(!Enumerable.SequenceEqual(currentConfig.AssetsFolder.OrderBy(t => t), savedConfig.AssetsFolder.OrderBy(t => t)) ||
                   !Enumerable.SequenceEqual(currentConfig.PluginsFolder.OrderBy(t => t), savedConfig.PluginsFolder.OrderBy(t => t)));
        }
Exemplo n.º 3
0
        public void RefreshProject()
        {
            var configPath = ProjenyEditorUtil.GetProjectConfigPath(_view.ProjectConfigType);

            if (!File.Exists(configPath))
            {
                ResetProject();
                return;
            }

            ProjectConfig savedConfig;

            try
            {
                savedConfig = DeserializeProjectConfig(configPath);
            }
            catch (Exception e)
            // This can happen if the file has yaml serialization errors
            {
                throw new PmProjectConfigDeserializationException(
                          "Found serialization errors when reading from '{0}'".Fmt(configPath), e);
            }

            // Null when file is empty
            if (savedConfig == null)
            {
                ResetProject();
            }
            else
            {
                PopulateModelFromConfig(savedConfig);
                LoadedConfigFile();
            }
        }
Exemplo n.º 4
0
        public void Update()
        {
            _eventManager.Flush();

            var configFileExists = File.Exists(ProjenyEditorUtil.GetProjectConfigPath(_view.ProjectConfigType));

            if (configFileExists)
            {
                _view.IsRevertEnabled = true;
            }
            else
            {
                _view.IsSaveEnabled   = true;
                _view.IsRevertEnabled = false;
            }

            _view.IsEditEnabled = configFileExists;
        }
Exemplo n.º 5
0
        IEnumerator TryChangeProjectType(ProjectConfigTypes configType)
        {
            if (_projectHandler.HasProjectConfigChanged())
            {
                var fileName = Path.GetFileName(ProjenyEditorUtil.GetProjectConfigPath(_view.ProjectConfigType));
                var choice   = _view.PromptForUserChoice(
                    "Do you want to save changes to {0}?".Fmt(fileName), new[] { "Save", "Don't Save", "Cancel" }, null, null, 0, 2);

                yield return(choice);

                switch (choice.Current)
                {
                case 0:
                {
                    _projectHandler.OverwriteConfig();
                    break;
                }

                case 1:
                {
                    // Do nothing
                    break;
                }

                case 2:
                {
                    yield break;
                }

                default:
                {
                    Assert.Throw();
                    break;
                }
                }
            }

            _view.ProjectConfigType = configType;
            _projectHandler.RefreshProject();
        }
Exemplo n.º 6
0
        public void OnClickedProjectEditButton()
        {
            var configPath = ProjenyEditorUtil.GetProjectConfigPath(_view.ProjectConfigType);

            InternalEditorUtility.OpenFileAtLineExternal(configPath, 1);
        }
Exemplo n.º 7
0
 public void OverwriteConfig()
 {
     File.WriteAllText(
         ProjenyEditorUtil.GetProjectConfigPath(_view.ProjectConfigType), GetSerializedProjectConfigFromLists());
     SavedConfigFile();
 }
        IEnumerator <PopupChoices> ShowPopup()
        {
            var label = "Enter new project name:";

            var choices = new PopupChoices();

            choices.NewProjectName = "Untitled";
            PmView.InputDialogStates state = PmView.InputDialogStates.None;

            bool isFirst = true;

            var popupId = _view.AddPopup(delegate(Rect fullRect)
            {
                if (Event.current.type == EventType.KeyDown)
                {
                    switch (Event.current.keyCode)
                    {
                    case KeyCode.Return:
                        {
                            state = PmView.InputDialogStates.Submitted;
                            break;
                        }

                    case KeyCode.Escape:
                        {
                            state = PmView.InputDialogStates.Cancelled;
                            break;
                        }
                    }
                }

                var popupRect = ImguiUtil.CenterRectInRect(fullRect, _settings.PopupSize);

                _view.DrawPopupCommon(fullRect, popupRect);

                var contentRect = ImguiUtil.CreateContentRectWithPadding(
                    popupRect, _pmSettings.InputDialog.PanelPadding);

                GUILayout.BeginArea(contentRect);
                {
                    GUILayout.Label(label, _pmSettings.InputDialog.LabelStyle);

                    GUI.SetNextControlName("PopupTextField");
                    choices.NewProjectName = GUILayout.TextField(choices.NewProjectName, 100);
                    GUI.SetNextControlName("");

                    GUILayout.Space(5);

                    GUILayout.BeginHorizontal();
                    {
                        choices.DuplicateSettings = GUILayout.Toggle(choices.DuplicateSettings, "", GUILayout.Height(_settings.CheckboxHeight));
                        GUILayout.Label("Share Project Settings with '{0}'".Fmt(ProjenyEditorUtil.GetCurrentProjectName()));
                        GUILayout.FlexibleSpace();
                    }
                    GUILayout.EndHorizontal();

                    GUILayout.Space(5);

                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.FlexibleSpace();

                        if (GUILayout.Button("Submit", GUILayout.MaxWidth(100)))
                        {
                            state = PmView.InputDialogStates.Submitted;
                        }

                        if (GUILayout.Button("Cancel", GUILayout.MaxWidth(100)))
                        {
                            state = PmView.InputDialogStates.Cancelled;
                        }
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndArea();

                if (isFirst)
                {
                    isFirst = false;
                    // Need to remove focus then regain focus on the text box for it to select the whole contents
                    GUI.FocusControl("");
                }
                else if (string.IsNullOrEmpty(GUI.GetNameOfFocusedControl()))
                {
                    GUI.FocusControl("PopupTextField");
                }
            });

            while (state == PmView.InputDialogStates.None)
            {
                yield return(null);
            }

            _view.RemovePopup(popupId);

            if (state == PmView.InputDialogStates.Submitted)
            {
                yield return(choices);
            }
            else
            {
                // Just return null
            }
        }