Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Animator controller.
- /// DavidOneill
- /// 17/7/14
- /// This class will manage all animation for characters( players, Enemies, bosses).
- /// simple npc animations will be using NpcAnimatorController.
- /// </summary>
- using UnityEngine;
- using System.Collections;
- //
- [RequireComponent (typeof (Animator))]
- //[RequireComponent (typeof (CombatFSM))]
- //
- public class AnimatorController : MonoBehaviour {
- public CombatFSM _combat;
- private Health _health;
- public playerMovement _Move;
- public enemyMovement _enemyMove;
- public enemySprite _sprite;
- private Animator _anim;
- public int _attackInt = 0;
- //public int _weaponType = 0; //need to add and Id int to weapons in CombatFsm.cs
- //These next 2 are for npcs only.
- protected Motion motion; //instance of motion static class.
- private NavMeshAgent _agent = null;
- // private AnimatorStateInfo _BaseInfo;
- // private AnimatorStateInfo _Layer1Info;
- // static int IdleState = Animator.StringToHash("Base Layer.Idle"); //These will he handy later.//
- public string myState;// checks FsmState.
- // Use this for initialization
- void Start () {
- //Key References
- _combat = GetComponent<CombatFSM>();
- myState = _combat.currentState.ToString();
- _health = GetComponent<Health>();
- _anim = GetComponent<Animator>();
- motion = new Motion(_anim);
- //_sprite = GetComponentInChildren<enemySprite>();
- if(_anim == null || _combat == null || _health == null || _sprite == null)
- {
- Debug.Log ("Key Component Missing!!");
- }
- //MoveMent
- if(_combat.isPlayer)
- {
- _Move = GetComponent<playerMovement>();
- _enemyMove = null;
- }
- else
- {
- //_Move = null;
- _enemyMove = GetComponent<enemyMovement>();
- _agent = GetComponent<NavMeshAgent>();
- }
- }
- void FixedUpdate()
- {
- if(_combat.isPlayer)
- {
- float h = _Move.MYdir;
- float v = _Move.mySpeed;
- _anim.SetFloat("Speed",v);
- _anim.SetFloat("Direction",h);
- }
- else// if i am an Npc do this instead.
- {
- if(_agent.enabled)
- {
- SetUpMotion();
- }
- }
- myState = _combat.currentState.ToString();
- // _BaseInfo = _anim.GetCurrentAnimatorStateInfo(0); //reads the current animator state of the base layer.
- // _Layer1Info = _anim.GetCurrentAnimatorStateInfo(1);// as above, but Layer 1.
- if(myState == "Ready")
- {
- _attackInt = 0;
- }
- if(myState == "AttackLight")
- {
- _attackInt = 1;
- }
- if(myState == "AttackHeavy")
- {
- _attackInt = 2;
- }
- if(myState == "AttackCombo")
- {
- _attackInt = 3;
- }
- }
- void LateUpdate()
- {
- if(_combat.isPlayer)
- {
- _anim.SetBool("Grounded",_Move.grounded);
- }
- else
- {
- _anim.SetBool("Grounded",_enemyMove.grounded);
- }
- _anim.SetBool("Hurt",_health.hurt);
- _anim.SetBool("Block", _combat.blocking);
- _anim.SetBool("Grappling", _combat.Grappling);
- _anim.SetBool("Grappled", _combat.grappled);
- if(_combat.grabbedObj !=null)
- {
- _anim.SetBool("Grab",true);
- }
- else{
- _anim.SetBool("Grab",false);
- }
- _anim.SetInteger("AttackType", _attackInt);
- }
- //Protected Nav mesh Shizzle
- protected void SetUpMotion()
- {
- if(AgentDone())
- {
- motion.Do(0,0);
- }
- else
- {
- float speed = _agent.desiredVelocity.magnitude;
- Vector3 velocity = Quaternion.Inverse(transform.rotation) * _agent.desiredVelocity;
- float angle = Mathf.Atan2(velocity.x,velocity.y) * 180.0f / 3.14159f;
- motion.Do(speed,angle);
- }
- }
- protected bool AgentDone()
- {
- return !_agent.pathPending && AgentStopping();
- }
- protected bool AgentStopping()
- {
- return _agent.remainingDistance <= _agent.stoppingDistance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement