Exemplo n.º 1
0
        private void MouseRightButton(Rect rect, Event e, PinnedItem item)
        {
            if (e.type == EventType.MouseDown)
            {
                var menu = new GenericMenu();

                GenericMenu.MenuFunction onMenuCommentCommand = () =>
                {
                    commentInputTarget = item;
                };

                menu.AddItem(new GUIContent("Comment"), false, onMenuCommentCommand);

                GenericMenu.MenuFunction onMenuRemoveCommand = () =>
                {
                    pinning.Remove(item);

                    Save();
                };

                menu.AddItem(new GUIContent("Remove"), false, onMenuRemoveCommand);

                menu.ShowAsContext();

                e.Use();
            }
        }
Exemplo n.º 2
0
        protected override void Load()
        {
            pinning = new List <PinnedItem>();

            var prefsKey = GetPinnedPrefsKey();

            var saveData = ProjectPrefs.Get <List <SaveData> >(prefsKey, null);

            if (saveData == null)
            {
                return;
            }

            if (saveData.Any())
            {
                // Hierarchy上のGameObjectを検索して取得.
                var hierarchyObjects = UnityEditorUtility.FindAllObjectsInHierarchy();

                foreach (var data in saveData)
                {
                    if (data.localIdentifierInFile == -1)
                    {
                        continue;
                    }

                    var targetObject = hierarchyObjects.FirstOrDefault(y => UnityEditorUtility.GetLocalIdentifierInFile(y) == data.localIdentifierInFile) as Object;

                    if (targetObject == null)
                    {
                        continue;
                    }

                    var item = new PinnedItem()
                    {
                        target  = targetObject,
                        comment = data.comment,
                    };

                    pinning.Add(item);
                }
            }
        }
Exemplo n.º 3
0
        protected override void Load()
        {
            pinning = new List <PinnedItem>();

            var saveData = ProjectPrefs.Get <List <SaveData> >(PinnedPrefsKey, null);

            if (saveData == null)
            {
                return;
            }

            foreach (var data in saveData)
            {
                if (string.IsNullOrEmpty(data.guid))
                {
                    continue;
                }

                var assetPath = AssetDatabase.GUIDToAssetPath(data.guid);

                if (string.IsNullOrEmpty(assetPath))
                {
                    continue;
                }

                var asset = AssetDatabase.LoadAssetAtPath <Object>(assetPath);

                if (asset == null)
                {
                    continue;
                }

                var item = new PinnedItem()
                {
                    target  = asset,
                    comment = data.comment,
                };

                pinning.Add(item);
            }
        }
Exemplo n.º 4
0
        private void MouseLeftButton(Rect rect, Event e, PinnedItem item)
        {
            if (e.type == EventType.MouseDown)
            {
                OnMouseLeftDown(item.target, e.clickCount);
            }

            if (e.type == EventType.DragPerform || e.type == EventType.DragUpdated)
            {
                if (DragAndDrop.objectReferences.Any())
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                    if (e.type == EventType.DragPerform)
                    {
                        DragAndDrop.AcceptDrag();
                        DragAndDrop.activeControlID = 0;

                        // 中心より上なら上に挿入.
                        var toAbove = new Rect(rect.position, new Vector2(rect.width, rect.height * 0.5f))
                                      .Contains(e.mousePosition);

                        Pin(DragAndDrop.objectReferences, item.target, toAbove);
                    }

                    e.Use();
                }
            }

            if (e.type == EventType.MouseDrag)
            {
                DragAndDrop.PrepareStartDrag();
                DragAndDrop.objectReferences = new[] { item.target };
                DragAndDrop.StartDrag("Dragging");

                e.Use();
            }
        }
Exemplo n.º 5
0
        private void Pin(Object[] targets, Object adjacentObject = null, bool toAbove = false)
        {
            foreach (var obj in targets)
            {
                var item = pinning.FirstOrDefault(x => x.target == obj);

                if (item != null)
                {
                    pinning.Remove(item);
                }
                else
                {
                    item = new PinnedItem()
                    {
                        target = obj
                    };
                }

                if (adjacentObject != null && pinning.Any())
                {
                    var insertion = pinning.FindIndex(x => x.target == adjacentObject) + (toAbove ? 0 : 1);

                    var index = Mathf.Clamp(insertion, 0, pinning.Count);

                    pinning.Insert(index, item);
                }
                else
                {
                    pinning.Add(item);
                }
            }

            Save();

            Repaint();
        }
