Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using Game.CharacterController;
- using Spine.Unity;
- namespace Game.Player {
- public class PlayerAnimationController : MonoBehaviour
- {
- //public Animator animator;
- public SkeletonAnimation SpineInstance;
- private PlayerInput _playerInput;
- private WeaponSystem _playerWeaponSystem;
- public struct AnimState {
- public bool isWalking;
- public bool isAttacking;
- public Spine.TrackEntry motionTrack;
- public Spine.TrackEntry attackTrack;
- public void Reset()
- {
- isWalking = isAttacking = false;
- attackTrack = motionTrack = null;
- }
- }
- public AnimState _animState;
- void Awake() {
- _playerInput = GetComponent<PlayerInput> ();
- _playerWeaponSystem = GetComponent<WeaponSystem> ();
- RegisterEvents ();
- _animState.Reset ();
- }
- void Start() {
- SpineInstance.AnimationState.Start += delegate (Spine.TrackEntry trackEntry) {
- // You can also use an anonymous delegate.
- Debug.Log(string.Format("track {0} started a new animation.", trackEntry.TrackIndex));
- };
- //set the character to idle
- _animState.motionTrack = SpineInstance.AnimationState.SetAnimation (0, "Idle", true);
- }
- void RegisterEvents() {
- //listen to events from PlayerInput
- _playerInput.events.OnWalk.AddListener(OnWalk);
- _playerInput.events.OnWalkStop.AddListener (OnWalkStop);
- _playerInput.events.OnJumpStart.AddListener (OnJumpStart);
- //listen to events from the weapon system
- _playerWeaponSystem.events.OnBlockStart.AddListener(OnBlockStart);
- _playerWeaponSystem.events.OnBlockEnd.AddListener(OnBlockEnd);
- _playerWeaponSystem.events.OnAttackStart.AddListener (OnAttackStart);
- _playerWeaponSystem.events.OnHeavyAttackStart.AddListener (OnHeavyAttackStart);
- _playerWeaponSystem.events.OnWarcryHealStart.AddListener (OnWarcry);
- _playerWeaponSystem.events.OnWarcrySlowTimeStart.AddListener (OnWarcry);
- }
- #region Player Movement
- public void OnWalk() {
- if (!_animState.isWalking) {
- _animState.motionTrack = SpineInstance.AnimationState.SetAnimation (0, "Run-1", true);
- _animState.isWalking = true;
- }
- //animator.SetBool ("IsWalking", true);
- }
- public void OnWalkStop() {
- if (_animState.isWalking) {
- _animState.motionTrack = SpineInstance.AnimationState.SetAnimation (0, "Idle", true);
- _animState.isWalking = false;
- }
- //animator.SetBool ("IsWalking", false);
- }
- public void OnJumpStart() {
- //animator.SetBool ("IsJumping", true);
- }
- #endregion
- #region Player Weapon System
- public void OnBlockStart() {
- //animator.SetBool ("IsBlocking", true);
- }
- public void OnBlockEnd() {
- //animator.SetBool ("IsBlocking", false);
- }
- public void OnAttackStart() {
- if (!_animState.isAttacking) {
- _animState.attackTrack = SpineInstance.AnimationState.SetAnimation (1, "Attack_normal-down", false);
- _animState.attackTrack.Alpha = 1f;
- _animState.attackTrack.AnimationEnd = 0.6f;
- _animState.attackTrack.TimeScale = 1.2f;
- //we need to disable the attack until the animation is completed
- _playerWeaponSystem.mainHandWeapon.canAttack = false;
- _animState.attackTrack.Complete += delegate(Spine.TrackEntry trackEntry) {
- //Debug.Log("Ended");
- //Debug.Break();
- _animState.isAttacking = false;
- _playerWeaponSystem.mainHandWeapon.canAttack = true;
- SpineInstance.AnimationState.ClearTrack(1);
- };
- _animState.isAttacking = true;
- }
- //animator.SetBool ("IsAttacking", true);
- }
- public void OnHeavyAttackStart() {
- //animator.SetBool ("IsHeavyAttacking", true);
- }
- #endregion
- #region Player Warcries
- public void OnWarcry() {
- //animator.SetBool ("IsUsingWarcry", true);
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement