|
@@ -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;
|
|
|
|
- if (isUI && activeGameObject != null)
|
|
|
|
- newTransform.SetParent(activeGameObject.transform, false);
|
|
|
|
|
|
+ var usedParent = data.parent != null ? data.parent.gameObject : isUI ? Selection.activeGameObject : null;
|
|
|
|
+ if (usedParent)
|
|
|
|
+ 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))
|
|
|
|
- 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) {
|
|
|
|
+ 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.");
|
|
|
|
+ }
|
|
|
|
|
|
- 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;
|