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();
            }
        }
Ejemplo n.º 2
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 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;
                }
            }
        }