Created
October 23, 2015 23:29
-
-
Save gamemachine/9b2193bbb8ecec04cea8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
namespace GameMachine { | |
namespace Animation { | |
public class AnimationController2 : MonoBehaviour { | |
public enum Layer { | |
Base, | |
UpperBody | |
} | |
public enum Name { | |
None, | |
Idle, | |
IdleLeft, | |
IdelRight, | |
IdleCombat, | |
Off, | |
Walk, | |
WalkLeft, | |
WalkRight, | |
WalkBack, | |
Run, | |
RunJump, | |
RunBack, | |
RunLeft, | |
RunRight, | |
Swim, | |
SwimIdle, | |
Harvest, | |
Skill1, | |
Skill2, | |
Skill3, | |
Skill4, | |
Skill5, | |
Skill6 | |
} | |
private Animator animator; | |
private AnimatorStateInfo stateInfo; | |
private Dictionary<Layer,int> layerIndex = new Dictionary<Layer,int>(); | |
private Dictionary<Name, int> triggerIds = new Dictionary<Name, int>(); | |
private Dictionary<Layer, int> currentLayerTrigger = new Dictionary<Layer, int>(); | |
void Start() { | |
animator = GetComponentInParent<Animator>() as Animator; | |
} | |
public void OnAnimatorMove() { | |
} | |
void Update() { | |
} | |
void SetAnimation(Name name, Layer layer) { | |
if (!layerIndex.ContainsKey(layer)) { | |
layerIndex[layer] = animator.GetLayerIndex(layer.ToString()); | |
} | |
if (triggerIds.ContainsKey(name)) { | |
triggerIds[name] = Animator.StringToHash(layer.ToString()+"."+name.ToString()); | |
} | |
int triggerId = triggerIds[name]; | |
stateInfo = animator.GetCurrentAnimatorStateInfo(layerIndex[layer]); | |
int currentTrigger = currentLayerTrigger[layer]; | |
if (stateInfo.fullPathHash == triggerId || currentTrigger == triggerId) { | |
return; | |
} | |
animator.SetTrigger(triggerId); | |
currentLayerTrigger[layer] = triggerId; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment