[unity] Update Spine Examples
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 173cd2c662ebd674f994bff2385cfbf6
|
||||
folderAsset: yes
|
||||
timeCreated: 1529972040
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b804088948820194cbda76af39c08174
|
||||
timeCreated: 1529972058
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,117 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
using Spine;
|
||||
using Spine.Unity;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace Spine.Unity.Examples {
|
||||
public class SpineAnimationTesterTool : MonoBehaviour, IHasSkeletonDataAsset, IHasSkeletonComponent {
|
||||
|
||||
public SkeletonAnimation skeletonAnimation;
|
||||
public SkeletonDataAsset SkeletonDataAsset { get { return skeletonAnimation.SkeletonDataAsset; } }
|
||||
public ISkeletonComponent SkeletonComponent { get { return skeletonAnimation; } }
|
||||
|
||||
public bool useOverrideMixDuration;
|
||||
public float overrideMixDuration = 0.2f;
|
||||
|
||||
[System.Serializable]
|
||||
public struct AnimationControl {
|
||||
[SpineAnimation]
|
||||
public string animationName;
|
||||
public bool loop;
|
||||
public KeyCode key;
|
||||
|
||||
[Space]
|
||||
public bool useCustomMixDuration;
|
||||
public float mixDuration;
|
||||
//public bool useChainToControl;
|
||||
//public int chainToControl;
|
||||
}
|
||||
[System.Serializable]
|
||||
public class ControlledTrack {
|
||||
public List<AnimationControl> controls = new List<AnimationControl>();
|
||||
}
|
||||
|
||||
[Space]
|
||||
public List<ControlledTrack> trackControls = new List<ControlledTrack>();
|
||||
|
||||
[Header("UI")]
|
||||
public UnityEngine.UI.Text boundAnimationsText;
|
||||
public UnityEngine.UI.Text skeletonNameText;
|
||||
|
||||
void OnValidate () {
|
||||
// Fill in the SkeletonData asset name
|
||||
if (skeletonNameText != null) {
|
||||
if (skeletonAnimation != null && skeletonAnimation.skeletonDataAsset != null) {
|
||||
skeletonNameText.text = SkeletonDataAsset.name.Replace("_SkeletonData", "");
|
||||
}
|
||||
}
|
||||
|
||||
// Fill in the control list.
|
||||
if (boundAnimationsText != null) {
|
||||
var boundAnimationsStringBuilder = new StringBuilder();
|
||||
boundAnimationsStringBuilder.AppendLine("Animation Controls:");
|
||||
|
||||
for (int trackIndex = 0; trackIndex < trackControls.Count; trackIndex++) {
|
||||
|
||||
if (trackIndex > 0)
|
||||
boundAnimationsStringBuilder.AppendLine();
|
||||
|
||||
boundAnimationsStringBuilder.AppendFormat("---- Track {0} ---- \n", trackIndex);
|
||||
foreach (var ba in trackControls[trackIndex].controls) {
|
||||
string animationName = ba.animationName;
|
||||
if (string.IsNullOrEmpty(animationName))
|
||||
animationName = "SetEmptyAnimation";
|
||||
|
||||
boundAnimationsStringBuilder.AppendFormat("[{0}] {1}\n", ba.key.ToString(), animationName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
boundAnimationsText.text = boundAnimationsStringBuilder.ToString();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Start () {
|
||||
if (useOverrideMixDuration) {
|
||||
skeletonAnimation.AnimationState.Data.DefaultMix = overrideMixDuration;
|
||||
}
|
||||
}
|
||||
|
||||
void Update () {
|
||||
var animationState = skeletonAnimation.AnimationState;
|
||||
|
||||
// For each track
|
||||
for (int trackIndex = 0; trackIndex < trackControls.Count; trackIndex++) {
|
||||
|
||||
// For each control in the track
|
||||
foreach (var control in trackControls[trackIndex].controls) {
|
||||
|
||||
// Check each control, and play the appropriate animation.
|
||||
if (Input.GetKeyDown(control.key)) {
|
||||
if (!string.IsNullOrEmpty(control.animationName)) {
|
||||
var trackEntry = animationState.SetAnimation(trackIndex, control.animationName, control.loop);
|
||||
if (control.useCustomMixDuration)
|
||||
trackEntry.MixDuration = control.mixDuration;
|
||||
|
||||
} else {
|
||||
float mix = control.useCustomMixDuration ? control.mixDuration : animationState.Data.DefaultMix;
|
||||
animationState.SetEmptyAnimation(trackIndex, mix);
|
||||
}
|
||||
|
||||
// Don't parse more than one animation per track.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b99b2d8e59226fa4db070f241259fd98
|
||||
timeCreated: 1529972356
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4766fcfd6167d2e46aad772ce3bc898c
|
||||
folderAsset: yes
|
||||
timeCreated: 1531292725
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afd3c9ec31200bc49b169c22f00b010b
|
||||
timeCreated: 1531300871
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cec34498f2eb26b488452ec274c54439
|
||||
timeCreated: 1531292741
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
mainObjectFileID: 9100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,62 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
using Spine;
|
||||
using Spine.Unity;
|
||||
|
||||
public class AnimationStateMecanimState : StateMachineBehaviour {
|
||||
|
||||
#region Inspector
|
||||
public AnimationReferenceAsset animation;
|
||||
|
||||
[System.Serializable]
|
||||
public struct AnimationTransition {
|
||||
public AnimationReferenceAsset from;
|
||||
public AnimationReferenceAsset transition;
|
||||
}
|
||||
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("transitions")]
|
||||
public List<AnimationTransition> fromTransitions = new List<AnimationTransition>();
|
||||
#endregion
|
||||
|
||||
Spine.AnimationState state;
|
||||
|
||||
public void Initialize (Animator animator) {
|
||||
if (state == null) {
|
||||
var animationStateComponent = (animator.GetComponent(typeof(IAnimationStateComponent))) as IAnimationStateComponent;
|
||||
state = animationStateComponent.AnimationState;
|
||||
}
|
||||
}
|
||||
|
||||
override public void OnStateEnter (Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
|
||||
if (state == null) {
|
||||
Initialize(animator);
|
||||
}
|
||||
|
||||
float timeScale = stateInfo.speed;
|
||||
var current = state.GetCurrent(layerIndex);
|
||||
|
||||
bool transitionPlayed = false;
|
||||
if (current != null && fromTransitions.Count > 0) {
|
||||
foreach (var t in fromTransitions) {
|
||||
if (t.from.Animation == current.Animation) {
|
||||
var transitionEntry = state.SetAnimation(layerIndex, t.transition.Animation, false);
|
||||
transitionEntry.TimeScale = timeScale;
|
||||
transitionPlayed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TrackEntry trackEntry;
|
||||
if (transitionPlayed) {
|
||||
trackEntry = state.AddAnimation(layerIndex, animation.Animation, stateInfo.loop, 0);
|
||||
} else {
|
||||
trackEntry = state.SetAnimation(layerIndex, animation.Animation, stateInfo.loop);
|
||||
}
|
||||
trackEntry.TimeScale = timeScale;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 536bdde8dc7bbb641b17da9221d6562f
|
||||
timeCreated: 1531293563
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,82 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
using Spine;
|
||||
using Spine.Unity;
|
||||
|
||||
namespace Spine.Unity.Examples {
|
||||
public class AnimationStateWithMecanimExample : MonoBehaviour {
|
||||
|
||||
SkeletonAnimation skeletonAnimation;
|
||||
Animator logicAnimator;
|
||||
|
||||
[Header("Controls")]
|
||||
public KeyCode walkButton = KeyCode.LeftShift;
|
||||
public KeyCode jumpButton = KeyCode.Space;
|
||||
|
||||
[Header("Animator Properties")]
|
||||
public string horizontalSpeedProperty = "Speed";
|
||||
public string verticalSpeedProperty = "VerticalSpeed";
|
||||
public string groundedProperty = "Grounded";
|
||||
|
||||
[Header("Fake Physics")]
|
||||
public float jumpDuration = 1.5f;
|
||||
public Vector2 speed;
|
||||
public bool isGrounded;
|
||||
|
||||
void Awake () {
|
||||
skeletonAnimation = GetComponent<SkeletonAnimation>();
|
||||
logicAnimator = GetComponent<Animator>();
|
||||
|
||||
isGrounded = true;
|
||||
}
|
||||
|
||||
void Update () {
|
||||
float x = Input.GetAxisRaw("Horizontal");
|
||||
if (Input.GetKey(walkButton)) {
|
||||
x *= 0.4f;
|
||||
}
|
||||
|
||||
speed.x = x;
|
||||
|
||||
// Flip skeleton.
|
||||
if (x != 0) {
|
||||
skeletonAnimation.Skeleton.ScaleX = x > 0 ? 1f : -1f;
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(jumpButton)) {
|
||||
if (isGrounded)
|
||||
StartCoroutine(FakeJump());
|
||||
}
|
||||
|
||||
logicAnimator.SetFloat(horizontalSpeedProperty, Mathf.Abs(speed.x));
|
||||
logicAnimator.SetFloat(verticalSpeedProperty, speed.y);
|
||||
logicAnimator.SetBool(groundedProperty, isGrounded);
|
||||
|
||||
}
|
||||
|
||||
IEnumerator FakeJump () {
|
||||
// Rise
|
||||
isGrounded = false;
|
||||
speed.y = 10f;
|
||||
float durationLeft = jumpDuration * 0.5f;
|
||||
while (durationLeft > 0) {
|
||||
durationLeft -= Time.deltaTime;
|
||||
if (!Input.GetKey(jumpButton)) break;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// Fall
|
||||
speed.y = -10f;
|
||||
float fallDuration = (jumpDuration * 0.5f) - durationLeft;
|
||||
yield return new WaitForSeconds(fallDuration);
|
||||
|
||||
// Land
|
||||
speed.y = 0f;
|
||||
isGrounded = true;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 782062825deffd64ba7e7e9f978788e5
|
||||
timeCreated: 1531300740
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -80,11 +80,11 @@ namespace Spine.Unity.Examples {
|
||||
} else {
|
||||
if (Input.GetKey(rightKey)) {
|
||||
skeletonAnimation.AnimationName = moveAnimation;
|
||||
skeletonAnimation.Skeleton.FlipX = false;
|
||||
skeletonAnimation.Skeleton.ScaleX = 1;
|
||||
transform.Translate(moveSpeed * Time.deltaTime, 0, 0);
|
||||
} else if(Input.GetKey(leftKey)) {
|
||||
skeletonAnimation.AnimationName = moveAnimation;
|
||||
skeletonAnimation.Skeleton.FlipX = true;
|
||||
skeletonAnimation.Skeleton.ScaleX = -1;
|
||||
transform.Translate(-moveSpeed * Time.deltaTime, 0, 0);
|
||||
} else {
|
||||
skeletonAnimation.AnimationName = idleAnimation;
|
||||
|
||||
@ -183,7 +183,7 @@ namespace Spine.Unity.Examples {
|
||||
|
||||
// Face intended direction.
|
||||
if (input.x != 0)
|
||||
skeletonAnimation.Skeleton.FlipX = input.x < 0;
|
||||
skeletonAnimation.Skeleton.ScaleX = Mathf.Sign(input.x);
|
||||
|
||||
|
||||
// Effects
|
||||
|
||||
@ -93,11 +93,11 @@ namespace Spine.Unity.Examples {
|
||||
spineAnimationState.AddAnimation(0, idleAnimationName, true, 0);
|
||||
yield return new WaitForSeconds(1f);
|
||||
|
||||
skeleton.FlipX = true; // skeleton allows you to flip the skeleton.
|
||||
skeleton.ScaleX = -1; // skeleton allows you to flip the skeleton.
|
||||
spineAnimationState.SetAnimation(0, idleTurnAnimationName, false);
|
||||
spineAnimationState.AddAnimation(0, idleAnimationName, true, 0);
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
skeleton.FlipX = false;
|
||||
skeleton.ScaleX = 1;
|
||||
spineAnimationState.SetAnimation(0, idleTurnAnimationName, false);
|
||||
spineAnimationState.AddAnimation(0, idleAnimationName, true, 0);
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
|
||||
@ -69,7 +69,7 @@ namespace Spine.Unity.Examples {
|
||||
if (skeletonAnimation == null) return;
|
||||
if (model == null) return;
|
||||
|
||||
if (skeletonAnimation.skeleton.FlipX != model.facingLeft) { // Detect changes in model.facingLeft
|
||||
if ((skeletonAnimation.skeleton.ScaleX < 0) != model.facingLeft) { // Detect changes in model.facingLeft
|
||||
Turn(model.facingLeft);
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ namespace Spine.Unity.Examples {
|
||||
}
|
||||
|
||||
public void Turn (bool facingLeft) {
|
||||
skeletonAnimation.Skeleton.FlipX = facingLeft;
|
||||
skeletonAnimation.Skeleton.ScaleX = facingLeft ? -1f : 1f;
|
||||
// Maybe play a transient turning animation too, then call ChangeStableAnimation.
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -23,7 +23,7 @@ namespace Spine.Unity.Examples {
|
||||
var mousePosition = Input.mousePosition;
|
||||
var worldMousePosition = camera.ScreenToWorldPoint(mousePosition);
|
||||
var skeletonSpacePoint = skeletonAnimation.transform.InverseTransformPoint(worldMousePosition);
|
||||
if (skeletonAnimation.Skeleton.FlipX) skeletonSpacePoint.x *= -1;
|
||||
//if (skeletonAnimation.Skeleton.FlipX) skeletonSpacePoint.x *= -1;
|
||||
bone.SetPosition(skeletonSpacePoint);
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,8 +69,8 @@ namespace Spine.Unity {
|
||||
sa.initialFlipX = this.initialFlipX;
|
||||
sa.initialFlipY = this.initialFlipY;
|
||||
var skeleton = sa.skeleton;
|
||||
skeleton.FlipX = this.initialFlipX;
|
||||
skeleton.FlipY = this.initialFlipY;
|
||||
skeleton.ScaleX = this.initialFlipX ? 1 : -1;
|
||||
skeleton.ScaleY = this.initialFlipY ? 1 : -1;
|
||||
|
||||
sa.Initialize(false);
|
||||
skeletonAnimations.Add(sa);
|
||||
|
||||
|
Before Width: | Height: | Size: 593 KiB After Width: | Height: | Size: 593 KiB |
|
Before Width: | Height: | Size: 192 KiB After Width: | Height: | Size: 192 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 51 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 6.8 KiB |