|
@@ -139,7 +139,7 @@ namespace Spine.Unity {
|
|
public bool flipBy180DegreeRotation = false;
|
|
public bool flipBy180DegreeRotation = false;
|
|
|
|
|
|
void Update () {
|
|
void Update () {
|
|
- var skeleton = skeletonRenderer.skeleton;
|
|
|
|
|
|
+ var skeleton = skeletonComponent.Skeleton;
|
|
if (skeleton != null && boneRoot != null) {
|
|
if (skeleton != null && boneRoot != null) {
|
|
|
|
|
|
if (flipBy180DegreeRotation) {
|
|
if (flipBy180DegreeRotation) {
|
|
@@ -151,14 +151,51 @@ namespace Spine.Unity {
|
|
else {
|
|
else {
|
|
boneRoot.localScale = new Vector3(skeleton.ScaleX, skeleton.ScaleY, 1f);
|
|
boneRoot.localScale = new Vector3(skeleton.ScaleX, skeleton.ScaleY, 1f);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (canvas != null) {
|
|
|
|
+ positionScale = canvas.referencePixelsPerUnit;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
[HideInInspector] public SkeletonRenderer skeletonRenderer;
|
|
[HideInInspector] public SkeletonRenderer skeletonRenderer;
|
|
- [HideInInspector] public ISkeletonAnimation skeletonAnimation;
|
|
|
|
|
|
+ [HideInInspector] public SkeletonGraphic skeletonGraphic;
|
|
|
|
+ private Canvas canvas;
|
|
|
|
+ [System.NonSerialized] public ISkeletonAnimation skeletonAnimation;
|
|
|
|
+
|
|
|
|
+ private ISkeletonComponent skeletonComponent;
|
|
[System.NonSerialized] public List<SkeletonUtilityBone> boneComponents = new List<SkeletonUtilityBone>();
|
|
[System.NonSerialized] public List<SkeletonUtilityBone> boneComponents = new List<SkeletonUtilityBone>();
|
|
[System.NonSerialized] public List<SkeletonUtilityConstraint> constraintComponents = new List<SkeletonUtilityConstraint>();
|
|
[System.NonSerialized] public List<SkeletonUtilityConstraint> constraintComponents = new List<SkeletonUtilityConstraint>();
|
|
|
|
|
|
|
|
+
|
|
|
|
+ public ISkeletonComponent SkeletonComponent {
|
|
|
|
+ get {
|
|
|
|
+ if (skeletonComponent == null) {
|
|
|
|
+ skeletonComponent = skeletonRenderer != null ? skeletonRenderer.GetComponent<ISkeletonComponent>() :
|
|
|
|
+ skeletonGraphic != null ? skeletonGraphic.GetComponent<ISkeletonComponent>() :
|
|
|
|
+ GetComponent<ISkeletonComponent>();
|
|
|
|
+ }
|
|
|
|
+ return skeletonComponent;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public Skeleton Skeleton {
|
|
|
|
+ get {
|
|
|
|
+ if (SkeletonComponent == null)
|
|
|
|
+ return null;
|
|
|
|
+ return skeletonComponent.Skeleton;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public bool IsValid {
|
|
|
|
+ get {
|
|
|
|
+ return (skeletonRenderer != null && skeletonRenderer.valid) ||
|
|
|
|
+ (skeletonGraphic != null && skeletonGraphic.IsValid);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public float PositionScale { get { return positionScale; } }
|
|
|
|
+
|
|
|
|
+ float positionScale = 1.0f;
|
|
bool hasOverrideBones;
|
|
bool hasOverrideBones;
|
|
bool hasConstraints;
|
|
bool hasConstraints;
|
|
bool needToReprocessBones;
|
|
bool needToReprocessBones;
|
|
@@ -167,18 +204,38 @@ namespace Spine.Unity {
|
|
OnDisable();
|
|
OnDisable();
|
|
OnEnable();
|
|
OnEnable();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
void OnEnable () {
|
|
void OnEnable () {
|
|
if (skeletonRenderer == null) {
|
|
if (skeletonRenderer == null) {
|
|
skeletonRenderer = GetComponent<SkeletonRenderer>();
|
|
skeletonRenderer = GetComponent<SkeletonRenderer>();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ if (skeletonGraphic == null) {
|
|
|
|
+ skeletonGraphic = GetComponent<SkeletonGraphic>();
|
|
|
|
+ }
|
|
if (skeletonAnimation == null) {
|
|
if (skeletonAnimation == null) {
|
|
- skeletonAnimation = GetComponent(typeof(ISkeletonAnimation)) as ISkeletonAnimation;
|
|
|
|
|
|
+ skeletonAnimation = skeletonRenderer != null ? skeletonRenderer.GetComponent<ISkeletonAnimation>() :
|
|
|
|
+ skeletonGraphic != null ? skeletonGraphic.GetComponent<ISkeletonAnimation>() :
|
|
|
|
+ GetComponent<ISkeletonAnimation>();
|
|
|
|
+ }
|
|
|
|
+ if (skeletonComponent == null) {
|
|
|
|
+ skeletonComponent = skeletonRenderer != null ? skeletonRenderer.GetComponent<ISkeletonComponent>() :
|
|
|
|
+ skeletonGraphic != null ? skeletonGraphic.GetComponent<ISkeletonComponent>() :
|
|
|
|
+ GetComponent<ISkeletonComponent>();
|
|
}
|
|
}
|
|
|
|
|
|
- skeletonRenderer.OnRebuild -= HandleRendererReset;
|
|
|
|
- skeletonRenderer.OnRebuild += HandleRendererReset;
|
|
|
|
|
|
+ if (skeletonRenderer != null) {
|
|
|
|
+ skeletonRenderer.OnRebuild -= HandleRendererReset;
|
|
|
|
+ skeletonRenderer.OnRebuild += HandleRendererReset;
|
|
|
|
+ }
|
|
|
|
+ else if (skeletonGraphic != null) {
|
|
|
|
+ skeletonGraphic.OnRebuild -= HandleRendererReset;
|
|
|
|
+ skeletonGraphic.OnRebuild += HandleRendererReset;
|
|
|
|
+ canvas = skeletonGraphic.canvas;
|
|
|
|
+ if (canvas == null)
|
|
|
|
+ canvas = skeletonGraphic.GetComponentInParent<Canvas>();
|
|
|
|
+ if (canvas == null)
|
|
|
|
+ positionScale = 100.0f;
|
|
|
|
+ }
|
|
|
|
|
|
if (skeletonAnimation != null) {
|
|
if (skeletonAnimation != null) {
|
|
skeletonAnimation.UpdateLocal -= UpdateLocal;
|
|
skeletonAnimation.UpdateLocal -= UpdateLocal;
|
|
@@ -194,7 +251,10 @@ namespace Spine.Unity {
|
|
}
|
|
}
|
|
|
|
|
|
void OnDisable () {
|
|
void OnDisable () {
|
|
- skeletonRenderer.OnRebuild -= HandleRendererReset;
|
|
|
|
|
|
+ if (skeletonRenderer != null)
|
|
|
|
+ skeletonRenderer.OnRebuild -= HandleRendererReset;
|
|
|
|
+ if (skeletonGraphic != null)
|
|
|
|
+ skeletonGraphic.OnRebuild -= HandleRendererReset;
|
|
|
|
|
|
if (skeletonAnimation != null) {
|
|
if (skeletonAnimation != null) {
|
|
skeletonAnimation.UpdateLocal -= UpdateLocal;
|
|
skeletonAnimation.UpdateLocal -= UpdateLocal;
|
|
@@ -208,6 +268,11 @@ namespace Spine.Unity {
|
|
CollectBones();
|
|
CollectBones();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ void HandleRendererReset (SkeletonGraphic g) {
|
|
|
|
+ if (OnReset != null) OnReset();
|
|
|
|
+ CollectBones();
|
|
|
|
+ }
|
|
|
|
+
|
|
public void RegisterBone (SkeletonUtilityBone bone) {
|
|
public void RegisterBone (SkeletonUtilityBone bone) {
|
|
if (boneComponents.Contains(bone)) {
|
|
if (boneComponents.Contains(bone)) {
|
|
return;
|
|
return;
|
|
@@ -235,7 +300,7 @@ namespace Spine.Unity {
|
|
}
|
|
}
|
|
|
|
|
|
public void CollectBones () {
|
|
public void CollectBones () {
|
|
- var skeleton = skeletonRenderer.skeleton;
|
|
|
|
|
|
+ var skeleton = skeletonComponent.Skeleton;
|
|
if (skeleton == null) return;
|
|
if (skeleton == null) return;
|
|
|
|
|
|
if (boneRoot != null) {
|
|
if (boneRoot != null) {
|
|
@@ -315,12 +380,16 @@ namespace Spine.Unity {
|
|
if (boneRoot != null)
|
|
if (boneRoot != null)
|
|
return boneRoot;
|
|
return boneRoot;
|
|
|
|
|
|
- boneRoot = new GameObject("SkeletonUtility-SkeletonRoot").transform;
|
|
|
|
|
|
+ var boneRootObject = new GameObject("SkeletonUtility-SkeletonRoot");
|
|
#if UNITY_EDITOR
|
|
#if UNITY_EDITOR
|
|
if (!Application.isPlaying)
|
|
if (!Application.isPlaying)
|
|
- UnityEditor.Undo.RegisterCreatedObjectUndo(boneRoot.gameObject, "Spawn Bone");
|
|
|
|
|
|
+ UnityEditor.Undo.RegisterCreatedObjectUndo(boneRootObject, "Spawn Bone");
|
|
#endif
|
|
#endif
|
|
- boneRoot.parent = transform;
|
|
|
|
|
|
+ if (skeletonGraphic != null)
|
|
|
|
+ boneRootObject.AddComponent<RectTransform>();
|
|
|
|
+
|
|
|
|
+ boneRoot = boneRootObject.transform;
|
|
|
|
+ boneRoot.SetParent(transform);
|
|
boneRoot.localPosition = Vector3.zero;
|
|
boneRoot.localPosition = Vector3.zero;
|
|
boneRoot.localRotation = Quaternion.identity;
|
|
boneRoot.localRotation = Quaternion.identity;
|
|
boneRoot.localScale = Vector3.one;
|
|
boneRoot.localScale = Vector3.one;
|
|
@@ -330,7 +399,7 @@ namespace Spine.Unity {
|
|
|
|
|
|
public GameObject SpawnRoot (SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca) {
|
|
public GameObject SpawnRoot (SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca) {
|
|
GetBoneRoot();
|
|
GetBoneRoot();
|
|
- Skeleton skeleton = this.skeletonRenderer.skeleton;
|
|
|
|
|
|
+ Skeleton skeleton = this.skeletonComponent.Skeleton;
|
|
|
|
|
|
GameObject go = SpawnBone(skeleton.RootBone, boneRoot, mode, pos, rot, sca);
|
|
GameObject go = SpawnBone(skeleton.RootBone, boneRoot, mode, pos, rot, sca);
|
|
CollectBones();
|
|
CollectBones();
|
|
@@ -339,7 +408,7 @@ namespace Spine.Unity {
|
|
|
|
|
|
public GameObject SpawnHierarchy (SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca) {
|
|
public GameObject SpawnHierarchy (SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca) {
|
|
GetBoneRoot();
|
|
GetBoneRoot();
|
|
- Skeleton skeleton = this.skeletonRenderer.skeleton;
|
|
|
|
|
|
+ Skeleton skeleton = this.skeletonComponent.Skeleton;
|
|
GameObject go = SpawnBoneRecursively(skeleton.RootBone, boneRoot, mode, pos, rot, sca);
|
|
GameObject go = SpawnBoneRecursively(skeleton.RootBone, boneRoot, mode, pos, rot, sca);
|
|
CollectBones();
|
|
CollectBones();
|
|
return go;
|
|
return go;
|
|
@@ -363,8 +432,11 @@ namespace Spine.Unity {
|
|
if (!Application.isPlaying)
|
|
if (!Application.isPlaying)
|
|
UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Spawn Bone");
|
|
UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Spawn Bone");
|
|
#endif
|
|
#endif
|
|
|
|
+ if (skeletonGraphic != null)
|
|
|
|
+ go.AddComponent<RectTransform>();
|
|
|
|
+
|
|
var goTransform = go.transform;
|
|
var goTransform = go.transform;
|
|
- goTransform.parent = parent;
|
|
|
|
|
|
+ goTransform.SetParent(parent);
|
|
|
|
|
|
SkeletonUtilityBone b = go.AddComponent<SkeletonUtilityBone>();
|
|
SkeletonUtilityBone b = go.AddComponent<SkeletonUtilityBone>();
|
|
b.hierarchy = this;
|
|
b.hierarchy = this;
|
|
@@ -380,7 +452,7 @@ namespace Spine.Unity {
|
|
|
|
|
|
if (mode == SkeletonUtilityBone.Mode.Override) {
|
|
if (mode == SkeletonUtilityBone.Mode.Override) {
|
|
if (rot) goTransform.localRotation = Quaternion.Euler(0, 0, b.bone.AppliedRotation);
|
|
if (rot) goTransform.localRotation = Quaternion.Euler(0, 0, b.bone.AppliedRotation);
|
|
- if (pos) goTransform.localPosition = new Vector3(b.bone.X, b.bone.Y, 0);
|
|
|
|
|
|
+ if (pos) goTransform.localPosition = new Vector3(b.bone.X * positionScale, b.bone.Y * positionScale, 0);
|
|
goTransform.localScale = new Vector3(b.bone.scaleX, b.bone.scaleY, 0);
|
|
goTransform.localScale = new Vector3(b.bone.scaleX, b.bone.scaleY, 0);
|
|
}
|
|
}
|
|
|
|
|