Exemple #1
0
            internal static void HandleDragAndDrop(int instanceId, Rect selectionRect)
            {
                // HACK: Uses EditorApplication.hierarchyWindowItemOnGUI.
                // Only works when there is at least one item in the scene.
                var  current         = UnityEngine.Event.current;
                var  eventType       = current.type;
                bool isDraggingEvent = eventType == EventType.DragUpdated;
                bool isDropEvent     = eventType == EventType.DragPerform;

                UnityEditor.DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                if (isDraggingEvent || isDropEvent)
                {
                    var mouseOverWindow = EditorWindow.mouseOverWindow;
                    if (mouseOverWindow != null)
                    {
                        // One, existing, valid SkeletonDataAsset
                        var references = UnityEditor.DragAndDrop.objectReferences;
                        if (references.Length == 1)
                        {
                            var skeletonDataAsset = references[0] as SkeletonDataAsset;
                            if (skeletonDataAsset != null && skeletonDataAsset.GetSkeletonData(true) != null)
                            {
                                // Allow drag-and-dropping anywhere in the Hierarchy Window.
                                // HACK: string-compare because we can't get its type via reflection.
                                const string HierarchyWindow     = "UnityEditor.SceneHierarchyWindow";
                                const string GenericDataTargetID = "target";
                                if (HierarchyWindow.Equals(mouseOverWindow.GetType().ToString(), System.StringComparison.Ordinal))
                                {
                                    if (isDraggingEvent)
                                    {
                                        var mouseOverTarget = UnityEditor.EditorUtility.InstanceIDToObject(instanceId);
                                        if (mouseOverTarget)
                                        {
                                            DragAndDrop.SetGenericData(GenericDataTargetID, mouseOverTarget);
                                        }
                                        // Note: do not call current.Use(), otherwise we get the wrong drop-target parent.
                                    }
                                    else if (isDropEvent)
                                    {
                                        var       parentGameObject = DragAndDrop.GetGenericData(GenericDataTargetID) as UnityEngine.GameObject;
                                        Transform parent           = parentGameObject != null ? parentGameObject.transform : null;
                                        // when dragging into empty space in hierarchy below last node, last node would be parent.
                                        if (IsLastNodeInHierarchy(parent))
                                        {
                                            parent = null;
                                        }
                                        DragAndDropInstantiation.ShowInstantiateContextMenu(skeletonDataAsset, Vector3.zero, parent);
                                        UnityEditor.DragAndDrop.AcceptDrag();
                                        current.Use();
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            internal static void HandleDragAndDrop(int instanceId, Rect selectionRect)
            {
                // HACK: Uses EditorApplication.hierarchyWindowItemOnGUI.
                // Only works when there is at least one item in the scene.
                var  current         = UnityEngine.Event.current;
                var  eventType       = current.type;
                bool isDraggingEvent = eventType == EventType.DragUpdated;
                bool isDropEvent     = eventType == EventType.DragPerform;

                if (isDraggingEvent || isDropEvent)
                {
                    var mouseOverWindow = EditorWindow.mouseOverWindow;
                    if (mouseOverWindow != null)
                    {
                        // One, existing, valid SkeletonDataAsset
                        var references = UnityEditor.DragAndDrop.objectReferences;
                        if (references.Length == 1)
                        {
                            var skeletonDataAsset = references[0] as SkeletonDataAsset;
                            if (skeletonDataAsset != null && skeletonDataAsset.GetSkeletonData(true) != null)
                            {
                                // Allow drag-and-dropping anywhere in the Hierarchy Window.
                                // HACK: string-compare because we can't get its type via reflection.
                                const string HierarchyWindow = "UnityEditor.SceneHierarchyWindow";
                                if (HierarchyWindow.Equals(mouseOverWindow.GetType().ToString(), System.StringComparison.Ordinal))
                                {
                                    if (isDraggingEvent)
                                    {
                                        UnityEditor.DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                                        current.Use();
                                    }
                                    else if (isDropEvent)
                                    {
                                        DragAndDropInstantiation.ShowInstantiateContextMenu(skeletonDataAsset, Vector3.zero);
                                        UnityEditor.DragAndDrop.AcceptDrag();
                                        current.Use();
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
Exemple #3
0
        static void HierarchyDragAndDrop(int instanceId, Rect selectionRect)
        {
            var  current         = UnityEngine.Event.current;
            var  eventType       = current.type;
            bool isDraggingEvent = eventType == EventType.DragUpdated;
            bool isDropEvent     = eventType == EventType.DragPerform;

            if (isDraggingEvent || isDropEvent)
            {
                var mouseOverWindow = EditorWindow.mouseOverWindow;
                if (mouseOverWindow != null)
                {
                    // One, existing, valid SkeletonDataAsset
                    var references = DragAndDrop.objectReferences;
                    if (references.Length == 1)
                    {
                        GameObject gameObject = references[0] as GameObject;
                        if (gameObject != null && gameObject.scene.path == null && gameObject.GetComponent <GunSoundSetting>())
                        {
                            var          soundSetting    = gameObject.GetComponent <GunSoundSetting>();
                            const string HierarchyWindow = "UnityEditor.SceneHierarchyWindow";
                            if (HierarchyWindow.Equals(mouseOverWindow.GetType().ToString(), System.StringComparison.Ordinal))
                            {
                                if (isDraggingEvent)
                                {
                                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                                    current.Use();
                                }
                                else if (isDropEvent)
                                {
                                    ShowInstantiateContextMenu(soundSetting, Vector3.zero);
                                    DragAndDrop.AcceptDrag();
                                    current.Use();
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }