PrepareStartDrag() 공개 정적인 메소드

Clears drag & drop data.

public static PrepareStartDrag ( ) : void
리턴 void
예제 #1
0
 public override void StartDrag(TreeViewItem draggedNode, List <int> draggedNodes)
 {
     if (!EditorApplication.isPlaying)
     {
         List <AudioMixerItem> audioMixerItemsFromIDs = this.GetAudioMixerItemsFromIDs(draggedNodes);
         DragAndDrop.PrepareStartDrag();
         DragAndDrop.SetGenericData("AudioMixerDragging", new AudioMixerTreeViewDragging.DragData(audioMixerItemsFromIDs));
         string title = draggedNodes.Count + " AudioMixer" + ((draggedNodes.Count <= 1) ? "" : "s");
         DragAndDrop.StartDrag(title);
     }
 }
        public override void StartDrag(TreeViewItem draggedNode, List <int> draggedNodes)
        {
            if (EditorApplication.isPlaying)
            {
                return;
            }
            List <AudioMixerItem> mixerItemsFromIds = this.GetAudioMixerItemsFromIDs(draggedNodes);

            DragAndDrop.PrepareStartDrag();
            DragAndDrop.SetGenericData("AudioMixerDragging", (object)new AudioMixerTreeViewDragging.DragData(mixerItemsFromIds));
            DragAndDrop.objectReferences = new UnityEngine.Object[0];
            DragAndDrop.StartDrag(draggedNodes.Count.ToString() + " AudioMixer" + (draggedNodes.Count <= 1 ? (object)string.Empty : (object)"s"));
        }
예제 #3
0
 public override void StartDrag(TreeViewItem draggedItem, List <int> draggedItemIDs)
 {
     DragAndDrop.PrepareStartDrag();
     DragAndDrop.objectReferences = ProjectWindowUtil.GetDragAndDropObjects(draggedItem.id, draggedItemIDs);
     DragAndDrop.paths            = ProjectWindowUtil.GetDragAndDropPaths(draggedItem.id, draggedItemIDs);
     if (DragAndDrop.objectReferences.Length > 1)
     {
         DragAndDrop.StartDrag("<Multiple>");
     }
     else
     {
         DragAndDrop.StartDrag(ObjectNames.GetDragAndDropTitle(InternalEditorUtility.GetObjectFromInstanceID(draggedItem.id)));
     }
 }
        public override void StartDrag(TreeViewItem draggedNode, List <int> draggedNodes)
        {
            if (EditorApplication.isPlaying)
            {
                return;
            }
            List <AudioMixerItem> audioMixerItemsFromIDs = this.GetAudioMixerItemsFromIDs(draggedNodes);

            DragAndDrop.PrepareStartDrag();
            DragAndDrop.SetGenericData("AudioMixerDragging", new AudioMixerTreeViewDragging.DragData(audioMixerItemsFromIDs));
            DragAndDrop.objectReferences = new UnityEngine.Object[0];
            string title = draggedNodes.Count + " AudioMixer" + ((draggedNodes.Count <= 1) ? string.Empty : "s");

            DragAndDrop.StartDrag(title);
        }
        public override void StartDrag(TreeViewItem draggedNode, List<int> draggedItemIDs)
        {
            DragAndDrop.PrepareStartDrag();
            var tvItems = SelectionManager.SelectedTrackGUI().Cast<TreeViewItem>().ToList();
            DragAndDrop.SetGenericData(k_GenericDragId, new TimelineDragData(tvItems));
            DragAndDrop.objectReferences = new UnityObject[] {};  // this IS required for dragging to work

            string title = draggedItemIDs.Count + (draggedItemIDs.Count > 1 ? "s" : ""); // title is only shown on OSX (at the cursor)

            TimelineGroupGUI groupGui = draggedNode as TimelineGroupGUI;
            if (groupGui != null)
            {
                title = groupGui.displayName;
            }
            DragAndDrop.StartDrag(title);
        }
예제 #6
0
        public override void StartDrag(TreeViewItem draggedNode, List <int> draggedItemIDs)
        {
            DragAndDrop.PrepareStartDrag();
            List <TreeViewItem> draggedItems = SelectionManager.SelectedTrackGUI().Cast <TreeViewItem>().ToList <TreeViewItem>();

            DragAndDrop.SetGenericData("TimelineDragging", new TimelineDragging.TimelineDragData(draggedItems));
            DragAndDrop.set_objectReferences(new Object[0]);
            string           text             = draggedItemIDs.Count + ((draggedItemIDs.Count <= 1) ? "" : "s");
            TimelineGroupGUI timelineGroupGUI = draggedNode as TimelineGroupGUI;

            if (timelineGroupGUI != null)
            {
                text = timelineGroupGUI.get_displayName();
            }
            DragAndDrop.StartDrag(text);
        }
        public override void StartDrag(TreeViewItem draggedNode, List <int> draggedNodes)
        {
            // We do not allow changing routing in playmode for now
            if (EditorApplication.isPlaying)
            {
                return;
            }

            List <AudioMixerItem> draggedItems = GetAudioMixerItemsFromIDs(draggedNodes);

            DragAndDrop.PrepareStartDrag();
            DragAndDrop.SetGenericData(k_AudioMixerDraggingID, new DragData(draggedItems));
            string title = draggedNodes.Count + " AudioMixer" + (draggedNodes.Count > 1 ? "s" : ""); // title is only shown on OSX (at the cursor)

            DragAndDrop.StartDrag(title);
        }
예제 #8
0
        internal static bool HandleDelayedDrag(Rect position, int id, UnityEngine.Object objectToDrag)
        {
            Event     current        = Event.current;
            EventType typeForControl = current.GetTypeForControl(id);
            bool      result;

            if (typeForControl != EventType.MouseDown)
            {
                if (typeForControl == EventType.MouseDrag)
                {
                    if (GUIUtility.hotControl == id)
                    {
                        DragAndDropDelay dragAndDropDelay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), id);
                        if (dragAndDropDelay.CanStartDrag())
                        {
                            GUIUtility.hotControl = 0;
                            DragAndDrop.PrepareStartDrag();
                            UnityEngine.Object[] objectReferences = new UnityEngine.Object[]
                            {
                                objectToDrag
                            };
                            DragAndDrop.objectReferences = objectReferences;
                            DragAndDrop.StartDrag(ObjectNames.GetDragAndDropTitle(objectToDrag));
                            result = true;
                            return(result);
                        }
                    }
                }
            }
            else if (position.Contains(current.mousePosition) && current.clickCount == 1)
            {
                if (current.button == 0 && (Application.platform != RuntimePlatform.OSXEditor || !current.control))
                {
                    GUIUtility.hotControl = id;
                    DragAndDropDelay dragAndDropDelay2 = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), id);
                    dragAndDropDelay2.mouseDownPosition = current.mousePosition;
                    result = true;
                    return(result);
                }
            }
            result = false;
            return(result);
        }
예제 #9
0
 public override void StartDrag(TreeViewItem draggedItem, List <int> draggedItemIDs)
 {
     DragAndDrop.PrepareStartDrag();
     draggedItemIDs = base.m_TreeView.SortIDsInVisiblityOrder(draggedItemIDs);
     DragAndDrop.objectReferences = ProjectWindowUtil.GetDragAndDropObjects(draggedItem.id, draggedItemIDs);
     DragAndDrop.paths            = ProjectWindowUtil.GetDragAndDropPaths(draggedItem.id, draggedItemIDs);
     if (DragAndDrop.objectReferences.Length > 1)
     {
         DragAndDrop.StartDrag("<Multiple>");
     }
     else
     {
         DragAndDrop.StartDrag(ObjectNames.GetDragAndDropTitle(InternalEditorUtility.GetObjectFromInstanceID(draggedItem.id)));
     }
     if (base.m_TreeView.data is GameObjectTreeViewDataSource)
     {
         ((GameObjectTreeViewDataSource)base.m_TreeView.data).SetupChildParentReferencesIfNeeded();
     }
 }
        internal static void StartDrag(int draggedInstanceID, List <int> selectedInstanceIDs)
        {
            if (draggedInstanceID == ProjectBrowser.kPackagesFolderInstanceId)
            {
                return;
            }

            DragAndDrop.PrepareStartDrag();

            string title = "";

            if (IsFavoritesItem(draggedInstanceID))
            {
                DragAndDrop.SetGenericData(k_DraggingFavoriteGenericData, draggedInstanceID);
            }
            else
            {
                // Normal assets dragging
                bool isFolder = IsFolder(draggedInstanceID);
                DragAndDrop.objectReferences = GetDragAndDropObjects(draggedInstanceID, selectedInstanceIDs);
                DragAndDrop.SetGenericData(k_IsFolderGenericData, isFolder ? "isFolder" : "");
                string[] paths = GetDragAndDropPaths(draggedInstanceID, selectedInstanceIDs);
                if (paths.Length > 0)
                {
                    DragAndDrop.paths = paths;
                }

                if (DragAndDrop.objectReferences.Length > 1)
                {
                    title = "<Multiple>";
                }
                else
                {
                    title = ObjectNames.GetDragAndDropTitle(InternalEditorUtility.GetObjectFromInstanceID(draggedInstanceID));
                }
            }

            DragAndDrop.StartDrag(title);
        }
예제 #11
0
            private void DrawHeader(Rect rect)
            {
                rect.x          = (rect.x - border);
                this.isExpanded = EditorGUI.Foldout(rect, this.isExpanded, string.Format("{0} [{1}]", this.property.displayName, this.property.arraySize));
                Rect rect2 = rect;

                if (this.list.count == 0)
                {
                    rect2.height = (rect2.height * 3f);
                }
                Event     current = Event.current;
                EventType type    = current.type;

                if (type != EventType.DragExited)
                {
                    if (type == EventType.DragUpdated || type == EventType.DragPerform)
                    {
                        if (rect2.Contains(current.mousePosition))
                        {
                            DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                            if (current.type == EventType.DragPerform)
                            {
                                DragAndDrop.AcceptDrag();
                                Object[] objectReferences = DragAndDrop.objectReferences;
                                for (int i = 0; i < objectReferences.Length; i++)
                                {
                                    Object obj = objectReferences[i];
                                    this.AddElement(obj);
                                }
                            }
                        }
                    }
                }
                else
                {
                    DragAndDrop.PrepareStartDrag();
                }
            }
