diff --git a/package/Editor/ImagePacker/ImagePackerDebugEditor.cs b/package/Editor/ImagePacker/ImagePackerDebugEditor.cs index 282911074..e1a5ace36 100755 --- a/package/Editor/ImagePacker/ImagePackerDebugEditor.cs +++ b/package/Editor/ImagePacker/ImagePackerDebugEditor.cs @@ -1,303 +1,300 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using UnityEditor.Experimental.UIElements; -using UnityEditorInternal; -using UnityEngine; -using UnityEngine.Experimental.UIElements; -using UnityEngine.Experimental.UIElements.StyleEnums; -using Object = UnityEngine.Object; - -namespace UnityEditor.Experimental.U2D.Common -{ - public class ImagePackerDebugEditor : EditorWindow - { - [MenuItem("Window/2D/Common/Image Packer Debug Editor")] - static void Launch() - { - var window = EditorWindow.GetWindow(); - var pos = window.position; - pos.height = pos.width = 400; - window.position = pos; - window.Show(); - } - - ReorderableList m_ReorderableList; - ImagePacker.ImagePackRect[] m_PackingRect = null; - List m_PackRects = new List(); - RectInt[] m_PackResult = null; - SpriteRect[] m_SpriteRects = null; - Texture2D m_Texture; - int m_TextureActualWidth = 0; - int m_TextureActualHeight = 0; - int m_PackWidth = 0; - int m_PackHeight = 0; - int m_Padding = 0; - Vector2 m_ConfigScroll = Vector2.zero; - float m_Zoom = 1; - IMGUIContainer m_PackArea; - int m_PackStep = -1; - protected const float k_MinZoomPercentage = 0.9f; - protected const float k_WheelZoomSpeed = 0.03f; - protected const float k_MouseZoomSpeed = 0.005f; - - void OnEnable() - { - var visualContainer = new VisualElement() - { - name = "Container", - style = - { - flex = new Flex(1), - flexDirection = FlexDirection.Row - } - }; - this.GetRootVisualContainer().Add(visualContainer); - - var imgui = new IMGUIContainer(OnConfigGUI) - { - name = "Config", - style = - { - width = 300 - } - }; - - visualContainer.Add(imgui); - - m_PackArea = new IMGUIContainer(OnImagePackerGUI) - { - name = "ImagePacker", - style = - { - flexGrow = 1, - flex = new Flex(1), - } - }; - visualContainer.Add(m_PackArea); - SetupConfigGUI(); - } - - void SetupConfigGUI() - { - m_ReorderableList = new ReorderableList(m_PackRects, typeof(RectInt), false, false, true, true); - m_ReorderableList.elementHeightCallback = (int index) => - { - return EditorGUIUtility.singleLineHeight * 2 + 6; - }; - m_ReorderableList.drawElementCallback = DrawListElement; - - m_ReorderableList.onAddCallback = (list) => - { - m_PackRects.Add(new RectInt()); - }; - m_ReorderableList.onRemoveCallback = (list) => - { - m_PackRects.RemoveAt(list.index); - }; - } - - void DrawListElement(Rect rect, int index, bool isactive, bool isfocused) - { - var rectInt = m_PackRects[index]; - var name = m_SpriteRects == null || index >= m_SpriteRects.Length ? index.ToString() : m_SpriteRects[index]. - name; - rectInt.size = EditorGUI.Vector2IntField(rect, name, rectInt.size); - m_PackRects[index] = rectInt; - } - - void OnConfigGUI() - { - EditorGUILayout.BeginVertical(); - m_ConfigScroll = EditorGUILayout.BeginScrollView(m_ConfigScroll); - m_ReorderableList.DoLayoutList(); - EditorGUILayout.EndScrollView(); - GUILayout.FlexibleSpace(); - - m_PackStep = EditorGUILayout.IntSlider("Step", m_PackStep, 0, m_PackRects.Count); - EditorGUI.BeginChangeCheck(); - m_Texture = EditorGUILayout.ObjectField(new GUIContent("Texture"), (Object)m_Texture, typeof(Texture2D), false) as Texture2D; - if (EditorGUI.EndChangeCheck()) - UpdateSpriteRect(); - m_Padding = EditorGUILayout.IntField("Padding", m_Padding); - EditorGUILayout.BeginHorizontal(); - if (GUILayout.Button("<<")) - { - m_PackStep = m_PackStep <= 0 ? 0 : m_PackStep - 1; - Pack(); - } - if (GUILayout.Button("Pack")) - Pack(); - if (GUILayout.Button(">>")) - { - m_PackStep = m_PackStep > m_PackRects.Count ? m_PackRects.Count : m_PackStep + 1; - Pack(); - } - if (GUILayout.Button("Clear")) - { - m_PackRects.Clear(); - m_Texture = null; - m_PackingRect = null; - m_PackResult = null; - m_SpriteRects = null; - } - - EditorGUILayout.EndHorizontal(); - EditorGUILayout.EndVertical(); - } - - void UpdateSpriteRect() - { - var dataProvider = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(m_Texture)) as ISpriteEditorDataProvider; - if (dataProvider == null) - return; - dataProvider.InitSpriteEditorDataProvider(); - dataProvider.GetDataProvider().GetTextureActualWidthAndHeight(out m_TextureActualWidth, out m_TextureActualHeight); - m_SpriteRects = dataProvider.GetDataProvider().GetSpriteRects(); - m_PackRects.Clear(); - m_PackRects.AddRange(m_SpriteRects.Select(x => new RectInt((int)x.rect.x, (int)x.rect.y, (int)x.rect.width, (int)x.rect.height))); - m_PackResult = null; - m_PackStep = m_PackRects.Count; - } - - void Pack() - { - int count = m_PackStep > 0 && m_PackStep < m_PackRects.Count ? m_PackStep : m_PackRects.Count; - m_PackingRect = new ImagePacker.ImagePackRect[m_PackRects.Count]; - for (int i = 0; i < m_PackRects.Count; ++i) - { - m_PackingRect[i] = new ImagePacker.ImagePackRect() - { - rect = m_PackRects[i], - index = i - }; - } - Array.Sort(m_PackingRect); - ImagePacker.Pack(m_PackingRect.Take(count).Select(x => x.rect).ToArray(), m_Padding, out m_PackResult, out m_PackWidth, out m_PackHeight); - } - - void DrawLabel(Rect rect, string label) - { - rect.position = Handles.matrix.MultiplyPoint(rect.position); - GUI.Label(rect, label); - } - - void OnImagePackerGUI() - { - if (m_PackResult == null) - return; - HandleZoom(); - var oldMatrix = Handles.matrix; - SetupHandlesMatrix(); - Handles.DrawSolidRectangleWithOutline(new Rect(0, 0, m_PackWidth, m_PackHeight), Color.gray, Color.black); - DrawLabel(new Rect(0, 0, m_PackWidth, m_PackHeight), m_PackWidth + "x" + m_PackHeight); - - int index = 0; - - foreach (var rect in m_PackResult) - { - Handles.DrawSolidRectangleWithOutline(new Rect(rect.x, rect.y, rect.width, rect.height), Color.white, Color.black); - var rect1 = new Rect(rect.x, rect.y + rect.height * 0.5f, rect.width, EditorGUIUtility.singleLineHeight); - DrawLabel(rect1, m_PackingRect[index].index.ToString()); - ++index; - } - - index = 0; - if (m_Texture != null && m_SpriteRects != null) - { - var material = new Material(Shader.Find("Sprites/Default")); - material.mainTexture = m_Texture; - material.SetPass(0); - - int mouseOverIndex = -1; - GL.PushMatrix(); - GL.LoadIdentity(); - GL.MultMatrix(GUI.matrix * Handles.matrix); - GL.Begin(GL.QUADS); - for (int i = 0; i < m_PackResult.Length; ++i) - { - index = m_PackingRect[i].index; - if (index >= m_SpriteRects.Length) - continue; - var rect = m_PackResult[i]; - GL.TexCoord(new Vector3(m_SpriteRects[index].rect.x / m_TextureActualWidth, m_SpriteRects[index].rect.y / m_TextureActualHeight, 0)); - GL.Vertex(new Vector3(rect.x, rect.y, 0)); - GL.TexCoord(new Vector3(m_SpriteRects[index].rect.xMax / m_TextureActualWidth, m_SpriteRects[index].rect.y / m_TextureActualHeight, 0)); - GL.Vertex(new Vector3(rect.x + rect.width, rect.y, 0)); - GL.TexCoord(new Vector3(m_SpriteRects[index].rect.xMax / m_TextureActualWidth, m_SpriteRects[index].rect.yMax / m_TextureActualHeight, 0)); - GL.Vertex(new Vector3(rect.x + rect.width, rect.y + rect.height, 0)); - GL.TexCoord(new Vector3(m_SpriteRects[index].rect.x / m_TextureActualWidth, m_SpriteRects[index].rect.yMax / m_TextureActualHeight, 0)); - GL.Vertex(new Vector3(rect.x, rect.y + rect.height, 0)); - var m = Handles.matrix.inverse.MultiplyPoint(Event.current.mousePosition); - if (rect.Contains(new Vector2Int((int)m.x, (int)m.y))) - { - mouseOverIndex = index; - } - ++index; - } - - GL.End(); - GL.PopMatrix(); - if (mouseOverIndex >= 0) - { - var text = new GUIContent(m_SpriteRects[mouseOverIndex].name + " " + index); - var length = EditorStyles.textArea.CalcSize(text); - var rect1 = new Rect(m_PackResult[mouseOverIndex].x, m_PackResult[mouseOverIndex].y + m_PackResult[mouseOverIndex].height * 0.5f, length.x, length.y); - rect1.position = Handles.matrix.MultiplyPoint(rect1.position); - if (Event.current.type == EventType.Repaint) - EditorStyles.textArea.Draw(rect1, text, false, false, false, false); - } - } - - Handles.matrix = oldMatrix; - } - - void SetupHandlesMatrix() - { - Vector3 handlesPos = new Vector3(0, m_PackHeight * m_Zoom, 0f); - Vector3 handlesScale = new Vector3(m_Zoom, -m_Zoom, 1f); - Handles.matrix = Matrix4x4.TRS(handlesPos, Quaternion.identity, handlesScale); - } - - protected void HandleZoom() - { - bool zoomMode = Event.current.alt && Event.current.button == 1; - if (zoomMode) - { - EditorGUIUtility.AddCursorRect(m_PackArea.worldBound, MouseCursor.Zoom); - } - - if ( - ((Event.current.type == EventType.MouseUp || Event.current.type == EventType.MouseDown) && zoomMode) || - ((Event.current.type == EventType.KeyUp || Event.current.type == EventType.KeyDown) && Event.current.keyCode == KeyCode.LeftAlt) - ) - { - Repaint(); - } - - if (Event.current.type == EventType.ScrollWheel || (Event.current.type == EventType.MouseDrag && Event.current.alt && Event.current.button == 1)) - { - float zoomMultiplier = 1f - Event.current.delta.y * (Event.current.type == EventType.ScrollWheel ? k_WheelZoomSpeed : -k_MouseZoomSpeed); - - // Clamp zoom - float wantedZoom = m_Zoom * zoomMultiplier; - - float currentZoom = Mathf.Clamp(wantedZoom, GetMinZoom(), 1); - - if (currentZoom != m_Zoom) - { - m_Zoom = currentZoom; - Event.current.Use(); - } - } - } - - protected float GetMinZoom() - { - if (m_Texture == null) - return 1.0f; - return Mathf.Min(m_PackArea.worldBound.width / m_PackWidth, m_PackArea.worldBound.height / m_PackHeight, 0.05f) * k_MinZoomPercentage; - } - } -} +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using UnityEditorInternal; +using UnityEngine; +using UnityEngine.UIElements; +using Object = UnityEngine.Object; + +namespace UnityEditor.Experimental.U2D.Common +{ + public class ImagePackerDebugEditor : EditorWindow + { + [MenuItem("Window/2D/Common/Image Packer Debug Editor")] + static void Launch() + { + var window = EditorWindow.GetWindow(); + var pos = window.position; + pos.height = pos.width = 400; + window.position = pos; + window.Show(); + } + + ReorderableList m_ReorderableList; + ImagePacker.ImagePackRect[] m_PackingRect = null; + List m_PackRects = new List(); + RectInt[] m_PackResult = null; + SpriteRect[] m_SpriteRects = null; + Texture2D m_Texture; + int m_TextureActualWidth = 0; + int m_TextureActualHeight = 0; + int m_PackWidth = 0; + int m_PackHeight = 0; + int m_Padding = 0; + Vector2 m_ConfigScroll = Vector2.zero; + float m_Zoom = 1; + IMGUIContainer m_PackArea; + int m_PackStep = -1; + protected const float k_MinZoomPercentage = 0.9f; + protected const float k_WheelZoomSpeed = 0.03f; + protected const float k_MouseZoomSpeed = 0.005f; + + void OnEnable() + { + var visualContainer = new VisualElement() + { + name = "Container", + style = + { + flexGrow = 1, + flexDirection = FlexDirection.Row + } + }; + this.rootVisualElement.Add(visualContainer); + + var imgui = new IMGUIContainer(OnConfigGUI) + { + name = "Config", + style = + { + width = 300 + } + }; + + visualContainer.Add(imgui); + + m_PackArea = new IMGUIContainer(OnImagePackerGUI) + { + name = "ImagePacker", + style = + { + flexGrow = 1, + } + }; + visualContainer.Add(m_PackArea); + SetupConfigGUI(); + } + + void SetupConfigGUI() + { + m_ReorderableList = new ReorderableList(m_PackRects, typeof(RectInt), false, false, true, true); + m_ReorderableList.elementHeightCallback = (int index) => + { + return EditorGUIUtility.singleLineHeight * 2 + 6; + }; + m_ReorderableList.drawElementCallback = DrawListElement; + + m_ReorderableList.onAddCallback = (list) => + { + m_PackRects.Add(new RectInt()); + }; + m_ReorderableList.onRemoveCallback = (list) => + { + m_PackRects.RemoveAt(list.index); + }; + } + + void DrawListElement(Rect rect, int index, bool isactive, bool isfocused) + { + var rectInt = m_PackRects[index]; + var name = m_SpriteRects == null || index >= m_SpriteRects.Length ? index.ToString() : m_SpriteRects[index]. + name; + rectInt.size = EditorGUI.Vector2IntField(rect, name, rectInt.size); + m_PackRects[index] = rectInt; + } + + void OnConfigGUI() + { + EditorGUILayout.BeginVertical(); + m_ConfigScroll = EditorGUILayout.BeginScrollView(m_ConfigScroll); + m_ReorderableList.DoLayoutList(); + EditorGUILayout.EndScrollView(); + GUILayout.FlexibleSpace(); + + m_PackStep = EditorGUILayout.IntSlider("Step", m_PackStep, 0, m_PackRects.Count); + EditorGUI.BeginChangeCheck(); + m_Texture = EditorGUILayout.ObjectField(new GUIContent("Texture"), (Object)m_Texture, typeof(Texture2D), false) as Texture2D; + if (EditorGUI.EndChangeCheck()) + UpdateSpriteRect(); + m_Padding = EditorGUILayout.IntField("Padding", m_Padding); + EditorGUILayout.BeginHorizontal(); + if (GUILayout.Button("<<")) + { + m_PackStep = m_PackStep <= 0 ? 0 : m_PackStep - 1; + Pack(); + } + if (GUILayout.Button("Pack")) + Pack(); + if (GUILayout.Button(">>")) + { + m_PackStep = m_PackStep > m_PackRects.Count ? m_PackRects.Count : m_PackStep + 1; + Pack(); + } + if (GUILayout.Button("Clear")) + { + m_PackRects.Clear(); + m_Texture = null; + m_PackingRect = null; + m_PackResult = null; + m_SpriteRects = null; + } + + EditorGUILayout.EndHorizontal(); + EditorGUILayout.EndVertical(); + } + + void UpdateSpriteRect() + { + var dataProvider = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(m_Texture)) as ISpriteEditorDataProvider; + if (dataProvider == null) + return; + dataProvider.InitSpriteEditorDataProvider(); + dataProvider.GetDataProvider().GetTextureActualWidthAndHeight(out m_TextureActualWidth, out m_TextureActualHeight); + m_SpriteRects = dataProvider.GetDataProvider().GetSpriteRects(); + m_PackRects.Clear(); + m_PackRects.AddRange(m_SpriteRects.Select(x => new RectInt((int)x.rect.x, (int)x.rect.y, (int)x.rect.width, (int)x.rect.height))); + m_PackResult = null; + m_PackStep = m_PackRects.Count; + } + + void Pack() + { + int count = m_PackStep > 0 && m_PackStep < m_PackRects.Count ? m_PackStep : m_PackRects.Count; + m_PackingRect = new ImagePacker.ImagePackRect[m_PackRects.Count]; + for (int i = 0; i < m_PackRects.Count; ++i) + { + m_PackingRect[i] = new ImagePacker.ImagePackRect() + { + rect = m_PackRects[i], + index = i + }; + } + Array.Sort(m_PackingRect); + ImagePacker.Pack(m_PackingRect.Take(count).Select(x => x.rect).ToArray(), m_Padding, out m_PackResult, out m_PackWidth, out m_PackHeight); + } + + void DrawLabel(Rect rect, string label) + { + rect.position = Handles.matrix.MultiplyPoint(rect.position); + GUI.Label(rect, label); + } + + void OnImagePackerGUI() + { + if (m_PackResult == null) + return; + HandleZoom(); + var oldMatrix = Handles.matrix; + SetupHandlesMatrix(); + Handles.DrawSolidRectangleWithOutline(new Rect(0, 0, m_PackWidth, m_PackHeight), Color.gray, Color.black); + DrawLabel(new Rect(0, 0, m_PackWidth, m_PackHeight), m_PackWidth + "x" + m_PackHeight); + + int index = 0; + + foreach (var rect in m_PackResult) + { + Handles.DrawSolidRectangleWithOutline(new Rect(rect.x, rect.y, rect.width, rect.height), Color.white, Color.black); + var rect1 = new Rect(rect.x, rect.y + rect.height * 0.5f, rect.width, EditorGUIUtility.singleLineHeight); + DrawLabel(rect1, m_PackingRect[index].index.ToString()); + ++index; + } + + index = 0; + if (m_Texture != null && m_SpriteRects != null) + { + var material = new Material(Shader.Find("Sprites/Default")); + material.mainTexture = m_Texture; + material.SetPass(0); + + int mouseOverIndex = -1; + GL.PushMatrix(); + GL.LoadIdentity(); + GL.MultMatrix(GUI.matrix * Handles.matrix); + GL.Begin(GL.QUADS); + for (int i = 0; i < m_PackResult.Length; ++i) + { + index = m_PackingRect[i].index; + if (index >= m_SpriteRects.Length) + continue; + var rect = m_PackResult[i]; + GL.TexCoord(new Vector3(m_SpriteRects[index].rect.x / m_TextureActualWidth, m_SpriteRects[index].rect.y / m_TextureActualHeight, 0)); + GL.Vertex(new Vector3(rect.x, rect.y, 0)); + GL.TexCoord(new Vector3(m_SpriteRects[index].rect.xMax / m_TextureActualWidth, m_SpriteRects[index].rect.y / m_TextureActualHeight, 0)); + GL.Vertex(new Vector3(rect.x + rect.width, rect.y, 0)); + GL.TexCoord(new Vector3(m_SpriteRects[index].rect.xMax / m_TextureActualWidth, m_SpriteRects[index].rect.yMax / m_TextureActualHeight, 0)); + GL.Vertex(new Vector3(rect.x + rect.width, rect.y + rect.height, 0)); + GL.TexCoord(new Vector3(m_SpriteRects[index].rect.x / m_TextureActualWidth, m_SpriteRects[index].rect.yMax / m_TextureActualHeight, 0)); + GL.Vertex(new Vector3(rect.x, rect.y + rect.height, 0)); + var m = Handles.matrix.inverse.MultiplyPoint(Event.current.mousePosition); + if (rect.Contains(new Vector2Int((int)m.x, (int)m.y))) + { + mouseOverIndex = index; + } + ++index; + } + + GL.End(); + GL.PopMatrix(); + if (mouseOverIndex >= 0) + { + var text = new GUIContent(m_SpriteRects[mouseOverIndex].name + " " + index); + var length = EditorStyles.textArea.CalcSize(text); + var rect1 = new Rect(m_PackResult[mouseOverIndex].x, m_PackResult[mouseOverIndex].y + m_PackResult[mouseOverIndex].height * 0.5f, length.x, length.y); + rect1.position = Handles.matrix.MultiplyPoint(rect1.position); + if (Event.current.type == EventType.Repaint) + EditorStyles.textArea.Draw(rect1, text, false, false, false, false); + } + } + + Handles.matrix = oldMatrix; + } + + void SetupHandlesMatrix() + { + Vector3 handlesPos = new Vector3(0, m_PackHeight * m_Zoom, 0f); + Vector3 handlesScale = new Vector3(m_Zoom, -m_Zoom, 1f); + Handles.matrix = Matrix4x4.TRS(handlesPos, Quaternion.identity, handlesScale); + } + + protected void HandleZoom() + { + bool zoomMode = Event.current.alt && Event.current.button == 1; + if (zoomMode) + { + EditorGUIUtility.AddCursorRect(m_PackArea.worldBound, MouseCursor.Zoom); + } + + if ( + ((Event.current.type == EventType.MouseUp || Event.current.type == EventType.MouseDown) && zoomMode) || + ((Event.current.type == EventType.KeyUp || Event.current.type == EventType.KeyDown) && Event.current.keyCode == KeyCode.LeftAlt) + ) + { + Repaint(); + } + + if (Event.current.type == EventType.ScrollWheel || (Event.current.type == EventType.MouseDrag && Event.current.alt && Event.current.button == 1)) + { + float zoomMultiplier = 1f - Event.current.delta.y * (Event.current.type == EventType.ScrollWheel ? k_WheelZoomSpeed : -k_MouseZoomSpeed); + + // Clamp zoom + float wantedZoom = m_Zoom * zoomMultiplier; + + float currentZoom = Mathf.Clamp(wantedZoom, GetMinZoom(), 1); + + if (currentZoom != m_Zoom) + { + m_Zoom = currentZoom; + Event.current.Use(); + } + } + } + + protected float GetMinZoom() + { + if (m_Texture == null) + return 1.0f; + return Mathf.Min(m_PackArea.worldBound.width / m_PackWidth, m_PackArea.worldBound.height / m_PackHeight, 0.05f) * k_MinZoomPercentage; + } + } +} diff --git a/package/Editor/InternalBridge/InternalEditorBridge.cs b/package/Editor/InternalBridge/InternalEditorBridge.cs index 2451e34eb..e4ef74844 100755 --- a/package/Editor/InternalBridge/InternalEditorBridge.cs +++ b/package/Editor/InternalBridge/InternalEditorBridge.cs @@ -4,6 +4,7 @@ using System.Reflection; using UnityEditor.ShortcutManagement; using UnityEngine; +using UnityEngine.Events; namespace UnityEditor.Experimental.U2D.Common { @@ -95,71 +96,24 @@ public bool active public object context { get; set; } } - public class WrappedShortcutAttribute : ShortcutAttribute - { - static readonly WrappedShortcutArguments[] k_ReusableShortcutArgs = { new WrappedShortcutArguments() }; - static readonly object[] k_EmptyReusableShortcutArgs = {}; - - public WrappedShortcutAttribute(string identifier, Type context = null, string defaultKeyCombination = null) - : base(identifier, context, defaultKeyCombination) - {} - - public override ShortcutEntry CreateShortcutEntry(MethodInfo methodInfo) - { - var identifier = new Identifier(methodInfo, this); - - IEnumerable defaultCombination; - - KeyCombination keyCombination; - if (KeyCombination.TryParseMenuItemBindingString(defaultKeyCombination, out keyCombination)) - defaultCombination = new[] { keyCombination }; - else - defaultCombination = Enumerable.Empty(); - - var type = ShortcutType.Action; - //var type = this is ClutchShortcutAttribute ? ShortcutType.Clutch : ShortcutType.Action; - var methodParams = methodInfo.GetParameters(); - Action action; - if (methodParams.Length == 0) - { - action = shortcutArgs => - { - methodInfo.Invoke(null, k_EmptyReusableShortcutArgs); - }; - } - else - { - action = shortcutArgs => - { - k_ReusableShortcutArgs[0].context = shortcutArgs.context; - k_ReusableShortcutArgs[0].state = shortcutArgs.state; - methodInfo.Invoke(null, k_ReusableShortcutArgs); - }; - } - - return new ShortcutEntry(identifier, defaultCombination, action, context, type); - } - } - - public class WrappedShortcutArguments + public static void RegisterShortcutContext(ShortcutContext context) { - public object context; - public ShortcutState state; + ShortcutIntegration.instance.contextManager.RegisterToolContext(context); } - public static ShortcutContext CreateShortcutContext(Func isActiveFunc) + public static void UnregisterShortcutContext(ShortcutContext context) { - return new ShortcutContext() { isActive = isActiveFunc, context = null }; + ShortcutIntegration.instance.contextManager.DeregisterToolContext(context); } - public static void RegisterShortcutContext(ShortcutContext context) + public static void AddEditorApplicationProjectLoadedCallback(UnityAction callback) { - ShortcutIntegration.instance.contextManager.RegisterToolContext(context); + EditorApplication.projectWasLoaded += callback; } - public static void UnregisterShortcutContext(ShortcutContext context) + public static void RemoveEditorApplicationProjectLoadedCallback(UnityAction callback) { - ShortcutIntegration.instance.contextManager.DeregisterToolContext(context); + EditorApplication.projectWasLoaded -= callback; } } } diff --git a/package/Runtime/InternalBridge/InternalEngineBridge.cs b/package/Runtime/InternalBridge/InternalEngineBridge.cs index 6d33533a1..9a5062ff7 100755 --- a/package/Runtime/InternalBridge/InternalEngineBridge.cs +++ b/package/Runtime/InternalBridge/InternalEngineBridge.cs @@ -1,4 +1,5 @@ -using UnityEngine.Experimental.UIElements; +using UnityEngine.UIElements; +using Unity.Collections; namespace UnityEngine.Experimental.U2D.Common { @@ -9,6 +10,11 @@ public static void SetLocalAABB(SpriteRenderer spriteRenderer, Bounds aabb) spriteRenderer.SetLocalAABB(aabb); } + public static void SetDeformableBuffer(SpriteRenderer spriteRenderer, NativeArray src) + { + spriteRenderer.SetDeformableBuffer(src); + } + public static Vector2 GUIUnclip(Vector2 v) { return GUIClip.Unclip(v); diff --git a/package/package.json b/package/package.json index 23bf1f1a4..98c37bd44 100755 --- a/package/package.json +++ b/package/package.json @@ -1,8 +1,8 @@ { "name": "com.unity.2d.common", "displayName": "2D Common", - "version": "1.0.11-preview.4", - "unity": "2018.3", + "version": "1.1.0-preview.1", + "unity": "2019.1", "description": "2D Common is a package that contains shared functionalities that are used by most of the other 2D packages.", "keywords": [ "2d" @@ -15,6 +15,6 @@ "repository": { "type": "git", "url": "https://gitlab.cds.internal.unity3d.com/upm-packages/2D/com.unity.2d.common.git", - "revision": "33cc6e43ea48d635922c284eebc5f04af50ea7fc" + "revision": "259866922626127fd2bb606a14c467775d65ddf1" } } diff --git a/versions.txt b/versions.txt index 10bcffe72..53419158a 100755 --- a/versions.txt +++ b/versions.txt @@ -13,3 +13,4 @@ 1.0.10-preview 1.0.11-preview.1 1.0.11-preview.4 +1.1.0-preview.1