private void DoBake() { UsabilityAnalytics.Track("/LightMapper/Start"); UsabilityAnalytics.Event("LightMapper", "Mode", LightmapSettings.lightmapsMode.ToString(), 1); UsabilityAnalytics.Event("LightMapper", "Button", "BakeScene", 1); Lightmapping.BakeAsync(); }
public static void AddAnimationToGO(GameObject go, Sprite[] frames) { if ((frames != null) && (frames.Length > 0)) { SpriteRenderer component = go.GetComponent <SpriteRenderer>(); if (component == null) { Debug.LogWarning("There should be a SpriteRenderer in dragged object"); component = go.AddComponent <SpriteRenderer>(); } component.sprite = frames[0]; if (frames.Length > 1) { UsabilityAnalytics.Event("Sprite Drag and Drop", "Drop multiple sprites to scene", "null", 1); if (!CreateAnimation(go, frames)) { Debug.LogError("Failed to create animation for dragged object"); } } else { UsabilityAnalytics.Event("Sprite Drag and Drop", "Drop single sprite to scene", "null", 1); } } }
public static void HandleSpriteSceneDrag(SceneView sceneView, IEvent evt, Object[] objectReferences, string[] paths, ShowFileDialogDelegate saveFileDialog) { if (evt.type != EventType.DragUpdated && evt.type != EventType.DragPerform && evt.type != EventType.DragExited) { return; } // Return if any of the dragged objects are null, e.g. a MonoBehaviour without a managed instance if (objectReferences.Any(obj => obj == null)) { return; } // Regardless of EditorBehaviorMode or SceneView mode we don't handle if texture is dragged over a GO with renderer if (objectReferences.Length == 1 && objectReferences[0] as UnityTexture2D != null) { GameObject go = HandleUtility.PickGameObject(evt.mousePosition, true); if (go != null) { var renderer = go.GetComponent <Renderer>(); if (renderer != null && !(renderer is SpriteRenderer)) { // There is an object where the cursor is // and we are dragging a texture. Most likely user wants to // assign texture to the GO // Case 730444: Proceed only if the go has a renderer CleanUp(true); return; } } } switch (evt.type) { case (EventType.DragUpdated): DragType newDragType = evt.alt ? DragType.CreateMultiple : DragType.SpriteAnimation; if (s_DragType != newDragType || s_SceneDragObjects == null) // Either this is first time we are here OR evt.alt changed during drag { if (!ExistingAssets(objectReferences) && PathsAreValidTextures(paths)) // External drag with images that are not in the project { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; s_SceneDragObjects = new List <Object>(); s_DragType = newDragType; } else // Internal drag with assets from project { List <Sprite> assets = GetSpriteFromPathsOrObjects(objectReferences, paths, evt.type); if (assets.Count == 0) { return; } if (s_DragType != DragType.NotInitialized) // evt.alt changed during drag, so we need to cleanup and start over { CleanUp(true); } s_DragType = newDragType; CreateSceneDragObjects(assets); IgnoreForRaycasts(s_SceneDragObjects); } } PositionSceneDragObjects(s_SceneDragObjects, sceneView, evt.mousePosition); DragAndDrop.visualMode = DragAndDropVisualMode.Copy; evt.Use(); break; case (EventType.DragPerform): List <Sprite> sprites = GetSpriteFromPathsOrObjects(objectReferences, paths, evt.type); if (sprites.Count > 0 && s_SceneDragObjects != null) { // Store current undoIndex to undo all operations done if any part of sprite creation fails int undoIndex = Undo.GetCurrentGroup(); // For external drags, we have delayed all creation to DragPerform because only now we have the imported sprite assets if (s_SceneDragObjects.Count == 0) { CreateSceneDragObjects(sprites); PositionSceneDragObjects(s_SceneDragObjects, sceneView, evt.mousePosition); } foreach (GameObject dragGO in s_SceneDragObjects) { dragGO.hideFlags = HideFlags.None; Undo.RegisterCreatedObjectUndo(dragGO, "Create Sprite"); EditorUtility.SetDirty(dragGO); } bool createGameObject = true; if (s_DragType == DragType.SpriteAnimation && sprites.Count > 1) { UsabilityAnalytics.Event("Sprite Drag and Drop", "Drop multiple sprites to scene", "null", 1); createGameObject = AddAnimationToGO((GameObject)s_SceneDragObjects[0], sprites.ToArray(), saveFileDialog); } else { UsabilityAnalytics.Event("Sprite Drag and Drop", "Drop single sprite to scene", "null", 1); } if (createGameObject) { Selection.objects = s_SceneDragObjects.ToArray(); } else { // Revert all Create Sprite actions if animation failed to be created or was cancelled Undo.RevertAllDownToGroup(undoIndex); } CleanUp(!createGameObject); evt.Use(); } break; case EventType.DragExited: if (s_SceneDragObjects != null) { CleanUp(true); evt.Use(); } break; } }
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(); } } } }