예제 #12
0
        private static void DoDragAndDrop(ListViewState listView, ListViewElement element, List <ColumnViewElement> columnViewElements, ColumnView.ObjectColumnGetDataFunction getDataForDraggingFunction)
        {
            if (GUIUtility.hotControl == listView.ID && Event.current.type == EventType.MouseDown && (element.position.Contains(Event.current.mousePosition) && Event.current.button == 0))
            {
                ((DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), listView.ID)).mouseDownPosition = Event.current.mousePosition;
            }
            if (GUIUtility.hotControl != listView.ID || Event.current.type != EventType.MouseDrag || (!GUIClip.visibleRect.Contains(Event.current.mousePosition) || !((DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), listView.ID)).CanStartDrag()))
            {
                return;
            }
            object data = getDataForDraggingFunction != null?getDataForDraggingFunction(columnViewElements[listView.row].value) : (object)null;

            if (data == null)
            {
                return;
            }
            DragAndDrop.PrepareStartDrag();
            DragAndDrop.objectReferences = new Object[0];
            DragAndDrop.paths            = (string[])null;
            DragAndDrop.SetGenericData("CustomDragData", data);
            DragAndDrop.StartDrag(columnViewElements[listView.row].name);
            Event.current.Use();
        }
        internal static bool HandleDelayedDrag(Rect position, int id, Object objectToDrag)
        {
            Event evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (position.Contains(evt.mousePosition) && evt.clickCount == 1)
                {
                    if (evt.button == 0 && !(Application.platform == RuntimePlatform.OSXEditor && evt.control == true))
                    {
                        GUIUtility.hotControl = id;
                        DragAndDropDelay delay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), id);
                        delay.mouseDownPosition = evt.mousePosition;
                        return(true);
                    }
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    DragAndDropDelay delay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), id);
                    if (delay.CanStartDrag())
                    {
                        GUIUtility.hotControl = 0;
                        DragAndDrop.PrepareStartDrag();
                        Object[] references = { objectToDrag };
                        DragAndDrop.objectReferences = references;
                        DragAndDrop.StartDrag(ObjectNames.GetDragAndDropTitle(objectToDrag));
                        return(true);
                    }
                }
                break;
            }
            return(false);
        }
예제 #14
0
        private static void DoDragAndDrop(ListViewState listView, ListViewElement element, List <ColumnViewElement> columnViewElements, ObjectColumnGetDataFunction getDataForDraggingFunction)
        {
            if (GUIUtility.hotControl == listView.ID && Event.current.type == EventType.MouseDown &&
                element.position.Contains(Event.current.mousePosition) &&
                Event.current.button == 0)
            {
                var delay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), listView.ID);
                delay.mouseDownPosition = Event.current.mousePosition;
            }

            if (GUIUtility.hotControl == listView.ID &&
                Event.current.type == EventType.MouseDrag &&
                GUIClip.visibleRect.Contains(Event.current.mousePosition))
            {
                var delay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), listView.ID);

                if (delay.CanStartDrag())
                {
                    var data = getDataForDraggingFunction == null ? null :
                               getDataForDraggingFunction(columnViewElements[listView.row].value);

                    if (data == null)
                    {
                        return;
                    }

                    DragAndDrop.PrepareStartDrag();

                    DragAndDrop.paths = null;

                    DragAndDrop.SetGenericData("CustomDragData", data);
                    DragAndDrop.StartDrag(columnViewElements[listView.row].name);

                    Event.current.Use();
                }
            }
        }
예제 #15
0
        internal static void StartDrag(int draggedInstanceID, List <int> selectedInstanceIDs)
        {
            DragAndDrop.PrepareStartDrag();
            string title = string.Empty;

            if (ProjectWindowUtil.IsFavoritesItem(draggedInstanceID))
            {
                DragAndDrop.SetGenericData(ProjectWindowUtil.k_DraggingFavoriteGenericData, (object)draggedInstanceID);
                DragAndDrop.objectReferences = new UnityEngine.Object[0];
            }
            else
            {
                bool flag = ProjectWindowUtil.IsFolder(draggedInstanceID);
                DragAndDrop.objectReferences = ProjectWindowUtil.GetDragAndDropObjects(draggedInstanceID, selectedInstanceIDs);
                DragAndDrop.SetGenericData(ProjectWindowUtil.k_IsFolderGenericData, !flag ? (object)string.Empty : (object)"isFolder");
                string[] dragAndDropPaths = ProjectWindowUtil.GetDragAndDropPaths(draggedInstanceID, selectedInstanceIDs);
                if (dragAndDropPaths.Length > 0)
                {
                    DragAndDrop.paths = dragAndDropPaths;
                }
                title = DragAndDrop.objectReferences.Length <= 1 ? ObjectNames.GetDragAndDropTitle(InternalEditorUtility.GetObjectFromInstanceID(draggedInstanceID)) : "<Multiple>";
            }
            DragAndDrop.StartDrag(title);
        }
예제 #16
0
        internal static void StartDrag(int draggedInstanceID, List <int> selectedInstanceIDs)
        {
            DragAndDrop.PrepareStartDrag();
            string title = string.Empty;

            if (ProjectWindowUtil.IsFavoritesItem(draggedInstanceID))
            {
                DragAndDrop.SetGenericData(ProjectWindowUtil.k_DraggingFavoriteGenericData, draggedInstanceID);
                DragAndDrop.objectReferences = new UnityEngine.Object[0];
            }
            else
            {
                bool flag = false;
                HierarchyProperty hierarchyProperty = new HierarchyProperty(HierarchyType.Assets);
                if (hierarchyProperty.Find(draggedInstanceID, null))
                {
                    flag = hierarchyProperty.isFolder;
                }
                DragAndDrop.objectReferences = ProjectWindowUtil.GetDragAndDropObjects(draggedInstanceID, selectedInstanceIDs);
                DragAndDrop.SetGenericData(ProjectWindowUtil.k_IsFolderGenericData, (!flag) ? string.Empty : "isFolder");
                string[] dragAndDropPaths = ProjectWindowUtil.GetDragAndDropPaths(draggedInstanceID, selectedInstanceIDs);
                if (dragAndDropPaths.Length > 0)
                {
                    DragAndDrop.paths = dragAndDropPaths;
                }
                if (DragAndDrop.objectReferences.Length > 1)
                {
                    title = "<Multiple>";
                }
                else
                {
                    title = ObjectNames.GetDragAndDropTitle(InternalEditorUtility.GetObjectFromInstanceID(draggedInstanceID));
                }
            }
            DragAndDrop.StartDrag(title);
        }
예제 #17
0
        internal static void DoBoneHandle(Transform target, Dictionary <Transform, bool> validBones, BoneRenderer renderer)
        {
            int   id  = target.name.GetHashCode();
            Event evt = Event.current;

            bool hasValidChildBones = false;

            if (validBones != null)
            {
                foreach (Transform child in target)
                {
                    if (validBones.ContainsKey(child))
                    {
                        hasValidChildBones = true;
                        break;
                    }
                }
            }

            Vector3 basePoint = target.position;

            List <Vector3> endPoints = new List <Vector3>();

            // [case 525602] do not draw root.
            if (!hasValidChildBones && target.parent != null)
            {
                endPoints.Add(target.position + (target.position - target.parent.position) * 0.4f);
            }
            else
            {
                foreach (Transform child in target)
                {
                    // Only render bone connections to valid bones
                    // (except if no child bones are valid - then draw all connections)
                    if (validBones != null && !validBones.ContainsKey(child))
                    {
                        continue;
                    }

                    endPoints.Add(child.position);
                }
            }

            for (int i = 0; i < endPoints.Count; i++)
            {
                Vector3 endPoint = endPoints[i];


                switch (evt.GetTypeForControl(id))
                {
                case EventType.Layout:
                {
                    // TODO : This is slow and should be revisited prior to exposing bone handles
                    Vector3[] vertices = BoneRenderer.GetBoneWireVertices(basePoint, endPoint);
                    if (vertices != null)
                    {
                        HandleUtility.AddControl(id, DistanceToPolygone(vertices));
                    }

                    break;
                }

                case EventType.MouseMove:
                    if (id == HandleUtility.nearestControl)
                    {
                        HandleUtility.Repaint();
                    }
                    break;

                case EventType.MouseDown:
                {
                    // am I closest to the thingy?
                    if (!evt.alt && HandleUtility.nearestControl == id && evt.button == 0)
                    {
                        GUIUtility.hotControl = id;     // Grab mouse focus
                        if (evt.shift)
                        {
                            Object[] selected = Selection.objects;
                            if (ArrayUtility.Contains(selected, target) == false)
                            {
                                ArrayUtility.Add(ref selected, target);
                                Selection.objects = selected;
                            }
                        }
                        else
                        {
                            Selection.activeObject = target;
                        }

                        EditorGUIUtility.PingObject(target);

                        evt.Use();
                    }
                    break;
                }

                case EventType.MouseDrag:
                {
                    if (!evt.alt && GUIUtility.hotControl == id)
                    {
                        DragAndDrop.PrepareStartDrag();
                        DragAndDrop.objectReferences = new UnityEngine.Object[] { target };
                        DragAndDrop.StartDrag(ObjectNames.GetDragAndDropTitle(target));

                        // having a hot control set during drag makes the control eat the drag events
                        // and dragging of bones no longer works over the avatar configure window
                        // see case 912016
                        GUIUtility.hotControl = 0;

                        evt.Use();
                    }
                    break;
                }

                case EventType.MouseUp:
                {
                    if (GUIUtility.hotControl == id && (evt.button == 0 || evt.button == 2))
                    {
                        GUIUtility.hotControl = 0;
                        evt.Use();
                    }
                    break;
                }

                case EventType.Repaint:
                {
                    color = GUIUtility.hotControl == 0 && HandleUtility.nearestControl == id ? Handles.preselectionColor : color;
                    if (hasValidChildBones)
                    {
                        renderer.AddBoneInstance(basePoint, endPoint, color);
                    }
                    else
                    {
                        renderer.AddBoneLeafInstance(basePoint, target.rotation, (endPoint - basePoint).magnitude, color);
                    }
                }
                break;
                }
            }
        }
