Beispiel #1
0
        private void LoadProject()
        {
            var path = EditorUtility.OpenFilePanel("Load File", Application.dataPath, $"{UTinyPersistence.ProjectFileImporterExtension},{UTinyPersistence.ModuleFileImporterExtension}");

            if (!string.IsNullOrEmpty(path))
            {
                if (!UTinyEditorApplication.SaveChanges())
                {
                    return;
                }

                // Convert to relative path
                if (path.StartsWith(Application.dataPath))
                {
                    path = "Assets" + path.Substring(Application.dataPath.Length);
                }

                m_TabType = TabType.Settings;
                UTinyEditorApplication.Close();

                var extension = Path.GetExtension(path);
                switch (extension)
                {
                case UTinyPersistence.ProjectFileExtension:
                    UTinyEditorApplication.LoadProject(path);
                    break;

                case UTinyPersistence.ModuleFileExtension:
                    UTinyEditorApplication.LoadModule(path);
                    break;
                }
            }
        }
Beispiel #2
0
        private void OnEnable()
        {
            s_ActiveWindows.Add(this);
            titleContent.text = $"{UTinyConstants.ApplicationName} Editor";
            UTinyEditorApplication.OnLoadProject     += OnLoadProject;
            UTinyEditorApplication.OnSaveProject     += OnSaveProject;
            UTinyEditorApplication.OnCloseProject    += OnCloseProject;
            UTinyEditorApplication.OnChangesDetected += SetDirtyAll;

            if (!EditorApplication.isPlayingOrWillChangePlaymode)
            {
                EditorApplication.delayCall += () =>
                {
                    if (UTinyEditorApplication.ContextType == EditorContextType.None)
                    {
                        UTinyEditorApplication.LoadTemp();
                    }
                    else
                    {
                        OnLoadProject(UTinyEditorApplication.Project);
                    }
                };
            }

            EditorApplication.update += Update;
        }
Beispiel #3
0
        private void NewModule()
        {
            if (!UTinyEditorApplication.SaveChanges())
            {
                return;
            }

            m_TabType = TabType.Settings;
            UTinyEditorApplication.NewModule();
        }
Beispiel #4
0
        public static bool OnOpenAsset(int instanceId, int line)
        {
            //HACK: using the selection instead of the instance ID since this hook is not reliable
            var obj = Selection.activeObject;

            if (obj is UTProject)
            {
                var window = UTinyProjectWindow.OpenAndShow();
                window.SetTabType(UTinyProjectWindow.TabType.Settings);
                UTinyEditorApplication.LoadProject(AssetDatabase.GetAssetPath(obj));
                return(true);
            }
            return(false);
        }
Beispiel #5
0
        private void DoLayoutToolbar()
        {
            GUILayout.Space(1);

            using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar))
            {
                using (var projectScope = new EditorGUILayout.HorizontalScope(GUILayout.Width(120)))
                {
                    var buttonLabel = GetProjectButtonName();

                    if (UTinyEditorApplication.IsChanged)
                    {
                        buttonLabel += " *";
                    }

                    if (GUILayout.Button(buttonLabel, EditorStyles.toolbarDropDown))
                    {
                        var menu = new GenericMenu();

                        menu.AddItem(new GUIContent("New Project"), false, NewProject);

                        menu.AddItem(new GUIContent("New Module"), false, NewModule);

                        menu.AddSeparator(string.Empty);
                        menu.AddItem(new GUIContent("Load..."), false, LoadProject);

                        menu.AddSeparator(string.Empty);

                        var save = new GUIContent("Save");
                        if (UTinyEditorApplication.Project == null)
                        {
                            menu.AddDisabledItem(save);
                        }
                        else
                        {
                            menu.AddItem(save, false, () =>
                            {
                                UTinyEditorApplication.Save();
                            });
                        }

                        var saveAs = new GUIContent("Save As...");
                        if (UTinyEditorApplication.Project == null)
                        {
                            menu.AddDisabledItem(saveAs);
                        }
                        else
                        {
                            menu.AddItem(saveAs, false, () =>
                            {
                                UTinyEditorApplication.SaveAs();
                            });
                        }

                        menu.AddSeparator(string.Empty);

                        var closeProject = new GUIContent("Close");
                        if (UTinyEditorApplication.Project == null)
                        {
                            menu.AddDisabledItem(closeProject);
                        }
                        else
                        {
                            menu.AddItem(closeProject, false, () =>
                            {
                                if (!UTinyEditorApplication.SaveChanges())
                                {
                                    return;
                                }

                                m_TabType = TabType.Settings;
                                UTinyEditorApplication.Close();
                            });
                        }

                        menu.DropDown(projectScope.rect);
                    }
                }

                GUILayout.FlexibleSpace();

                if (UTinyEditorApplication.ContextType == EditorContextType.Project)
                {
                    var project   = UTinyEditorApplication.Project;
                    var workspace = UTinyEditorApplication.EditorContext.Workspace;

                    if (null != project && null != workspace)
                    {
                        var lastBuildConfiguration = workspace.BuildConfiguration;
                        workspace.BuildConfiguration = (UTinyBuildConfiguration)EditorGUILayout.EnumPopup(workspace.BuildConfiguration, EditorStyles.toolbarDropDown, GUILayout.Width(100));
                        if (workspace.BuildConfiguration != lastBuildConfiguration)
                        {
                            UTinyEditorUtility.RepaintAllWindows();
                        }

                        if (GUILayout.Button("Export", EditorStyles.toolbarButton, GUILayout.Width(100)))
                        {
                            UTinyBuildPipeline.Export(project);
                        }

                        workspace.Preview = GUILayout.Toggle(
                            workspace.Preview,
                            new GUIContent(UTinyIcons.Export, "Toggles preview in browser."),
                            EditorStyles.toolbarButton,
                            GUILayout.Width(35));
                    }
                }
            }
        }
Beispiel #6
0
 private static void HandleSceneOpening(string path, OpenSceneMode mode)
 {
     UTinyEditorApplication.SaveChanges();
     UTinyEditorApplication.Close();
 }
Beispiel #7
0
 private static void HandleSceneCreated(Scene scene, NewSceneSetup setup, NewSceneMode mode)
 {
     UTinyEditorApplication.SaveChanges();
     UTinyEditorApplication.Close();
 }