Beispiel #1
0
        internal static void OpenedScene(Scene myNewScene, OpenSceneMode mode)
        {
            if (newScene == myNewScene.path && !_comingFromNewScene)
            {
                return;
            }

            _previousScene = _lastScene;
            _lastScene     = myNewScene.path;

            var now         = System.DateTime.Now;
            var lastOpened  = $"{now.ToShortDateString()} at {now.ToShortTimeString()}";
            var recentScene = new RecentScene(myNewScene, instance, lastOpened);

            if (recentScene.data != null)
            {
                recentScene.data.Save();
            }


            pathAndScene[myNewScene.path] = recentScene;
            newScene = myNewScene.path;

            if (instance == null)
            {
                instance = ScriptableObject.CreateInstance <RecentSceneData>();
            }

            UpdatePreviousScenes();
        }
Beispiel #2
0
        internal static void SceneClosed(Scene closingScene)
        {
            if (!pathAndScene.ContainsKey(closingScene.path))
            {
                return;
            }

            if (instance == null)
            {
                instance = ScriptableObject.CreateInstance <RecentSceneData>();
            }

            var originalScene = pathAndScene.ContainsKey(closingScene.path)
                ? pathAndScene[closingScene.path]
                : new RecentScene(closingScene, instance);

            var scene = new RecentScene(closingScene, instance, originalScene.lastOpened);

            pathAndScene[closingScene.path] = scene;
        }
Beispiel #3
0
        internal static void NewSceneCreated(Scene myNewScene, NewSceneSetup setup, NewSceneMode mode)
        {
            _previousScene    = _lastScene;
            _lastScene        = newScene;
            _newSceneNotSaved = true;
            var now        = System.DateTime.Now;
            var lastOpened = $"{now.ToShortDateString()} at {now.ToShortTimeString()}";
            var scene      = new RecentScene(myNewScene, instance, lastOpened, true);

            if (scene.data != null)
            {
                var userName = GetUserName();
                scene.data.lastEditedBy   = userName;
                scene.data.lastEditedDate = lastOpened;
                scene.data.Save();
            }

            pathAndScene[myNewScene.path] = scene;
            UpdatePreviousScenes();
        }
Beispiel #4
0
        internal static void SceneSaved(Scene savedScene)
        {
            if (pathAndScene.ContainsKey(savedScene.path))
            {
                if (instance == null)
                {
                    instance = ScriptableObject.CreateInstance <RecentSceneData>();
                }

                var originalScene = pathAndScene.ContainsKey(savedScene.path)
                    ? pathAndScene[savedScene.path]
                    : new RecentScene(savedScene, instance);

                var scene = new RecentScene(savedScene, instance, originalScene.lastOpened, true);
                if (scene.data != null)
                {
                    var now        = System.DateTime.Now;
                    var lastEdited = $"{now.ToShortDateString()} at {now.ToShortTimeString()}";
                    var userName   = GetUserName();
                    scene.data.lastEditedBy   = userName;
                    scene.data.lastEditedDate = lastEdited;
                    scene.data.Save();
                }

                pathAndScene[savedScene.path] = scene;
            }

            if (!_newSceneNotSaved)
            {
                return;
            }

            newScene            = savedScene.path;
            _newSceneNotSaved   = false;
            _comingFromNewScene = true;
        }