예제 #18
0
        private void ListArea(Rect rect, PresetLibrary lib, object newPresetObject)
        {
            if (lib != null)
            {
                int   num2;
                int   num3;
                Event current = Event.current;
                if ((this.m_PresetLibraryFileLocation == PresetFileLocation.ProjectFolder) && (current.type == EventType.Repaint))
                {
                    this.m_IsOpenForEdit = AssetDatabase.IsOpenForEdit(this.pathWithExtension);
                }
                else if (this.m_PresetLibraryFileLocation == PresetFileLocation.PreferencesFolder)
                {
                    this.m_IsOpenForEdit = true;
                }
                if (!this.m_IsOpenForEdit)
                {
                    Rect rect2 = new Rect(rect.x, rect.yMax - this.versionControlAreaHeight, rect.width, this.versionControlAreaHeight);
                    this.VersionControlArea(rect2);
                    rect.height -= this.versionControlAreaHeight;
                }
                for (int i = 0; i < 2; i++)
                {
                    this.gridWidth = !this.m_ShowedScrollBarLastFrame ? rect.width : (rect.width - 17f);
                    this.SetupGrid(this.gridWidth, lib.Count());
                    bool flag = this.m_Grid.height > rect.height;
                    if (flag == this.m_ShowedScrollBarLastFrame)
                    {
                        break;
                    }
                    this.m_ShowedScrollBarLastFrame = flag;
                }
                if ((this.m_ShowedScrollBarLastFrame || this.alwaysShowScrollAreaHorizontalLines) && (Event.current.type == EventType.Repaint))
                {
                    Rect rect3 = new RectOffset(1, 1, 1, 1).Add(rect);
                    rect3.height = 1f;
                    EditorGUI.DrawRect(rect3, new Color(0f, 0f, 0f, 0.3f));
                    rect3.y += rect.height + 1f;
                    EditorGUI.DrawRect(rect3, new Color(0f, 0f, 0f, 0.3f));
                }
                Rect viewRect = new Rect(0f, 0f, 1f, this.m_Grid.height);
                this.m_State.m_ScrollPosition = GUI.BeginScrollView(rect, this.m_State.m_ScrollPosition, viewRect);
                float gridStartY = 0f;
                int   maxIndex   = !this.m_ShowAddNewPresetItem ? (lib.Count() - 1) : lib.Count();
                bool  flag2      = this.m_Grid.IsVisibleInScrollView(rect.height, this.m_State.m_ScrollPosition.y, gridStartY, maxIndex, out num2, out num3);
                bool  flag3      = false;
                if (flag2)
                {
                    if (this.GetRenameOverlay().IsRenaming() && !this.GetRenameOverlay().isWaitingForDelay)
                    {
                        if (!this.m_State.m_RenameOverlay.OnGUI())
                        {
                            this.EndRename();
                            current.Use();
                        }
                        this.Repaint();
                    }
                    for (int j = num2; j <= num3; j++)
                    {
                        bool flag4;
                        Rect dragRect;
                        int  controlID  = j + 0xf4240;
                        Rect itemRect   = this.m_Grid.CalcRect(j, gridStartY);
                        Rect buttonRect = itemRect;
                        Rect position   = itemRect;
                        PresetLibraryEditorState.ItemViewMode itemViewMode = this.m_State.itemViewMode;
                        if ((itemViewMode != PresetLibraryEditorState.ItemViewMode.Grid) && (itemViewMode == PresetLibraryEditorState.ItemViewMode.List))
                        {
                            buttonRect.width = this.m_State.m_PreviewHeight * this.m_PreviewAspect;
                            position.x      += buttonRect.width + 8f;
                            position.width  -= buttonRect.width + 10f;
                            position.height  = 16f;
                            position.y       = itemRect.yMin + ((itemRect.height - 16f) * 0.5f);
                        }
                        if (this.m_ShowAddNewPresetItem && (j == lib.Count()))
                        {
                            this.CreateNewPresetButton(buttonRect, newPresetObject, lib, this.m_IsOpenForEdit);
                        }
                        else
                        {
                            flag4 = this.IsRenaming(j);
                            if (flag4)
                            {
                                Rect rect8 = position;
                                rect8.y--;
                                rect8.x--;
                                this.m_State.m_RenameOverlay.editFieldRect = rect8;
                            }
                            switch (current.type)
                            {
                            case EventType.MouseDown:
                                if ((current.button == 0) && itemRect.Contains(current.mousePosition))
                                {
                                    GUIUtility.hotControl = controlID;
                                    if (current.clickCount == 1)
                                    {
                                        this.m_ItemClickedCallback(current.clickCount, lib.GetPreset(j));
                                        current.Use();
                                    }
                                }
                                break;

                            case EventType.MouseUp:
                                if (GUIUtility.hotControl == controlID)
                                {
                                    GUIUtility.hotControl = 0;
                                    if (((current.button == 0) && itemRect.Contains(current.mousePosition)) && (Event.current.alt && this.m_IsOpenForEdit))
                                    {
                                        this.DeletePreset(j);
                                        current.Use();
                                    }
                                }
                                break;

                            case EventType.MouseMove:
                                if (!itemRect.Contains(current.mousePosition))
                                {
                                    goto Label_0812;
                                }
                                if (this.m_State.m_HoverIndex != j)
                                {
                                    this.m_State.m_HoverIndex = j;
                                    this.Repaint();
                                }
                                break;

                            case EventType.MouseDrag:
                                if ((GUIUtility.hotControl == controlID) && this.m_IsOpenForEdit)
                                {
                                    DragAndDropDelay stateObject = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), controlID);
                                    if (stateObject.CanStartDrag())
                                    {
                                        DragAndDrop.PrepareStartDrag();
                                        DragAndDrop.SetGenericData("DraggingPreset", j);
                                        DragAndDrop.objectReferences = new UnityEngine.Object[0];
                                        DragAndDrop.StartDrag(string.Empty);
                                        this.m_DragState.draggingIndex = j;
                                        this.m_DragState.dragUponIndex = j;
                                        GUIUtility.hotControl          = 0;
                                    }
                                    current.Use();
                                }
                                break;

                            case EventType.Repaint:
                                if ((this.m_State.m_HoverIndex == j) && !itemRect.Contains(current.mousePosition))
                                {
                                    goto Label_046D;
                                }
                                goto Label_0479;

                            case EventType.DragUpdated:
                            case EventType.DragPerform:
                                dragRect = this.GetDragRect(itemRect);
                                if (!dragRect.Contains(current.mousePosition))
                                {
                                    break;
                                }
                                this.m_DragState.dragUponIndex = j;
                                this.m_DragState.dragUponRect  = itemRect;
                                if (this.m_State.itemViewMode != PresetLibraryEditorState.ItemViewMode.List)
                                {
                                    goto Label_0694;
                                }
                                this.m_DragState.insertAfterIndex = ((current.mousePosition.y - dragRect.y) / dragRect.height) > 0.5f;
                                goto Label_06C5;

                            case EventType.DragExited:
                                if (this.m_DragState.IsDragging())
                                {
                                    this.ClearDragState();
                                    current.Use();
                                }
                                break;

                            case EventType.ContextClick:
                                if (itemRect.Contains(current.mousePosition))
                                {
                                    PresetContextMenu <T> .Show(this.m_IsOpenForEdit, j, newPresetObject, (PresetLibraryEditor <T>) this);

                                    current.Use();
                                }
                                break;
                            }
                        }
                        continue;
Label_046D:
                        this.m_State.m_HoverIndex = -1;
Label_0479:
                        if ((this.m_DragState.draggingIndex == j) || (GUIUtility.hotControl == controlID))
                        {
                            this.DrawHoverEffect(itemRect, false);
                        }
                        lib.Draw(buttonRect, j);
                        if (!flag4 && this.drawLabels)
                        {
                            GUI.Label(position, GUIContent.Temp(lib.GetName(j)));
                        }
                        if ((this.m_DragState.dragUponIndex == j) && (this.m_DragState.draggingIndex != this.m_DragState.dragUponIndex))
                        {
                            flag3 = true;
                        }
                        if (((GUIUtility.hotControl == 0) && Event.current.alt) && this.m_IsOpenForEdit)
                        {
                            EditorGUIUtility.AddCursorRect(itemRect, MouseCursor.ArrowMinus);
                        }
                        continue;
Label_0694:
                        this.m_DragState.insertAfterIndex = ((current.mousePosition.x - dragRect.x) / dragRect.width) > 0.5f;
Label_06C5:
                        if (current.type == EventType.DragPerform)
                        {
                            if (this.m_DragState.draggingIndex >= 0)
                            {
                                this.MovePreset(this.m_DragState.draggingIndex, this.m_DragState.dragUponIndex, this.m_DragState.insertAfterIndex);
                                DragAndDrop.AcceptDrag();
                            }
                            this.ClearDragState();
                        }
                        DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                        current.Use();
                        continue;
Label_0812:
                        if (this.m_State.m_HoverIndex == j)
                        {
                            this.m_State.m_HoverIndex = -1;
                            this.Repaint();
                        }
                    }
                    if (flag3)
                    {
                        this.DrawDragInsertionMarker();
                    }
                }
                GUI.EndScrollView();
            }
        }
        public override void StartDrag(TreeViewItem draggedItem, List <int> draggedItemIDs)
        {
            DragAndDrop.PrepareStartDrag();

            if (Event.current.control || Event.current.command)
            {
                draggedItemIDs.Add(draggedItem.id);
            }

            // Ensure correct order for hierarchy items (to preserve visible order when dropping at new location)
            draggedItemIDs = m_TreeView.SortIDsInVisiblityOrder(draggedItemIDs);

            if (!draggedItemIDs.Contains(draggedItem.id))
            {
                draggedItemIDs = new List <int> {
                    draggedItem.id
                }
            }
            ;

            Object[] draggedObjReferences = ProjectWindowUtil.GetDragAndDropObjects(draggedItem.id, draggedItemIDs);
            DragAndDrop.objectReferences = draggedObjReferences;

            // After introducing multi-scene, UnityEngine.Scene can be selected in HierarchyWindow.
            // UnityEngine.Scene is not a UnityEngine.Object.
            // So DragAndDrop.objectReferences can't cover this case.
            List <Scene> draggedScenes = GetDraggedScenes(draggedItemIDs);

            if (draggedScenes != null)
            {
                DragAndDrop.SetGenericData(kSceneHeaderDragString, draggedScenes);

                List <string> paths = new List <string>();
                foreach (Scene scene in draggedScenes)
                {
                    if (scene.path.Length > 0)
                    {
                        paths.Add(scene.path);
                    }
                }
                DragAndDrop.paths = paths.ToArray();
            }
            else
            {
                DragAndDrop.paths = new string[0];
            }

            string title;

            if (draggedItemIDs.Count > 1)
            {
                title = "<Multiple>";
            }
            else
            {
                if (draggedObjReferences.Length == 1)
                {
                    title = ObjectNames.GetDragAndDropTitle(draggedObjReferences[0]);
                }
                else if (draggedScenes != null && draggedScenes.Count == 1)
                {
                    title = draggedScenes[0].path;
                }
                else
                {
                    title = "Unhandled dragged item";
                    Debug.LogError("Unhandled dragged item");
                }
            }
            DragAndDrop.StartDrag(title);

            dataSource.SetupChildParentReferencesIfNeeded();
        }

        GameObjectTreeViewDataSource dataSource {
            get { return((GameObjectTreeViewDataSource)m_TreeView.data); }
        }
