GetDragAndDropTitle() private method

private GetDragAndDropTitle ( Object obj ) : string
obj Object
return string
Exemplo n.º 1
0
        internal static bool HandleDelayedDrag(Rect position, int id, Object objectToDrag)
        {
            Event current = Event.current;

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

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id && ((DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), id)).CanStartDrag())
                {
                    GUIUtility.hotControl = 0;
                    DragAndDrop.PrepareStartDrag();
                    DragAndDrop.objectReferences = new Object[1] {
                        objectToDrag
                    };
                    DragAndDrop.StartDrag(ObjectNames.GetDragAndDropTitle(objectToDrag));
                    return(true);
                }
                break;
            }
            return(false);
        }
Exemplo n.º 2
0
        internal static void StartDrag(int draggedInstanceID, List <int> selectedInstanceIDs)
        {
            DragAndDrop.PrepareStartDrag();
            string title = "";

            if (ProjectWindowUtil.IsFavoritesItem(draggedInstanceID))
            {
                DragAndDrop.SetGenericData(ProjectWindowUtil.k_DraggingFavoriteGenericData, 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) ? "" : "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);
        }
Exemplo n.º 3
0
        internal static bool HandleDelayedDrag(Rect position, int id, UnityEngine.Object objectToDrag)
        {
            Event     current        = Event.current;
            EventType typeForControl = current.GetTypeForControl(id);

            if (typeForControl != EventType.MouseDown)
            {
                if ((typeForControl == EventType.MouseDrag) && (GUIUtility.hotControl == id))
                {
                    DragAndDropDelay stateObject = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), id);
                    if (stateObject.CanStartDrag())
                    {
                        GUIUtility.hotControl = 0;
                        PrepareStartDrag();
                        UnityEngine.Object[] objArray = new UnityEngine.Object[] { objectToDrag };
                        objectReferences = objArray;
                        StartDrag(ObjectNames.GetDragAndDropTitle(objectToDrag));
                        return(true);
                    }
                }
            }
            else if ((position.Contains(current.mousePosition) && (current.clickCount == 1)) && ((current.button == 0) && ((Application.platform != RuntimePlatform.OSXEditor) || !current.control)))
            {
                GUIUtility.hotControl = id;
                DragAndDropDelay delay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), id);
                delay.mouseDownPosition = current.mousePosition;
                return(true);
            }
            return(false);
        }
Exemplo n.º 4
0
        internal static void StartDrag(int draggedInstanceID, List <int> selectedInstanceIDs)
        {
            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);
        }
        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", 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();
            }
        }
Exemplo n.º 6
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)));
     }
 }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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();
     }
 }
Exemplo n.º 9
0
        internal static bool HandleDelayedDrag(Rect position, int id, UnityEngine.Object objectToDrag)
        {
            Event current = Event.current;

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

            case EventType.MouseDrag:
            {
                if (GUIUtility.hotControl != id)
                {
                    break;
                }
                DragAndDropDelay delay2 = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), id);
                if (!delay2.CanStartDrag())
                {
                    break;
                }
                GUIUtility.hotControl = 0;
                PrepareStartDrag();
                UnityEngine.Object[] objArray = new UnityEngine.Object[] { objectToDrag };
                objectReferences = objArray;
                StartDrag(ObjectNames.GetDragAndDropTitle(objectToDrag));
                return(true);
            }
            }
            return(false);
        }
        // HandleDelayedDrag can be used to start a drag and drop
        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))
                    {
                        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;
                        PrepareStartDrag();
                        Object[] references = { objectToDrag };
                        objectReferences = references;
                        StartDrag(ObjectNames.GetDragAndDropTitle(objectToDrag));
                        return(true);
                    }
                }
                break;
            }
            return(false);
        }
        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); }
        }
Exemplo n.º 12
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;
                }
                }
            }
        }
Exemplo n.º 13
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;
                }
            }
        }