SpineboyFreeze.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Spine.Unity.Examples {
  5. public class SpineboyFreeze : MonoBehaviour {
  6. public SkeletonAnimation skeletonAnimation;
  7. public AnimationReferenceAsset freeze;
  8. public AnimationReferenceAsset idle;
  9. public Color freezeColor;
  10. public Color freezeBlackColor;
  11. public ParticleSystem particles;
  12. public float freezePoint = 0.5f;
  13. public string colorProperty = "_Color";
  14. public string blackTintProperty = "_Black";
  15. MaterialPropertyBlock block;
  16. MeshRenderer meshRenderer;
  17. IEnumerator Start () {
  18. block = new MaterialPropertyBlock();
  19. meshRenderer = GetComponent<MeshRenderer>();
  20. particles.Stop();
  21. particles.Clear();
  22. var main = particles.main;
  23. main.loop = false;
  24. var state = skeletonAnimation.AnimationState;
  25. while (true) {
  26. yield return new WaitForSeconds(1f);
  27. // Play freeze animation
  28. state.SetAnimation(0, freeze, false);
  29. yield return new WaitForSeconds(freezePoint);
  30. // Freeze effects
  31. particles.Play();
  32. block.SetColor(colorProperty, freezeColor);
  33. block.SetColor(blackTintProperty, freezeBlackColor);
  34. meshRenderer.SetPropertyBlock(block);
  35. yield return new WaitForSeconds(2f);
  36. // Return to Idle
  37. state.SetAnimation(0, idle, true);
  38. block.SetColor(colorProperty, Color.white);
  39. block.SetColor(blackTintProperty, Color.black);
  40. meshRenderer.SetPropertyBlock(block);
  41. yield return null;
  42. }
  43. }
  44. }
  45. }