예제 #20
0
            public bool MoveNext()
            {
                if (this.xPos > -1)
                {
                    if (ListViewShared.HasMouseDown(this.ilvState, this.rect))
                    {
                        this.ilvState.state.selectionChanged = true;
                        this.ilvState.state.row       = this.yPos;
                        this.ilvState.state.column    = this.xPos;
                        this.ilvState.state.scrollPos = ListViewShared.ListViewScrollToRow(this.ilvState, this.yPos);
                        if ((this.ilvState.wantsReordering || this.ilvState.wantsToStartCustomDrag) && GUIUtility.hotControl == this.ilvState.state.ID)
                        {
                            ((DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), this.ilvState.state.ID)).mouseDownPosition = Event.current.mousePosition;
                            this.ilvState.dragItem       = this.yPos;
                            ListViewShared.dragControlID = this.ilvState.state.ID;
                        }
                    }
                    if ((this.ilvState.wantsReordering || this.ilvState.wantsToStartCustomDrag) && (GUIUtility.hotControl == this.ilvState.state.ID && Event.current.type == EventType.MouseDrag) && GUIClip.visibleRect.Contains(Event.current.mousePosition))
                    {
                        if (((DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), this.ilvState.state.ID)).CanStartDrag())
                        {
                            DragAndDrop.PrepareStartDrag();
                            DragAndDrop.objectReferences = new UnityEngine.Object[0];
                            DragAndDrop.paths            = (string[])null;
                            if (this.ilvState.wantsReordering)
                            {
                                this.ilvState.state.dropHereRect = new Rect(this.ilvState.rect.x, 0.0f, this.ilvState.rect.width, (float)(this.ilvState.state.rowHeight * 2));
                                DragAndDrop.StartDrag(this.dragTitle);
                            }
                            else if (this.ilvState.wantsToStartCustomDrag)
                            {
                                DragAndDrop.SetGenericData("CustomDragID", (object)this.ilvState.state.ID);
                                DragAndDrop.StartDrag(this.dragTitle);
                            }
                        }
                        Event.current.Use();
                    }
                }
                ++this.xPos;
                if (this.xPos > this.xTo)
                {
                    this.xPos = 0;
                    ++this.yPos;
                    this.rect.x     = this.firstRect.x;
                    this.rect.width = (float)this.colWidths[0];
                    if (this.yPos > this.yTo)
                    {
                        this.quiting = true;
                    }
                    else
                    {
                        this.rect.y += this.rect.height;
                    }
                }
                else
                {
                    if (this.xPos >= 1)
                    {
                        this.rect.x += (float)this.colWidths[this.xPos - 1];
                    }
                    this.rect.width = (float)this.colWidths[this.xPos];
                }
                this.element.row      = this.yPos;
                this.element.column   = this.xPos;
                this.element.position = this.rect;
                if (this.element.row >= this.ilvState.state.totalRows)
                {
                    this.quiting = true;
                }
                if (this.isLayouted && Event.current.type == EventType.Layout && this.yFrom + 1 == this.yPos)
                {
                    this.quiting = true;
                }
                if (this.isLayouted && this.yPos != this.yFrom)
                {
                    GUILayout.EndHorizontal();
                }
                if (this.quiting)
                {
                    if (this.ilvState.state.drawDropHere && Event.current.GetTypeForControl(this.ilvState.state.ID) == EventType.Repaint)
                    {
                        GUIStyle insertion = (GUIStyle)ListViewShared.Constants.insertion;
                        insertion.Draw(insertion.margin.Remove(this.ilvState.state.dropHereRect), false, false, false, false);
                    }
                    if (ListViewShared.ListViewKeyboard(this.ilvState, this.colWidths.Length))
                    {
                        this.ilvState.state.selectionChanged = true;
                    }
                    if (Event.current.GetTypeForControl(this.ilvState.state.ID) == EventType.MouseUp)
                    {
                        GUIUtility.hotControl = 0;
                    }
                    if (this.ilvState.wantsReordering && GUIUtility.hotControl == this.ilvState.state.ID)
                    {
                        ListViewState state = this.ilvState.state;
                        switch (Event.current.type)
                        {
                        case EventType.DragUpdated:
                            DragAndDrop.visualMode = !this.ilvState.rect.Contains(Event.current.mousePosition) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Move;
                            Event.current.Use();
                            if (DragAndDrop.visualMode != DragAndDropVisualMode.None)
                            {
                                state.dropHereRect.y = (float)((Mathf.RoundToInt(Event.current.mousePosition.y / (float)state.rowHeight) - 1) * state.rowHeight);
                                if ((double)state.dropHereRect.y >= (double)(state.rowHeight * state.totalRows))
                                {
                                    state.dropHereRect.y = (float)(state.rowHeight * (state.totalRows - 1));
                                }
                                state.drawDropHere = true;
                                break;
                            }
                            break;

                        case EventType.DragPerform:
                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition))
                            {
                                this.ilvState.state.draggedFrom = this.ilvState.dragItem;
                                this.ilvState.state.draggedTo   = Mathf.RoundToInt(Event.current.mousePosition.y / (float)state.rowHeight);
                                if (this.ilvState.state.draggedTo > this.ilvState.state.totalRows)
                                {
                                    this.ilvState.state.draggedTo = this.ilvState.state.totalRows;
                                }
                                this.ilvState.state.row = this.ilvState.state.draggedTo <= this.ilvState.state.draggedFrom ? this.ilvState.state.draggedTo : this.ilvState.state.draggedTo - 1;
                                this.ilvState.state.selectionChanged = true;
                                DragAndDrop.AcceptDrag();
                                Event.current.Use();
                                this.ilvState.wantsReordering    = false;
                                this.ilvState.state.drawDropHere = false;
                            }
                            GUIUtility.hotControl = 0;
                            break;

                        case EventType.DragExited:
                            this.ilvState.wantsReordering    = false;
                            this.ilvState.state.drawDropHere = false;
                            GUIUtility.hotControl            = 0;
                            break;
                        }
                    }
                    else if (this.ilvState.wantsExternalFiles)
                    {
                        switch (Event.current.type)
                        {
                        case EventType.DragUpdated:
                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition) && DragAndDrop.paths != null && DragAndDrop.paths.Length != 0)
                            {
                                DragAndDrop.visualMode = !this.ilvState.rect.Contains(Event.current.mousePosition) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Copy;
                                Event.current.Use();
                                if (DragAndDrop.visualMode != DragAndDropVisualMode.None)
                                {
                                    this.ilvState.state.dropHereRect = new Rect(this.ilvState.rect.x, (float)((Mathf.RoundToInt(Event.current.mousePosition.y / (float)this.ilvState.state.rowHeight) - 1) * this.ilvState.state.rowHeight), this.ilvState.rect.width, (float)this.ilvState.state.rowHeight);
                                    if ((double)this.ilvState.state.dropHereRect.y >= (double)(this.ilvState.state.rowHeight * this.ilvState.state.totalRows))
                                    {
                                        this.ilvState.state.dropHereRect.y = (float)(this.ilvState.state.rowHeight * (this.ilvState.state.totalRows - 1));
                                    }
                                    this.ilvState.state.drawDropHere = true;
                                    break;
                                }
                                break;
                            }
                            break;

                        case EventType.DragPerform:
                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition))
                            {
                                this.ilvState.state.fileNames = DragAndDrop.paths;
                                DragAndDrop.AcceptDrag();
                                Event.current.Use();
                                this.ilvState.wantsExternalFiles = false;
                                this.ilvState.state.drawDropHere = false;
                                this.ilvState.state.draggedTo    = Mathf.RoundToInt(Event.current.mousePosition.y / (float)this.ilvState.state.rowHeight);
                                if (this.ilvState.state.draggedTo > this.ilvState.state.totalRows)
                                {
                                    this.ilvState.state.draggedTo = this.ilvState.state.totalRows;
                                }
                                this.ilvState.state.row = this.ilvState.state.draggedTo;
                            }
                            GUIUtility.hotControl = 0;
                            break;

                        case EventType.DragExited:
                            this.ilvState.wantsExternalFiles = false;
                            this.ilvState.state.drawDropHere = false;
                            GUIUtility.hotControl            = 0;
                            break;
                        }
                    }
                    else if (this.ilvState.wantsToAcceptCustomDrag && ListViewShared.dragControlID != this.ilvState.state.ID)
                    {
                        switch (Event.current.type)
                        {
                        case EventType.DragUpdated:
                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition) && DragAndDrop.GetGenericData("CustomDragID") != null)
                            {
                                DragAndDrop.visualMode = !this.ilvState.rect.Contains(Event.current.mousePosition) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Move;
                                Event.current.Use();
                                break;
                            }
                            break;

                        case EventType.DragPerform:
                            object genericData = DragAndDrop.GetGenericData("CustomDragID");
                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition) && genericData != null)
                            {
                                this.ilvState.state.customDraggedFromID = (int)genericData;
                                DragAndDrop.AcceptDrag();
                                Event.current.Use();
                            }
                            GUIUtility.hotControl = 0;
                            break;

                        case EventType.DragExited:
                            GUIUtility.hotControl = 0;
                            break;
                        }
                    }
                    if (this.ilvState.beganHorizontal)
                    {
                        EditorGUILayout.EndScrollView();
                        GUILayout.EndHorizontal();
                        this.ilvState.beganHorizontal = false;
                    }
                    if (this.isLayouted)
                    {
                        GUILayoutUtility.EndLayoutGroup();
                        EditorGUILayout.EndScrollView();
                    }
                    this.ilvState.wantsReordering    = false;
                    this.ilvState.wantsExternalFiles = false;
                }
                else if (this.isLayouted)
                {
                    if (this.yPos != this.yFrom)
                    {
                        this.ilvStateL.group.ResetCursor();
                        this.ilvStateL.group.AddY();
                    }
                    else
                    {
                        this.ilvStateL.group.AddY((float)(this.ilvState.invisibleRows * this.ilvState.state.rowHeight));
                    }
                }
                if (this.isLayouted)
                {
                    if (!this.quiting)
                    {
                        GUILayout.BeginHorizontal(GUIStyle.none, new GUILayoutOption[0]);
                    }
                    else
                    {
                        GUILayout.EndHorizontal();
                    }
                }
                return(!this.quiting);
            }
