[unity] Assorted cleanup.

This commit is contained in:
pharan 2018-10-08 04:55:47 +08:00
parent 230ae89d66
commit 910e88bbb3
13 changed files with 126 additions and 139 deletions

View File

@ -341,12 +341,6 @@ namespace Spine.Unity.Editor {
public SerializedSortingProperties (Renderer r) : this(new SerializedObject(r)) {}
public SerializedSortingProperties (Object[] renderers) : this(new SerializedObject(renderers)) {}
/// <summary>
/// Initializes a new instance of the
/// <see cref="Spine.Unity.Editor.SpineInspectorUtility.SerializedSortingProperties"/> struct.
/// </summary>
/// <param name="rendererSerializedObject">SerializedObject of the renderer. Use
/// <see cref="Spine.Unity.Editor.SpineInspectorUtility.GetRenderersSerializedObject"/> to easily generate this.</param>
public SerializedSortingProperties (SerializedObject rendererSerializedObject) {
renderer = rendererSerializedObject;
sortingLayerID = renderer.FindProperty("m_SortingLayerID");

View File

@ -53,7 +53,6 @@ namespace Spine.Unity.Editor {
bool canCreateHingeChain = false;
Dictionary<Slot, List<BoundingBoxAttachment>> boundingBoxTable = new Dictionary<Slot, List<BoundingBoxAttachment>>();
//string currentSkinName = "";
void OnEnable () {
mode = this.serializedObject.FindProperty("mode");
@ -81,7 +80,6 @@ namespace Spine.Unity.Editor {
if (skeleton.Skin == null)
skin = skeleton.Data.DefaultSkin;
//currentSkinName = skin.Name;
for(int i = 0; i < slotCount; i++){
Slot slot = skeletonUtility.skeletonRenderer.skeleton.Slots.Items[i];
if (slot.Bone == utilityBone.bone) {
@ -103,7 +101,7 @@ namespace Spine.Unity.Editor {
void EvaluateFlags () {
utilityBone = (SkeletonUtilityBone)target;
skeletonUtility = utilityBone.skeletonUtility;
skeletonUtility = utilityBone.hierarchy;
if (Selection.objects.Length == 1) {
containsFollows = utilityBone.mode == SkeletonUtilityBone.Mode.Follow;
@ -146,7 +144,7 @@ namespace Spine.Unity.Editor {
using (new GUILayout.HorizontalScope()) {
EditorGUILayout.PrefixLabel("Bone");
if (GUILayout.Button(str, EditorStyles.popup)) {
BoneSelectorContextMenu(str, ((SkeletonUtilityBone)target).skeletonUtility.skeletonRenderer.skeleton.Bones, "<None>", TargetBoneSelected);
BoneSelectorContextMenu(str, ((SkeletonUtilityBone)target).hierarchy.skeletonRenderer.skeleton.Bones, "<None>", TargetBoneSelected);
}
}
}
@ -166,7 +164,7 @@ namespace Spine.Unity.Editor {
using (new GUILayout.HorizontalScope()) {
EditorGUILayout.Space();
using (new EditorGUI.DisabledGroupScope(multiObject || !utilityBone.valid || utilityBone.bone == null || utilityBone.bone.Children.Count == 0)) {
if (GUILayout.Button(SpineInspectorUtility.TempContent("Add Child", Icons.bone), GUILayout.MinWidth(120), GUILayout.Height(24)))
if (GUILayout.Button(SpineInspectorUtility.TempContent("Add Child Bone", Icons.bone), GUILayout.MinWidth(120), GUILayout.Height(24)))
BoneSelectorContextMenu("", utilityBone.bone.Children, "<Recursively>", SpawnChildBoneSelected);
}
using (new EditorGUI.DisabledGroupScope(multiObject || !utilityBone.valid || utilityBone.bone == null || containsOverrides)) {
@ -260,12 +258,12 @@ namespace Spine.Unity.Editor {
GameObject go = skeletonUtility.SpawnBoneRecursively(bone, utilityBone.transform, utilityBone.mode, utilityBone.position, utilityBone.rotation, utilityBone.scale);
SkeletonUtilityBone[] newUtilityBones = go.GetComponentsInChildren<SkeletonUtilityBone>();
foreach (SkeletonUtilityBone utilBone in newUtilityBones)
SkeletonUtilityInspector.AttachIcon(utilBone);
SkeletonGameObjectsInspector.AttachIcon(utilBone);
}
} else {
var bone = (Bone)obj;
GameObject go = skeletonUtility.SpawnBone(bone, utilityBone.transform, utilityBone.mode, utilityBone.position, utilityBone.rotation, utilityBone.scale);
SkeletonUtilityInspector.AttachIcon(go.GetComponent<SkeletonUtilityBone>());
SkeletonGameObjectsInspector.AttachIcon(go.GetComponent<SkeletonUtilityBone>());
Selection.activeGameObject = go;
EditorGUIUtility.PingObject(go);
}
@ -274,7 +272,7 @@ namespace Spine.Unity.Editor {
void SpawnOverride () {
GameObject go = skeletonUtility.SpawnBone(utilityBone.bone, utilityBone.transform.parent, SkeletonUtilityBone.Mode.Override, utilityBone.position, utilityBone.rotation, utilityBone.scale);
go.name = go.name + " [Override]";
SkeletonUtilityInspector.AttachIcon(go.GetComponent<SkeletonUtilityBone>());
SkeletonGameObjectsInspector.AttachIcon(go.GetComponent<SkeletonUtilityBone>());
Selection.activeGameObject = go;
EditorGUIUtility.PingObject(go);
}

View File

@ -41,18 +41,17 @@ namespace Spine.Unity.Editor {
using Icons = SpineEditorUtilities.Icons;
[CustomEditor(typeof(SkeletonUtility))]
public class SkeletonUtilityInspector : UnityEditor.Editor {
public class SkeletonGameObjectsInspector : UnityEditor.Editor {
SkeletonUtility skeletonUtility;
SkeletonUtility skeletonGameObjects;
Skeleton skeleton;
SkeletonRenderer skeletonRenderer;
bool isPrefab;
GUIContent SpawnHierarchyButtonLabel = new GUIContent("Spawn Hierarchy", Icons.skeleton);
readonly GUIContent SpawnHierarchyButtonLabel = new GUIContent("Spawn Hierarchy", Icons.skeleton);
void OnEnable () {
skeletonUtility = (SkeletonUtility)target;
skeletonRenderer = skeletonUtility.GetComponent<SkeletonRenderer>();
skeletonGameObjects = (SkeletonUtility)target;
skeletonRenderer = skeletonGameObjects.GetComponent<SkeletonRenderer>();
skeleton = skeletonRenderer.Skeleton;
if (skeleton == null) {
@ -77,9 +76,13 @@ namespace Spine.Unity.Editor {
return;
}
skeletonUtility.boneRoot = (Transform)EditorGUILayout.ObjectField("Bone Root", skeletonUtility.boneRoot, typeof(Transform), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("boneRoot"), SpineInspectorUtility.TempContent("Skeleton Root"));
bool hasRootBone = skeletonGameObjects.boneRoot != null;
if (!hasRootBone)
EditorGUILayout.HelpBox("No hierarchy found. Use Spawn Hierarchy to generate GameObjects for bones.", MessageType.Info);
bool hasRootBone = skeletonUtility.boneRoot != null;
using (new EditorGUI.DisabledGroupScope(hasRootBone)) {
if (SpineInspectorUtility.LargeCenteredButton(SpawnHierarchyButtonLabel))
SpawnHierarchyContextMenu();
@ -87,37 +90,37 @@ namespace Spine.Unity.Editor {
if (hasRootBone) {
if (SpineInspectorUtility.CenteredButton(new GUIContent("Remove Hierarchy"))) {
Undo.RegisterCompleteObjectUndo(skeletonUtility, "Remove Hierarchy");
Undo.DestroyObjectImmediate(skeletonUtility.boneRoot.gameObject);
skeletonUtility.boneRoot = null;
Undo.RegisterCompleteObjectUndo(skeletonGameObjects, "Remove Hierarchy");
Undo.DestroyObjectImmediate(skeletonGameObjects.boneRoot.gameObject);
skeletonGameObjects.boneRoot = null;
}
}
}
void SpawnHierarchyContextMenu () {
GenericMenu menu = new GenericMenu();
var menu = new GenericMenu();
menu.AddItem(new GUIContent("Follow"), false, SpawnFollowHierarchy);
menu.AddItem(new GUIContent("Follow all bones"), false, SpawnFollowHierarchy);
menu.AddItem(new GUIContent("Follow (Root Only)"), false, SpawnFollowHierarchyRootOnly);
menu.AddSeparator("");
menu.AddItem(new GUIContent("Override"), false, SpawnOverrideHierarchy);
menu.AddItem(new GUIContent("Override all bones"), false, SpawnOverrideHierarchy);
menu.AddItem(new GUIContent("Override (Root Only)"), false, SpawnOverrideHierarchyRootOnly);
menu.ShowAsContext();
}
public static void AttachIcon (SkeletonUtilityBone utilityBone) {
Skeleton skeleton = utilityBone.skeletonUtility.skeletonRenderer.skeleton;
Texture2D icon = utilityBone.bone.Data.Length == 0 ? Icons.nullBone : Icons.boneNib;
public static void AttachIcon (SkeletonUtilityBone boneComponent) {
Skeleton skeleton = boneComponent.hierarchy.skeletonRenderer.skeleton;
Texture2D icon = boneComponent.bone.Data.Length == 0 ? Icons.nullBone : Icons.boneNib;
foreach (IkConstraint c in skeleton.IkConstraints)
if (c.Target == utilityBone.bone) {
if (c.Target == boneComponent.bone) {
icon = Icons.constraintNib;
break;
}
typeof(EditorGUIUtility).InvokeMember("SetIconForObject", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, null, new object[2] {
utilityBone.gameObject,
boneComponent.gameObject,
icon
});
}
@ -131,23 +134,23 @@ namespace Spine.Unity.Editor {
}
void SpawnFollowHierarchy () {
Selection.activeGameObject = skeletonUtility.SpawnHierarchy(SkeletonUtilityBone.Mode.Follow, true, true, true);
AttachIconsToChildren(skeletonUtility.boneRoot);
Selection.activeGameObject = skeletonGameObjects.SpawnHierarchy(SkeletonUtilityBone.Mode.Follow, true, true, true);
AttachIconsToChildren(skeletonGameObjects.boneRoot);
}
void SpawnFollowHierarchyRootOnly () {
Selection.activeGameObject = skeletonUtility.SpawnRoot(SkeletonUtilityBone.Mode.Follow, true, true, true);
AttachIconsToChildren(skeletonUtility.boneRoot);
Selection.activeGameObject = skeletonGameObjects.SpawnRoot(SkeletonUtilityBone.Mode.Follow, true, true, true);
AttachIconsToChildren(skeletonGameObjects.boneRoot);
}
void SpawnOverrideHierarchy () {
Selection.activeGameObject = skeletonUtility.SpawnHierarchy(SkeletonUtilityBone.Mode.Override, true, true, true);
AttachIconsToChildren(skeletonUtility.boneRoot);
Selection.activeGameObject = skeletonGameObjects.SpawnHierarchy(SkeletonUtilityBone.Mode.Override, true, true, true);
AttachIconsToChildren(skeletonGameObjects.boneRoot);
}
void SpawnOverrideHierarchyRootOnly () {
Selection.activeGameObject = skeletonUtility.SpawnRoot(SkeletonUtilityBone.Mode.Override, true, true, true);
AttachIconsToChildren(skeletonUtility.boneRoot);
Selection.activeGameObject = skeletonGameObjects.SpawnRoot(SkeletonUtilityBone.Mode.Override, true, true, true);
AttachIconsToChildren(skeletonGameObjects.boneRoot);
}
}

View File

@ -1,8 +1,18 @@
fileFormatVersion: 2
guid: f1b3b4b945939a54ea0b23d3396115fb
timeCreated: 1536403985
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
defaultReferences:
- multiplyMaterialTemplate: {fileID: 2100000, guid: 53bf0ab317d032d418cf1252d68f51df,
type: 2}
- screenMaterialTemplate: {fileID: 2100000, guid: 73f0f46d3177c614baf0fa48d646a9be,
type: 2}
- additiveMaterialTemplate: {fileID: 2100000, guid: 4deba332d47209e4780b3c5fcf0e3745,
type: 2}
- skeletonJSON: {instanceID: 0}
- controller: {instanceID: 0}
executionOrder: 0
icon: {fileID: 2800000, guid: 68defdbc95b30a74a9ad396bfc9a2277, type: 3}
userData:

View File

@ -65,10 +65,8 @@ namespace Spine.Unity {
#endregion
[NonSerialized] public bool valid;
/// <summary>
/// The bone.
/// </summary>
[NonSerialized] public Bone bone;
Transform skeletonTransform;
bool skeletonTransformIsParent;

View File

@ -58,7 +58,6 @@ namespace Spine.Unity {
[System.NonSerialized] public readonly List<Slot> separatorSlots = new List<Slot>();
[Range(-0.1f, 0f)] public float zSpacing;
//public bool renderMeshes = true;
public bool useClipping = true;
public bool immutableTriangles = false;
public bool pmaVertexColors = true;
@ -311,7 +310,9 @@ namespace Spine.Unity {
// STEP 3. Move the mesh data into a UnityEngine.Mesh ===========================================================================
var currentMesh = currentSmartMesh.mesh;
meshGenerator.FillVertexData(currentMesh);
rendererBuffers.UpdateSharedMaterials(workingSubmeshInstructions);
if (updateTriangles) { // Check if the triangles should also be updated.
meshGenerator.FillTriangles(currentMesh);
meshRenderer.sharedMaterials = rendererBuffers.GetUpdatedSharedMaterialsArray();

View File

@ -36,8 +36,6 @@ namespace Spine.Unity {
event UpdateBonesDelegate UpdateLocal;
event UpdateBonesDelegate UpdateWorld;
event UpdateBonesDelegate UpdateComplete;
//void LateUpdate ();
Skeleton Skeleton { get; }
}

View File

@ -805,6 +805,12 @@ namespace Spine.Unity.Modules.AttachmentTools {
skin.AddAttachment(slotIndex, keyName, attachment);
}
/// <summary>Adds skin items from another skin. For items that already exist, the previous values are replaced.</summary>
public static void AddAttachments (this Skin skin, Skin otherSkin) {
if (otherSkin == null) return;
otherSkin.CopyTo(skin, true, false);
}
/// <summary>Gets an attachment from the skin for the specified slot index and name.</summary>
public static Attachment GetAttachment (this Skin skin, string slotName, string keyName, Skeleton skeleton) {
int slotIndex = skeleton.FindSlotIndex(slotName);
@ -835,6 +841,7 @@ namespace Spine.Unity.Modules.AttachmentTools {
skin.Attachments.Clear();
}
//[System.Obsolete]
public static void Append (this Skin destination, Skin source) {
source.CopyTo(destination, true, false);
}

View File

@ -42,9 +42,7 @@ namespace Spine.Unity.Modules {
Vector3 centerPoint;
protected override void OnEnable () {
if (!Application.isPlaying)
return;
if (!Application.isPlaying) return;
base.OnEnable();
Bounds centerBounds = new Bounds(eyes[0].localPosition, Vector3.zero);
@ -58,19 +56,14 @@ namespace Spine.Unity.Modules {
}
protected override void OnDisable () {
if (!Application.isPlaying)
return;
if (!Application.isPlaying) return;
base.OnDisable();
}
public override void DoUpdate () {
if (target != null)
targetPosition = target.position;
if (target != null) targetPosition = target.position;
Vector3 goal = targetPosition;
Vector3 center = transform.TransformPoint(centerPoint);
Vector3 dir = goal - center;

View File

@ -105,8 +105,8 @@ namespace Spine.Unity.Modules {
v.y = Mathf.Clamp(v.y, Mathf.Min(lastHitY, hitY), float.MaxValue);
transform.position = v;
utilBone.bone.X = transform.localPosition.x;
utilBone.bone.Y = transform.localPosition.y;
bone.bone.X = transform.localPosition.x;
bone.bone.Y = transform.localPosition.y;
lastHitY = hitY;
}

View File

@ -37,7 +37,7 @@ using Spine;
namespace Spine.Unity {
[RequireComponent(typeof(ISkeletonAnimation))]
[ExecuteInEditMode]
public class SkeletonUtility : MonoBehaviour {
public sealed class SkeletonUtility : MonoBehaviour {
#region BoundingBoxAttachment
public static PolygonCollider2D AddBoundingBoxGameObject (Skeleton skeleton, string skinName, string slotName, string attachmentName, Transform parent, bool isTrigger = true) {
@ -122,23 +122,19 @@ namespace Spine.Unity {
void Update () {
var skeleton = skeletonRenderer.skeleton;
if (boneRoot != null && skeleton != null) {
if (skeleton != null && boneRoot != null) {
boneRoot.localScale = new Vector3(skeleton.scaleX, skeleton.scaleY, 1f);
}
}
[HideInInspector]
public SkeletonRenderer skeletonRenderer;
[HideInInspector]
public ISkeletonAnimation skeletonAnimation;
[System.NonSerialized]
public List<SkeletonUtilityBone> utilityBones = new List<SkeletonUtilityBone>();
[System.NonSerialized]
public List<SkeletonUtilityConstraint> utilityConstraints = new List<SkeletonUtilityConstraint>();
[HideInInspector] public SkeletonRenderer skeletonRenderer;
[HideInInspector] public ISkeletonAnimation skeletonAnimation;
[System.NonSerialized] public List<SkeletonUtilityBone> boneComponents = new List<SkeletonUtilityBone>();
[System.NonSerialized] public List<SkeletonUtilityConstraint> constraintComponents = new List<SkeletonUtilityConstraint>();
protected bool hasTransformBones;
protected bool hasUtilityConstraints;
protected bool needToReprocessBones;
bool hasOverrideBones;
bool hasConstraints;
bool needToReprocessBones;
void OnEnable () {
if (skeletonRenderer == null) {
@ -176,36 +172,34 @@ namespace Spine.Unity {
}
void HandleRendererReset (SkeletonRenderer r) {
if (OnReset != null)
OnReset();
if (OnReset != null) OnReset();
CollectBones();
}
public void RegisterBone (SkeletonUtilityBone bone) {
if (utilityBones.Contains(bone))
if (boneComponents.Contains(bone)) {
return;
else {
utilityBones.Add(bone);
} else {
boneComponents.Add(bone);
needToReprocessBones = true;
}
}
public void UnregisterBone (SkeletonUtilityBone bone) {
utilityBones.Remove(bone);
boneComponents.Remove(bone);
}
public void RegisterConstraint (SkeletonUtilityConstraint constraint) {
if (utilityConstraints.Contains(constraint))
if (constraintComponents.Contains(constraint))
return;
else {
utilityConstraints.Add(constraint);
constraintComponents.Add(constraint);
needToReprocessBones = true;
}
}
public void UnregisterConstraint (SkeletonUtilityConstraint constraint) {
utilityConstraints.Remove(constraint);
constraintComponents.Remove(constraint);
}
public void CollectBones () {
@ -222,31 +216,31 @@ namespace Spine.Unity {
for (int i = 0, n = transformConstraints.Count; i < n; i++)
constraintTargets.Add(transformConstraints.Items[i].target);
var utilityBones = this.utilityBones;
for (int i = 0, n = utilityBones.Count; i < n; i++) {
var b = utilityBones[i];
var boneComponents = this.boneComponents;
for (int i = 0, n = boneComponents.Count; i < n; i++) {
var b = boneComponents[i];
if (b.bone == null) continue;
hasTransformBones |= (b.mode == SkeletonUtilityBone.Mode.Override);
hasUtilityConstraints |= constraintTargets.Contains(b.bone);
hasOverrideBones |= (b.mode == SkeletonUtilityBone.Mode.Override);
hasConstraints |= constraintTargets.Contains(b.bone);
}
hasUtilityConstraints |= utilityConstraints.Count > 0;
hasConstraints |= constraintComponents.Count > 0;
if (skeletonAnimation != null) {
skeletonAnimation.UpdateWorld -= UpdateWorld;
skeletonAnimation.UpdateComplete -= UpdateComplete;
if (hasTransformBones || hasUtilityConstraints)
if (hasOverrideBones || hasConstraints)
skeletonAnimation.UpdateWorld += UpdateWorld;
if (hasUtilityConstraints)
if (hasConstraints)
skeletonAnimation.UpdateComplete += UpdateComplete;
}
needToReprocessBones = false;
} else {
utilityBones.Clear();
utilityConstraints.Clear();
boneComponents.Clear();
constraintComponents.Clear();
}
}
@ -254,18 +248,18 @@ namespace Spine.Unity {
if (needToReprocessBones)
CollectBones();
var utilityBones = this.utilityBones;
if (utilityBones == null) return;
for (int i = 0, n = utilityBones.Count; i < n; i++)
utilityBones[i].transformLerpComplete = false;
var boneComponents = this.boneComponents;
if (boneComponents == null) return;
for (int i = 0, n = boneComponents.Count; i < n; i++)
boneComponents[i].transformLerpComplete = false;
UpdateAllBones(SkeletonUtilityBone.UpdatePhase.Local);
}
void UpdateWorld (ISkeletonAnimation anim) {
UpdateAllBones(SkeletonUtilityBone.UpdatePhase.World);
for (int i = 0, n = utilityConstraints.Count; i < n; i++)
utilityConstraints[i].DoUpdate();
for (int i = 0, n = constraintComponents.Count; i < n; i++)
constraintComponents[i].DoUpdate();
}
void UpdateComplete (ISkeletonAnimation anim) {
@ -276,17 +270,17 @@ namespace Spine.Unity {
if (boneRoot == null)
CollectBones();
var utilityBones = this.utilityBones;
if (utilityBones == null) return;
for (int i = 0, n = utilityBones.Count; i < n; i++)
utilityBones[i].DoUpdate(phase);
var boneComponents = this.boneComponents;
if (boneComponents == null) return;
for (int i = 0, n = boneComponents.Count; i < n; i++)
boneComponents[i].DoUpdate(phase);
}
public Transform GetBoneRoot () {
if (boneRoot != null)
return boneRoot;
boneRoot = new GameObject("SkeletonUtility-Root").transform;
boneRoot = new GameObject("SkeletonUtility-SkeletonRoot").transform;
boneRoot.parent = transform;
boneRoot.localPosition = Vector3.zero;
boneRoot.localRotation = Quaternion.identity;
@ -326,10 +320,11 @@ namespace Spine.Unity {
public GameObject SpawnBone (Bone bone, Transform parent, SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca) {
GameObject go = new GameObject(bone.Data.Name);
go.transform.parent = parent;
var goTransform = go.transform;
goTransform.parent = parent;
SkeletonUtilityBone b = go.AddComponent<SkeletonUtilityBone>();
b.skeletonUtility = this;
b.hierarchy = this;
b.position = pos;
b.rotation = rot;
b.scale = sca;
@ -341,13 +336,9 @@ namespace Spine.Unity {
b.valid = true;
if (mode == SkeletonUtilityBone.Mode.Override) {
if (rot)
go.transform.localRotation = Quaternion.Euler(0, 0, b.bone.AppliedRotation);
if (pos)
go.transform.localPosition = new Vector3(b.bone.X, b.bone.Y, 0);
go.transform.localScale = new Vector3(b.bone.scaleX, b.bone.scaleY, 0);
if (rot) goTransform.localRotation = Quaternion.Euler(0, 0, b.bone.AppliedRotation);
if (pos) goTransform.localPosition = new Vector3(b.bone.X, b.bone.Y, 0);
goTransform.localScale = new Vector3(b.bone.scaleX, b.bone.scaleY, 0);
}
return go;

View File

@ -28,15 +28,13 @@
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
// Contributed by: Mitch Thompson
using UnityEngine;
using Spine;
namespace Spine.Unity {
/// <summary>Sets a GameObject's transform to match a bone on a Spine skeleton.</summary>
[ExecuteInEditMode]
[AddComponentMenu("Spine/SkeletonUtilityBone")]
[AddComponentMenu("Spine/SkeletonGameObjectsBone")]
public class SkeletonUtilityBone : MonoBehaviour {
public enum Mode {
Follow,
@ -59,7 +57,7 @@ namespace Spine.Unity {
public float overrideAlpha = 1;
#endregion
[System.NonSerialized] public SkeletonUtility skeletonUtility;
[System.NonSerialized] public SkeletonUtility hierarchy;
[System.NonSerialized] public Bone bone;
[System.NonSerialized] public bool transformLerpComplete;
[System.NonSerialized] public bool valid;
@ -71,23 +69,21 @@ namespace Spine.Unity {
public void Reset () {
bone = null;
cachedTransform = transform;
valid = skeletonUtility != null && skeletonUtility.skeletonRenderer != null && skeletonUtility.skeletonRenderer.valid;
valid = hierarchy != null && hierarchy.skeletonRenderer != null && hierarchy.skeletonRenderer.valid;
if (!valid)
return;
skeletonTransform = skeletonUtility.transform;
skeletonUtility.OnReset -= HandleOnReset;
skeletonUtility.OnReset += HandleOnReset;
skeletonTransform = hierarchy.transform;
hierarchy.OnReset -= HandleOnReset;
hierarchy.OnReset += HandleOnReset;
DoUpdate(UpdatePhase.Local);
}
void OnEnable () {
skeletonUtility = transform.GetComponentInParent<SkeletonUtility>();
hierarchy = transform.GetComponentInParent<SkeletonUtility>();
if (hierarchy == null) return;
if (skeletonUtility == null)
return;
skeletonUtility.RegisterBone(this);
skeletonUtility.OnReset += HandleOnReset;
hierarchy.RegisterBone(this);
hierarchy.OnReset += HandleOnReset;
}
void HandleOnReset () {
@ -95,9 +91,9 @@ namespace Spine.Unity {
}
void OnDisable () {
if (skeletonUtility != null) {
skeletonUtility.OnReset -= HandleOnReset;
skeletonUtility.UnregisterBone(this);
if (hierarchy != null) {
hierarchy.OnReset -= HandleOnReset;
hierarchy.UnregisterBone(this);
}
}
@ -107,7 +103,7 @@ namespace Spine.Unity {
return;
}
var skeleton = skeletonUtility.skeletonRenderer.skeleton;
var skeleton = hierarchy.skeletonRenderer.skeleton;
if (bone == null) {
if (string.IsNullOrEmpty(boneName)) return;

View File

@ -28,25 +28,23 @@
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
// Contributed by: Mitch Thompson
using UnityEngine;
namespace Spine.Unity {
[RequireComponent(typeof(SkeletonUtilityBone)), ExecuteInEditMode]
public abstract class SkeletonUtilityConstraint : MonoBehaviour {
protected SkeletonUtilityBone utilBone;
protected SkeletonUtility skeletonUtility;
protected SkeletonUtilityBone bone;
protected SkeletonUtility hierarchy;
protected virtual void OnEnable () {
utilBone = GetComponent<SkeletonUtilityBone>();
skeletonUtility = transform.GetComponentInParent<SkeletonUtility>();
skeletonUtility.RegisterConstraint(this);
bone = GetComponent<SkeletonUtilityBone>();
hierarchy = transform.GetComponentInParent<SkeletonUtility>();
hierarchy.RegisterConstraint(this);
}
protected virtual void OnDisable () {
skeletonUtility.UnregisterConstraint(this);
hierarchy.UnregisterConstraint(this);
}
public abstract void DoUpdate ();