示例#1
0
 public static void HandleSpriteSceneDrag(SceneView sceneView, IEvent evt, UnityEngine.Object[] objectReferences, string[] paths, SpriteUtility.ShowFileDialogDelegate saveFileDialog)
 {
     if (evt.type == EventType.DragUpdated || evt.type == EventType.DragPerform || evt.type == EventType.DragExited)
     {
         if (!objectReferences.Any((UnityEngine.Object obj) => obj == null))
         {
             if (objectReferences.Length == 1 && objectReferences[0] as UnityEngine.Texture2D != null)
             {
                 GameObject gameObject = HandleUtility.PickGameObject(evt.mousePosition, true);
                 if (gameObject != null)
                 {
                     Renderer component = gameObject.GetComponent <Renderer>();
                     if (component != null && !(component is SpriteRenderer))
                     {
                         SpriteUtility.CleanUp(true);
                         return;
                     }
                 }
             }
             EventType type = evt.type;
             if (type != EventType.DragUpdated)
             {
                 if (type != EventType.DragPerform)
                 {
                     if (type == EventType.DragExited)
                     {
                         if (SpriteUtility.s_SceneDragObjects != null)
                         {
                             SpriteUtility.CleanUp(true);
                             evt.Use();
                         }
                     }
                 }
                 else
                 {
                     List <Sprite> spriteFromPathsOrObjects = SpriteUtility.GetSpriteFromPathsOrObjects(objectReferences, paths, evt.type);
                     if (spriteFromPathsOrObjects.Count > 0 && SpriteUtility.s_SceneDragObjects != null)
                     {
                         int currentGroup = Undo.GetCurrentGroup();
                         if (SpriteUtility.s_SceneDragObjects.Count == 0)
                         {
                             SpriteUtility.CreateSceneDragObjects(spriteFromPathsOrObjects);
                             SpriteUtility.PositionSceneDragObjects(SpriteUtility.s_SceneDragObjects, sceneView, evt.mousePosition);
                         }
                         using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                         {
                             while (enumerator.MoveNext())
                             {
                                 GameObject gameObject2 = (GameObject)enumerator.Current;
                                 gameObject2.hideFlags = HideFlags.None;
                                 Undo.RegisterCreatedObjectUndo(gameObject2, "Create Sprite");
                                 EditorUtility.SetDirty(gameObject2);
                             }
                         }
                         bool flag = true;
                         if (SpriteUtility.s_DragType == SpriteUtility.DragType.SpriteAnimation && spriteFromPathsOrObjects.Count > 1)
                         {
                             UsabilityAnalytics.Event("Sprite Drag and Drop", "Drop multiple sprites to scene", "null", 1);
                             flag = SpriteUtility.AddAnimationToGO((GameObject)SpriteUtility.s_SceneDragObjects[0], spriteFromPathsOrObjects.ToArray(), saveFileDialog);
                         }
                         else
                         {
                             UsabilityAnalytics.Event("Sprite Drag and Drop", "Drop single sprite to scene", "null", 1);
                         }
                         if (flag)
                         {
                             Selection.objects = SpriteUtility.s_SceneDragObjects.ToArray();
                         }
                         else
                         {
                             Undo.RevertAllDownToGroup(currentGroup);
                         }
                         SpriteUtility.CleanUp(!flag);
                         evt.Use();
                     }
                 }
             }
             else
             {
                 SpriteUtility.DragType dragType = (!evt.alt) ? SpriteUtility.DragType.SpriteAnimation : SpriteUtility.DragType.CreateMultiple;
                 if (SpriteUtility.s_DragType != dragType || SpriteUtility.s_SceneDragObjects == null)
                 {
                     if (!SpriteUtility.ExistingAssets(objectReferences) && SpriteUtility.PathsAreValidTextures(paths))
                     {
                         DragAndDrop.visualMode           = DragAndDropVisualMode.Copy;
                         SpriteUtility.s_SceneDragObjects = new List <UnityEngine.Object>();
                         SpriteUtility.s_DragType         = dragType;
                     }
                     else
                     {
                         List <Sprite> spriteFromPathsOrObjects2 = SpriteUtility.GetSpriteFromPathsOrObjects(objectReferences, paths, evt.type);
                         if (spriteFromPathsOrObjects2.Count == 0)
                         {
                             return;
                         }
                         if (SpriteUtility.s_DragType != SpriteUtility.DragType.NotInitialized)
                         {
                             SpriteUtility.CleanUp(true);
                         }
                         SpriteUtility.s_DragType = dragType;
                         SpriteUtility.CreateSceneDragObjects(spriteFromPathsOrObjects2);
                         SpriteUtility.IgnoreForRaycasts(SpriteUtility.s_SceneDragObjects);
                     }
                 }
                 SpriteUtility.PositionSceneDragObjects(SpriteUtility.s_SceneDragObjects, sceneView, evt.mousePosition);
                 DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                 evt.Use();
             }
         }
     }
 }