예제 #21
0
        private void ListArea(Rect rect, PresetLibrary lib, object newPresetObject)
        {
            if (lib == null)
            {
                return;
            }
            Event current = Event.current;

            if (this.m_PresetLibraryFileLocation == PresetFileLocation.ProjectFolder && current.type == EventType.Repaint)
            {
                this.m_IsOpenForEdit = AssetDatabase.IsOpenForEdit(this.pathWithExtension);
            }
            else
            {
                if (this.m_PresetLibraryFileLocation == PresetFileLocation.PreferencesFolder)
                {
                    this.m_IsOpenForEdit = true;
                }
            }
            if (!this.m_IsOpenForEdit)
            {
                Rect rect2 = new Rect(rect.x, rect.yMax - this.versionControlAreaHeight, rect.width, this.versionControlAreaHeight);
                this.VersionControlArea(rect2);
                rect.height -= this.versionControlAreaHeight;
            }
            for (int i = 0; i < 2; i++)
            {
                this.gridWidth = ((!this.m_ShowedScrollBarLastFrame) ? rect.width : (rect.width - 17f));
                this.SetupGrid(this.gridWidth, lib.Count());
                bool flag = this.m_Grid.height > rect.height;
                if (flag == this.m_ShowedScrollBarLastFrame)
                {
                    break;
                }
                this.m_ShowedScrollBarLastFrame = flag;
            }
            if ((this.m_ShowedScrollBarLastFrame || this.alwaysShowScrollAreaHorizontalLines) && Event.current.type == EventType.Repaint)
            {
                Rect rect3 = new RectOffset(1, 1, 1, 1).Add(rect);
                rect3.height = 1f;
                EditorGUI.DrawRect(rect3, new Color(0f, 0f, 0f, 0.3f));
                rect3.y += rect.height + 1f;
                EditorGUI.DrawRect(rect3, new Color(0f, 0f, 0f, 0.3f));
            }
            Rect viewRect = new Rect(0f, 0f, 1f, this.m_Grid.height);

            this.m_State.m_ScrollPosition = GUI.BeginScrollView(rect, this.m_State.m_ScrollPosition, viewRect);
            float num      = 0f;
            int   maxIndex = (!this.m_ShowAddNewPresetItem) ? (lib.Count() - 1) : lib.Count();
            int   num2;
            int   num3;
            bool  flag2 = this.m_Grid.IsVisibleInScrollView(rect.height, this.m_State.m_ScrollPosition.y, num, maxIndex, out num2, out num3);
            bool  flag3 = false;

            if (flag2)
            {
                if (this.GetRenameOverlay().IsRenaming() && !this.GetRenameOverlay().isWaitingForDelay)
                {
                    if (!this.m_State.m_RenameOverlay.OnGUI())
                    {
                        this.EndRename();
                        current.Use();
                    }
                    this.Repaint();
                }
                for (int j = num2; j <= num3; j++)
                {
                    int  num4  = j + 1000000;
                    Rect rect4 = this.m_Grid.CalcRect(j, num);
                    Rect rect5 = rect4;
                    Rect rect6 = rect4;
                    PresetLibraryEditorState.ItemViewMode itemViewMode = this.m_State.itemViewMode;
                    if (itemViewMode != PresetLibraryEditorState.ItemViewMode.Grid)
                    {
                        if (itemViewMode == PresetLibraryEditorState.ItemViewMode.List)
                        {
                            rect5.width  = this.m_State.m_PreviewHeight * this.m_PreviewAspect;
                            rect6.x     += rect5.width + 8f;
                            rect6.width -= rect5.width + 10f;
                            rect6.height = 16f;
                            rect6.y      = rect4.yMin + (rect4.height - 16f) * 0.5f;
                        }
                    }
                    if (this.m_ShowAddNewPresetItem && j == lib.Count())
                    {
                        this.CreateNewPresetButton(rect5, newPresetObject, lib, this.m_IsOpenForEdit);
                    }
                    else
                    {
                        bool flag4 = this.IsRenaming(j);
                        if (flag4)
                        {
                            Rect editFieldRect = rect6;
                            editFieldRect.y -= 1f;
                            editFieldRect.x -= 1f;
                            this.m_State.m_RenameOverlay.editFieldRect = editFieldRect;
                        }
                        switch (current.type)
                        {
                        case EventType.MouseDown:
                            if (current.button == 0 && rect4.Contains(current.mousePosition))
                            {
                                GUIUtility.hotControl = num4;
                                if (current.clickCount == 1)
                                {
                                    this.m_ItemClickedCallback(current.clickCount, lib.GetPreset(j));
                                    current.Use();
                                }
                            }
                            break;

                        case EventType.MouseUp:
                            if (GUIUtility.hotControl == num4)
                            {
                                GUIUtility.hotControl = 0;
                                if (current.button == 0 && rect4.Contains(current.mousePosition) && Event.current.alt && this.m_IsOpenForEdit)
                                {
                                    this.DeletePreset(j);
                                    current.Use();
                                }
                            }
                            break;

                        case EventType.MouseMove:
                            if (rect4.Contains(current.mousePosition))
                            {
                                if (this.m_State.m_HoverIndex != j)
                                {
                                    this.m_State.m_HoverIndex = j;
                                    this.Repaint();
                                }
                            }
                            else
                            {
                                if (this.m_State.m_HoverIndex == j)
                                {
                                    this.m_State.m_HoverIndex = -1;
                                    this.Repaint();
                                }
                            }
                            break;

                        case EventType.MouseDrag:
                            if (GUIUtility.hotControl == num4 && this.m_IsOpenForEdit)
                            {
                                DragAndDropDelay dragAndDropDelay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), num4);
                                if (dragAndDropDelay.CanStartDrag())
                                {
                                    DragAndDrop.PrepareStartDrag();
                                    DragAndDrop.SetGenericData("DraggingPreset", j);
                                    DragAndDrop.objectReferences = new UnityEngine.Object[0];
                                    DragAndDrop.StartDrag(string.Empty);
                                    this.m_DragState.draggingIndex = j;
                                    this.m_DragState.dragUponIndex = j;
                                    GUIUtility.hotControl          = 0;
                                }
                                current.Use();
                            }
                            break;

                        case EventType.Repaint:
                            if (this.m_State.m_HoverIndex == j)
                            {
                                if (!rect4.Contains(current.mousePosition))
                                {
                                    this.m_State.m_HoverIndex = -1;
                                }
                            }
                            if (this.m_DragState.draggingIndex == j || GUIUtility.hotControl == num4)
                            {
                                this.DrawHoverEffect(rect4, false);
                            }
                            lib.Draw(rect5, j);
                            if (!flag4 && this.drawLabels)
                            {
                                GUI.Label(rect6, GUIContent.Temp(lib.GetName(j)));
                            }
                            if (this.m_DragState.dragUponIndex == j && this.m_DragState.draggingIndex != this.m_DragState.dragUponIndex)
                            {
                                flag3 = true;
                            }
                            if (GUIUtility.hotControl == 0 && Event.current.alt && this.m_IsOpenForEdit)
                            {
                                EditorGUIUtility.AddCursorRect(rect4, MouseCursor.ArrowMinus);
                            }
                            break;

                        case EventType.DragUpdated:
                        case EventType.DragPerform:
                        {
                            Rect dragRect = this.GetDragRect(rect4);
                            if (dragRect.Contains(current.mousePosition))
                            {
                                this.m_DragState.dragUponIndex = j;
                                this.m_DragState.dragUponRect  = rect4;
                                if (this.m_State.itemViewMode == PresetLibraryEditorState.ItemViewMode.List)
                                {
                                    this.m_DragState.insertAfterIndex = ((current.mousePosition.y - dragRect.y) / dragRect.height > 0.5f);
                                }
                                else
                                {
                                    this.m_DragState.insertAfterIndex = ((current.mousePosition.x - dragRect.x) / dragRect.width > 0.5f);
                                }
                                bool flag5 = current.type == EventType.DragPerform;
                                if (flag5)
                                {
                                    if (this.m_DragState.draggingIndex >= 0)
                                    {
                                        this.MovePreset(this.m_DragState.draggingIndex, this.m_DragState.dragUponIndex, this.m_DragState.insertAfterIndex);
                                        DragAndDrop.AcceptDrag();
                                    }
                                    this.ClearDragState();
                                }
                                DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                                current.Use();
                            }
                            break;
                        }

                        case EventType.DragExited:
                            if (this.m_DragState.IsDragging())
                            {
                                this.ClearDragState();
                                current.Use();
                            }
                            break;

                        case EventType.ContextClick:
                            if (rect4.Contains(current.mousePosition))
                            {
                                PresetLibraryEditor <T> .PresetContextMenu.Show(this.m_IsOpenForEdit, j, newPresetObject, this);

                                current.Use();
                            }
                            break;
                        }
                    }
                }
                if (flag3)
                {
                    this.DrawDragInsertionMarker();
                }
            }
            GUI.EndScrollView();
        }
예제 #22
0
        public override void StartDrag(TreeViewItem draggedItem, List <int> draggedItemIDs)
        {
            DragAndDrop.PrepareStartDrag();
            draggedItemIDs = this.m_TreeView.SortIDsInVisiblityOrder(draggedItemIDs);
            if (!draggedItemIDs.Contains(draggedItem.id))
            {
                draggedItemIDs = new List <int>()
                {
                    draggedItem.id
                }
            }
            ;
            UnityEngine.Object[] dragAndDropObjects = ProjectWindowUtil.GetDragAndDropObjects(draggedItem.id, draggedItemIDs);
            DragAndDrop.objectReferences = dragAndDropObjects;
            List <Scene> draggedScenes = this.GetDraggedScenes(draggedItemIDs);

            if (draggedScenes != null)
            {
                DragAndDrop.SetGenericData("SceneHeaderList", (object)draggedScenes);
                List <string> stringList = new List <string>();
                using (List <Scene> .Enumerator enumerator = draggedScenes.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Scene current = enumerator.Current;
                        if (current.path.Length > 0)
                        {
                            stringList.Add(current.path);
                        }
                    }
                }
                DragAndDrop.paths = stringList.ToArray();
            }
            else
            {
                DragAndDrop.paths = new string[0];
            }
            string title;

            if (draggedItemIDs.Count > 1)
            {
                title = "<Multiple>";
            }
            else if (dragAndDropObjects.Length == 1)
            {
                title = ObjectNames.GetDragAndDropTitle(dragAndDropObjects[0]);
            }
            else if (draggedScenes != null && draggedScenes.Count == 1)
            {
                title = draggedScenes[0].path;
            }
            else
            {
                title = "Unhandled dragged item";
                Debug.LogError((object)"Unhandled dragged item");
            }
            DragAndDrop.StartDrag(title);
            if (!(this.m_TreeView.data is GameObjectTreeViewDataSource))
            {
                return;
            }
            ((GameObjectTreeViewDataSource)this.m_TreeView.data).SetupChildParentReferencesIfNeeded();
        }
        public override void StartDrag(TreeViewItem draggedItem, List <int> draggedItemIDs)
        {
            DragAndDrop.PrepareStartDrag();
            if (Event.current.control || Event.current.command)
            {
                draggedItemIDs.Add(draggedItem.id);
            }
            draggedItemIDs = this.m_TreeView.SortIDsInVisiblityOrder(draggedItemIDs);
            if (!draggedItemIDs.Contains(draggedItem.id))
            {
                draggedItemIDs = new List <int>
                {
                    draggedItem.id
                };
            }
            UnityEngine.Object[] dragAndDropObjects = ProjectWindowUtil.GetDragAndDropObjects(draggedItem.id, draggedItemIDs);
            DragAndDrop.objectReferences = dragAndDropObjects;
            List <Scene> draggedScenes = this.GetDraggedScenes(draggedItemIDs);

            if (draggedScenes != null)
            {
                DragAndDrop.SetGenericData("SceneHeaderList", draggedScenes);
                List <string> list = new List <string>();
                foreach (Scene current in draggedScenes)
                {
                    if (current.path.Length > 0)
                    {
                        list.Add(current.path);
                    }
                }
                DragAndDrop.paths = list.ToArray();
            }
            else
            {
                DragAndDrop.paths = new string[0];
            }
            string title;

            if (draggedItemIDs.Count > 1)
            {
                title = "<Multiple>";
            }
            else if (dragAndDropObjects.Length == 1)
            {
                title = ObjectNames.GetDragAndDropTitle(dragAndDropObjects[0]);
            }
            else if (draggedScenes != null && draggedScenes.Count == 1)
            {
                title = draggedScenes[0].path;
            }
            else
            {
                title = "Unhandled dragged item";
                Debug.LogError("Unhandled dragged item");
            }
            DragAndDrop.StartDrag(title);
            if (this.m_TreeView.data is GameObjectTreeViewDataSource)
            {
                ((GameObjectTreeViewDataSource)this.m_TreeView.data).SetupChildParentReferencesIfNeeded();
            }
        }