Beispiel #5
0
        private static void DisplayInfo(string path)
        {
            var recentScene = new RecentScene();

            if (RecentSceneManager.pathAndScene.ContainsKey(path))
            {
                recentScene = RecentSceneManager.pathAndScene[path];
            }

            if (string.IsNullOrWhiteSpace(recentScene.name))
            {
                EditorGUILayout.Space();
                var bold = new GUIStyle(GUI.skin.label)
                {
                    fontStyle = FontStyle.Bold,
                    wordWrap  = true,
                    alignment = TextAnchor.MiddleCenter
                };
                EditorGUILayout.LabelField(OPENFORDETAILS, bold);
                EditorGUILayout.Space();
            }


            var scene = SceneManager.GetSceneByPath(path);

            EditorGUILayout.BeginHorizontal();
            if (!string.IsNullOrWhiteSpace(recentScene.lastOpened))
            {
                EditorGUILayout.LabelField("Last Opened:", recentScene.lastOpened);
            }

            if (RecentSceneManager.trackScenePreview && recentScene.ScenePreview != null)
            {
                if (GUILayout.Button("Preview", EditorStyles.miniButton, GUILayout.MaxWidth(80)))
                {
                    var tex = recentScene.ScenePreview;
                    if (tex != null)
                    {
                        PreviewWindow.Init(recentScene.name, tex);
                    }
                }
            }

            EditorGUILayout.EndHorizontal();

            var lastEdit = System.IO.File.GetLastWriteTime(path);

            if (RecentSceneManager.trackEditedBy && recentScene.data != null)
            {
                var editedBy = new GUIContent(LASTEDITEDBY, LASTEDITEDBYTOOLTIP);
                EditorGUILayout.LabelField(editedBy,
                                           recentScene.data ? recentScene.data.lastEditedBy : string.Empty);

                var editedDate = new GUIContent(LASTEDITEDDATE, LASTEDITEDDATETOOLTIP);
                EditorGUILayout.LabelField(editedDate,
                                           recentScene.data
                        ? recentScene.data.lastEditedDate
                        : $"{lastEdit.ToShortDateString()} at {lastEdit.ToShortTimeString()}");
            }
            else
            {
                var editedDate       = new GUIContent(LASTEDITEDDATE, LASTEDITEDDATETOOLTIP);
                var actualEditedDate = new GUIContent($"{lastEdit.ToShortDateString()} at {lastEdit.ToShortTimeString()}");
                EditorGUILayout.LabelField(editedDate, actualEditedDate);
            }

            if (string.IsNullOrWhiteSpace(recentScene.path))
            {
                recentScene.path = path;
            }

            var locationTitle   = new GUIContent(LOCATION, LOCTOOLTIP);
            var locationContent = new GUIContent(recentScene.path, recentScene.path);

            EditorGUILayout.LabelField(locationTitle, locationContent);
            EditorGUILayout.BeginHorizontal();
            if (!string.IsNullOrWhiteSpace(recentScene.objCount))
            {
                var objCount    = new GUIContent(GAMEOBJCOUNT, GAMEOBJCOUNTTOOLTIP);
                var actualCount = new GUIContent(recentScene.objCount);
                EditorGUILayout.LabelField(objCount, actualCount);
            }

            if (scene.IsValid() && !scene.isDirty)
            {
                if (_refreshBttn == null)
                {
                    _refreshBttn = EditorGUIUtility.Load(REFRESHICON) as Texture2D;
                }

                var refreshContent = new GUIContent(_refreshBttn, REFRESHTOOLTIP);
                if (GUILayout.Button(refreshContent, GUIStyle.none, GUILayout.MaxWidth(25)))
                {
                    recentScene.objCount = RecentScene.GetSceneObjCount(scene);
                    RecentSceneManager.pathAndScene[path] = recentScene;
                }
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(SCENELOADED, (scene.IsValid() && scene.isLoaded).ToString());
            EditorGUILayout.Space();

            if (FavoriteScenesManager.favoritedScenes.Contains(path))
            {
                if (_favBttnOn == null)
                {
                    _favBttnOn = Resources.Load(FAVORITEON) as Texture2D;
                }

                var favContent = new GUIContent(_favBttnOn, FAVORITEONTOOLTIP);

                if (GUILayout.Button(favContent, GUIStyle.none, GUILayout.MaxHeight(20), GUILayout.MaxWidth(20)))
                {
                    if (EditorUtility.DisplayDialog($"Unfavorite {recentScene.name}?",
                                                    $"Are you sure you would like to remove {recentScene.name} from the favorited scenes?",
                                                    RecentSceneManager.YES, RecentSceneManager.NO))
                    {
                        FavoriteScenesManager.RemoveFromFavorites(path);
                    }
                }
            }
            else
            {
                if (_favBttnOff == null)
                {
                    _favBttnOff = Resources.Load(FAVORITEOFF) as Texture2D;
                }

                var favContent = new GUIContent(_favBttnOff, FAVORITEOFFTOOLTIP);

                if (GUILayout.Button(favContent, GUIStyle.none, GUILayout.MaxHeight(20), GUILayout.MaxWidth(20),
                                     GUILayout.Width(20), GUILayout.Height(20)))
                {
                    FavoriteScenesManager.AddToFavorites(path);
                }
            }


            EditorGUILayout.EndHorizontal();
        }