/// <summary>
        /// Triggered by the runtime when <see cref="LoadProject"/> method completes.
        /// </summary>
        private static void Internal_OnProjectLoaded()
        {
            SetStatusProject(false);
            if (!unitTestsExecuted)
            {
                RunUnitTests();
                unitTestsExecuted = true;
            }

            if (!IsProjectLoaded)
            {
                ProjectWindow.Open();
                return;
            }

            string projectPath = ProjectPath;

            RecentProject[] recentProjects = EditorSettings.RecentProjects;
            bool            foundPath      = false;

            for (int i = 0; i < recentProjects.Length; i++)
            {
                if (PathEx.Compare(recentProjects[i].path, projectPath))
                {
                    recentProjects[i].accessTimestamp = (ulong)DateTime.Now.Ticks;
                    EditorSettings.RecentProjects     = recentProjects;
                    foundPath = true;
                    break;
                }
            }

            if (!foundPath)
            {
                List <RecentProject> extendedRecentProjects = new List <RecentProject>();
                extendedRecentProjects.AddRange(recentProjects);

                RecentProject newProject = new RecentProject();
                newProject.path            = projectPath;
                newProject.accessTimestamp = (ulong)DateTime.Now.Ticks;

                extendedRecentProjects.Add(newProject);

                EditorSettings.RecentProjects = extendedRecentProjects.ToArray();
            }

            EditorSettings.LastOpenProject = projectPath;
            EditorSettings.Save();

            ProjectLibrary.Refresh();
            monitor             = new FolderMonitor(ProjectLibrary.ResourceFolder);
            monitor.OnAdded    += OnAssetModified;
            monitor.OnRemoved  += OnAssetModified;
            monitor.OnModified += OnAssetModified;

            if (!string.IsNullOrWhiteSpace(ProjectSettings.LastOpenScene))
            {
                Scene.Load(ProjectSettings.LastOpenScene);
                SetSceneDirty(false);
            }
        }
        /// <summary>
        /// Saves the currently loaded scene to the specified path.
        /// </summary>
        /// <param name="path">Path relative to the resource folder. This can be the path to the existing scene
        ///                    prefab if it just needs updating. </param>
        public static void SaveScene(string path)
        {
            Prefab scene = Internal_SaveScene(path);

            Scene.SetActive(scene);

            ProjectLibrary.Refresh(true);
            SetSceneDirty(false);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new shader containing a rough code outline in the specified folder.
        /// </summary>
        /// <param name="folder">Folder relative to project library to create the shader in.</param>
        public static void CreateEmptyShader(string folder)
        {
            string path = Path.Combine(folder, "New Shader.bsl");

            path = Path.Combine(ProjectLibrary.ResourceFolder, path);
            path = GetUniquePath(path);

            File.WriteAllText(path, EditorBuiltin.EmptyShaderCode);
            ProjectLibrary.Refresh(path);
        }
Esempio n. 4
0
        /// <summary>
        /// Attempts to save the current scene by applying the changes to a prefab, instead of saving it as a brand new
        /// scene. This is necessary for generic prefabs that have don't have a scene root included in the prefab. If the
        /// object added any other objects to the root, or has moved or deleted the original generic prefab the user
        /// will be asked to save the scene normally, creating a brand new prefab.
        /// </summary>
        private static void SaveGenericPrefab(Action onSuccess = null, Action onFailure = null)
        {
            // Find prefab root
            SceneObject root = null;

            int numChildren       = Scene.Root.GetNumChildren();
            int numNormalChildren = 0;

            for (int i = 0; i < numChildren; i++)
            {
                SceneObject child = Scene.Root.GetChild(i);

                if (EditorUtility.IsInternal(child))
                {
                    continue;
                }

                UUID prefabUUID = PrefabUtility.GetPrefabUUID(child);
                if (prefabUUID == Scene.ActiveSceneUUID)
                {
                    root = child;
                }

                // If user added any other prefabs other than the initial one, the scene no longer represents a generic
                // prefab (as we can now longer save it by applying changes only to that prefab)
                numNormalChildren++;
                if (numNormalChildren > 1)
                {
                    root = null;
                    break;
                }
            }

            if (root != null)
            {
                PrefabUtility.ApplyPrefab(root, false);

                ProjectLibrary.Refresh(true);
                SetSceneDirty(false);

                if (onSuccess != null)
                {
                    onSuccess();
                }
            }
            else
            {
                SaveSceneAs(onSuccess, onFailure);
            }
        }
 /// <summary>
 /// Triggered when the folder monitor detects an asset in the monitored folder was modified.
 /// </summary>
 /// <param name="path">Path to the modified file or folder.</param>
 private static void OnAssetModified(string path)
 {
     ProjectLibrary.Refresh(path);
 }