예제 #24
0
        internal static void DoBoneHandle(Transform target, Dictionary <Transform, bool> validBones)
        {
            int   id  = target.name.GetHashCode();
            Event evt = Event.current;

            bool hasValidChildBones = false;

            if (validBones != null)
            {
                foreach (Transform child in target)
                {
                    if (validBones.ContainsKey(child))
                    {
                        hasValidChildBones = true;
                        break;
                    }
                }
            }

            Vector3 basePoint = target.position;

            List <Vector3> endPoints = new List <Vector3>();

            // [case 525602] do not draw root.
            if (!hasValidChildBones && target.parent != null)
            {
                endPoints.Add(target.position + (target.position - target.parent.position) * 0.4f);
            }
            else
            {
                foreach (Transform child in target)
                {
                    // Only render bone connections to valid bones
                    // (except if no child bones are valid - then draw all connections)
                    if (validBones != null && !validBones.ContainsKey(child))
                    {
                        continue;
                    }

                    endPoints.Add(child.position);
                }
            }

            for (int i = 0; i < endPoints.Count; i++)
            {
                Vector3 endPoint = endPoints[i];


                switch (evt.GetTypeForControl(id))
                {
                case EventType.Layout:
                {
                    float     len      = Vector3.Magnitude(endPoint - basePoint);
                    float     size     = len * k_BoneThickness;
                    Vector3[] vertices = GetBoneVertices(endPoint, basePoint, size);

                    HandleUtility.AddControl(id, DistanceToPolygone(vertices));

                    break;
                }

                case EventType.MouseMove:
                    if (id == HandleUtility.nearestControl)
                    {
                        HandleUtility.Repaint();
                    }
                    break;

                case EventType.MouseDown:
                {
                    // am I closest to the thingy?
                    if (!evt.alt && HandleUtility.nearestControl == id && evt.button == 0)
                    {
                        GUIUtility.hotControl = id;     // Grab mouse focus
                        if (evt.shift)
                        {
                            Object[] selected = Selection.objects;
                            if (ArrayUtility.Contains(selected, target) == false)
                            {
                                ArrayUtility.Add(ref selected, target);
                                Selection.objects = selected;
                            }
                        }
                        else
                        {
                            Selection.activeObject = target;
                        }

                        EditorGUIUtility.PingObject(target);

                        evt.Use();
                    }
                    break;
                }

                case EventType.MouseDrag:
                {
                    if (!evt.alt && GUIUtility.hotControl == id)
                    {
                        DragAndDrop.PrepareStartDrag();
                        DragAndDrop.objectReferences = new UnityEngine.Object[] { target };
                        DragAndDrop.StartDrag(ObjectNames.GetDragAndDropTitle(target));

                        // having a hot control set during drag makes the control eat the drag events
                        // and dragging of bones no longer works over the avatar configure window
                        // see case 912016
                        GUIUtility.hotControl = 0;

                        evt.Use();
                    }
                    break;
                }

                case EventType.MouseUp:
                {
                    if (GUIUtility.hotControl == id && (evt.button == 0 || evt.button == 2))
                    {
                        GUIUtility.hotControl = 0;
                        evt.Use();
                    }
                    break;
                }

                case EventType.Repaint:
                {
                    float len = Vector3.Magnitude(endPoint - basePoint);
                    if (len > 0)
                    {
                        color = GUIUtility.hotControl == 0 && HandleUtility.nearestControl == id ? Handles.preselectionColor : color;

                        // size used to be based on sqrt of length but that makes bones for
                        // huge creatures hair-thin and bones for tiny creatures bulky.
                        // So base on a fixed proportion instead.
                        float size = len * k_BoneThickness;
                        if (hasValidChildBones)
                        {
                            Handles.DrawBone(endPoint, basePoint, size);
                        }
                        else
                        {
                            Handles.SphereHandleCap(id, basePoint, target.rotation, size * .2f, EventType.Repaint);
                        }
                    }
                    break;
                }
                }
            }
        }
예제 #25
0
        private void ListArea(Rect rect, PresetLibrary lib, object newPresetObject)
        {
            if ((UnityEngine.Object)lib == (UnityEngine.Object)null)
            {
                return;
            }
            Event current = Event.current;

            if (this.m_PresetLibraryFileLocation == PresetFileLocation.ProjectFolder && current.type == EventType.Repaint)
            {
                this.m_IsOpenForEdit = AssetDatabase.IsOpenForEdit(this.pathWithExtension);
            }
            else if (this.m_PresetLibraryFileLocation == PresetFileLocation.PreferencesFolder)
            {
                this.m_IsOpenForEdit = true;
            }
            if (!this.m_IsOpenForEdit)
            {
                this.VersionControlArea(new Rect(rect.x, rect.yMax - this.versionControlAreaHeight, rect.width, this.versionControlAreaHeight));
                rect.height -= this.versionControlAreaHeight;
            }
            for (int index = 0; index < 2; ++index)
            {
                this.gridWidth = !this.m_ShowedScrollBarLastFrame ? rect.width : rect.width - 17f;
                this.SetupGrid(this.gridWidth, lib.Count());
                bool flag = (double)this.m_Grid.height > (double)rect.height;
                if (flag != this.m_ShowedScrollBarLastFrame)
                {
                    this.m_ShowedScrollBarLastFrame = flag;
                }
                else
                {
                    break;
                }
            }
            if ((this.m_ShowedScrollBarLastFrame || this.alwaysShowScrollAreaHorizontalLines) && Event.current.type == EventType.Repaint)
            {
                Rect rect1 = new RectOffset(1, 1, 1, 1).Add(rect);
                rect1.height = 1f;
                EditorGUI.DrawRect(rect1, new Color(0.0f, 0.0f, 0.0f, 0.3f));
                rect1.y += rect.height + 1f;
                EditorGUI.DrawRect(rect1, new Color(0.0f, 0.0f, 0.0f, 0.3f));
            }
            Rect viewRect = new Rect(0.0f, 0.0f, 1f, this.m_Grid.height);

            this.m_State.m_ScrollPosition = GUI.BeginScrollView(rect, this.m_State.m_ScrollPosition, viewRect);
            float num      = 0.0f;
            int   maxIndex = !this.m_ShowAddNewPresetItem ? lib.Count() - 1 : lib.Count();
            int   startIndex;
            int   endIndex;
            bool  flag1 = this.m_Grid.IsVisibleInScrollView(rect.height, this.m_State.m_ScrollPosition.y, num, maxIndex, out startIndex, out endIndex);
            bool  flag2 = false;

            if (flag1)
            {
                if (this.GetRenameOverlay().IsRenaming() && !this.GetRenameOverlay().isWaitingForDelay)
                {
                    if (!this.m_State.m_RenameOverlay.OnGUI())
                    {
                        this.EndRename();
                        current.Use();
                    }
                    this.Repaint();
                }
                for (int index = startIndex; index <= endIndex; ++index)
                {
                    int  controlID = index + 1000000;
                    Rect rect1     = this.m_Grid.CalcRect(index, num);
                    Rect rect2     = rect1;
                    Rect position  = rect1;
                    switch (this.m_State.itemViewMode)
                    {
                    case PresetLibraryEditorState.ItemViewMode.List:
                        rect2.width     = this.m_State.m_PreviewHeight * this.m_PreviewAspect;
                        position.x     += rect2.width + 8f;
                        position.width -= rect2.width + 10f;
                        position.height = 16f;
                        position.y      = rect1.yMin + (float)(((double)rect1.height - 16.0) * 0.5);
                        break;
                    }
                    if (this.m_ShowAddNewPresetItem && index == lib.Count())
                    {
                        this.CreateNewPresetButton(rect2, newPresetObject, lib, this.m_IsOpenForEdit);
                    }
                    else
                    {
                        bool flag3 = this.IsRenaming(index);
                        if (flag3)
                        {
                            Rect rect3 = position;
                            --rect3.y;
                            --rect3.x;
                            this.m_State.m_RenameOverlay.editFieldRect = rect3;
                        }
                        switch (current.type)
                        {
                        case EventType.MouseDown:
                            if (current.button == 0 && rect1.Contains(current.mousePosition))
                            {
                                GUIUtility.hotControl = controlID;
                                if (current.clickCount == 1)
                                {
                                    this.m_ItemClickedCallback(current.clickCount, lib.GetPreset(index));
                                    current.Use();
                                    continue;
                                }
                                continue;
                            }
                            continue;

                        case EventType.MouseUp:
                            if (GUIUtility.hotControl == controlID)
                            {
                                GUIUtility.hotControl = 0;
                                if (current.button == 0 && rect1.Contains(current.mousePosition) && (Event.current.alt && this.m_IsOpenForEdit))
                                {
                                    this.DeletePreset(index);
                                    current.Use();
                                    continue;
                                }
                                continue;
                            }
                            continue;

                        case EventType.MouseMove:
                            if (rect1.Contains(current.mousePosition))
                            {
                                if (this.m_State.m_HoverIndex != index)
                                {
                                    this.m_State.m_HoverIndex = index;
                                    this.Repaint();
                                    continue;
                                }
                                continue;
                            }
                            if (this.m_State.m_HoverIndex == index)
                            {
                                this.m_State.m_HoverIndex = -1;
                                this.Repaint();
                                continue;
                            }
                            continue;

                        case EventType.MouseDrag:
                            if (GUIUtility.hotControl == controlID && this.m_IsOpenForEdit)
                            {
                                if (((DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), controlID)).CanStartDrag())
                                {
                                    DragAndDrop.PrepareStartDrag();
                                    DragAndDrop.SetGenericData("DraggingPreset", (object)index);
                                    DragAndDrop.objectReferences = new UnityEngine.Object[0];
                                    DragAndDrop.StartDrag(string.Empty);
                                    this.m_DragState.draggingIndex = index;
                                    this.m_DragState.dragUponIndex = index;
                                    GUIUtility.hotControl          = 0;
                                }
                                current.Use();
                                continue;
                            }
                            continue;

                        case EventType.Repaint:
                            if (this.m_State.m_HoverIndex == index && !rect1.Contains(current.mousePosition))
                            {
                                this.m_State.m_HoverIndex = -1;
                            }
                            if (this.m_DragState.draggingIndex == index || GUIUtility.hotControl == controlID)
                            {
                                this.DrawHoverEffect(rect1, false);
                            }
                            lib.Draw(rect2, index);
                            if (!flag3 && this.drawLabels)
                            {
                                GUI.Label(position, GUIContent.Temp(lib.GetName(index)));
                            }
                            if (this.m_DragState.dragUponIndex == index && this.m_DragState.draggingIndex != this.m_DragState.dragUponIndex)
                            {
                                flag2 = true;
                            }
                            if (GUIUtility.hotControl == 0 && Event.current.alt && this.m_IsOpenForEdit)
                            {
                                EditorGUIUtility.AddCursorRect(rect1, MouseCursor.ArrowMinus);
                                continue;
                            }
                            continue;

                        case EventType.DragUpdated:
                        case EventType.DragPerform:
                            Rect dragRect = this.GetDragRect(rect1);
                            if (dragRect.Contains(current.mousePosition))
                            {
                                this.m_DragState.dragUponIndex    = index;
                                this.m_DragState.dragUponRect     = rect1;
                                this.m_DragState.insertAfterIndex = this.m_State.itemViewMode != PresetLibraryEditorState.ItemViewMode.List ? ((double)current.mousePosition.x - (double)dragRect.x) / (double)dragRect.width > 0.5 : ((double)current.mousePosition.y - (double)dragRect.y) / (double)dragRect.height > 0.5;
                                if (current.type == EventType.DragPerform)
                                {
                                    if (this.m_DragState.draggingIndex >= 0)
                                    {
                                        this.MovePreset(this.m_DragState.draggingIndex, this.m_DragState.dragUponIndex, this.m_DragState.insertAfterIndex);
                                        DragAndDrop.AcceptDrag();
                                    }
                                    this.ClearDragState();
                                }
                                DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                                current.Use();
                                continue;
                            }
                            continue;

                        case EventType.DragExited:
                            if (this.m_DragState.IsDragging())
                            {
                                this.ClearDragState();
                                current.Use();
                                continue;
                            }
                            continue;

                        case EventType.ContextClick:
                            if (rect1.Contains(current.mousePosition))
                            {
                                PresetLibraryEditor <T> .PresetContextMenu.Show(this.m_IsOpenForEdit, index, newPresetObject, this);

                                current.Use();
                                continue;
                            }
                            continue;

                        default:
                            continue;
                        }
                    }
                }
                if (flag2)
                {
                    this.DrawDragInsertionMarker();
                }
            }
            GUI.EndScrollView();
        }
