static UnitySceneMemoHierarchyView()
        {
            if (!UnityEditorMemoPrefs.UnitySceneMemoActive)
            {
                return;
            }

            UnitySceneMemoHelper.Initialize();
            if (UnitySceneMemoHelper.Data == null)
            {
                return;
            }

            EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyView;

            Undo.undoRedoPerformed += () => {
                EditorApplication.RepaintHierarchyWindow();
                for (int i = 0; i < EditorSceneManager.sceneCount; i++)
                {
                    UnitySceneMemoHelper.InitializeSceneMemo(EditorSceneManager.GetSceneAt(i));
                }
            };

#if UNITY_2019_1_OR_NEWER
            SceneView.duringSceneGui += (view) => {
                UnitySceneMemoSceneView.OnGUI(currentMemo);
            };
#else
            // draw at SceneView
            SceneView.onSceneGUIDelegate += (view) => {
                UnitySceneMemoSceneView.OnGUI(currentMemo);
            };
#endif
        }
        static UnitySceneMemoHierarchyView()
        {
            if (!UnityEditorMemoPrefs.UnitySceneMemoActive)
            {
                return;
            }

            UnitySceneMemoHelper.Initialize();
            if (UnitySceneMemoHelper.Data == null)
            {
                return;
            }

            EditorApplication.hierarchyWindowItemOnGUI += OnGUI;
            Undo.undoRedoPerformed += () => {
                EditorApplication.RepaintHierarchyWindow();
                for (int i = 0; i < EditorSceneManager.sceneCount; i++)
                {
                    UnitySceneMemoHelper.InitializeSceneMemo(EditorSceneManager.GetSceneAt(i));
                }
            };
            SceneView.onSceneGUIDelegate += (view) => {
                UnitySceneMemoSceneView.DrawMemo(currentMemo);
            };
        }
        public static void OnGUI(int instanceID, Rect selectionRect)
        {
            if (Application.isPlaying)
            {
                return;
            }
            var obj = EditorUtility.InstanceIDToObject(instanceID);

            if (obj == null)
            {
                return;
            }

            var localIdentifier = UnitySceneMemoHelper.GetLocalIdentifierInFile(obj);

            if (localIdentifier == 0)
            {
                return;
            }
            if (IsNoSelection)
            {
                currentMemo = null;
            }
            var gameObject = obj as GameObject;
            var buttonRect = ButtonRect(selectionRect, gameObject.transform.childCount > 0);
            var isSelected = CheckSelected(instanceID);

            var memo = UnitySceneMemoHelper.GetMemo(gameObject, localIdentifier);

            if (memo == null)
            {
                if (isSelected)
                {
                    if (GUI.Button(buttonRect, ""))
                    {
                        UndoHelper.SceneMemoUndo(UndoHelper.UNDO_SCENEMEMO_ADD);
                        UnitySceneMemoHelper.AddMemo(obj as GameObject, localIdentifier);
                    }
                    GUI.Label(buttonRect, "+");
                }
            }
            else
            {
                if (isSelected)
                {
                    currentMemo = memo;
                }

                GUI.color = GUIHelper.Colors.LabelColor(memo.Label);
                GUI.DrawTexture(buttonRect, GUIHelper.Textures.Balloon);
                if (GUI.Button(buttonRect, "", GUIStyle.none))
                {
                    UnitySceneMemoHelper.PopupWindowContent.Initialize(memo);
                    PopupWindow.Show(selectionRect, UnitySceneMemoHelper.PopupWindowContent);
                }
                GUI.color = Color.white;
                SceneView.RepaintAll();
            }
        }
        private void sceneObjectProcess(Object obj)
        {
            var go = obj as GameObject;

            SceneMemo = UnitySceneMemoHelper.GetMemo(go);
            if (SceneMemo != null)
            {
                ScenePath             = go.scene.path;
                LocalIdentifierInFile = SceneMemo.LocalIdentifierInFile;
            }
            Obj = null;
        }
 public void Initialize()
 {
     if (isSceneMemoValid)
     {
         SceneMemo = UnitySceneMemoHelper.GetMemo(ScenePath, LocalIdentifierInFile);
         if (SceneMemo == null)
         {
             ScenePath             = "";
             LocalIdentifierInFile = 0;
         }
     }
 }
