Exemplo n.º 1
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();
        }