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]
|
||||
public string attackAnimation;
|
||||
|
||||
[SpineAnimation]
|
||||
public string moveAnimation;
|
||||
|
||||
[SpineSlot]
|
||||
public string eyesSlot;
|
||||
|
||||
@ -54,22 +57,33 @@ public class FootSoldierExample : MonoBehaviour {
|
||||
[Range(0, 0.2f)]
|
||||
public float blinkDuration = 0.05f;
|
||||
|
||||
public float moveSpeed = 3;
|
||||
|
||||
private SkeletonAnimation skeletonAnimation;
|
||||
|
||||
void Awake() {
|
||||
skeletonAnimation = GetComponent<SkeletonAnimation>();
|
||||
skeletonAnimation.OnReset += Apply;
|
||||
}
|
||||
|
||||
void Start() {
|
||||
skeletonAnimation.state.SetAnimation(0, idleAnimation, true);
|
||||
void Apply(SkeletonRenderer skeletonRenderer) {
|
||||
StartCoroutine("Blink");
|
||||
}
|
||||
|
||||
void Update() {
|
||||
if (Input.GetKey(KeyCode.Space)) {
|
||||
if (skeletonAnimation.state.GetCurrent(0).Animation.Name != attackAnimation) {
|
||||
skeletonAnimation.state.SetAnimation(0, attackAnimation, false);
|
||||
skeletonAnimation.state.AddAnimation(0, idleAnimation, true, 0);
|
||||
skeletonAnimation.AnimationName = attackAnimation;
|
||||
} else {
|
||||
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,15 +17,15 @@ public class AtlasRegionAttacher : MonoBehaviour {
|
||||
public AtlasAsset atlasAsset;
|
||||
public SlotRegionPair[] attachments;
|
||||
|
||||
[HideInInspector]
|
||||
public SkeletonRenderer skeletonRenderer;
|
||||
|
||||
|
||||
Atlas atlas;
|
||||
|
||||
void Start() {
|
||||
void Awake() {
|
||||
GetComponent<SkeletonRenderer>().OnReset += Apply;
|
||||
}
|
||||
|
||||
|
||||
void Apply(SkeletonRenderer skeletonRenderer) {
|
||||
atlas = atlasAsset.GetAtlas();
|
||||
this.skeletonRenderer = GetComponent<SkeletonRenderer>();
|
||||
|
||||
AtlasAttachmentLoader loader = new AtlasAttachmentLoader(atlas);
|
||||
|
||||
@ -41,7 +41,7 @@ public class AtlasRegionAttacher : MonoBehaviour {
|
||||
regionAttachment.SetColor(new Color(1, 1, 1, 1));
|
||||
regionAttachment.UpdateOffset();
|
||||
|
||||
var slot = this.skeletonRenderer.skeleton.FindSlot(entry.slot);
|
||||
var slot = skeletonRenderer.skeleton.FindSlot(entry.slot);
|
||||
slot.Attachment = regionAttachment;
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,8 +118,18 @@ public class SkeletonRenderer : MonoBehaviour {
|
||||
OnReset(this);
|
||||
}
|
||||
|
||||
public void Awake () {
|
||||
Reset();
|
||||
public virtual void OnEnable() {
|
||||
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 () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user