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 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(); } } } }
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; } }