Exemplo n.º 6
0
        public UnitySceneMemo GetMemo(GameObject obj)
        {
            var            instanceId = obj.GetInstanceID();
            UnitySceneMemo memo       = getMemoFromCache(instanceId);

            if (memo == null)
            {
                var localIdentifierInFile = UnitySceneMemoHelper.GetLocalIdentifierInFile(obj);
                memo = GetMemo(localIdentifierInFile);
                if (memo != null)
                {
                    memo.Initialize(instanceId);
                    CachedMemo.Add(instanceId, memo);
                }
            }
            return(memo);
        }
        public void SetReference(Object obj)
        {
            tryFlag = false;

            var path = AssetDatabase.GetAssetPath(obj);

            if (string.IsNullOrEmpty(path))
            {
                var go = obj as GameObject;
                SceneMemo = UnitySceneMemoHelper.GetMemo(go);
                if (SceneMemo != null)
                {
                    ScenePath             = go.scene.path;
                    LocalIdentifierInFile = SceneMemo.LocalIdentifierInFile;
                }
                Obj = null;
            }
            else
            {
                Obj                   = obj;
                ScenePath             = "";
                LocalIdentifierInFile = 0;
            }
        }
        public static void OnHierarchyView(int instanceID, Rect selectionRect)
        {
            if (Application.isPlaying)
            {
                return;
            }

            var obj = EditorUtility.InstanceIDToObject(instanceID);

            if (obj == null)
            {
                return;
            }

            var localIdentifier = UnitySceneMemoHelper.GetLocalIdentifierInFile(obj);

            if (localIdentifier == 0)
            {
                return;
            }

            if (CheckNoGameObjectSelected())
            {
                currentMemo = null;
            }

            var gameObject = obj as GameObject;
            var buttonRect = ButtonRect(selectionRect, gameObject.transform.childCount > 0);
            var isSelected = CheckSelected(instanceID);

            var memo = UnitySceneMemoHelper.GetMemo(gameObject, localIdentifier);

            if (memo == null)
            {
                if (isSelected)
                {
                    if (GUI.Button(buttonRect, ""))
                    {
                        UndoHelper.SceneMemoUndo(UndoHelper.UNDO_SCENEMEMO_ADD);
                        UnitySceneMemoHelper.AddMemo(obj as GameObject, localIdentifier);
                    }
                    GUI.Label(buttonRect, "+");
                }
            }
            else
            {
                GUI.color = GUIHelper.Colors.LabelColor(memo.Label);
                GUI.DrawTexture(buttonRect, GUIHelper.Textures.Balloon);
                if (GUI.Button(buttonRect, "", GUIStyle.none))
                {
                    UnitySceneMemoHelper.PopupWindowContent.Initialize(memo);
                    PopupWindow.Show(selectionRect, UnitySceneMemoHelper.PopupWindowContent);
                }
                GUI.color = Color.white;

                //if (buttonRect.Contains(Event.current.mousePosition))
                //{
                //    if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
                //    {
                //        GenericMenu menu = new GenericMenu();

                //        menu.AddItem(new GUIContent("Remove Memo"), false, () =>
                //        {
                //            UndoHelper.SceneMemoUndo(UndoHelper.UNDO_SCENEMEMO_DELETE);
                //            UnitySceneMemoHelper.RemoveMemo(memo);
                //        });

                //        menu.ShowAsContext();
                //    }
                //}


                //SceneView.RepaintAll();

                if (isSelected)
                {
                    currentMemo = memo;
                }
            }
        }