mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 09:46:02 +08:00
[unity] Sample scripts now use properties.
This commit is contained in:
parent
95527b630a
commit
986e74f62b
@ -93,7 +93,7 @@ namespace Spine.Unity.Examples {
|
|||||||
|
|
||||||
void Start () {
|
void Start () {
|
||||||
// Register a callback for Spine Events (in this case, Footstep)
|
// Register a callback for Spine Events (in this case, Footstep)
|
||||||
skeletonAnimation.state.Event += HandleEvent;
|
skeletonAnimation.AnimationState.Event += HandleEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleEvent (Spine.TrackEntry trackEntry, Spine.Event e) {
|
void HandleEvent (Spine.TrackEntry trackEntry, Spine.Event e) {
|
||||||
|
|||||||
@ -59,8 +59,8 @@ namespace Spine.Unity.Examples {
|
|||||||
void Start () {
|
void Start () {
|
||||||
// Make sure you get these AnimationState and Skeleton references in Start or Later. Getting and using them in Awake is not guaranteed by default execution order.
|
// Make sure you get these AnimationState and Skeleton references in Start or Later. Getting and using them in Awake is not guaranteed by default execution order.
|
||||||
skeletonAnimation = GetComponent<SkeletonAnimation>();
|
skeletonAnimation = GetComponent<SkeletonAnimation>();
|
||||||
spineAnimationState = skeletonAnimation.state;
|
spineAnimationState = skeletonAnimation.AnimationState;
|
||||||
skeleton = skeletonAnimation.skeleton;
|
skeleton = skeletonAnimation.Skeleton;
|
||||||
|
|
||||||
StartCoroutine(DoDemoRoutine());
|
StartCoroutine(DoDemoRoutine());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,7 +44,7 @@ namespace Spine.Unity.Examples {
|
|||||||
IEnumerator Start () {
|
IEnumerator Start () {
|
||||||
var skeletonAnimation = GetComponent<SkeletonAnimation>(); if (skeletonAnimation == null) yield break;
|
var skeletonAnimation = GetComponent<SkeletonAnimation>(); if (skeletonAnimation == null) yield break;
|
||||||
while (true) {
|
while (true) {
|
||||||
skeletonAnimation.state.SetAnimation(SpineBlinkPlayer.BlinkTrack, blinkAnimation, false);
|
skeletonAnimation.AnimationState.SetAnimation(SpineBlinkPlayer.BlinkTrack, blinkAnimation, false);
|
||||||
yield return new WaitForSeconds(Random.Range(minimumDelay, maximumDelay));
|
yield return new WaitForSeconds(Random.Range(minimumDelay, maximumDelay));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,7 +57,7 @@ namespace Spine.Unity.Examples {
|
|||||||
void Start () {
|
void Start () {
|
||||||
if (skeletonAnimation == null) return;
|
if (skeletonAnimation == null) return;
|
||||||
model.ShootEvent += PlayShoot;
|
model.ShootEvent += PlayShoot;
|
||||||
skeletonAnimation.state.Event += HandleEvent;
|
skeletonAnimation.AnimationState.Event += HandleEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleEvent (Spine.TrackEntry trackEntry, Spine.Event e) {
|
void HandleEvent (Spine.TrackEntry trackEntry, Spine.Event e) {
|
||||||
@ -104,7 +104,7 @@ namespace Spine.Unity.Examples {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
skeletonAnimation.state.SetAnimation(0, nextAnimation, true);
|
skeletonAnimation.AnimationState.SetAnimation(0, nextAnimation, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayFootstepSound () {
|
void PlayFootstepSound () {
|
||||||
@ -114,7 +114,7 @@ namespace Spine.Unity.Examples {
|
|||||||
|
|
||||||
[ContextMenu("Check Tracks")]
|
[ContextMenu("Check Tracks")]
|
||||||
void CheckTracks () {
|
void CheckTracks () {
|
||||||
var state = skeletonAnimation.state;
|
var state = skeletonAnimation.AnimationState;
|
||||||
Debug.Log(state.GetCurrent(0));
|
Debug.Log(state.GetCurrent(0));
|
||||||
Debug.Log(state.GetCurrent(1));
|
Debug.Log(state.GetCurrent(1));
|
||||||
}
|
}
|
||||||
@ -122,7 +122,7 @@ namespace Spine.Unity.Examples {
|
|||||||
#region Transient Actions
|
#region Transient Actions
|
||||||
public void PlayShoot () {
|
public void PlayShoot () {
|
||||||
// Play the shoot animation on track 1.
|
// Play the shoot animation on track 1.
|
||||||
skeletonAnimation.state.SetAnimation(1, shoot, false);
|
skeletonAnimation.AnimationState.SetAnimation(1, shoot, false);
|
||||||
//skeletonAnimation.state.AddEmptyAnimation(1, 0.1f, 0f);
|
//skeletonAnimation.state.AddEmptyAnimation(1, 0.1f, 0f);
|
||||||
gunSource.pitch = GetRandomPitch(gunsoundPitchOffset);
|
gunSource.pitch = GetRandomPitch(gunsoundPitchOffset);
|
||||||
gunSource.Play();
|
gunSource.Play();
|
||||||
@ -131,7 +131,7 @@ namespace Spine.Unity.Examples {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Turn (bool facingLeft) {
|
public void Turn (bool facingLeft) {
|
||||||
skeletonAnimation.skeleton.FlipX = facingLeft;
|
skeletonAnimation.Skeleton.FlipX = facingLeft;
|
||||||
// Maybe play a transient turning animation too, then call ChangeStableAnimation.
|
// Maybe play a transient turning animation too, then call ChangeStableAnimation.
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -47,13 +47,13 @@ namespace Spine.Unity.Examples {
|
|||||||
healthText.text = currentHealth + "/" + maxHealth;
|
healthText.text = currentHealth + "/" + maxHealth;
|
||||||
|
|
||||||
if (currentHealth > 0) {
|
if (currentHealth > 0) {
|
||||||
spineboy.state.SetAnimation(0, "hit", false);
|
spineboy.AnimationState.SetAnimation(0, "hit", false);
|
||||||
spineboy.state.AddAnimation(0, "idle", true, 0);
|
spineboy.AnimationState.AddAnimation(0, "idle", true, 0);
|
||||||
gauge.fillPercent = (float)currentHealth/(float)maxHealth;
|
gauge.fillPercent = (float)currentHealth/(float)maxHealth;
|
||||||
} else {
|
} else {
|
||||||
if (currentHealth >= 0) {
|
if (currentHealth >= 0) {
|
||||||
gauge.fillPercent = 0;
|
gauge.fillPercent = 0;
|
||||||
spineboy.state.SetAnimation(0, "death", false).TrackEnd = float.PositiveInfinity;
|
spineboy.AnimationState.SetAnimation(0, "death", false).TrackEnd = float.PositiveInfinity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -80,11 +80,11 @@ namespace Spine.Unity.Examples {
|
|||||||
} else {
|
} else {
|
||||||
if (Input.GetKey(rightKey)) {
|
if (Input.GetKey(rightKey)) {
|
||||||
skeletonAnimation.AnimationName = moveAnimation;
|
skeletonAnimation.AnimationName = moveAnimation;
|
||||||
skeletonAnimation.skeleton.FlipX = false;
|
skeletonAnimation.Skeleton.FlipX = false;
|
||||||
transform.Translate(moveSpeed * Time.deltaTime, 0, 0);
|
transform.Translate(moveSpeed * Time.deltaTime, 0, 0);
|
||||||
} else if(Input.GetKey(leftKey)) {
|
} else if(Input.GetKey(leftKey)) {
|
||||||
skeletonAnimation.AnimationName = moveAnimation;
|
skeletonAnimation.AnimationName = moveAnimation;
|
||||||
skeletonAnimation.skeleton.FlipX = true;
|
skeletonAnimation.Skeleton.FlipX = true;
|
||||||
transform.Translate(-moveSpeed * Time.deltaTime, 0, 0);
|
transform.Translate(-moveSpeed * Time.deltaTime, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
skeletonAnimation.AnimationName = idleAnimation;
|
skeletonAnimation.AnimationName = idleAnimation;
|
||||||
@ -95,9 +95,9 @@ namespace Spine.Unity.Examples {
|
|||||||
IEnumerator Blink() {
|
IEnumerator Blink() {
|
||||||
while (true) {
|
while (true) {
|
||||||
yield return new WaitForSeconds(Random.Range(0.25f, 3f));
|
yield return new WaitForSeconds(Random.Range(0.25f, 3f));
|
||||||
skeletonAnimation.skeleton.SetAttachment(eyesSlot, blinkAttachment);
|
skeletonAnimation.Skeleton.SetAttachment(eyesSlot, blinkAttachment);
|
||||||
yield return new WaitForSeconds(blinkDuration);
|
yield return new WaitForSeconds(blinkDuration);
|
||||||
skeletonAnimation.skeleton.SetAttachment(eyesSlot, eyesOpenAttachment);
|
skeletonAnimation.Skeleton.SetAttachment(eyesSlot, eyesOpenAttachment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,7 +43,7 @@ namespace Spine.Unity.Examples {
|
|||||||
|
|
||||||
public void Start () {
|
public void Start () {
|
||||||
skeletonAnimation = GetComponent<SkeletonAnimation>();
|
skeletonAnimation = GetComponent<SkeletonAnimation>();
|
||||||
headBone = skeletonAnimation.skeleton.FindBone("head");
|
headBone = skeletonAnimation.Skeleton.FindBone("head");
|
||||||
skeletonAnimation.UpdateLocal += UpdateLocal;
|
skeletonAnimation.UpdateLocal += UpdateLocal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,16 +53,16 @@ namespace Spine.Unity.Examples {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void OnMouseDown () {
|
public void OnMouseDown () {
|
||||||
skeletonAnimation.skeleton.SetSkin(girlSkin ? "goblin" : "goblingirl");
|
skeletonAnimation.Skeleton.SetSkin(girlSkin ? "goblin" : "goblingirl");
|
||||||
skeletonAnimation.skeleton.SetSlotsToSetupPose();
|
skeletonAnimation.Skeleton.SetSlotsToSetupPose();
|
||||||
|
|
||||||
girlSkin = !girlSkin;
|
girlSkin = !girlSkin;
|
||||||
|
|
||||||
if (girlSkin) {
|
if (girlSkin) {
|
||||||
skeletonAnimation.skeleton.SetAttachment("right hand item", null);
|
skeletonAnimation.Skeleton.SetAttachment("right hand item", null);
|
||||||
skeletonAnimation.skeleton.SetAttachment("left hand item", "spear");
|
skeletonAnimation.Skeleton.SetAttachment("left hand item", "spear");
|
||||||
} else
|
} else
|
||||||
skeletonAnimation.skeleton.SetAttachment("left hand item", "dagger");
|
skeletonAnimation.Skeleton.SetAttachment("left hand item", "dagger");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ namespace Spine.Unity.Examples {
|
|||||||
// Case 1: Create an attachment from an atlas.
|
// Case 1: Create an attachment from an atlas.
|
||||||
RegionAttachment newHand = handSource.GetAtlas().FindRegion(handRegion).ToRegionAttachment("new hand");
|
RegionAttachment newHand = handSource.GetAtlas().FindRegion(handRegion).ToRegionAttachment("new hand");
|
||||||
newHand.SetPositionOffset(newHandOffset);
|
newHand.SetPositionOffset(newHandOffset);
|
||||||
newHand.rotation = newHandRotation;
|
newHand.Rotation = newHandRotation;
|
||||||
newHand.UpdateOffset();
|
newHand.UpdateOffset();
|
||||||
int handSlotIndex = skeleton.FindSlotIndex(handSlot);
|
int handSlotIndex = skeleton.FindSlotIndex(handSlot);
|
||||||
handTexture = newHand.GetRegion().ToTexture();
|
handTexture = newHand.GetRegion().ToTexture();
|
||||||
|
|||||||
@ -29,7 +29,6 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
using Spine;
|
using Spine;
|
||||||
using Spine.Unity;
|
using Spine.Unity;
|
||||||
|
|
||||||
@ -39,21 +38,22 @@ namespace Spine.Unity.Examples {
|
|||||||
|
|
||||||
public void Start () {
|
public void Start () {
|
||||||
skeletonAnimation = GetComponent<SkeletonAnimation>(); // Get the SkeletonAnimation component for the GameObject this script is attached to.
|
skeletonAnimation = GetComponent<SkeletonAnimation>(); // Get the SkeletonAnimation component for the GameObject this script is attached to.
|
||||||
|
var animationState = skeletonAnimation.AnimationState;
|
||||||
|
|
||||||
skeletonAnimation.state.Event += HandleEvent;; // Call our method any time an animation fires an event.
|
animationState.Event += HandleEvent;; // Call our method any time an animation fires an event.
|
||||||
skeletonAnimation.state.End += (entry) => Debug.Log("start: " + entry.trackIndex); // A lambda can be used for the callback instead of a method.
|
animationState.End += (entry) => Debug.Log("start: " + entry.TrackIndex); // A lambda can be used for the callback instead of a method.
|
||||||
|
|
||||||
skeletonAnimation.state.AddAnimation(0, "jump", false, 2); // Queue jump to be played on track 0 two seconds after the starting animation.
|
animationState.AddAnimation(0, "jump", false, 2); // Queue jump to be played on track 0 two seconds after the starting animation.
|
||||||
skeletonAnimation.state.AddAnimation(0, "run", true, 0); // Queue walk to be looped on track 0 after the jump animation.
|
animationState.AddAnimation(0, "run", true, 0); // Queue walk to be looped on track 0 after the jump animation.
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleEvent (TrackEntry trackEntry, Spine.Event e) {
|
void HandleEvent (TrackEntry trackEntry, Spine.Event e) {
|
||||||
Debug.Log(trackEntry.trackIndex + " " + trackEntry.animation.name + ": event " + e + ", " + e.Int);
|
Debug.Log(trackEntry.TrackIndex + " " + trackEntry.Animation.Name + ": event " + e + ", " + e.Int);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnMouseDown () {
|
public void OnMouseDown () {
|
||||||
skeletonAnimation.state.SetAnimation(0, "jump", false); // Set jump to be played on track 0 immediately.
|
skeletonAnimation.AnimationState.SetAnimation(0, "jump", false); // Set jump to be played on track 0 immediately.
|
||||||
skeletonAnimation.state.AddAnimation(0, "run", true, 0); // Queue walk to be looped on track 0 after the jump animation.
|
skeletonAnimation.AnimationState.AddAnimation(0, "run", true, 0); // Queue walk to be looped on track 0 after the jump animation.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user