mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Merge branch '3.8' into 3.9-beta
This commit is contained in:
commit
98393ad244
@ -115,6 +115,15 @@ namespace Spine.Unity.Editor {
|
|||||||
EditorGUILayout.LabelField("UI", EditorStyles.boldLabel);
|
EditorGUILayout.LabelField("UI", EditorStyles.boldLabel);
|
||||||
EditorGUILayout.PropertyField(raycastTarget);
|
EditorGUILayout.PropertyField(raycastTarget);
|
||||||
|
|
||||||
|
EditorGUILayout.BeginHorizontal(GUILayout.Height(EditorGUIUtility.singleLineHeight + 5));
|
||||||
|
EditorGUILayout.PrefixLabel("Match RectTransform with Mesh");
|
||||||
|
if (GUILayout.Button("Match", EditorStyles.miniButton, GUILayout.Width(65f))) {
|
||||||
|
foreach (var skeletonGraphic in targets) {
|
||||||
|
MatchRectTransformWithBounds((SkeletonGraphic)skeletonGraphic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EditorGUILayout.EndHorizontal();
|
||||||
|
|
||||||
bool wasChanged = EditorGUI.EndChangeCheck();
|
bool wasChanged = EditorGUI.EndChangeCheck();
|
||||||
|
|
||||||
if (wasChanged)
|
if (wasChanged)
|
||||||
@ -125,29 +134,12 @@ namespace Spine.Unity.Editor {
|
|||||||
[MenuItem("CONTEXT/SkeletonGraphic/Match RectTransform with Mesh Bounds")]
|
[MenuItem("CONTEXT/SkeletonGraphic/Match RectTransform with Mesh Bounds")]
|
||||||
static void MatchRectTransformWithBounds (MenuCommand command) {
|
static void MatchRectTransformWithBounds (MenuCommand command) {
|
||||||
var skeletonGraphic = (SkeletonGraphic)command.context;
|
var skeletonGraphic = (SkeletonGraphic)command.context;
|
||||||
Mesh mesh = skeletonGraphic.GetLastMesh();
|
MatchRectTransformWithBounds(skeletonGraphic);
|
||||||
if (mesh == null) {
|
}
|
||||||
|
|
||||||
|
static void MatchRectTransformWithBounds (SkeletonGraphic skeletonGraphic) {
|
||||||
|
if (!skeletonGraphic.MatchRectTransformWithBounds())
|
||||||
Debug.Log("Mesh was not previously generated.");
|
Debug.Log("Mesh was not previously generated.");
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mesh.vertexCount == 0) {
|
|
||||||
skeletonGraphic.rectTransform.sizeDelta = new Vector2(50f, 50f);
|
|
||||||
skeletonGraphic.rectTransform.pivot = new Vector2(0.5f, 0.5f);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mesh.RecalculateBounds();
|
|
||||||
var bounds = mesh.bounds;
|
|
||||||
var size = bounds.size;
|
|
||||||
var center = bounds.center;
|
|
||||||
var p = new Vector2(
|
|
||||||
0.5f - (center.x / size.x),
|
|
||||||
0.5f - (center.y / size.y)
|
|
||||||
);
|
|
||||||
|
|
||||||
skeletonGraphic.rectTransform.sizeDelta = size;
|
|
||||||
skeletonGraphic.rectTransform.pivot = p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[MenuItem("GameObject/Spine/SkeletonGraphic (UnityUI)", false, 15)]
|
[MenuItem("GameObject/Spine/SkeletonGraphic (UnityUI)", false, 15)]
|
||||||
@ -200,7 +192,6 @@ namespace Spine.Unity.Editor {
|
|||||||
graphic.initialSkinName = skin.Name;
|
graphic.initialSkinName = skin.Name;
|
||||||
graphic.Skeleton.UpdateWorldTransform();
|
graphic.Skeleton.UpdateWorldTransform();
|
||||||
graphic.UpdateMesh();
|
graphic.UpdateMesh();
|
||||||
|
|
||||||
return graphic;
|
return graphic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -47,6 +47,7 @@ namespace Spine.Unity.Editor {
|
|||||||
public static class DragAndDropInstantiation {
|
public static class DragAndDropInstantiation {
|
||||||
public struct SpawnMenuData {
|
public struct SpawnMenuData {
|
||||||
public Vector3 spawnPoint;
|
public Vector3 spawnPoint;
|
||||||
|
public Transform parent;
|
||||||
public SkeletonDataAsset skeletonDataAsset;
|
public SkeletonDataAsset skeletonDataAsset;
|
||||||
public EditorInstantiation.InstantiateDelegate instantiateDelegate;
|
public EditorInstantiation.InstantiateDelegate instantiateDelegate;
|
||||||
public bool isUI;
|
public bool isUI;
|
||||||
@ -81,7 +82,7 @@ namespace Spine.Unity.Editor {
|
|||||||
RectTransform rectTransform = (Selection.activeGameObject == null) ? null : Selection.activeGameObject.GetComponent<RectTransform>();
|
RectTransform rectTransform = (Selection.activeGameObject == null) ? null : Selection.activeGameObject.GetComponent<RectTransform>();
|
||||||
Plane plane = (rectTransform == null) ? new Plane(Vector3.back, Vector3.zero) : new Plane(-rectTransform.forward, rectTransform.position);
|
Plane plane = (rectTransform == null) ? new Plane(Vector3.back, Vector3.zero) : new Plane(-rectTransform.forward, rectTransform.position);
|
||||||
Vector3 spawnPoint = MousePointToWorldPoint2D(mousePos, sceneview.camera, plane);
|
Vector3 spawnPoint = MousePointToWorldPoint2D(mousePos, sceneview.camera, plane);
|
||||||
ShowInstantiateContextMenu(skeletonDataAsset, spawnPoint);
|
ShowInstantiateContextMenu(skeletonDataAsset, spawnPoint, null);
|
||||||
DragAndDrop.AcceptDrag();
|
DragAndDrop.AcceptDrag();
|
||||||
current.Use();
|
current.Use();
|
||||||
}
|
}
|
||||||
@ -90,13 +91,14 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ShowInstantiateContextMenu (SkeletonDataAsset skeletonDataAsset, Vector3 spawnPoint) {
|
public static void ShowInstantiateContextMenu (SkeletonDataAsset skeletonDataAsset, Vector3 spawnPoint, Transform parent) {
|
||||||
var menu = new GenericMenu();
|
var menu = new GenericMenu();
|
||||||
|
|
||||||
// SkeletonAnimation
|
// SkeletonAnimation
|
||||||
menu.AddItem(new GUIContent("SkeletonAnimation"), false, HandleSkeletonComponentDrop, new SpawnMenuData {
|
menu.AddItem(new GUIContent("SkeletonAnimation"), false, HandleSkeletonComponentDrop, new SpawnMenuData {
|
||||||
skeletonDataAsset = skeletonDataAsset,
|
skeletonDataAsset = skeletonDataAsset,
|
||||||
spawnPoint = spawnPoint,
|
spawnPoint = spawnPoint,
|
||||||
|
parent = parent,
|
||||||
instantiateDelegate = (data) => EditorInstantiation.InstantiateSkeletonAnimation(data),
|
instantiateDelegate = (data) => EditorInstantiation.InstantiateSkeletonAnimation(data),
|
||||||
isUI = false
|
isUI = false
|
||||||
});
|
});
|
||||||
@ -109,6 +111,7 @@ namespace Spine.Unity.Editor {
|
|||||||
menu.AddItem(new GUIContent("SkeletonGraphic (UI)"), false, HandleSkeletonComponentDrop, new SpawnMenuData {
|
menu.AddItem(new GUIContent("SkeletonGraphic (UI)"), false, HandleSkeletonComponentDrop, new SpawnMenuData {
|
||||||
skeletonDataAsset = skeletonDataAsset,
|
skeletonDataAsset = skeletonDataAsset,
|
||||||
spawnPoint = spawnPoint,
|
spawnPoint = spawnPoint,
|
||||||
|
parent = parent,
|
||||||
instantiateDelegate = System.Delegate.CreateDelegate(typeof(EditorInstantiation.InstantiateDelegate), graphicInstantiateDelegate) as EditorInstantiation.InstantiateDelegate,
|
instantiateDelegate = System.Delegate.CreateDelegate(typeof(EditorInstantiation.InstantiateDelegate), graphicInstantiateDelegate) as EditorInstantiation.InstantiateDelegate,
|
||||||
isUI = true
|
isUI = true
|
||||||
});
|
});
|
||||||
@ -120,7 +123,9 @@ namespace Spine.Unity.Editor {
|
|||||||
menu.AddItem(new GUIContent("SkeletonMecanim"), false, HandleSkeletonComponentDrop, new SpawnMenuData {
|
menu.AddItem(new GUIContent("SkeletonMecanim"), false, HandleSkeletonComponentDrop, new SpawnMenuData {
|
||||||
skeletonDataAsset = skeletonDataAsset,
|
skeletonDataAsset = skeletonDataAsset,
|
||||||
spawnPoint = spawnPoint,
|
spawnPoint = spawnPoint,
|
||||||
instantiateDelegate = (data) => EditorInstantiation.InstantiateSkeletonMecanim(data)
|
parent = parent,
|
||||||
|
instantiateDelegate = (data) => EditorInstantiation.InstantiateSkeletonMecanim(data),
|
||||||
|
isUI = false
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -141,16 +146,21 @@ namespace Spine.Unity.Editor {
|
|||||||
GameObject newGameObject = newSkeletonComponent.gameObject;
|
GameObject newGameObject = newSkeletonComponent.gameObject;
|
||||||
Transform newTransform = newGameObject.transform;
|
Transform newTransform = newGameObject.transform;
|
||||||
|
|
||||||
var activeGameObject = Selection.activeGameObject;
|
var usedParent = data.parent != null ? data.parent.gameObject : isUI ? Selection.activeGameObject : null;
|
||||||
if (isUI && activeGameObject != null)
|
if (usedParent)
|
||||||
newTransform.SetParent(activeGameObject.transform, false);
|
newTransform.SetParent(usedParent.transform, false);
|
||||||
|
|
||||||
newTransform.position = isUI ? data.spawnPoint : RoundVector(data.spawnPoint, 2);
|
newTransform.position = isUI ? data.spawnPoint : RoundVector(data.spawnPoint, 2);
|
||||||
|
|
||||||
if (isUI && (activeGameObject == null || activeGameObject.GetComponent<RectTransform>() == null))
|
if (isUI) {
|
||||||
|
if (usedParent != null && usedParent.GetComponent<RectTransform>() != null) {
|
||||||
|
((SkeletonGraphic)newSkeletonComponent).MatchRectTransformWithBounds();
|
||||||
|
}
|
||||||
|
else
|
||||||
Debug.Log("Created a UI Skeleton GameObject not under a RectTransform. It may not be visible until you parent it to a canvas.");
|
Debug.Log("Created a UI Skeleton GameObject not under a RectTransform. It may not be visible until you parent it to a canvas.");
|
||||||
|
}
|
||||||
|
|
||||||
if (!isUI && activeGameObject != null && activeGameObject.transform.localScale != Vector3.one)
|
if (!isUI && usedParent != null && usedParent.transform.localScale != Vector3.one)
|
||||||
Debug.Log("New Spine GameObject was parented to a scaled Transform. It may not be the intended size.");
|
Debug.Log("New Spine GameObject was parented to a scaled Transform. It may not be the intended size.");
|
||||||
|
|
||||||
Selection.activeGameObject = newGameObject;
|
Selection.activeGameObject = newGameObject;
|
||||||
|
|||||||
@ -299,6 +299,7 @@ namespace Spine.Unity.Editor {
|
|||||||
var eventType = current.type;
|
var eventType = current.type;
|
||||||
bool isDraggingEvent = eventType == EventType.DragUpdated;
|
bool isDraggingEvent = eventType == EventType.DragUpdated;
|
||||||
bool isDropEvent = eventType == EventType.DragPerform;
|
bool isDropEvent = eventType == EventType.DragPerform;
|
||||||
|
|
||||||
if (isDraggingEvent || isDropEvent) {
|
if (isDraggingEvent || isDropEvent) {
|
||||||
var mouseOverWindow = EditorWindow.mouseOverWindow;
|
var mouseOverWindow = EditorWindow.mouseOverWindow;
|
||||||
if (mouseOverWindow != null) {
|
if (mouseOverWindow != null) {
|
||||||
@ -312,12 +313,19 @@ namespace Spine.Unity.Editor {
|
|||||||
// Allow drag-and-dropping anywhere in the Hierarchy Window.
|
// Allow drag-and-dropping anywhere in the Hierarchy Window.
|
||||||
// HACK: string-compare because we can't get its type via reflection.
|
// HACK: string-compare because we can't get its type via reflection.
|
||||||
const string HierarchyWindow = "UnityEditor.SceneHierarchyWindow";
|
const string HierarchyWindow = "UnityEditor.SceneHierarchyWindow";
|
||||||
|
const string GenericDataTargetID = "target";
|
||||||
if (HierarchyWindow.Equals(mouseOverWindow.GetType().ToString(), System.StringComparison.Ordinal)) {
|
if (HierarchyWindow.Equals(mouseOverWindow.GetType().ToString(), System.StringComparison.Ordinal)) {
|
||||||
if (isDraggingEvent) {
|
if (isDraggingEvent) {
|
||||||
UnityEditor.DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
|
UnityEditor.DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
|
||||||
current.Use();
|
|
||||||
|
var mouseOverTarget = UnityEditor.EditorUtility.InstanceIDToObject(instanceId);
|
||||||
|
if (mouseOverTarget)
|
||||||
|
DragAndDrop.SetGenericData(GenericDataTargetID, mouseOverTarget);
|
||||||
|
// note: do not use the current event, otherwise we lose the nice mouse-over highlighting.
|
||||||
} else if (isDropEvent) {
|
} else if (isDropEvent) {
|
||||||
DragAndDropInstantiation.ShowInstantiateContextMenu(skeletonDataAsset, Vector3.zero);
|
var parentGameObject = DragAndDrop.GetGenericData(GenericDataTargetID) as UnityEngine.GameObject;
|
||||||
|
Transform parent = parentGameObject != null ? parentGameObject.transform : null;
|
||||||
|
DragAndDropInstantiation.ShowInstantiateContextMenu(skeletonDataAsset, Vector3.zero, parent);
|
||||||
UnityEditor.DragAndDrop.AcceptDrag();
|
UnityEditor.DragAndDrop.AcceptDrag();
|
||||||
current.Use();
|
current.Use();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -239,6 +239,34 @@ namespace Spine.Unity {
|
|||||||
return meshBuffers.GetCurrent().mesh;
|
return meshBuffers.GetCurrent().mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool MatchRectTransformWithBounds () {
|
||||||
|
UpdateMesh();
|
||||||
|
|
||||||
|
Mesh mesh = this.GetLastMesh();
|
||||||
|
if (mesh == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mesh.vertexCount == 0) {
|
||||||
|
this.rectTransform.sizeDelta = new Vector2(50f, 50f);
|
||||||
|
this.rectTransform.pivot = new Vector2(0.5f, 0.5f);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mesh.RecalculateBounds();
|
||||||
|
var bounds = mesh.bounds;
|
||||||
|
var size = bounds.size;
|
||||||
|
var center = bounds.center;
|
||||||
|
var p = new Vector2(
|
||||||
|
0.5f - (center.x / size.x),
|
||||||
|
0.5f - (center.y / size.y)
|
||||||
|
);
|
||||||
|
|
||||||
|
this.rectTransform.sizeDelta = size;
|
||||||
|
this.rectTransform.pivot = p;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public event UpdateBonesDelegate UpdateLocal;
|
public event UpdateBonesDelegate UpdateLocal;
|
||||||
public event UpdateBonesDelegate UpdateWorld;
|
public event UpdateBonesDelegate UpdateWorld;
|
||||||
public event UpdateBonesDelegate UpdateComplete;
|
public event UpdateBonesDelegate UpdateComplete;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user