Exemplo n.º 1
0
        /// <summary>
        /// Closes the current Tiny project
        /// </summary>
        public static void Close()
        {
            if (null == EditorContext)
            {
                return;
            }

            OnCloseProject?.Invoke(EditorContext.Project);

            EditorContext?.Unload();
            EditorContext = null;

            UTinyTemp.Delete();
            UTinyModificationProcessor.ClearChanged();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Trys to loads the last saved temp file
        /// </summary>
        public static void LoadTemp()
        {
            Assert.IsFalse(EditorApplication.isPlayingOrWillChangePlaymode);

            if (!UTinyTemp.Exists())
            {
                return;
            }

            var context  = new UTinyContext();
            var registry = context.Registry;

            string persistenceId;

            if (!UTinyTemp.Accept(registry, out persistenceId))
            {
                LoadPersistenceId(persistenceId);
                return;
            }

            var project = registry.FindAllByType <UTinyProject>().FirstOrDefault();
            UTinyEditorContext editorContext = null;

            if (project != null)
            {
                SetupProject(registry, project);

                editorContext = new UTinyEditorContext((UTinyProject.Reference)project, EditorContextType.Project, context, UTinyEditorPrefs.LoadLastWorkspace());
            }
            else
            {
                var module = registry.FindAllBySource(UTinyRegistry.DefaultSourceIdentifier).OfType <UTinyModule>().First();

                SetupModule(registry, module);

                if (null != module)
                {
                    project        = registry.CreateProject(UTinyId.Generate(KWorkspaceProjectName), KWorkspaceProjectName);
                    project.Module = (UTinyModule.Reference)module;

                    editorContext = new UTinyEditorContext((UTinyProject.Reference)project, EditorContextType.Module, context, UTinyEditorPrefs.LoadLastWorkspace());
                }
            }

            Assert.IsNotNull(project);
            LoadContext(editorContext, true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Saves the current context as a temp file
        /// </summary>
        public static void SaveTemp()
        {
            if (null == EditorContext)
            {
                return;
            }

            IPersistentObject obj;

            switch (ContextType)
            {
            case EditorContextType.Project:
                obj = Project;
                break;

            case EditorContextType.Module:
                obj = Module;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (string.IsNullOrEmpty(obj.PersistenceId))
            {
                // This is a temporary asset
                // Save the full object state
                UTinyTemp.SaveTemporary(obj);
            }
            else
            {
                if (UTinyModificationProcessor.IsChanged)
                {
                    // This is a persistent asset but the user has made some changes
                    // Save the full object state WITH the persistent Id
                    UTinyTemp.SavePersistentChanged(obj);
                }
                else
                {
                    // We only need to save the persistentId in this case
                    // We will reload any asset changes from disc without prompting the user
                    UTinyTemp.SavePersistentUnchanged(obj.PersistenceId);
                }
            }
        }