void Update() { if (_startedDestroy) { _destroyTimer += Time.deltaTime; var tempColor = _renderRef.color; var tempScale = transform.localScale; tempColor.a -= Time.deltaTime; tempScale += new Vector3(Time.deltaTime, Time.deltaTime, Time.deltaTime) * 0.15f; if (tempColor.a < 0) { tempColor.a = 0; } transform.localScale = tempScale; _renderRef.color = tempColor; if (_destroyTimer > 1.0f) { Destroy(this.gameObject); } } else { var currentClipInfo = _animatorRef?.GetCurrentAnimatorClipInfo(0); if (currentClipInfo != null && currentClipInfo[0].clip.name == "AOEAttackIdle") { _startedDestroy = true; } } }
//OnStateExit is called before OnStateExit is called on any state inside this state machine public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { AnimatorClipInfo aci = animator.GetCurrentAnimatorClipInfo(layerIndex)[0]; Debug.Log("离开:" + aci.clip.name + "-" + stateInfo.fullPathHash + "-" + stateInfo.length + "-" + stateInfo.normalizedTime + "-" + (stateInfo.normalizedTime - prev)); //Debug.Log(3 + "-" + stateInfo.fullPathHash + "-" + stateInfo.length + "-" + stateInfo.normalizedTime + "-" + (stateInfo.normalizedTime - prev)); prev = stateInfo.normalizedTime; }
/// <summary> /// Returns true when the current current animation is playing. /// </summary> /// <param name="name">name of animation</param> /// <param name="animator">animator object</param> /// <returns></returns> public static bool IsAnimationPlaying(string name, Animator animator) { for (int i = 0; i < animator.layerCount; i++) { AnimatorClipInfo[] clipInfoArray = animator.GetCurrentAnimatorClipInfo(i); foreach (AnimatorClipInfo info in clipInfoArray) if (info.clip.name.Equals(name)) return true; } return false; }
// Use this for initialization void Start() { sktAnimator = GetComponent<SkeletonAnimator>(); if (sktAnimator == null) { Debug.LogError("sktAnimator == null"); } else { sktAnimator.GetSkeleton().flipX = true; sktAnimator.GetSkeleton().SetColor(new Color(1.0f, 0.0f, 0.0f)); } sktAnimation = GetComponent<SkeletonAnimation>(); if (sktAnimation == null) { Debug.LogError("sktAnimation == null"); } else { Debug.Log("animation : " + sktAnimation.state.GetCurrent(0)); } animator = GetComponent<Animator>(); if (animator == null) { Debug.LogError("animator == null"); } else { AnimatorClipInfo[] items = animator.GetCurrentAnimatorClipInfo(0); Debug.Log("items length : " + items.Length); foreach (AnimatorClipInfo item in items) { Debug.Log("" + item.clip.name); } Debug.Log("ok"); // Debug.Log ("animator : " + animator.GetComponent<UnityEngine.Animation>().name); } sktUtility = GetComponent<SkeletonUtility>(); if (sktUtility == null) { Debug.LogError ("sktUtility == null"); } else { Debug.Log ("123123" + sktUtility.skeletonAnimation.Skeleton.Slots); // foreach (Slot item in sktUtility.skeletonAnimation.Skeleton.Slots) // { // Debug.Log ("item : " + item.ToString()); // if (item.ToString().Equals("front_bracer")) // { // item.SetColor(new Color(0.0f, 1.0f, 0.0f)); // } // } } }
static void CharacterAnimFixedUpdatePrefix(ref Animator ___m_animator, Character ___m_character) { //Make sure this is being applied to the right things if (Player.m_localPlayer == null || !___m_character.IsPlayer() || ___m_character.IsPlayer() && (___m_character as Player).GetPlayerID() != Player.m_localPlayer.GetPlayerID()) { return; } //Make sure there is animation playing if (___m_animator?.GetCurrentAnimatorClipInfo(0)?.Any() != true || ___m_animator.GetCurrentAnimatorClipInfo(0)[0].clip == null) { return; } //Log.LogInfo(___m_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name); //Check if weapon is a sword if (___m_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.StartsWith("Attack")) { if ((bool)((___m_character as Humanoid).GetCurrentWeapon()?.m_shared?.m_name.Contains("greatsword")) || (bool)((___m_character as Humanoid).GetCurrentWeapon()?.m_shared?.m_name.Contains("folcbrand"))) { ___m_animator.speed = ChangeSpeed(___m_character, ___m_animator, (float)balance["GreatswordAnimationSpeedAdjust"]); } } if (___m_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.StartsWith("Bomb")) { //Log.LogWarning("Throwing Bomb"); if ((bool)((___m_character as Humanoid).GetCurrentWeapon()?.m_shared?.m_name.Contains("throwingaxe"))) { //Log.LogWarning("Is throwingaxe"); ___m_animator.speed = ChangeSpeed(___m_character, ___m_animator, (float)balance["ThrowingAxeAnimationSpeedAdjust"]); } } if (___m_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.StartsWith("BattleAxe1")) { if ((bool)((___m_character as Humanoid).GetCurrentWeapon()?.m_shared?.m_name.Contains("greatsword"))) { //Log.LogWarning("Is throwingaxe"); ___m_animator.speed = ChangeSpeed(___m_character, ___m_animator, (float)balance["GreatswordStartAnimationSpeedAdjust"]); } } else if (___m_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.StartsWith("BattleAxe")) { if ((bool)((___m_character as Humanoid).GetCurrentWeapon()?.m_shared?.m_name.Contains("greatsword"))) { //Log.LogWarning("Is throwingaxe"); ___m_animator.speed = ChangeSpeed(___m_character, ___m_animator, (float)balance["GreatswordAnimationSpeedAdjust"]); } } }
// OnStateEnter is called before OnStateEnter is called on any state inside this state machine public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { Debug.Log(1 + "-" + stateInfo.fullPathHash + "-" + Animator.StringToHash("Base.Idle.idle1")+"-"+ stateInfo.length + "-" + stateInfo.normalizedTime + "-" + (stateInfo.normalizedTime - prev)); prev = stateInfo.normalizedTime; // animationManager.initState(animator, stateInfo); AnimationEvent ae = new AnimationEvent(); ae.functionName = "animationEvent"; AnimatorTransitionInfo ati = animator.GetAnimatorTransitionInfo(layerIndex); AnimatorClipInfo aci = animator.GetCurrentAnimatorClipInfo(layerIndex)[0]; aci.clip.AddEvent(ae); Debug.Log( "进入:"+ aci.clip.name +"-"+ stateInfo.fullPathHash + "-" + stateInfo.length + "-" + stateInfo.normalizedTime + "-" + (stateInfo.normalizedTime - prev)); //animator.SetInteger("idle",Random.Range(1, 3)); //AnimationAction animationAction = AnimationManager.getAnimationAction(animator); }
static void Prefix(Animator ___m_animator, Character ___m_character, ref float speedScale) { if (!modEnabled.Value || !(___m_character is Player)) { return; } if (___m_animator?.GetCurrentAnimatorClipInfo(0)?.Any() != true || ___m_animator.GetCurrentAnimatorClipInfo(0)[0].clip == null) { return; } //Dbgl($"{___m_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name} speed {speedScale}"); if (___m_animator.GetCurrentAnimatorStateInfo(0).IsName("dodge")) { speedScale *= dodgeSpeedMult.Value; //Dbgl($"Dodge speed after {speedScale}"); } }
// OnStateUpdate is called before OnStateUpdate is called on any state inside this state machine public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { Debug.Break(); AnimatorTransitionInfo ati = animator.GetAnimatorTransitionInfo(layerIndex); AnimatorClipInfo []acis = animator.GetCurrentAnimatorClipInfo(layerIndex); string acit = ""; foreach (AnimatorClipInfo aci in acis){ acit += "["+aci.weight + ":" + aci.clip.name+"],"; } //Debug.Log(2 + "-[" + ati.normalizedTime + "]-["+animator.GetCurrentAnimatorClipInfo(layerIndex)[0].clip.name+ "]-["+stateInfo.normalizedTime+"]-"+ (stateInfo.normalizedTime-prev)); prev = stateInfo.normalizedTime; Debug.Log("update:" + stateInfo.fullPathHash+"-"+acit+stateInfo.normalizedTime); if (stateInfo.normalizedTime>0.8f) { // Debug.Log(stateInfo.fullPathHash); //animator.SetInteger("Attack", 0); //Debug.Break(); } }
void OnEnable() { AnimatorClipInfo[] clipInfo = animator.GetCurrentAnimatorClipInfo(0); Destroy(gameObject, clipInfo[0].clip.length); damageText = animator.GetComponent <Text>(); }
void Update() { float input = Input.GetAxisRaw("Horizontal") * speed; float newVelocityX = GetComponent <Rigidbody2D>().velocity.x; float newVelocityY = GetComponent <Rigidbody2D>().velocity.y; if (state == 0) { newVelocityX = input; } else if (state == 1) { newVelocityY = input; } else if (state == 2) { newVelocityY = -input; } else if (state == 3) { newVelocityX = -input; } if (newVelocityY < -maxVelocity) { newVelocityY = -maxVelocity; } else if (newVelocityY > maxVelocity) { newVelocityY = maxVelocity; } if (newVelocityX < -maxVelocity) { newVelocityX = -maxVelocity; } else if (newVelocityX > maxVelocity) { newVelocityX = maxVelocity; } GetComponent <Rigidbody2D>().velocity = new Vector2(newVelocityX, newVelocityY); if (input != 0f) { text.transform.localScale = new Vector3(0f, 0f, 0f); //Removes starttext if (anim.GetCurrentAnimatorClipInfo(0)[0].clip.name != "running" && input > 0) { anim.Play("Base Layer.running", 0, 1); } else if (anim.GetCurrentAnimatorClipInfo(0)[0].clip.name != "running2" && input < 0) { anim.Play("Base Layer.running2", 0, 1); } } else if (Physics2D.Raycast(transform.position, -Vector2.up).collider != null) { if (anim.GetCurrentAnimatorClipInfo(0)[0].clip.name != "landing" && onGround == false) { //anim.Play("Base Layer.landing", 0, 1); //onGround = true; } if (anim.GetCurrentAnimatorClipInfo(0)[0].clip.name != "Idel" && anim.GetCurrentAnimatorClipInfo(0)[0].clip.name != "landing") { anim.Play("Base Layer.Idel", 0, 1); } } //else if(Physics2D.Raycast(transform.position, -Vector2.up).collider == null) //{ // onGround = false; //} if (transform.rotation.eulerAngles.z != rotation) { GetComponent <Rigidbody2D>().freezeRotation = false; if (transform.rotation.eulerAngles.z < rotation + 1 && transform.rotation.eulerAngles.z > rotation - 1) { transform.rotation = Quaternion.Euler(transform.rotation.x, transform.rotation.y, rotation); } else if (transform.rotation.eulerAngles.z < rotation) { transform.Rotate(new Vector3(0, 0, 1f)); } else if (transform.rotation.eulerAngles.z > rotation) { transform.Rotate(new Vector3(0, 0, -1f)); } GetComponent <Rigidbody2D>().freezeRotation = true; } if (transform.position.x < -mapsizeX) { transform.position = new Vector3(transform.position.x + mapsizeX * 2, transform.position.y, transform.position.z); } else if (transform.position.x > mapsizeX) { transform.position = new Vector3(transform.position.x - mapsizeX * 2, transform.position.y, transform.position.z); } else if (transform.position.y < -mapsizeY) { transform.position = new Vector3(transform.position.x, transform.position.y + mapsizeY * 2, transform.position.z); } else if (transform.position.y > mapsizeY) { transform.position = new Vector3(transform.position.x, transform.position.y - mapsizeY * 2, transform.position.z); } }
IEnumerator slide() { yield return(new WaitForSeconds(menuSlide.GetCurrentAnimatorClipInfo(0).Length - 0.1f)); menuSlide.Stop(); }
void Update() { if (GameData.Paused) { if (anim.speed == 1) { anim.speed = 0; } return; } if (anim.speed == 0) { anim.speed = 1; } EverythingMoves.MoveSpeed += 0.0000230f; if (anim.GetCurrentAnimatorClipInfoCount(animIndex) != 0) { currentClip = anim.GetCurrentAnimatorClipInfo(animIndex)[0].clip.name; } if (Input.GetKeyDown(KeyCode.R)) { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } // Check from both sides bool grounded = CheckGround(0.3f); if (grounded) { CoyoteTime = CoyoteCooldown; } else if (CoyoteTime > 0) { CoyoteTime--; } // ==================== // JUMPING/ENDING SLIDE // ==================== if (currentClip == "Jump") { jumpPeak = Mathf.Max(jumpPeak, t.position.y); } if (Input.GetKeyDown(GameData.Jump) && CoyoteTime > 0 && allowsJump.Contains(currentClip)) { Jump(); } Vector2 vel = rigidBody.velocity; if (Input.GetKeyUp(GameData.Jump)) { if (vel.y > 0) { vel.y = 0; rigidBody.velocity = vel; } downtime = 0; wasFromSlide = false; } if (Input.GetKeyDown(GameData.Jump) && allowsEndSlide.Contains(currentClip)) { anim.SetTrigger("EndSlide"); } if (Input.GetKey(GameData.Jump)) { downtime++; // It wasn't intended this caused mid-air jumps // But it is, now. if (downtime == 9 && wasFromSlide && allowsJump.Contains(currentClip)) { Jump(); } } // ================== // LANDING & FREEFALL // ================== if ((grounded && !previousGrounded) || (grounded && airborneStates.Contains(currentClip))) { if (allowsSafeLanding.Contains(currentClip)) { anim.SetTrigger("SafeLanding"); } else if (allowsUnsafeLanding.Contains(currentClip)) { anim.SetTrigger("UnsafeLanding"); } } // =================== // HORIZONTAL MOVEMENT // =================== // Input, otherwise drag in input direction. // Not using rigidbody's drag because vertical should have no drag. bool dragL = false, dragR = false; if (Input.GetKey(GameData.Left) && allowsHorizontal.Contains(currentClip)) { rigidBody.AddForce(Vector2.left * Speed, ForceMode2D.Impulse); } else { dragL = true; } if (Input.GetKey(GameData.Right) && allowsHorizontal.Contains(currentClip)) { rigidBody.AddForce(Vector2.right * Speed, ForceMode2D.Impulse); } else { dragR = true; } vel = rigidBody.velocity; if (dragL && vel.x < 0) { vel.x *= HDrag; } else if (dragR && vel.x > 0) { vel.x *= HDrag; } if (vel.x < -MaxSpeed) { vel.x = -MaxSpeed; } else if (vel.x > MaxSpeed) { vel.x = MaxSpeed; } rigidBody.velocity = vel; Vector3 p = t.position; bool hit = p.y < -8.5f; hit |= p.x < -10; if (p.x > 9.6f) { p.x = 9.6f; } t.position = p; if (hit) { GetHit(); } // ================== // DIAG ATTACK/SLIDES // ================== if (Input.GetKeyDown(GameData.Down)) { if (grounded || (rigidBody.velocity.y < 0 && CheckGround(3f))) { if (allowsStartSlide.Contains(currentClip)) { wasFromSlide = true; anim.SetTrigger("StartSlide"); } } else if (allowsDiagAttack.Contains(currentClip)) { anim.SetTrigger("DiagAttack"); } } previousGrounded = grounded; }
//Perform IK (Sequence) IEnumerator PerformSequence(int id, List <IKSequence> iKSequence, bool smoothEntry, bool isLoop, int counts) { playing = true; int activeAttachment = 0; IKAttachment ik = stateIKs[id].IKs[activeAttachment]; ik.iKAttachment.localPosition = ik.initPos; ik.iKAttachment.localRotation = ik.initRot; if (!iKSequence[0].useDefault) { if (smoothEntry && counts == 0) { float i = 0; while (i < 1) { while (animator.speed == 0) { yield return(0); } i += Time.deltaTime / iKSequence[activeAttachment].speed; ik.weight = Mathf.Lerp(0, 1, i); yield return(0); } } ik.weight = 1; } else { if (smoothEntry && counts == 0) { float i = 0; while (i < 1) { while (animator.speed == 0) { yield return(0); } i += Time.deltaTime / iKSequence[activeAttachment].speed; ik.weight = Mathf.Lerp(1, 0, i); yield return(0); } } ik.weight = 0; } Vector3 endPos = Vector3.zero; Quaternion endRot = Quaternion.identity; for (int j = 1; j < iKSequence.Count; j++) { if (stateIKs[id].IKs.Count <= iKSequence[j].attachment) { Debug.Log("No IK attachments with ID:" + (iKSequence[j].attachment.ToString("00")) + " found in State IK: " + stateIKs[id].iKName + " - " + this.gameObject.name); break; } if (stateIKs[id].IKs[iKSequence[j].attachment].iKAttachment == null) { Debug.Log("Missing attachment Transform with ID:" + (iKSequence[j].attachment.ToString("00")) + " found in State IK: " + stateIKs[id].iKName + " - " + this.gameObject.name); break; } if (counts == 0) { if (j == 1) { yield return(new WaitForSeconds(iKSequence[j].time - iKSequence[0].speed)); } else { yield return(new WaitForSeconds(iKSequence[j].time)); } } else { yield return(new WaitForSeconds(iKSequence[j].time)); } if (ik.weight == 0) {//Follow default animation without IK (first IK Attachment) activeAttachment = iKSequence[j].attachment; stateIKs[id].activeAttachment = activeAttachment; ik = stateIKs[id].IKs[activeAttachment]; ik.weight = 0; float h = 0; while (h < 1) { while (animator.speed == 0) { yield return(0); } h += Time.deltaTime / iKSequence[activeAttachment].speed; ik.weight = Mathf.Lerp(0, 1, h); yield return(0); } } else { if (!iKSequence[j].useDefault) { //To next Transform IK attachment IKAttachment previousIKAttachment = ik; endPos = stateIKs[id].IKs[iKSequence[j].attachment].iKAttachment.localPosition; endRot = stateIKs[id].IKs[iKSequence[j].attachment].iKAttachment.localRotation; float k = 0; while (k < 1) { while (animator.speed == 0) { yield return(0); } k += Time.deltaTime / iKSequence[j].speed; ik.iKAttachment.localPosition = Vector3.Lerp(ik.initPos, endPos, k); ik.iKAttachment.localRotation = Quaternion.Lerp(ik.initRot, endRot, k); yield return(0); } activeAttachment = iKSequence[j].attachment; stateIKs[id].activeAttachment = activeAttachment; ik = stateIKs[id].IKs[activeAttachment]; ik.weight = 1; previousIKAttachment.iKAttachment.localPosition = previousIKAttachment.initPos; previousIKAttachment.iKAttachment.localRotation = previousIKAttachment.initRot; } else { //Follow default animation without IK ik.weight = 1; float h = 0; while (h < 1) { while (animator.speed == 0) { yield return(0); } h += Time.deltaTime / iKSequence[j].speed; ik.weight = Mathf.Lerp(1, 0, h); yield return(0); } } } } if (isLoop) { AnimatorStateInfo animationState = animator.GetCurrentAnimatorStateInfo(0); AnimatorClipInfo[] animClip = animator.GetCurrentAnimatorClipInfo(0); float animationTime = animationState.normalizedTime - (1 * counts); if (animationTime < 1) { while (animationTime < 1) { animationState = animator.GetCurrentAnimatorStateInfo(0); animClip = animator.GetCurrentAnimatorClipInfo(0); animationTime = animationState.normalizedTime - (1 * counts); yield return(0); } } counts++; stateIKs[id].isActive = true; stateIKs[id].stateCoroutine = PerformSequence(id, iKSequence, smoothEntry, isLoop, counts); StartCoroutine(stateIKs[id].stateCoroutine); } }
void Awake() { AnimatorClipInfo[] clipsInfo = anim.GetCurrentAnimatorClipInfo(0); Destroy(gameObject, 1.5f); damageText = anim.GetComponent <Text>(); }
// Use this for initialization void Start() { AnimatorClipInfo[] clip_info = animator.GetCurrentAnimatorClipInfo(0); //PoolManager.Despawn(gameObject, clip_info[0].clip.length); Destroy(gameObject, clip_info[0].clip.length); }
void Start() { AnimatorClipInfo[] clipInfo = animator.GetCurrentAnimatorClipInfo(0); Destroy(this.gameObject, clipInfo[0].clip.length); }
// Use this for initialization void Start () { animator = GetComponent<Animator>(); AnimatorClipInfo[] clipInfo = animator.GetCurrentAnimatorClipInfo(0); //Debug.Log(clipInfo[0].clip.length); Destroy(this.gameObject, clipInfo[0].clip.length); }
private CinemachineVirtualCameraBase ChooseCurrentCamera() { if (m_ChildCameras == null || m_ChildCameras.Length == 0) { mActivationTime = 0; return(null); } CinemachineVirtualCameraBase defaultCam = m_ChildCameras[0]; if (m_AnimatedTarget == null || !m_AnimatedTarget.gameObject.activeSelf || m_AnimatedTarget.runtimeAnimatorController == null || m_LayerIndex < 0 || !m_AnimatedTarget.hasBoundPlayables || m_LayerIndex >= m_AnimatedTarget.layerCount) { mActivationTime = 0; return(defaultCam); } // Get the current state int hash; if (m_AnimatedTarget.IsInTransition(m_LayerIndex)) { // Force "current" state to be the state we're transitioning to AnimatorStateInfo info = m_AnimatedTarget.GetNextAnimatorStateInfo(m_LayerIndex); m_AnimatedTarget.GetNextAnimatorClipInfo(m_LayerIndex, m_clipInfoList); hash = GetClipHash(info.fullPathHash, m_clipInfoList); } else { AnimatorStateInfo info = m_AnimatedTarget.GetCurrentAnimatorStateInfo(m_LayerIndex); m_AnimatedTarget.GetCurrentAnimatorClipInfo(m_LayerIndex, m_clipInfoList); hash = GetClipHash(info.fullPathHash, m_clipInfoList); } // If we don't have an instruction for this state, find a suitable default while (hash != 0 && !mInstructionDictionary.ContainsKey(hash)) { hash = mStateParentLookup.ContainsKey(hash) ? mStateParentLookup[hash] : 0; } float now = CinemachineCore.CurrentTime; if (mActivationTime != 0) { // Is it active now? if (mActiveInstruction.m_FullHash == hash) { // Yes, cancel any pending mPendingActivationTime = 0; return(mActiveInstruction.m_VirtualCamera); } // Is it pending? if (PreviousStateIsValid) { if (mPendingActivationTime != 0 && mPendingInstruction.m_FullHash == hash) { // Has it been pending long enough, and are we allowed to switch away // from the active action? if ((now - mPendingActivationTime) > mPendingInstruction.m_ActivateAfter && ((now - mActivationTime) > mActiveInstruction.m_MinDuration || mPendingInstruction.m_VirtualCamera.Priority > mActiveInstruction.m_VirtualCamera.Priority)) { // Yes, activate it now mActiveInstruction = mPendingInstruction; mActivationTime = now; mPendingActivationTime = 0; } return(mActiveInstruction.m_VirtualCamera); } } } // Neither active nor pending. mPendingActivationTime = 0; // cancel the pending, if any if (!mInstructionDictionary.ContainsKey(hash)) { // No defaults set, we just ignore this state if (mActivationTime != 0) { return(mActiveInstruction.m_VirtualCamera); } return(defaultCam); } // Can we activate it now? Instruction newInstr = m_Instructions[mInstructionDictionary[hash]]; if (newInstr.m_VirtualCamera == null) { newInstr.m_VirtualCamera = defaultCam; } if (PreviousStateIsValid && mActivationTime > 0) { if (newInstr.m_ActivateAfter > 0 || ((now - mActivationTime) < mActiveInstruction.m_MinDuration && newInstr.m_VirtualCamera.Priority <= mActiveInstruction.m_VirtualCamera.Priority)) { // Too early - make it pending mPendingInstruction = newInstr; mPendingActivationTime = now; if (mActivationTime != 0) { return(mActiveInstruction.m_VirtualCamera); } return(defaultCam); } } // Activate now mActiveInstruction = newInstr; mActivationTime = now; return(mActiveInstruction.m_VirtualCamera); }
private IEnumerator _AnimateComicBook() { m_comicBookModel = GameObject.Find("ComicCharacter").GetComponent<Animator>(); m_comicBookModel.SetBool("IdleToIdle", false); m_comicBookModel.SetBool("AttackToIdle", false); m_comicBookModel.SetBool("IdleToAttack", true); yield return new WaitForSeconds(0.3f); Debug.Log("Animator clip info = " + m_comicBookModel.GetCurrentAnimatorClipInfo(0)); float animationLength = m_comicBookModel.GetCurrentAnimatorClipInfo(0)[0].clip.length; yield return new WaitForSeconds(animationLength); m_comicBookModel.SetBool("IdleToIdle", true); m_comicBookModel.SetBool("IdleToAttack", false); m_comicBookModel.SetBool("AttackToIdle", true); }
void Start() { animatorEnabled = anim.enabled; clipCount = anim.GetCurrentAnimatorClipInfo(0).Length; }
private IEnumerator _AnimateFantasy() { m_fantasyModel = GameObject.Find("FantasyCharacter").GetComponent<Animator>(); m_fantasyModel.SetBool("IdleToIdle", false); m_fantasyModel.SetBool("AttackToIdle", false); m_fantasyModel.SetBool("IdleToAttack", true); yield return new WaitForSeconds(0.3f); float animationLength = m_fantasyModel.GetCurrentAnimatorClipInfo(0)[0].clip.length; yield return new WaitForSeconds(animationLength - 0.2f); m_fantasyModel.SetBool("IdleToIdle", true); m_fantasyModel.SetBool("IdleToAttack", false); m_fantasyModel.SetBool("AttackToIdle", true); }
private CinemachineVirtualCameraBase ChooseCurrentCamera(float deltaTime) { if (m_ChildCameras == null || m_ChildCameras.Length == 0) { mActivationTime = 0; return(null); } CinemachineVirtualCameraBase defaultCam = m_ChildCameras[0]; if (m_AnimatedTarget == null || m_LayerIndex < 0 || m_LayerIndex >= m_AnimatedTarget.layerCount) { mActivationTime = 0; return(defaultCam); } // Get the current state AnimatorStateInfo info = m_AnimatedTarget.GetCurrentAnimatorStateInfo(m_LayerIndex); int hash = info.fullPathHash; // Is there an animation clip substate? AnimatorClipInfo[] clips = m_AnimatedTarget.GetCurrentAnimatorClipInfo(m_LayerIndex); if (clips.Length > 1) { // Find the strongest-weighted one int bestClip = -1; for (int i = 0; i < clips.Length; ++i) { if (bestClip < 0 || clips[i].weight > clips[bestClip].weight) { bestClip = i; } } // Use its hash if (bestClip >= 0 && clips[bestClip].weight > 0) { hash = Animator.StringToHash(CreateFakeHashName(hash, clips[bestClip].clip.name)); } } // If we don't have an instruction for this state, find a suitable default while (hash != 0 && !mInstructionDictionary.ContainsKey(hash)) { hash = mStateParentLookup.ContainsKey(hash) ? mStateParentLookup[hash] : 0; } float now = Time.time; if (mActivationTime != 0) { // Is it active now? if (mActiveInstruction.m_FullHash == hash) { // Yes, cancel any pending mPendingActivationTime = 0; return(mActiveInstruction.m_VirtualCamera); } // Is it pending? if (deltaTime > 0) { if (mPendingActivationTime != 0 && mPendingInstruction.m_FullHash == hash) { // Has it been pending long enough, and are we allowed to switch away // from the active action? if ((now - mPendingActivationTime) > mPendingInstruction.m_ActivateAfter && ((now - mActivationTime) > mActiveInstruction.m_MinDuration || mPendingInstruction.m_VirtualCamera.Priority > mActiveInstruction.m_VirtualCamera.Priority)) { // Yes, activate it now mActiveInstruction = mPendingInstruction; mActivationTime = now; mPendingActivationTime = 0; } return(mActiveInstruction.m_VirtualCamera); } } } // Neither active nor pending. mPendingActivationTime = 0; // cancel the pending, if any if (!mInstructionDictionary.ContainsKey(hash)) { // No defaults set, we just ignore this state if (mActivationTime != 0) { return(mActiveInstruction.m_VirtualCamera); } return(defaultCam); } // Can we activate it now? Instruction newInstr = m_Instructions[mInstructionDictionary[hash]]; if (newInstr.m_VirtualCamera == null) { newInstr.m_VirtualCamera = defaultCam; } if (deltaTime > 0 && mActivationTime > 0) { if (newInstr.m_ActivateAfter > 0 || ((now - mActivationTime) < mActiveInstruction.m_MinDuration && newInstr.m_VirtualCamera.Priority <= mActiveInstruction.m_VirtualCamera.Priority)) { // Too early - make it pending mPendingInstruction = newInstr; mPendingActivationTime = now; if (mActivationTime != 0) { return(mActiveInstruction.m_VirtualCamera); } return(defaultCam); } } // Activate now mActiveInstruction = newInstr; mActivationTime = now; return(mActiveInstruction.m_VirtualCamera); }
// Update is called once per frame void Update() { if (CurrentHealth < MaximumHealth) { CurrentHealth += Time.deltaTime * 5; if (CurrentHealth <= 0) { Anim.SetBool("Dead", true); CharacterController CharCtrler = GetComponent <CharacterController>(); CharCtrler.height = .3f; CharCtrler.center = new Vector3(0, .3f, 0); CapsuleCollider CapColl = GetComponent <CapsuleCollider>(); CapColl.height = .3f; CapColl.center = new Vector3(0, .3f, 0); GetComponent <BaseControl>().Controllable = false; } } else { CurrentHealth = MaximumHealth; } if (CurrentMana < MaximumMana) { CurrentMana += Time.deltaTime; } else { CurrentMana = MaximumMana; } if (CurrentStats > 0) { for (short StatusCheck = 1; StatusCheck <= 8; StatusCheck = (short)(StatusCheck << 1)) { switch (CurrentStats & StatusCheck) { case 1: if (Anim.GetCurrentAnimatorClipInfo(2).Length > 0 && Anim.GetCurrentAnimatorStateInfo(2).normalizedTime <= 1.0f) { if (charController != null) { charController.Controllable = false; } StartAnimation = true; } else if (StartAnimation) { if (charController != null) { charController.Controllable = true; } CurrentStats &= 14; StartAnimation = false; } break; case 2: CurrentFireDuration -= Time.deltaTime; int burnIntensity = (int)(CurrentFireDuration / 2.5); Burning burn = GetComponentInChildren <Burning>(); if (burn != null) { burn.ChangeIntensity(burnIntensity); } CurrentHealth -= CurrentFireDuration * FireDamageOverTime * Time.deltaTime; if (CurrentFireDuration <= 0) { CurrentFireDuration = 0; CurrentStats &= 13; } CurrentSlowedDuration = CurrentSlowedDuration >= 0 ? CurrentSlowedDuration - Time.deltaTime : 0; break; case 4: CurrentSlowedDuration -= Time.deltaTime; if (MaxSlowedDuration < CurrentSlowedDuration) { CurrentSlowedDuration = MaxSlowedDuration; } float ChilledIntensity = CurrentSlowedDuration / MaxSlowedDuration; movements.SetAnimationSpeed(1 - ChilledIntensity); Chilled chilled = GetComponentInChildren <Chilled>(); if (chilled != null) { chilled.ChangeIntensity(ChilledIntensity); } if (CurrentSlowedDuration <= 0 && chilled != null) { CurrentSlowedDuration = 0; chilled.Unchill = true; movements.SetAnimationSpeed(1); CurrentStats &= 11; } break; case 8: break; } } } }
void Update() { //タップした判定 if (Input.GetMouseButtonDown(0)) { //gcって仮の変数にGameControllerのコンポーネントを入れる GameController gc = gameController.GetComponent <GameController>(); Ray ray = new Ray(); RaycastHit hit = new RaycastHit(); ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { zombie = hit.collider.gameObject; //tapしたobject取得 // Debug.Log("name : " + zombie.transform.name); } else { zombie = null; //zombie以外をタッチした扱い } //zombieがタッチされた時判定。error対策 if (zombie != null) { //daialog表示中はタッチできなくする if (gc.dialogCanvas.enabled == false) { //Zombieをtapしたら if (zombie.tag == "Zombie") { //再生中animation取得 AnimatorClipInfo clipInfo = anim.GetCurrentAnimatorClipInfo(0)[0]; // Debug.Log ("アニメーションクリップ名 : " + clipInfo.clip.name); string anim_name = clipInfo.clip.name; //再生中animation名を保存 //タッチに反応 if (isTap == false) { //自分がタッチされたか判定 if (this.transform.name == zombie.name) { //motion_wait再生中かどうか判定 if (anim_name == "motion_wait") { int criticalType = Random.Range(0, 4); //ランダムでクリティカル攻撃決める int animType = Random.Range(0, 2); //ランダムでanimation決める //ダメージ発生 if (criticalType < 1) { //クリティカルダメージ zombieHP = zombieHP - criticalDamage; //クリティカルダメージ //SEをその場で鳴らす AudioSource.PlayClipAtPoint(seDamage2, transform.position); //SE再生 Debug.Log("クリティカルダメージ"); } else { //通常ダメージ zombieHP--; //通常ダメージ //SEをその場で鳴らす AudioSource.PlayClipAtPoint(seDamage1, transform.position); //SE再生 } //tap数 gc.zombieTap++; //ダメージ処理 if (zombieHP > 0) { anim.SetBool("isDamage", true); //animator用flag変更 } else if (zombieHP <= 0) { gc.zombieKill++; //kill数加算 //SEをその場で鳴らす AudioSource.PlayClipAtPoint(seKill, transform.position); //SE再生 //animetion分岐 switch (animType) { case 0: anim.SetBool("isDown", true); //animator用flag変更 zombieHP = zombieHPMax; //HP初期値にする break; case 1: anim.SetBool("isDown2", true); //animator用flag変更 zombieHP = zombieHPMax; //HP初期値にする break; } } } } } } } } } }
private CinemachineVirtualCameraBase ChooseCurrentCamera(float deltaTime) { //UnityEngine.Profiling.Profiler.BeginSample("CinemachineStateDrivenCamera.ChooseCurrentCamera"); if (m_ChildCameras == null || m_ChildCameras.Length == 0) { mActivationTime = 0; //UnityEngine.Profiling.Profiler.EndSample(); return(null); } CinemachineVirtualCameraBase defaultCam = m_ChildCameras[0]; /* Old method * if (m_AnimatedTarget == null || !m_AnimatedTarget.gameObject.activeSelf || m_AnimatedTarget.runtimeAnimatorController == null || m_LayerIndex < 0 || m_LayerIndex >= m_AnimatedTarget.layerCount) ||{ || mActivationTime = 0; || //UnityEngine.Profiling.Profiler.EndSample(); || return defaultCam; ||} */ // Fix from https://forum.unity.com/threads/cinemachine-state-machine-animator-is-not-playing-an-animatorcontroller-warnings.508523/ if (m_AnimatedTarget == null || !m_AnimatedTarget.gameObject.activeSelf || m_AnimatedTarget.runtimeAnimatorController == null || m_LayerIndex < 0 || !m_AnimatedTarget.hasBoundPlayables || m_LayerIndex >= m_AnimatedTarget.layerCount) { mActivationTime = 0; //UnityEngine.Profiling.Profiler.EndSample(); return(defaultCam); } // Get the current state int hash; if (m_AnimatedTarget.IsInTransition(m_LayerIndex)) { // Force "current" state to be the state we're transitionaing to AnimatorStateInfo info = m_AnimatedTarget.GetNextAnimatorStateInfo(m_LayerIndex); hash = info.fullPathHash; if (m_AnimatedTarget.GetNextAnimatorClipInfoCount(m_LayerIndex) > 1) { m_AnimatedTarget.GetNextAnimatorClipInfo(m_LayerIndex, m_clipInfoList); hash = GetClipHash(info.fullPathHash, m_clipInfoList); } } else { AnimatorStateInfo info = m_AnimatedTarget.GetCurrentAnimatorStateInfo(m_LayerIndex); hash = info.fullPathHash; if (m_AnimatedTarget.GetCurrentAnimatorClipInfoCount(m_LayerIndex) > 1) { m_AnimatedTarget.GetCurrentAnimatorClipInfo(m_LayerIndex, m_clipInfoList); hash = GetClipHash(info.fullPathHash, m_clipInfoList); } } // If we don't have an instruction for this state, find a suitable default while (hash != 0 && !mInstructionDictionary.ContainsKey(hash)) { hash = mStateParentLookup.ContainsKey(hash) ? mStateParentLookup[hash] : 0; } float now = Time.time; if (mActivationTime != 0) { // Is it active now? if (mActiveInstruction.m_FullHash == hash) { // Yes, cancel any pending mPendingActivationTime = 0; //UnityEngine.Profiling.Profiler.EndSample(); return(mActiveInstruction.m_VirtualCamera); } // Is it pending? if (deltaTime >= 0) { if (mPendingActivationTime != 0 && mPendingInstruction.m_FullHash == hash) { // Has it been pending long enough, and are we allowed to switch away // from the active action? if ((now - mPendingActivationTime) > mPendingInstruction.m_ActivateAfter && ((now - mActivationTime) > mActiveInstruction.m_MinDuration || mPendingInstruction.m_VirtualCamera.Priority > mActiveInstruction.m_VirtualCamera.Priority)) { // Yes, activate it now mActiveInstruction = mPendingInstruction; mActivationTime = now; mPendingActivationTime = 0; } //UnityEngine.Profiling.Profiler.EndSample(); return(mActiveInstruction.m_VirtualCamera); } } } // Neither active nor pending. mPendingActivationTime = 0; // cancel the pending, if any if (!mInstructionDictionary.ContainsKey(hash)) { // No defaults set, we just ignore this state if (mActivationTime != 0) { return(mActiveInstruction.m_VirtualCamera); } //UnityEngine.Profiling.Profiler.EndSample(); return(defaultCam); } // Can we activate it now? Instruction newInstr = m_Instructions[mInstructionDictionary[hash]]; if (newInstr.m_VirtualCamera == null) { newInstr.m_VirtualCamera = defaultCam; } if (deltaTime >= 0 && mActivationTime > 0) { if (newInstr.m_ActivateAfter > 0 || ((now - mActivationTime) < mActiveInstruction.m_MinDuration && newInstr.m_VirtualCamera.Priority <= mActiveInstruction.m_VirtualCamera.Priority)) { // Too early - make it pending mPendingInstruction = newInstr; mPendingActivationTime = now; if (mActivationTime != 0) { return(mActiveInstruction.m_VirtualCamera); } //UnityEngine.Profiling.Profiler.EndSample(); return(defaultCam); } } // Activate now mActiveInstruction = newInstr; mActivationTime = now; //UnityEngine.Profiling.Profiler.EndSample(); return(mActiveInstruction.m_VirtualCamera); }
public void Update() { if (m_Animator == null || m_Actor == null) { return; } int numLayers = m_Animator.layerCount; for (int i = 0; i < numLayers; i++) { float layerMix = i == 0 ? 1.0f : m_Animator.GetLayerWeight(i); AnimatorStateInfo stateInfo = m_Animator.GetCurrentAnimatorStateInfo(i); AnimatorStateInfo nextStateInfo = m_Animator.GetNextAnimatorStateInfo(i); bool hasNext = nextStateInfo.fullPathHash != 0; AnimatorClipInfo[] clipInfos = m_Animator.GetCurrentAnimatorClipInfo(i); AnimatorClipInfo[] nextClipInfos = m_Animator.GetNextAnimatorClipInfo(i); for (int c = 0; c < clipInfos.Length; c++) { AnimatorClipInfo clipInfo = clipInfos[c]; float mix = clipInfo.weight * layerMix; if (mix == 0.0f) { continue; } Nima.Animation.ActorAnimation actorAnimation = ClipToAnimation(clipInfo.clip); if (actorAnimation != null) { float time = (stateInfo.normalizedTime * clipInfo.clip.length); if (stateInfo.loop) { time %= actorAnimation.Duration; } actorAnimation.Apply(time, m_Actor, mix); } } if (hasNext) { for (int c = 0; c < nextClipInfos.Length; c++) { AnimatorClipInfo clipInfo = nextClipInfos[c]; float mix = clipInfo.weight * layerMix; if (mix == 0.0f) { continue; } Nima.Animation.ActorAnimation actorAnimation = ClipToAnimation(clipInfo.clip); if (actorAnimation != null) { float time = (nextStateInfo.normalizedTime * clipInfo.clip.length); if (nextStateInfo.loop) { time %= actorAnimation.Duration; } actorAnimation.Apply(time, m_Actor, mix); } } } } }
void FixedUpdate() { //vanha toteutus /* * Vector2 positionOnScreen = Camera.main.WorldToViewportPoint(transform.position); * Vector2 mouseOnScreen = (Vector2)Camera.main.ScreenToViewportPoint(Input.mousePosition); * * if (_isFiring) * { * float directionx = positionOnScreen.x + mouseOnScreen.x; * float directiony = positionOnScreen.y - mouseOnScreen.y; * if (_rb2D.velocity.sqrMagnitude < maxVelocity) * { * _rb2D.AddForce(new Vector2(directionx * thrustForce, directiony * thrustForce), ForceMode2D.Impulse); * } * } * else * { * //jos haluat jarrutusta * _rb2D.velocity = _rb2D.velocity * breakVelocity; * } */ switch (mode) { case PlayerMode.Walk: _rb2D.velocity = moveDir * moveSpeed; _anime.SetFloat("MoveX", _rb2D.velocity.x); _anime.SetFloat("MoveY", _rb2D.velocity.y); CheckMoveDirection(); if (Input.GetAxisRaw("Horizontal") == 1 || Input.GetAxisRaw("Horizontal") == -1 || Input.GetAxisRaw("Vertical") == 1 || Input.GetAxisRaw("Vertical") == -1) { _anime.SetFloat("LastMoveX", Input.GetAxisRaw("Horizontal")); _anime.SetFloat("LastMoveY", Input.GetAxisRaw("Vertical")); //tallennetaan meidän kaiki animaatio clipit ja otetaan ensimmäinen clip ja tallennetaan se clipInfo = _anime.GetCurrentAnimatorClipInfo(0); UpdatePlayerLookDirection(clipInfo[0].clip.name); } break; case PlayerMode.ThrustMode: if (_rb2D.velocity.sqrMagnitude > 0) { //kierre duunaa paremmaksi kun ehdit /*float turn = 250; * _rb2D.AddTorque( turn, ForceMode2D.Impulse);*/ if (_rb2D.velocity.sqrMagnitude < 0.001) { _rb2D.velocity = Vector2.zero; _canLaunch = true; ChangeColor(originalColor); //spriteRenderer.color = Color.Lerp(spriteRenderer.color, originalColor, 50 * Time.deltaTime); } else { _rb2D.velocity = _rb2D.velocity * breakVelocity; _canLaunch = false; ChangeColor(activatedColor); //spriteRenderer.color = Color.Lerp(spriteRenderer.color, activatedColor, 50 * Time.deltaTime); } } break; case PlayerMode.Attack: break; case PlayerMode.Die: break; } //Debug.Log(lookDir); }
public TimedAnimationController(Animator animator, string layerName = "Base Layer") { _animator = animator; _animator.speed = 0; if (_animator.layerCount > 1) { var found = false; for (var i = 0; i < _animator.layerCount; i++) { var currentLayerName = _animator.GetLayerName(i); if (currentLayerName == layerName) { _layerIndex = i; found = true; break; } } if (!found) { Debug.LogWarningFormat("Layer `{0}` was not found, using layer 0.", layerName); } else if (_layerIndex > 0) { var weight = _animator.GetLayerWeight(_layerIndex); if (Math.Abs(weight) < Mathf.Epsilon) { Debug.LogWarningFormat($"Layer `{layerName}`:{_layerIndex} of {_animator.name} has zero weight, setting to 1.0.", _animator); _animator.SetLayerWeight(_layerIndex, 1.0f); } } } var clips = _animator.GetCurrentAnimatorClipInfo(_layerIndex); if (clips == null || clips.Length == 0 || clips[0].clip == null) { Debug.LogAssertion("Invalid ClipDefinition in TimedAnimationController " + animator, animator); return; } _playedClip = clips[0].clip; var clipName = _playedClip.name; _clipNameHash = Animator.StringToHash(clipName); if (!_animator.HasState(_layerIndex, _clipNameHash)) { // To fix this assertion: // 1. Double click the animation controller linked in the inspector // 2. Select the state // 3. Make sure that the name of animator-state matches the name of the motion-clip Debug.LogAssertion($"Could not find State {clipName} ClipDefinition in Layer {layerName} TimedAnimationController. " + $"This usually happens when renaming animation clips, ensure to rename the animator state as well.", animator); var currentState = _animator.GetCurrentAnimatorStateInfo(_layerIndex); var replacementState = currentState.shortNameHash; _clipNameHash = replacementState; Debug.LogWarningFormat($"State `{clipName}` was not found, using replacementState {replacementState}.", animator); } }
public void ShortKnightAction() { AnimatorClipInfo[] ClipInfo = EnemyAnimator.GetCurrentAnimatorClipInfo(0); }
// Use this for initialization void Awake() { AnimatorClipInfo[] clipInfo = m_animator.GetCurrentAnimatorClipInfo(0); Destroy(gameObject, clipInfo [0].clip.length); m_indicatorText = m_animator.GetComponent <Text> (); }
static void Postfix(ref Animator ___m_animator, Character ___m_character) { if (!modEnabled.Value || !(___m_character is Humanoid || ___m_character is Player) || Player.m_localPlayer == null || (___m_character is Player && (___m_character as Player).GetPlayerID() != Player.m_localPlayer.GetPlayerID())) { return; } bool enemy = !(___m_character is Player); string name = ___m_animator.name; if (___m_character.InAttack()) { /* * try * { * if (___m_animator.GetCurrentAnimatorClipInfo(0)?.Any() == true) * Dbgl($"{___m_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name}"); * } * catch { } * try * { * if ((___m_character as Humanoid).GetCurrentWeapon() != null) * Dbgl($"{(___m_character as Humanoid).GetCurrentWeapon()?.m_dropPrefab.name} {(___m_character as Humanoid).GetCurrentWeapon()?.m_shared.m_skillType}"); * * } * catch { } */ if (___m_animator.GetCurrentAnimatorClipInfo(0)?.Any() == true && ___m_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.StartsWith("Attack")) { if ((___m_character as Humanoid).GetCurrentWeapon().m_shared.m_skillType == Skills.SkillType.Clubs) { ___m_animator.speed = enemy ? clubEnemySpeed.Value : clubSpeed.Value; } else if ((___m_character as Humanoid).GetCurrentWeapon().m_shared.m_skillType == Skills.SkillType.Swords) { ___m_animator.speed = enemy ? swordEnemySpeed.Value : swordSpeed.Value; } else { ___m_animator.speed = enemy ? swordEnemySpeed.Value : swordSpeed.Value; } } else if (___m_animator.GetCurrentAnimatorClipInfo(0)?.Any() == true && ___m_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.StartsWith("Sledge-Attack")) { ___m_animator.speed = enemy ? hammerEnemySpeed.Value : hammerSpeed.Value; } else if (___m_animator.GetCurrentAnimatorClipInfo(0)?.Any() == true && (___m_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.StartsWith("BattleAxe"))) { ___m_animator.speed = enemy ? battleAxeEnemySpeed.Value : battleAxeSpeed.Value; } else if (___m_animator.GetCurrentAnimatorClipInfo(0)?.Any() == true && (___m_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name == "axe_swing" || ___m_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.StartsWith("Axe"))) { ___m_animator.speed = enemy ? axeEnemySpeed.Value : axeSpeed.Value; } else if (___m_animator.GetCurrentAnimatorClipInfo(0)?.Any() == true && ___m_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.StartsWith("knife_slash")) { ___m_animator.speed = enemy ? knifeEnemySpeed.Value : knifeSpeed.Value; } else if (___m_animator.GetCurrentAnimatorClipInfo(0)?.Any() == true && ___m_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.StartsWith("2Hand-Spear-")) { ___m_animator.speed = enemy ? atgeirEnemySpeed.Value : atgeirSpeed.Value; } else if (___m_animator.GetCurrentAnimatorStateInfo(0).IsName("bow_fire")) { ___m_animator.speed = enemy ? bowFireEnemySpeed.Value : bowFireSpeed.Value; } else if (___m_animator.GetCurrentAnimatorStateInfo(0).IsName("spear_poke")) { ___m_animator.speed = enemy ? spearEnemySpeed.Value : spearSpeed.Value; } else if (___m_animator.GetCurrentAnimatorStateInfo(0).IsName("swing_pickaxe")) { ___m_animator.speed = enemy ? pickAxeEnemySpeed.Value : pickAxeSpeed.Value; } else if (___m_animator.GetCurrentAnimatorClipInfo(0)?.Any() == true && ___m_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.StartsWith("Punchstep")) { ___m_animator.speed = enemy ? unarmedEnemySpeed.Value : unarmedSpeed.Value; } } }
private void Update() { #region COME BACK if (_creatureManager.CurrentState == CreatureState.OnComeBack) { // ON WALL if (_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name != "AC_GoFromWall") { RotateToTarget(_playerPosition.GetChild(0), false); MoveToTarget(_playerPosition.GetChild(0), _creatureStats.CurrentMoveSpeedChaseAndComeBack); _joystick.Direction = Vector2.zero; } /*else * { * RotateToDirection(_collision.WallDirection); * _rb.velocity = Vector2.zero; * _rb.angularVelocity = 0f; * }*/ // ON ENEMY /* if(_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name != "AC_GoFromCharacter") * { * RotateToTarget(_playerPosition.GetChild(0), false); * MoveToTarget(_playerPosition.GetChild(0), _creatureStats.CurrentMoveSpeedChaseAndComeBack); * _joystick.Direction = Vector2.zero; * } * else * { * RotateToTarget(_playerPosition.GetChild(0), false); * MoveToTargetPosition(_creatureSearching.Enemy.position + new Vector3(0f, 2.5f, 0f), 150f); * }*/ // CHECK IF CREATURE IS ON PLAYER if (this.transform.position == _playerPosition.GetChild(0).position) { _collision.CollideWithCharacter(CreatureState.OnCharacter, _playerPosition); } } #endregion #region MOVING if (_creatureManager.CurrentState == CreatureState.Moving) { if (_joystick.Direction != Vector3.zero) { //RotateToDirection(_joystick.Direction); if (_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name != "AC_GoFromCharacter") { MoveToDirection(_joystick.Direction); } else { RotateToDirection(_joystick.Direction); MoveToTarget(_playerPosition.GetChild(0), 150f); } } else { //RotateToDirection(_direction); if (_animator.GetCurrentAnimatorClipInfo(0)[0].clip.name != "AC_GoFromCharacter") { //_rb.AddForce(Vector2.left * _direction); MoveToDirection(_direction); } else { RotateToDirection(_direction); MoveToTarget(_playerPosition.GetChild(0), 150f); } } } #endregion #region ON WALL if (_creatureManager.CurrentState == CreatureState.OnWall) { StuckOnWall(); } #endregion #region CHASING if (_creatureManager.CurrentState == CreatureState.Chasing) { MoveToTarget(_creatureSearching.Enemy.GetChild(0), _creatureStats.CurrentMoveSpeedChaseAndComeBack); RotateToTarget(_creatureSearching.Enemy.GetChild(0), false); /*if (this.transform.position == _creatureSearching.Enemy.GetChild(0).position) * _collision.CollideWithCharacter(CreatureState.OnEnemy, _creatureSearching.Enemy);*/ } #endregion #region ON CHARACTER if (_creatureManager.CurrentState == CreatureState.OnCharacter) { MoveToTargetPosition(_playerPosition.position + new Vector3(0f, 2.5f, 0f), 150f); _rb.constraints = RigidbodyConstraints2D.FreezeRotation; } else { _rb.constraints = RigidbodyConstraints2D.None; } #endregion #region ON ENEMY if (_creatureManager.CurrentState == CreatureState.OnEnemy) { if (_creatureSearching.Enemy != null) { MoveToTargetPosition(_creatureSearching.Enemy.position + new Vector3(0f, 2.5f, 0f), 150f); _rb.constraints = RigidbodyConstraints2D.FreezeRotation; } else { _creatureManager.CurrentState = CreatureState.OnComeBack; } } else { _rb.constraints = RigidbodyConstraints2D.None; } #endregion }
// Update is called once per frame void Update() { // check current animationclip clipInfo = mascot_animator.GetCurrentAnimatorClipInfo(0); clipName = clipInfo[0].clip.name; Fcount++; //Debug.Log(Fcount+":"+clipName); if (clipName == "m_talk") { if (isTalkingFace == false) { isIdleFace = false; isIdleCuteFace = false; isTalkingFace = true; isStartHiFace = false; //Debug.Log(Fcount+" : FACE : talking"); IEnumerator talkBlink = talkBlinker(0.1f, 0.03f, 0.1f); StartCoroutine(talkBlink); } } else if (clipName == "m_idlecute") { if (isIdleCuteFace == false) { isIdleFace = false; isIdleCuteFace = true; isTalkingFace = false; isStartHiFace = false; //Debug.Log(Fcount+" : FACE : cute"); IEnumerator blingBlink = blingBlinker(0.1f, 0.03f, 0.1f); StartCoroutine(blingBlink); } /* * } else if (clipName =="m_starthi"){ * if (isStartHiFace == false){ * isIdleFace = false; * isIdleCuteFace = false; * isTalkingFace = false; * isStartHiFace = true; * Debug.Log(Fcount+" : FACE : cute"); * IEnumerator talkOnBlink = talkOnBlinker(0.1f, 0.04f, 0.1f); * StartCoroutine(talkOnBlink); * } */ } else { if (isIdleFace == false) { isIdleFace = true; isIdleCuteFace = false; isTalkingFace = false; isStartHiFace = false; //Debug.Log(Fcount+" : FACE : idle"); IEnumerator idleBlink = idleBlinker(1.0f, 0.03f, 0.3f); StartCoroutine(idleBlink); } } }
bool AnimatorIsPlaying() { return(animator.GetCurrentAnimatorClipInfo(0).Length > animator.GetCurrentAnimatorStateInfo(0).normalizedTime); }
public void Apply(Skeleton skeleton) { if (layerMixModes.Length < animator.layerCount) { System.Array.Resize <MixMode>(ref layerMixModes, animator.layerCount); } //skeleton.Update(Time.deltaTime); // Doesn't actually do anything, currently. (Spine 3.6). // Clear Previous if (autoReset) { var previousAnimations = this.previousAnimations; for (int i = 0, n = previousAnimations.Count; i < n; i++) { previousAnimations[i].SetKeyedItemsToSetupPose(skeleton); } previousAnimations.Clear(); for (int layer = 0, n = animator.layerCount; layer < n; layer++) { float layerWeight = (layer == 0) ? 1 : animator.GetLayerWeight(layer); // Animator.GetLayerWeight always returns 0 on the first layer. Should be interpreted as 1. if (layerWeight <= 0) { continue; } AnimatorStateInfo nextStateInfo = animator.GetNextAnimatorStateInfo(layer); bool hasNext = nextStateInfo.fullPathHash != 0; AnimatorClipInfo[] clipInfo = animator.GetCurrentAnimatorClipInfo(layer); AnimatorClipInfo[] nextClipInfo = animator.GetNextAnimatorClipInfo(layer); for (int c = 0; c < clipInfo.Length; c++) { var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } previousAnimations.Add(animationTable[NameHashCode(info.clip)]); } if (hasNext) { for (int c = 0; c < nextClipInfo.Length; c++) { var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } previousAnimations.Add(animationTable[NameHashCode(info.clip)]); } } } } // Apply for (int layer = 0, n = animator.layerCount; layer < n; layer++) { float layerWeight = (layer == 0) ? 1 : animator.GetLayerWeight(layer); // Animator.GetLayerWeight always returns 0 on the first layer. Should be interpreted as 1. AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(layer); AnimatorStateInfo nextStateInfo = animator.GetNextAnimatorStateInfo(layer); bool hasNext = nextStateInfo.fullPathHash != 0; AnimatorClipInfo[] clipInfo = animator.GetCurrentAnimatorClipInfo(layer); AnimatorClipInfo[] nextClipInfo = animator.GetNextAnimatorClipInfo(layer); //UNITY 4 //bool hasNext = nextStateInfo.nameHash != 0; //var clipInfo = animator.GetCurrentAnimationClipState(i); //var nextClipInfo = animator.GetNextAnimationClipState(i); MixMode mode = layerMixModes[layer]; if (mode == MixMode.AlwaysMix) { // Always use Mix instead of Applying the first non-zero weighted clip. for (int c = 0; c < clipInfo.Length; c++) { var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, AnimationTime(stateInfo.normalizedTime, info.clip.length, stateInfo.loop, stateInfo.speed < 0), stateInfo.loop, null, weight, MixPose.Current, MixDirection.In); } if (hasNext) { for (int c = 0; c < nextClipInfo.Length; c++) { var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, AnimationTime(nextStateInfo.normalizedTime, info.clip.length, nextStateInfo.speed < 0), nextStateInfo.loop, null, weight, MixPose.Current, MixDirection.In); } } } else // case MixNext || SpineStyle // Apply first non-zero weighted clip { int c = 0; for (; c < clipInfo.Length; c++) { var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, AnimationTime(stateInfo.normalizedTime, info.clip.length, stateInfo.loop, stateInfo.speed < 0), stateInfo.loop, null, 1f, MixPose.Current, MixDirection.In); break; } // Mix the rest for (; c < clipInfo.Length; c++) { var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, AnimationTime(stateInfo.normalizedTime, info.clip.length, stateInfo.loop, stateInfo.speed < 0), stateInfo.loop, null, weight, MixPose.Current, MixDirection.In); } c = 0; if (hasNext) { // Apply next clip directly instead of mixing (ie: no crossfade, ignores mecanim transition weights) if (mode == MixMode.SpineStyle) { for (; c < nextClipInfo.Length; c++) { var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, AnimationTime(nextStateInfo.normalizedTime, info.clip.length, nextStateInfo.speed < 0), nextStateInfo.loop, null, 1f, MixPose.Current, MixDirection.In); break; } } // Mix the rest for (; c < nextClipInfo.Length; c++) { var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } animationTable[NameHashCode(info.clip)].Apply(skeleton, 0, AnimationTime(nextStateInfo.normalizedTime, info.clip.length, nextStateInfo.speed < 0), nextStateInfo.loop, null, weight, MixPose.Current, MixDirection.In); } } } } }
void Update() { if (!valid) { return; } if (layerMixModes.Length != animator.layerCount) { System.Array.Resize <MixMode>(ref layerMixModes, animator.layerCount); } float deltaTime = Time.time - lastTime; skeleton.Update(Time.deltaTime); //apply int layerCount = animator.layerCount; for (int i = 0; i < layerCount; i++) { float layerWeight = animator.GetLayerWeight(i); if (i == 0) { layerWeight = 1; } var stateInfo = animator.GetCurrentAnimatorStateInfo(i); var nextStateInfo = animator.GetNextAnimatorStateInfo(i); #if UNITY_5_4 var clipInfo = animator.GetCurrentAnimatorClipInfo(i); var nextClipInfo = animator.GetNextAnimatorClipInfo(i); #else var clipInfo = animator.GetCurrentAnimationClipState(i); var nextClipInfo = animator.GetNextAnimationClipState(i); #endif MixMode mode = layerMixModes[i]; if (mode == MixMode.AlwaysMix) { //always use Mix instead of Applying the first non-zero weighted clip for (int c = 0; c < clipInfo.Length; c++) { var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } float time = stateInfo.normalizedTime * info.clip.length; animationTable[GetAnimationClipNameHashCode(info.clip)].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, stateInfo.loop, events, weight); #if USE_SPINE_EVENTS FireEvents(events, weight, this.AnimationEvent); #endif } #if UNITY_5_4 if (nextStateInfo.fullPathHash != 0) { #else if (nextStateInfo.nameHash != 0) { #endif for (int c = 0; c < nextClipInfo.Length; c++) { var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } float time = nextStateInfo.normalizedTime * info.clip.length; animationTable[GetAnimationClipNameHashCode(info.clip)].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, nextStateInfo.loop, events, weight); #if USE_SPINE_EVENTS FireEvents(events, weight, this.AnimationEvent); #endif } } } else if (mode >= MixMode.MixNext) { //apply first non-zero weighted clip int c = 0; for (; c < clipInfo.Length; c++) { var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } float time = stateInfo.normalizedTime * info.clip.length; animationTable[GetAnimationClipNameHashCode(info.clip)].Apply(skeleton, Mathf.Max(0, time - deltaTime), time, stateInfo.loop, events); #if USE_SPINE_EVENTS FireEvents(events, weight, this.AnimationEvent); #endif break; } //mix the rest for (; c < clipInfo.Length; c++) { var info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } float time = stateInfo.normalizedTime * info.clip.length; animationTable[GetAnimationClipNameHashCode(info.clip)].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, stateInfo.loop, events, weight); #if USE_SPINE_EVENTS FireEvents(events, weight, this.AnimationEvent); #endif } c = 0; #if UNITY_5_4 if (nextStateInfo.fullPathHash != 0) { #else if (nextStateInfo.nameHash != 0) { #endif //apply next clip directly instead of mixing (ie: no crossfade, ignores mecanim transition weights) if (mode == MixMode.SpineStyle) { for (; c < nextClipInfo.Length; c++) { var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } float time = nextStateInfo.normalizedTime * info.clip.length; animationTable[GetAnimationClipNameHashCode(info.clip)].Apply(skeleton, Mathf.Max(0, time - deltaTime), time, nextStateInfo.loop, events); #if USE_SPINE_EVENTS FireEvents(events, weight, this.AnimationEvent); #endif break; } } //mix the rest for (; c < nextClipInfo.Length; c++) { var info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } float time = nextStateInfo.normalizedTime * info.clip.length; animationTable[GetAnimationClipNameHashCode(info.clip)].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, nextStateInfo.loop, events, weight); #if USE_SPINE_EVENTS FireEvents(events, weight, this.AnimationEvent); #endif } } } } if (_UpdateLocal != null) { _UpdateLocal(this); } skeleton.UpdateWorldTransform(); if (_UpdateWorld != null) { _UpdateWorld(this); skeleton.UpdateWorldTransform(); } if (_UpdateComplete != null) { _UpdateComplete(this); } lastTime = Time.time; }
AnimationClip GetCurrentAnimationClip(int Layer, int Index) { AnimatorClipInfo[] AnimationList; AnimationList = AnimatorComponent.GetCurrentAnimatorClipInfo(Layer); return(AnimationList [Index].clip); }
private void OnEnable() { AnimatorClipInfo[] info = anim.GetCurrentAnimatorClipInfo(0); Destroy(gameObject, info[0].clip.length); txt = anim.GetComponent <Text>(); }
// Use this for initialization void Start() { anim = GetComponent<Animator>(); timer = Time.time + anim.GetCurrentAnimatorClipInfo(0).Length; }