IEnumerator updateJumpAnim() { float currJumpValue = 0.11f; //跳跃起始时间 float jumpValueTotal = 1.79f; //跳跃时间 float jumpHeight = 4; //跳跃高度 float startUpSpeed = 2 * jumpHeight / (jumpValueTotal / 2); // v = at/2 up方向起始速度 float upA = -startUpSpeed / (jumpValueTotal / 2); //跳跃up方向加速度 float currUpSpeed = startUpSpeed; //当前跳跃up方向速度 float costTime = 1.0f; //整个跳跃动画花费时间 float jumpValueGrowSpeed = jumpValueTotal / costTime; //每次 jumpValue 增长多少 double currTime = Time.time; int times = 0; do { times++; currTime += Time.deltaTime; float offJumpValue = jumpValueGrowSpeed * Time.deltaTime; currJumpValue = currJumpValue + offJumpValue; AnimCtl.setAnimValue("newJump", currJumpValue); //跳跃时前进 float forwardDis = offJumpValue * AnimCtl.NavAgent.speed; //跳跃时上升 float startUpSpeedInner = currUpSpeed; currUpSpeed = startUpSpeedInner + upA * offJumpValue; // vt = v0 + at float upDis = (Mathf.Pow(currUpSpeed, 2) - Mathf.Pow(startUpSpeedInner, 2)) / (2 * upA); AnimCtl.transform.position += AnimCtl.transform.forward * forwardDis + AnimCtl.transform.up * upDis; yield return(0); } while (currJumpValue <= 1.9f); needSwitchAnim = true; }
void onEvent(string evt, object obj) { Debug.Log("wanghy -- HeroAttackState evt = " + evt); resetAnimValue(); switch (evt) { case Events.EVENT_SKILL0: AnimCtl.setAnimValue("attack0", true); break; case Events.EVENT_SKILL1: AnimCtl.setAnimValue("attack1", true); break; case Events.EVENT_SKILL2: AnimCtl.setAnimValue("attack2", true); break; case Events.EVENT_SKILL3: AnimCtl.setAnimValue("attack3", true); break; case Events.EVENT_SKILL4: AnimCtl.setAnimValue("attack4", true); break; } }
public override void onUpdate() { if (waitRebirth)//第三步等待重生 { Debug.Log("wanghy -- dead state update 1"); //移动到出生点 } else if (fadeout)//第二步淡出 { Debug.Log("wanghy -- dead state update 2"); Color currColor = renderer.material.color; Color targetColor = new Color(currColor.r, currColor.g, currColor.b, 0); Color setColor = Color.Lerp(currColor, targetColor, Time.deltaTime); renderer.material.color = setColor; if (setColor.a <= 0.05) { waitRebirth = true; } } else//第一步 dead 动画 { //检查dead动画 AnimatorStateInfo info = AnimCtl.Anim.GetCurrentAnimatorStateInfo(0); Debug.Log("wanghy -- dead state update 3 normalizedTime=" + info.normalizedTime + ", length=" + info.length); if (info.normalizedTime >= info.length)//动画结束 { AnimCtl.setAnimValue("isDead", false); fadeout = true; } } }
void resetAnimValue() { AnimCtl.setAnimValue("attack0", false); AnimCtl.setAnimValue("attack1", false); AnimCtl.setAnimValue("attack2", false); AnimCtl.setAnimValue("attack3", false); AnimCtl.setAnimValue("attack4", false); }
public override void onEnter() { AnimCtl.setAnimValue("attackState", true); mapEvent(Events.EVENT_SKILL0, onEvent); mapEvent(Events.EVENT_SKILL1, onEvent); mapEvent(Events.EVENT_SKILL2, onEvent); mapEvent(Events.EVENT_SKILL3, onEvent); mapEvent(Events.EVENT_SKILL4, onEvent); }
public override void onExit() { rebirth = false; fadeout = false; waitRebirth = false; rebirthCount = 0; rebirth = false; AnimCtl.setAnimValue("isDead", false); }
public override void onExit() { AnimCtl.setAnimValue("attackState", false); resetAnimValue(); }
public override void onEnter() { Debug.Log("wanghy -- dead state enter"); renderer = GameObject.transform.FindChild("model").GetComponent <Renderer>(); AnimCtl.setAnimValue("isDead", true); }