mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
Modified SkeletonRenderer to destroy mesh1 and mesh2 when disabled if the gameobject its attached to is no longer visible.
This commit is contained in:
parent
7638ed96ff
commit
dc5873876b
@ -42,6 +42,9 @@ public class FootSoldierExample : MonoBehaviour {
|
|||||||
[SpineAnimation]
|
[SpineAnimation]
|
||||||
public string attackAnimation;
|
public string attackAnimation;
|
||||||
|
|
||||||
|
[SpineAnimation]
|
||||||
|
public string moveAnimation;
|
||||||
|
|
||||||
[SpineSlot]
|
[SpineSlot]
|
||||||
public string eyesSlot;
|
public string eyesSlot;
|
||||||
|
|
||||||
@ -54,22 +57,33 @@ public class FootSoldierExample : MonoBehaviour {
|
|||||||
[Range(0, 0.2f)]
|
[Range(0, 0.2f)]
|
||||||
public float blinkDuration = 0.05f;
|
public float blinkDuration = 0.05f;
|
||||||
|
|
||||||
|
public float moveSpeed = 3;
|
||||||
|
|
||||||
private SkeletonAnimation skeletonAnimation;
|
private SkeletonAnimation skeletonAnimation;
|
||||||
|
|
||||||
void Awake() {
|
void Awake() {
|
||||||
skeletonAnimation = GetComponent<SkeletonAnimation>();
|
skeletonAnimation = GetComponent<SkeletonAnimation>();
|
||||||
|
skeletonAnimation.OnReset += Apply;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Start() {
|
void Apply(SkeletonRenderer skeletonRenderer) {
|
||||||
skeletonAnimation.state.SetAnimation(0, idleAnimation, true);
|
|
||||||
StartCoroutine("Blink");
|
StartCoroutine("Blink");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update() {
|
void Update() {
|
||||||
if (Input.GetKey(KeyCode.Space)) {
|
if (Input.GetKey(KeyCode.Space)) {
|
||||||
if (skeletonAnimation.state.GetCurrent(0).Animation.Name != attackAnimation) {
|
skeletonAnimation.AnimationName = attackAnimation;
|
||||||
skeletonAnimation.state.SetAnimation(0, attackAnimation, false);
|
} else {
|
||||||
skeletonAnimation.state.AddAnimation(0, idleAnimation, true, 0);
|
if (Input.GetKey(KeyCode.RightArrow)) {
|
||||||
|
skeletonAnimation.AnimationName = moveAnimation;
|
||||||
|
skeletonAnimation.skeleton.FlipX = false;
|
||||||
|
transform.Translate(moveSpeed * Time.deltaTime, 0, 0);
|
||||||
|
} else if(Input.GetKey(KeyCode.LeftArrow)) {
|
||||||
|
skeletonAnimation.AnimationName = moveAnimation;
|
||||||
|
skeletonAnimation.skeleton.FlipX = true;
|
||||||
|
transform.Translate(-moveSpeed * Time.deltaTime, 0, 0);
|
||||||
|
} else {
|
||||||
|
skeletonAnimation.AnimationName = idleAnimation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,16 +17,16 @@ public class AtlasRegionAttacher : MonoBehaviour {
|
|||||||
public AtlasAsset atlasAsset;
|
public AtlasAsset atlasAsset;
|
||||||
public SlotRegionPair[] attachments;
|
public SlotRegionPair[] attachments;
|
||||||
|
|
||||||
[HideInInspector]
|
|
||||||
public SkeletonRenderer skeletonRenderer;
|
|
||||||
|
|
||||||
|
|
||||||
Atlas atlas;
|
Atlas atlas;
|
||||||
|
|
||||||
void Start() {
|
void Awake() {
|
||||||
atlas = atlasAsset.GetAtlas();
|
GetComponent<SkeletonRenderer>().OnReset += Apply;
|
||||||
this.skeletonRenderer = GetComponent<SkeletonRenderer>();
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Apply(SkeletonRenderer skeletonRenderer) {
|
||||||
|
atlas = atlasAsset.GetAtlas();
|
||||||
|
|
||||||
AtlasAttachmentLoader loader = new AtlasAttachmentLoader(atlas);
|
AtlasAttachmentLoader loader = new AtlasAttachmentLoader(atlas);
|
||||||
|
|
||||||
float scaleMultiplier = skeletonRenderer.skeletonDataAsset.scale;
|
float scaleMultiplier = skeletonRenderer.skeletonDataAsset.scale;
|
||||||
@ -41,7 +41,7 @@ public class AtlasRegionAttacher : MonoBehaviour {
|
|||||||
regionAttachment.SetColor(new Color(1, 1, 1, 1));
|
regionAttachment.SetColor(new Color(1, 1, 1, 1));
|
||||||
regionAttachment.UpdateOffset();
|
regionAttachment.UpdateOffset();
|
||||||
|
|
||||||
var slot = this.skeletonRenderer.skeleton.FindSlot(entry.slot);
|
var slot = skeletonRenderer.skeleton.FindSlot(entry.slot);
|
||||||
slot.Attachment = regionAttachment;
|
slot.Attachment = regionAttachment;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -117,9 +117,19 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
if (OnReset != null)
|
if (OnReset != null)
|
||||||
OnReset(this);
|
OnReset(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Awake () {
|
public virtual void OnEnable() {
|
||||||
Reset();
|
if(mesh1 == null || mesh2 == null)
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnDisable() {
|
||||||
|
if (Application.isPlaying && gameObject.activeInHierarchy == false) {
|
||||||
|
if (mesh1 != null)
|
||||||
|
Destroy(mesh1);
|
||||||
|
if (mesh2 != null)
|
||||||
|
Destroy(mesh2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mesh newMesh () {
|
private Mesh newMesh () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user