// Use this for initialization protected virtual void Start() { print("ADrunk start"); nav = GetComponent <NavMeshAgent>(); actionList = new List <ActionEnum.ActionData>(); actionMethode = new Dictionary <ActionEnum.Action, Action>(); actions = new List <AAction>(); comportement = gameObject.GetComponent <AIComportement>(); /*foreach(CapsuleCollider col in gameObject.GetComponents<CapsuleCollider>()) * { * if (!col.isTrigger) * collider = col; * }*///maybe later, was use to disable the collider when AI fall animations = (AAnimation)Activator.CreateInstance(Type.GetType(AnimationClassName)); animations.Initialize(this); foreach (string s in ActionClassName) { actions.Add((AAction)Activator.CreateInstance(Type.GetType(s))); actions[actions.Count - 1].Initialize(this); } actionMethode.Add(ActionEnum.Action.ActionDone, ActionDone); actionMethode.Add(ActionEnum.Action.Walk, SetDirection); actionMethode.Add(ActionEnum.Action.GetBottle, GetBottle); actionMethode.Add(ActionEnum.Action.ThrowBottle, ThrowBottle); actionMethode.Add(ActionEnum.Action.Hide, Hide); actionMethode.Add(ActionEnum.Action.Sit, Sit); actionMethode.Add(ActionEnum.Action.Leave, Leave); actionMethode.Add(ActionEnum.Action.Kick, Kick); actionMethode.Add(ActionEnum.Action.Slip, Slip); actionMethode.Add(ActionEnum.Action.Stun, Stun); actionMethode.Add(ActionEnum.Action.BottleStrick, BottleStrick); actionMethode.Add(ActionEnum.Action.Dance, Dance); actionMethode.Add(ActionEnum.Action.Drink, Drink); actionMethode.Add(ActionEnum.Action.Dart, Dart); actionMethode.Add(ActionEnum.Action.Fire, Fire); walking = false; anim = false; bottle = null; destination = null; forceActionDone = false; DrinkWanted = DrinkName.NOTHING; forceLiving = false; animator.SetFloat("alcool", alcool); }
// Update is called once per frame void Update() { if (currentAAnimation != null) { //更新动画的局部时间. currentAAnimation.Update(Time.deltaTime * Speed); if (targetAAnimation != null) { targetAAnimation.Update(Time.deltaTime * Speed); transitionWight += Time.deltaTime * 5; //过渡结束. if (transitionWight >= 1) { transitionWight = 0; currentAAnimation = targetAAnimation; targetAAnimation = null; reallySQT = targetSQT; } } //更新动画数据. int JointsCount = JointsList.Count; for (int i = 0; i < JointsCount; i++) { jointName = JointsList[i]; //如果设置了骨骼遮罩,则直接返回. if (JointMaskDic.ContainsKey(jointName) && JointMaskDic[jointName]) { continue; } currentJointTransform = GetJointsByName(jointName); if (currentJointTransform == null) { continue; } Transform joint = DrawJoints(jointName); if (joint != null) { joint.parent = currentJointTransform; joint.localScale = new Vector3(0.1f, 0.1f, 0.1f); joint.localPosition = Vector3.zero; joint.localRotation = Quaternion.identity; joint.gameObject.SetActive(drawJoints); } currentSQT = currentAAnimation.UpdateSQT(jointName); if (targetAAnimation != null) { targetSQT = targetAAnimation.UpdateSQT(jointName); } else { targetSQT.SetAllWeight(0); } reallySQT = ToolSQT.Lerp(currentSQT, targetSQT, transitionWight); if (reallySQT.Position_Weight != 0) { currentJointTransform.localPosition = reallySQT.Position; } if (reallySQT.Rotation_Weight != 0) { currentJointTransform.localRotation = reallySQT.Rotation; } if (reallySQT.Scale_Weight != 0) { currentJointTransform.localScale = reallySQT.Scale; } } } }
void Test() { currentAAnimation = AAnimations[DeafultAnimationClip.name]; }
/*--------------------------------------------演示 end--------------------------------------------*/ public void SetTrigger(EAniTrigger value) { targetAAnimation = AAnimations[targetClip.name]; transitionWight = 0; }