Example #1
0
 private static void CreateSceneDragObjects(List <Sprite> sprites)
 {
     if (SpriteUtility.s_SceneDragObjects == null)
     {
         SpriteUtility.s_SceneDragObjects = new List <UnityEngine.Object>();
     }
     if (SpriteUtility.s_DragType == SpriteUtility.DragType.CreateMultiple)
     {
         foreach (Sprite current in sprites)
         {
             SpriteUtility.s_SceneDragObjects.Add(SpriteUtility.CreateDragGO(current, Vector3.zero));
         }
     }
     else
     {
         SpriteUtility.s_SceneDragObjects.Add(SpriteUtility.CreateDragGO(sprites[0], Vector3.zero));
     }
 }
Example #2
0
        public static void OnSceneDrag(SceneView sceneView)
        {
            Event current = Event.current;

            if (current.type != EventType.DragUpdated && current.type != EventType.DragPerform && current.type != EventType.DragExited)
            {
                return;
            }
            if (!sceneView.in2DMode)
            {
                GameObject gameObject = HandleUtility.PickGameObject(Event.current.mousePosition, true);
                if (gameObject != null && DragAndDrop.objectReferences.Length == 1 && DragAndDrop.objectReferences[0] as Texture != null && gameObject.GetComponent <Renderer>() != null)
                {
                    SpriteUtility.CleanUp(true);
                    return;
                }
            }
            EventType type = current.type;

            if (type != EventType.DragUpdated)
            {
                if (type != EventType.DragPerform)
                {
                    if (type == EventType.DragExited)
                    {
                        if (SpriteUtility.s_SceneDragObjects != null && SpriteUtility.s_SceneDragObjects != null)
                        {
                            SpriteUtility.CleanUp(true);
                            current.Use();
                        }
                    }
                }
                else
                {
                    Sprite[] spriteFromDraggedPathsOrObjects = SpriteUtility.GetSpriteFromDraggedPathsOrObjects();
                    if (spriteFromDraggedPathsOrObjects != null && SpriteUtility.s_SceneDragObjects != null)
                    {
                        if (SpriteUtility.s_DragType == SpriteUtility.DragType.SpriteAnimation)
                        {
                            SpriteUtility.AddAnimationToGO((GameObject)SpriteUtility.s_SceneDragObjects[0], spriteFromDraggedPathsOrObjects);
                        }
                        using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                GameObject gameObject2 = (GameObject)enumerator.Current;
                                Undo.RegisterCreatedObjectUndo(gameObject2, "Create Sprite");
                                gameObject2.hideFlags = HideFlags.None;
                            }
                        }
                        Selection.objects = SpriteUtility.s_SceneDragObjects.ToArray();
                        SpriteUtility.CleanUp(false);
                        current.Use();
                    }
                }
            }
            else
            {
                SpriteUtility.DragType dragType = (!current.alt) ? SpriteUtility.DragType.SpriteAnimation : SpriteUtility.DragType.CreateMultiple;
                if (SpriteUtility.s_DragType != dragType || SpriteUtility.s_SceneDragObjects == null)
                {
                    Sprite[] spriteFromDraggedPathsOrObjects2 = SpriteUtility.GetSpriteFromDraggedPathsOrObjects();
                    if (spriteFromDraggedPathsOrObjects2 == null || spriteFromDraggedPathsOrObjects2.Length == 0)
                    {
                        return;
                    }
                    Sprite x = spriteFromDraggedPathsOrObjects2[0];
                    if (x == null)
                    {
                        return;
                    }
                    if (SpriteUtility.s_DragType != SpriteUtility.DragType.NotInitialized)
                    {
                        SpriteUtility.CleanUp(true);
                    }
                    SpriteUtility.s_DragType         = dragType;
                    SpriteUtility.s_SceneDragObjects = new List <UnityEngine.Object>();
                    if (SpriteUtility.s_DragType == SpriteUtility.DragType.CreateMultiple)
                    {
                        Sprite[] array = spriteFromDraggedPathsOrObjects2;
                        for (int i = 0; i < array.Length; i++)
                        {
                            Sprite frame = array[i];
                            SpriteUtility.s_SceneDragObjects.Add(SpriteUtility.CreateDragGO(frame, Vector3.zero));
                        }
                    }
                    else
                    {
                        SpriteUtility.s_SceneDragObjects.Add(SpriteUtility.CreateDragGO(spriteFromDraggedPathsOrObjects2[0], Vector3.zero));
                    }
                    List <Transform> list = new List <Transform>();
                    using (List <UnityEngine.Object> .Enumerator enumerator2 = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                    {
                        while (enumerator2.MoveNext())
                        {
                            GameObject gameObject3 = (GameObject)enumerator2.Current;
                            list.AddRange(gameObject3.GetComponentsInChildren <Transform>());
                            gameObject3.hideFlags = HideFlags.HideInHierarchy;
                        }
                    }
                    HandleUtility.ignoreRaySnapObjects = list.ToArray();
                }
                Vector3 position = Vector3.zero;
                position = HandleUtility.GUIPointToWorldRay(current.mousePosition).GetPoint(10f);
                if (sceneView.in2DMode)
                {
                    position.z = 0f;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    object obj = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current.mousePosition));
                    if (obj != null)
                    {
                        position = ((RaycastHit)obj).point;
                    }
                }
                using (List <UnityEngine.Object> .Enumerator enumerator3 = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                {
                    while (enumerator3.MoveNext())
                    {
                        GameObject gameObject4 = (GameObject)enumerator3.Current;
                        gameObject4.transform.position = position;
                    }
                }
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                current.Use();
            }
        }
        public static void OnSceneDrag(SceneView sceneView)
        {
            Event current1 = Event.current;

            if (current1.type != EventType.DragUpdated && current1.type != EventType.DragPerform && current1.type != EventType.DragExited)
            {
                return;
            }
            if (!sceneView.in2DMode)
            {
                GameObject gameObject = HandleUtility.PickGameObject(Event.current.mousePosition, true);
                if ((UnityEngine.Object)gameObject != (UnityEngine.Object)null && DragAndDrop.objectReferences.Length == 1 && ((UnityEngine.Object)(DragAndDrop.objectReferences[0] as Texture) != (UnityEngine.Object)null && (UnityEngine.Object)gameObject.GetComponent <Renderer>() != (UnityEngine.Object)null))
                {
                    return;
                }
            }
            switch (current1.type)
            {
            case EventType.DragUpdated:
                SpriteUtility.DragType dragType = !current1.alt ? SpriteUtility.DragType.SpriteAnimation : SpriteUtility.DragType.CreateMultiple;
                if (SpriteUtility.s_DragType != dragType || SpriteUtility.s_SceneDragObjects == null)
                {
                    Sprite[] draggedPathsOrObjects = SpriteUtility.GetSpriteFromDraggedPathsOrObjects();
                    if (draggedPathsOrObjects == null || draggedPathsOrObjects.Length == 0 || (UnityEngine.Object)draggedPathsOrObjects[0] == (UnityEngine.Object)null)
                    {
                        break;
                    }
                    if (SpriteUtility.s_DragType != SpriteUtility.DragType.NotInitialized)
                    {
                        SpriteUtility.CleanUp();
                    }
                    SpriteUtility.s_DragType         = dragType;
                    SpriteUtility.s_SceneDragObjects = new List <UnityEngine.Object>();
                    if (SpriteUtility.s_DragType == SpriteUtility.DragType.CreateMultiple)
                    {
                        foreach (Sprite frame in draggedPathsOrObjects)
                        {
                            SpriteUtility.s_SceneDragObjects.Add((UnityEngine.Object)SpriteUtility.CreateDragGO(frame, Vector3.zero));
                        }
                    }
                    else
                    {
                        SpriteUtility.s_SceneDragObjects.Add((UnityEngine.Object)SpriteUtility.CreateDragGO(draggedPathsOrObjects[0], Vector3.zero));
                    }
                    List <Transform> transformList = new List <Transform>();
                    using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            GameObject current2 = (GameObject)enumerator.Current;
                            transformList.AddRange((IEnumerable <Transform>)current2.GetComponentsInChildren <Transform>());
                            current2.hideFlags = HideFlags.HideInHierarchy;
                        }
                    }
                    HandleUtility.ignoreRaySnapObjects = transformList.ToArray();
                }
                Vector3 zero  = Vector3.zero;
                Vector3 point = HandleUtility.GUIPointToWorldRay(current1.mousePosition).GetPoint(10f);
                if (sceneView.in2DMode)
                {
                    point.z = 0.0f;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    object obj = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current1.mousePosition));
                    if (obj != null)
                    {
                        point = ((RaycastHit)obj).point;
                    }
                }
                using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ((GameObject)enumerator.Current).transform.position = point;
                    }
                }
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                current1.Use();
                break;

            case EventType.DragPerform:
                Sprite[] draggedPathsOrObjects1 = SpriteUtility.GetSpriteFromDraggedPathsOrObjects();
                if (draggedPathsOrObjects1 == null || SpriteUtility.s_SceneDragObjects == null)
                {
                    break;
                }
                if (SpriteUtility.s_DragType == SpriteUtility.DragType.SpriteAnimation)
                {
                    SpriteUtility.AddAnimationToGO((GameObject)SpriteUtility.s_SceneDragObjects[0], draggedPathsOrObjects1);
                }
                using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        GameObject current2 = (GameObject)enumerator.Current;
                        Undo.RegisterCreatedObjectUndo((UnityEngine.Object)current2, "Create Sprite");
                        current2.hideFlags = HideFlags.None;
                    }
                }
                Selection.objects = SpriteUtility.s_SceneDragObjects.ToArray();
                SpriteUtility.CleanUp();
                current1.Use();
                break;

            case EventType.DragExited:
                if (SpriteUtility.s_SceneDragObjects == null || SpriteUtility.s_SceneDragObjects == null)
                {
                    break;
                }
                using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        UnityEngine.Object.DestroyImmediate(enumerator.Current, false);
                    }
                }
                SpriteUtility.CleanUp();
                current1.Use();
                break;
            }
        }