예제 #26
0
            public bool MoveNext()
            {
                if (xPos > -1)
                {
                    if (ListViewShared.HasMouseDown(ilvState, rect))
                    {
                        var previousRow = ilvState.state.row;
                        ilvState.state.selectionChanged = true;
                        ilvState.state.row       = yPos;
                        ilvState.state.column    = xPos;
                        ilvState.state.scrollPos = ListViewShared.ListViewScrollToRow(ilvState, yPos); // this is about clicking on a row that is partially visible

                        if (ilvState.wantsRowMultiSelection)
                        {
                            MultiSelection(ilvState, previousRow);
                        }

                        if ((ilvState.wantsReordering || ilvState.wantsToStartCustomDrag) && (GUIUtility.hotControl == ilvState.state.ID))
                        {
                            DragAndDropDelay delay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), ilvState.state.ID);
                            delay.mouseDownPosition = Event.current.mousePosition;
                            ilvState.dragItem       = yPos;
                            dragControlID           = ilvState.state.ID;
                        }
                    }
                    // On Mouse drag, start drag & drop
                    if (!ListViewShared.isDragging &&
                        (ilvState.wantsReordering || ilvState.wantsToStartCustomDrag) &&
                        GUIUtility.hotControl == ilvState.state.ID &&
                        Event.current.type == EventType.MouseDrag &&
                        GUIClip.visibleRect.Contains(Event.current.mousePosition))
                    {
                        DragAndDropDelay delay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), ilvState.state.ID);

                        if (delay.CanStartDrag())
                        {
                            DragAndDrop.PrepareStartDrag();

                            DragAndDrop.objectReferences = new UnityEngine.Object[] {};  // this IS required for dragging to work
                            DragAndDrop.paths            = null;

                            if (ilvState.wantsReordering)
                            {
                                ilvState.state.dropHereRect = new Rect(ilvState.rect.x, 0, ilvState.rect.width, ilvState.state.rowHeight * 2);
                                DragAndDrop.StartDrag(dragTitle);
                            }
                            else if (ilvState.wantsToStartCustomDrag)
                            {
                                DragAndDrop.SetGenericData("CustomDragID", ilvState.state.ID);
                                DragAndDrop.StartDrag(dragTitle);
                            }

                            ListViewShared.isDragging = true;
                        }

                        Event.current.Use();
                    }
                }

                xPos++;

                if (xPos > xTo)
                {
                    xPos = 0;
                    yPos++;

                    rect.x     = firstRect.x;
                    rect.width = colWidths[0];

                    if (yPos > yTo)
                    {
                        quiting = true;
                    }
                    else // move vertically
                    {
                        rect.y += rect.height;
                    }
                }
                else // move horizontally
                {
                    if (xPos >= 1)
                    {
                        rect.x += colWidths[xPos - 1];
                    }

                    rect.width = colWidths[xPos];
                }

                element.row      = yPos;
                element.column   = xPos;
                element.position = rect;

                if (element.row >= ilvState.state.totalRows)
                {
                    quiting = true;
                }

                if (isLayouted && Event.current.type == EventType.Layout)
                {
                    // this is just "on layout event enumerate just first row" (so we get height of single row)
                    if (yFrom + 1 == yPos)
                    {
                        quiting = true;
                    }
                }

                if (isLayouted && yPos != yFrom)
                {
                    GUILayout.EndHorizontal();
                }

                if (quiting)
                {
                    if (ilvState.state.drawDropHere && Event.current.GetTypeForControl(ilvState.state.ID) == EventType.Repaint)
                    {
                        GUIStyle insertion = Constants.insertion;
                        insertion.Draw(insertion.margin.Remove(ilvState.state.dropHereRect), false, false, false, false);
                    }

                    if (ListViewShared.ListViewKeyboard(ilvState, colWidths.Length))
                    {
                        ilvState.state.selectionChanged = true;
                    }

                    if (Event.current.GetTypeForControl(ilvState.state.ID) == EventType.MouseUp)
                    {
                        GUIUtility.hotControl = 0;
                    }

                    if (ilvState.wantsReordering && (GUIUtility.hotControl == ilvState.state.ID))
                    {
                        ListViewState lv = ilvState.state;

                        switch (Event.current.type)
                        {
                        case EventType.DragUpdated:
                        {
                            DragAndDrop.visualMode = ilvState.rect.Contains(Event.current.mousePosition) ?
                                                     DragAndDropVisualMode.Move : DragAndDropVisualMode.None;

                            Event.current.Use();

                            if (DragAndDrop.visualMode != DragAndDropVisualMode.None)
                            {
                                lv.dropHereRect.y = (Mathf.RoundToInt(Event.current.mousePosition.y / lv.rowHeight) - 1) * lv.rowHeight;

                                if (lv.dropHereRect.y >= lv.rowHeight * lv.totalRows)
                                {
                                    lv.dropHereRect.y = lv.rowHeight * (lv.totalRows - 1);
                                }

                                lv.drawDropHere = true;
                            }

                            break;
                        }

                        case EventType.DragPerform:
                        {
                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition))
                            {
                                ilvState.state.draggedFrom = ilvState.dragItem;
                                ilvState.state.draggedTo   = Mathf.RoundToInt(Event.current.mousePosition.y / lv.rowHeight);

                                if (ilvState.state.draggedTo > ilvState.state.totalRows)
                                {
                                    ilvState.state.draggedTo = ilvState.state.totalRows;
                                }

                                // the guy handling this would better actually rearrange items...
                                if (ilvState.state.draggedTo > ilvState.state.draggedFrom)
                                {
                                    ilvState.state.row = ilvState.state.draggedTo - 1;
                                }
                                else
                                {
                                    ilvState.state.row = ilvState.state.draggedTo;
                                }

                                ilvState.state.selectionChanged = true;

                                DragAndDrop.AcceptDrag();
                                Event.current.Use();
                                ilvState.wantsReordering    = false;
                                ilvState.state.drawDropHere = false;
                            }

                            GUIUtility.hotControl = 0;
                            break;
                        }

                        case EventType.DragExited:
                        {
                            ilvState.wantsReordering    = false;
                            ilvState.state.drawDropHere = false;

                            GUIUtility.hotControl = 0;
                            break;
                        }
                        }
                    }
                    else if (ilvState.wantsExternalFiles)
                    {
                        switch (Event.current.type)
                        {
                        case EventType.DragUpdated:
                        {
                            if ((GUIClip.visibleRect.Contains(Event.current.mousePosition)) &&
                                (DragAndDrop.paths != null) && (DragAndDrop.paths.Length != 0))             // dragging files from somewhere
                            {
                                DragAndDrop.visualMode = ilvState.rect.Contains(Event.current.mousePosition) ?
                                                         DragAndDropVisualMode.Copy : DragAndDropVisualMode.None;

                                Event.current.Use();

                                if (DragAndDrop.visualMode != DragAndDropVisualMode.None)
                                {
                                    ilvState.state.dropHereRect = new Rect(ilvState.rect.x,
                                                                           (Mathf.RoundToInt(Event.current.mousePosition.y / ilvState.state.rowHeight) - 1) * ilvState.state.rowHeight,
                                                                           ilvState.rect.width, ilvState.state.rowHeight);

                                    if (ilvState.state.dropHereRect.y >= ilvState.state.rowHeight * ilvState.state.totalRows)
                                    {
                                        ilvState.state.dropHereRect.y = ilvState.state.rowHeight * (ilvState.state.totalRows - 1);
                                    }

                                    ilvState.state.drawDropHere = true;
                                }
                            }
                            break;
                        }

                        case EventType.DragPerform:
                        {
                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition))
                            {
                                ilvState.state.fileNames = DragAndDrop.paths;
                                DragAndDrop.AcceptDrag();
                                Event.current.Use();
                                ilvState.wantsExternalFiles = false;
                                ilvState.state.drawDropHere = false;
                                ilvState.state.draggedTo    = Mathf.RoundToInt(Event.current.mousePosition.y / ilvState.state.rowHeight);
                                if (ilvState.state.draggedTo > ilvState.state.totalRows)
                                {
                                    ilvState.state.draggedTo = ilvState.state.totalRows;
                                }
                                ilvState.state.row = ilvState.state.draggedTo;
                            }

                            GUIUtility.hotControl = 0;

                            break;
                        }

                        case EventType.DragExited:
                        {
                            ilvState.wantsExternalFiles = false;
                            ilvState.state.drawDropHere = false;

                            GUIUtility.hotControl = 0;
                            break;
                        }
                        }
                    }
                    else if (ilvState.wantsToAcceptCustomDrag && (dragControlID != ilvState.state.ID))
                    {
                        switch (Event.current.type)
                        {
                        case EventType.DragUpdated:
                        {
                            object data = DragAndDrop.GetGenericData("CustomDragID");

                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition) && data != null)
                            {
                                DragAndDrop.visualMode = ilvState.rect.Contains(Event.current.mousePosition) ?
                                                         DragAndDropVisualMode.Move : DragAndDropVisualMode.None;

                                Event.current.Use();
                            }
                            break;
                        }

                        case EventType.DragPerform:
                        {
                            object data = DragAndDrop.GetGenericData("CustomDragID");

                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition) && data != null)
                            {
                                ilvState.state.customDraggedFromID = (int)data;
                                DragAndDrop.AcceptDrag();
                                Event.current.Use();
                            }

                            GUIUtility.hotControl = 0;
                            break;
                        }

                        case EventType.DragExited:
                        {
                            GUIUtility.hotControl = 0;
                            break;
                        }
                        }
                    }

                    if (ilvState.beganHorizontal)
                    {
                        EditorGUILayout.EndScrollView();
                        GUILayout.EndHorizontal();
                        ilvState.beganHorizontal = false;
                    }

                    if (isLayouted)
                    {
                        GUILayoutUtility.EndLayoutGroup();
                        EditorGUILayout.EndScrollView();
                    }

                    ilvState.wantsReordering    = false;
                    ilvState.wantsExternalFiles = false;
                }
                else if (isLayouted)
                {
                    if (yPos != yFrom)
                    {
                        ilvStateL.group.ResetCursor();
                        ilvStateL.group.AddY();
                    }
                    else
                    {
                        ilvStateL.group.AddY(ilvState.invisibleRows * ilvState.state.rowHeight);
                    }
                }

                if (isLayouted)
                {
                    if (!quiting)
                    {
                        GUILayout.BeginHorizontal(GUIStyle.none); // for each row
                    }
                    else
                    {
                        GUILayout.EndHorizontal(); // the one used for drawing LVs background
                    }
                }

                return(!quiting);
            }