Exemplo n.º 6
0
        void OnGUI()
        {
            if (pinning == null)
            {
                return;
            }

            var e = Event.current;

            UpdatePinnedObject();

            using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar))
            {
                if (GUILayout.Button("+", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
                {
                    Pin(Selection.activeObject);

                    commentInputTarget = null;
                }

                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Clear", EditorStyles.toolbarButton, GUILayout.Width(45f)))
                {
                    pinning.Clear();

                    commentInputTarget = null;

                    Save();
                }

                GUILayout.Space(4f);
            }

            GUILayout.Space(2f);

            using (var scrollViewScope = new EditorGUILayout.ScrollViewScope(scrollPosition))
            {
                var originIconSize = EditorGUIUtility.GetIconSize();

                var iconSize = new Vector2(16f, 16f);

                var requestSave = false;

                var labelStyle = new GUIStyle(GUI.skin.label);

                labelStyle.alignment = TextAnchor.MiddleLeft;

                EditorGUIUtility.SetIconSize(iconSize);

                for (var i = 0; i < pinning.Count; i++)
                {
                    var item = pinning[i];

                    if (item == null || item.target == null)
                    {
                        continue;
                    }

                    var thumbnail = (Texture)AssetPreview.GetMiniThumbnail(item.target);

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        using (new EditorGUILayout.HorizontalScope())
                        {
                            GUILayout.Space(3f);

                            //------ icon ------

                            var toolTipText = GetToolTipText(item.target);

                            var originLabelWidth = EditorGUIUtility.labelWidth;

                            EditorGUIUtility.labelWidth = 0f;

                            var iconContent = new GUIContent(thumbnail, toolTipText);

                            // アイコンが見切れるのでサイズを補正.
                            GUILayout.Label(iconContent, labelStyle, GUILayout.Width(iconSize.x + 3.5f));

                            EditorGUIUtility.labelWidth = originLabelWidth;

                            //------ label ------

                            var labelText = GetLabelName(item.target);

                            var labelContent = new GUIContent(labelText, toolTipText);

                            GUILayout.Label(labelContent, labelStyle, GUILayout.Height(18f));

                            //------ comment ------

                            if (item == commentInputTarget)
                            {
                                EditorGUI.BeginChangeCheck();

                                var comment = EditorGUILayout.DelayedTextField(item.comment);

                                if (EditorGUI.EndChangeCheck())
                                {
                                    item.comment = comment;

                                    commentInputTarget = null;

                                    requestSave = true;
                                }
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(item.comment))
                                {
                                    EditorGUILayout.LabelField(item.comment, EditorStyles.miniLabel);
                                }
                            }
                        }

                        //------ mouse action ------

                        var rect = GUILayoutUtility.GetLastRect();

                        if (rect.Contains(e.mousePosition))
                        {
                            switch (e.button)
                            {
                            case 0:
                                MouseLeftButton(rect, e, item);
                                break;

                            case 1:
                                MouseRightButton(rect, e, item);

                                break;
                            }
                        }
                    }
                }

                if (requestSave)
                {
                    Save();
                }

                EditorGUIUtility.SetIconSize(originIconSize);

                scrollPosition = scrollViewScope.scrollPosition;

                // ドロップエリア
                switch (Event.current.type)
                {
                case EventType.DragUpdated:
                case EventType.DragPerform:
                {
                    var validate = ValidatePinned(DragAndDrop.objectReferences);

                    DragAndDrop.visualMode = validate ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected;

                    if (e.type == EventType.DragPerform)
                    {
                        DragAndDrop.AcceptDrag();
                        DragAndDrop.activeControlID = 0;

                        if (validate)
                        {
                            Pin(DragAndDrop.objectReferences);
                        }
                    }
                }
                break;
                }
            }
        }
Exemplo n.º 7
0
        void OnLostFocus()
        {
            commentInputTarget = null;

            Repaint();
        }
Exemplo n.º 8
0
 void OnFocus()
 {
     commentInputTarget = null;
 }