예제 #27
0
        void ListArea(Rect rect, PresetLibrary lib, object newPresetObject)
        {
            if (lib == null)
            {
                return;
            }

            Event evt = Event.current;

            if (m_PresetLibraryFileLocation == PresetFileLocation.ProjectFolder && evt.type == EventType.Repaint)
            {
                m_IsOpenForEdit = AssetDatabase.IsOpenForEdit(pathWithExtension, StatusQueryOptions.UseCachedIfPossible);
            }
            else if (m_PresetLibraryFileLocation == PresetFileLocation.PreferencesFolder)
            {
                m_IsOpenForEdit = true;
            }

            if (!m_IsOpenForEdit)
            {
                Rect versionControlRect = new Rect(rect.x, rect.yMax - versionControlAreaHeight, rect.width, versionControlAreaHeight);
                VersionControlArea(versionControlRect);
                rect.height -= versionControlAreaHeight;
            }

            // To ensure we setup grid to visible rect we need to run once to check if scrollbar is taking up screen estate.
            // To optimize the first width is based on the last frame and we therefore most likely will only run once.
            for (int i = 0; i < 2; i++)
            {
                gridWidth = m_ShowedScrollBarLastFrame ? rect.width - 17 : rect.width;
                SetupGrid(gridWidth, lib.Count());
                bool isShowingScrollBar = m_Grid.height > rect.height;
                if (isShowingScrollBar == m_ShowedScrollBarLastFrame)
                {
                    break;
                }
                else
                {
                    m_ShowedScrollBarLastFrame = isShowingScrollBar;
                }
            }

            // Draw horizontal lines for scrollview content to clip against
            if ((m_ShowedScrollBarLastFrame || alwaysShowScrollAreaHorizontalLines) && Event.current.type == EventType.Repaint)
            {
                Rect scrollEdgeRect = new RectOffset(1, 1, 1, 1).Add(rect);
                scrollEdgeRect.height = 1;
                EditorGUI.DrawRect(scrollEdgeRect, new Color(0, 0, 0, 0.3f));
                scrollEdgeRect.y += rect.height + 1;
                EditorGUI.DrawRect(scrollEdgeRect, new Color(0, 0, 0, 0.3f));
            }

            Rect contentRect = new Rect(0, 0, 1, m_Grid.height);

            m_State.m_ScrollPosition = GUI.BeginScrollView(rect, m_State.m_ScrollPosition, contentRect);
            {
                int   startIndex, endIndex;
                float yOffset                 = 0f;
                int   maxIndex                = m_ShowAddNewPresetItem ? lib.Count() : lib.Count() - 1;
                bool  isGridVisible           = m_Grid.IsVisibleInScrollView(rect.height, m_State.m_ScrollPosition.y, yOffset, maxIndex, out startIndex, out endIndex);
                bool  drawDragInsertionMarker = false;
                if (isGridVisible)
                {
                    // Handle renaming overlay before item handling because its needs mouse input first to end renaming if clicked outside
                    if (GetRenameOverlay().IsRenaming() && !GetRenameOverlay().isWaitingForDelay)
                    {
                        if (!m_State.m_RenameOverlay.OnGUI())
                        {
                            EndRename();
                            evt.Use();
                        }
                        Repaint();
                    }

                    for (int i = startIndex; i <= endIndex; ++i)
                    {
                        int itemControlID = i + 1000000;

                        Rect itemRect    = m_Grid.CalcRect(i, yOffset);
                        Rect previewRect = itemRect;
                        Rect labelRect   = itemRect;
                        switch (m_State.itemViewMode)
                        {
                        case PresetLibraryEditorState.ItemViewMode.List:
                            previewRect.width = m_State.m_PreviewHeight * m_PreviewAspect;
                            labelRect.x      += previewRect.width + 8f;
                            labelRect.width  -= previewRect.width + 10f;
                            labelRect.height  = kGridLabelHeight;
                            labelRect.y       = itemRect.yMin + (itemRect.height - kGridLabelHeight) * 0.5f;
                            break;

                        case PresetLibraryEditorState.ItemViewMode.Grid:
                            // only preview is shown: no label
                            break;
                        }

                        // Add new preset button
                        if (m_ShowAddNewPresetItem && i == lib.Count())
                        {
                            CreateNewPresetButton(previewRect, newPresetObject, lib, m_IsOpenForEdit);
                            continue;
                        }

                        // Rename overlay
                        bool isRenamingThisItem = IsRenaming(i);
                        if (isRenamingThisItem)
                        {
                            Rect renameRect = labelRect;
                            renameRect.y -= 1f; renameRect.x -= 1f; // adjustment to fit perfectly
                            m_State.m_RenameOverlay.editFieldRect = renameRect;
                        }

                        // Handle event
                        switch (evt.type)
                        {
                        case EventType.Repaint:
                            if (m_State.m_HoverIndex == i)
                            {
                                if (itemRect.Contains(evt.mousePosition))
                                {
                                    // TODO: We need a better hover effect so disabling for now...
                                    //if (!GetRenameOverlay().IsRenaming ())
                                    //  DrawHoverEffect (itemRect, false);
                                }
                                else
                                {
                                    m_State.m_HoverIndex = -1;
                                }
                            }

                            if (m_DragState.draggingIndex == i || GUIUtility.hotControl == itemControlID)
                            {
                                DrawHoverEffect(itemRect, false);
                            }

                            lib.Draw(previewRect, i);
                            if (!isRenamingThisItem && drawLabels)
                            {
                                GUI.Label(labelRect, GUIContent.Temp(lib.GetName(i)));
                            }

                            if (m_DragState.dragUponIndex == i && m_DragState.draggingIndex != m_DragState.dragUponIndex)
                            {
                                drawDragInsertionMarker = true;
                            }

                            // We delete presets on alt-click
                            if (GUIUtility.hotControl == 0 && Event.current.alt && m_IsOpenForEdit)
                            {
                                EditorGUIUtility.AddCursorRect(itemRect, MouseCursor.ArrowMinus);
                            }

                            break;

                        case EventType.MouseDown:
                            if (evt.button == 0 && itemRect.Contains(evt.mousePosition))
                            {
                                GUIUtility.hotControl = itemControlID;
                                if (evt.clickCount == 1)
                                {
                                    m_ItemClickedCallback(evt.clickCount, lib.GetPreset(i));
                                    evt.Use();
                                }
                            }
                            break;

                        case EventType.MouseDrag:
                            if (GUIUtility.hotControl == itemControlID && m_IsOpenForEdit)
                            {
                                DragAndDropDelay delay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), itemControlID);
                                if (delay.CanStartDrag())
                                {
                                    // Start drag
                                    DragAndDrop.PrepareStartDrag();
                                    DragAndDrop.SetGenericData("DraggingPreset", i);
                                    DragAndDrop.StartDrag("");
                                    m_DragState.draggingIndex = i;
                                    m_DragState.dragUponIndex = i;
                                    GUIUtility.hotControl     = 0;
                                }
                                evt.Use();
                            }
                            break;

                        case EventType.DragUpdated:
                        case EventType.DragPerform:
                        {
                            Rect dragRect = GetDragRect(itemRect);
                            if (dragRect.Contains(evt.mousePosition))
                            {
                                m_DragState.dragUponIndex = i;
                                m_DragState.dragUponRect  = itemRect;

                                if (m_State.itemViewMode == PresetLibraryEditorState.ItemViewMode.List)
                                {
                                    m_DragState.insertAfterIndex = ((evt.mousePosition.y - dragRect.y) / dragRect.height) > 0.5f;
                                }
                                else
                                {
                                    m_DragState.insertAfterIndex = ((evt.mousePosition.x - dragRect.x) / dragRect.width) > 0.5f;
                                }

                                bool perform = evt.type == EventType.DragPerform;
                                if (perform)
                                {
                                    if (m_DragState.draggingIndex >= 0)
                                    {
                                        MovePreset(m_DragState.draggingIndex, m_DragState.dragUponIndex, m_DragState.insertAfterIndex);
                                        DragAndDrop.AcceptDrag();
                                    }
                                    ClearDragState();
                                }
                                DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                                evt.Use();
                            }
                        }
                        break;

                        case EventType.DragExited:
                            if (m_DragState.IsDragging())
                            {
                                ClearDragState();
                                evt.Use();
                            }
                            break;

                        case EventType.MouseUp:
                            if (GUIUtility.hotControl == itemControlID)
                            {
                                GUIUtility.hotControl = 0;
                                if (evt.button == 0 && itemRect.Contains(evt.mousePosition))
                                {
                                    if (Event.current.alt && m_IsOpenForEdit)
                                    {
                                        DeletePreset(i);
                                        evt.Use();
                                    }
                                }
                            }
                            break;

                        case EventType.ContextClick:
                            if (itemRect.Contains(evt.mousePosition))
                            {
                                PresetContextMenu.Show(m_IsOpenForEdit, i, newPresetObject, this);
                                evt.Use();
                            }
                            break;

                        case EventType.MouseMove:
                            if (itemRect.Contains(evt.mousePosition))
                            {
                                if (m_State.m_HoverIndex != i)
                                {
                                    m_State.m_HoverIndex = i;
                                    Repaint();
                                }
                            }
                            else if (m_State.m_HoverIndex == i)
                            {
                                m_State.m_HoverIndex = -1;
                                Repaint();
                            }

                            break;
                        }
                    } // end foreach item

                    // Draw above all items
                    if (drawDragInsertionMarker)
                    {
                        DrawDragInsertionMarker();
                    }
                }
            } GUI.EndScrollView();
        }