code show as below:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ARModeAnimationController : MonoBehaviour { public Animator animatorTemp; public Animator OtherAnimatorTemp; public int ClickNumber; private double t1; private double t2; public bool isCurrentAnimator; public bool isCanPlayOpen=true; public GameObject[] HideGameObject; public GameObject[] HideSteam; public int isOnlyUIAnimation=0; public bool isELE; // Use this for initialization void Start() { //animatorTemp = GetComponent<Animator>(); OnARHideGameobject(HideGameObject, true); OnARHideGameobject(HideSteam, false); isCanPlayOpen = true; } public void OnHideGameobject( bool isHide) { foreach (var item in HideGameObject) { Debug.LogError("hide"); item.SetActive(isHide); } } public void OnARHideGameobject(GameObject[] hideObject, bool isHide) { foreach (var item in hideObject) { //Debug.LogError("hide"); item.SetActive(isHide); } } //双击播放动画 public void OnDoubleClickPlayAnimation() { if (Input.GetMouseButtonDown(0)) { Ray ray = ARGlobalData.ARCameraInstance.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo)) { if (hitInfo.collider.gameObject.layer == 8) { if (hitInfo.collider.gameObject.tag == "Mode") { t2 = Time.realtimeSinceStartup; if (t2 - t1 < 0.3) { if (isCanPlayOpen) { Debug.LogError("double click"); PlayAnimation(); ClickNumber++; } //Debug.LogError("click "); } t1 = t2; } } } } //if (isCurrentAnimator) //{ // Debug.LogError("current "+GetClipLength(animatorTemp, "Open")); // AnimatorStateInfo info = animatorTemp.GetCurrentAnimatorStateInfo(0); // Debug.LogError("info.normalizedTime" + info.normalizedTime); // if (info.normalizedTime >= 1f) // { // Debug.LogError("哈哈哈"+ info.normalizedTime); // } //} } // Update is called once per frame void Update() { //OnPlayAnimation(); OnDoubleClickPlayAnimation(); } //单击播放动画 private void OnPlayAnimation() { if (Input.GetMouseButtonDown(0)) { Ray ray = ARGlobalData.ARCameraInstance.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo)) { if (hitInfo.collider.gameObject.layer == 8) { if (hitInfo.collider.gameObject.tag == "Mode") { PlayAnimation(); ClickNumber++; Debug.LogError("click "); } } } } } private void PlayAnimation() { if (ClickNumber % 2 == 0) { animatorTemp.SetBool("IsOpen", true); animatorTemp.SetBool("IsTake001", false); Debug.LogError(GetClipLength(animatorTemp, "Open")); } else { animatorTemp.SetBool("IsOpen", false); animatorTemp.SetBool("IsTake001", false); isCurrentAnimator = true; } } public void OnClickUIPlayAnimation(bool isPlay) { if(isOnlyUIAnimation==-1) { if (!isELE) { ///2018.9.11蒸汽箭头动画和设备一体 isCurrentAnimator = true; animatorTemp.SetBool ("IsTake001", isPlay); animatorTemp.SetBool ("IsNewState", !isPlay); } else { isCurrentAnimator = true; animatorTemp.SetBool ( "IsTake001", DisplayRID);Steam arrow 11 animations into separate item // isCurrentAnimator = true; animatorTemp.SetBool ("IsNewState", !isPlay); animatorTemp.SetBool (! "IsAroundClose", DisplayRID); } } the else IF (isOnlyUIAnimation ==. 1) { /// 2018.9.11 steam arrow animations into individual items isCurrentAnimator = to true; OtherAnimatorTemp.SetBool ( "IsSteam", DisplayRID); //OtherAnimator.SetBool("IsNewState "!, DisplayRID); } /////2018.9.11 steam arrows animation apparatus and integrally //// = isCurrentAnimator to true; ////animatorTemp.SetBool("IsTake001", DisplayRID ); ////animatorTemp.SetBool("IsNewState ", isplay);! ///// 2018.9.11 steam arrow animation projects into a separately //OtherAnimatorTemp.SetBool("IsSteam", isPlay); ////OtherAnimator.SetBool("IsNewState", DisplayRID);! } // get the current animation state machine movieclip duration public float GetClipLength (Animator animator, string Clip) { IF (Animator == null || String.IsNullOrEmpty (Clip) || animator.runtimeAnimatorController == null) { Debug.LogError ( "0"); return 0F; } RuntimeAnimatorController AC = animator.runtimeAnimatorController; AnimationClip [] = ac.animationClips tAnimationClipS; IF (== null || tAnimationClipS.Length tAnimationClipS <= 0) { Debug.LogError ( "0"); return 0F; } AnimationClip tAnimationClip; for (int tCounter = 0, tLen = tAnimationClipS.Length; tCounter < tLen; tCounter++) { tAnimationClip = ac.animationClips[tCounter]; if (null != tAnimationClip && tAnimationClip.name == clip) { //Debug.LogError("0" + tAnimationClip.length); return tAnimationClip.length; } } Debug.LogError("0"); return 0f; } }
using System.Collections;using System.Collections.Generic;using UnityEngine;
public class ARModeAnimationController : MonoBehaviour { public Animator animatorTemp; public Animator OtherAnimatorTemp; public int ClickNumber; private double t1; private double t2; public bool isCurrentAnimator; public bool isCanPlayOpen=true; public GameObject[] HideGameObject; public GameObject[] HideSteam; public int isOnlyUIAnimation=0;public bool isELE; // Use this for initialization void Start() { //animatorTemp = GetComponent<Animator>(); OnARHideGameobject(HideGameObject, true); OnARHideGameobject(HideSteam, false); isCanPlayOpen = true; } public void OnHideGameobject( bool isHide) { foreach (var item in HideGameObject) { Debug.LogError("hide"); item.SetActive(isHide); } } public void OnARHideGameobject(GameObject[] hideObject, bool isHide) { foreach (var item in hideObject) { //Debug.LogError("hide"); item.SetActive(isHide); } } //双击播放动画 public void OnDoubleClickPlayAnimation() { if (Input.GetMouseButtonDown(0)) { Ray ray = ARGlobalData.ARCameraInstance.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo)) { if (hitInfo.collider.gameObject.layer == 8) { if (hitInfo.collider.gameObject.tag == "Mode") { t2 = Time.realtimeSinceStartup; if (t2 - t1 < 0.3) { if (isCanPlayOpen) { Debug.LogError("double click");
PlayAnimation(); ClickNumber++; } //Debug.LogError("click "); } t1 = t2; } } } } //if (isCurrentAnimator) //{ // Debug.LogError("current "+GetClipLength(animatorTemp, "Open")); // AnimatorStateInfo info = animatorTemp.GetCurrentAnimatorStateInfo(0); // Debug.LogError("info.normalizedTime" + info.normalizedTime);
// if (info.normalizedTime >= 1f) // { // Debug.LogError("哈哈哈"+ info.normalizedTime); // } //} } // Update is called once per frame void Update() { //OnPlayAnimation(); OnDoubleClickPlayAnimation(); } //单击播放动画 private void OnPlayAnimation() { if (Input.GetMouseButtonDown(0)) { Ray ray = ARGlobalData.ARCameraInstance.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo)) { if (hitInfo.collider.gameObject.layer == 8) { if (hitInfo.collider.gameObject.tag == "Mode") { PlayAnimation(); ClickNumber++; Debug.LogError("click "); } } } }
} private void PlayAnimation() { if (ClickNumber % 2 == 0) {
animatorTemp.SetBool("IsOpen", true); animatorTemp.SetBool("IsTake001", false); Debug.LogError(GetClipLength(animatorTemp, "Open")); } else { animatorTemp.SetBool("IsOpen", false); animatorTemp.SetBool("IsTake001", false); isCurrentAnimator = true;
} } public void OnClickUIPlayAnimation(bool isPlay) { if(isOnlyUIAnimation==-1) {if (!isELE) {///2018.9.11蒸汽箭头动画和设备一体isCurrentAnimator = true;
animatorTemp.SetBool ( "IsTake001", isPlay) ; animatorTemp.SetBool ( "IsNewState", isPlay!);} else {isCurrentAnimator = true; animatorTemp.SetBool ( "IsTake001", isPlay); animatorTemp.SetBool ( "IsNewState",! DisplayRID);! animatorTemp.SetBool ( "IsAroundClose", DisplayRID);
}
} the else IF (isOnlyUIAnimation ==. 1) {/// 2018.9.11 steam arrow animations into individual items isCurrentAnimator = true; OtherAnimatorTemp.SetBool ( "IsSteam ", DisplayRID); //OtherAnimator.SetBool("IsNewState ", DisplayRID);!}
/////2018.9.11 steam arrows animation apparatus and integrally //// isCurrentAnimator = true;
////animatorTemp.SetBool("IsTake001 ", isPlay); ////animatorTemp.SetBool("IsNewState" , isPlay);! ///// 2018.9.11 steam introduction arrows project separate animations // isCurrentAnimator = true ; //OtherAnimatorTemp.SetBool("IsSteam ", DisplayRID); ////OtherAnimator.SetBool("IsNewState", DisplayRID);!}
// get the current animation state machine movieclip duration public float GetClipLength (Animator animator, string clip) {if (null == animator || string.IsNullOrEmpty (clip) || null == animator.runtimeAnimatorController) {Debug.LogError ( "0"); return 0f;} RuntimeAnimatorController ac = animator.runtimeAnimatorController; AnimationClip [ ] tAnimationClipS = ac.animationClips; if (null == tAnimationClipS || tAnimationClipS.Length <= 0) { Debug.LogError("0");
return 0f; } AnimationClip tAnimationClip; for (int tCounter = 0, tLen = tAnimationClipS.Length; tCounter < tLen; tCounter++) { tAnimationClip = ac.animationClips[tCounter]; if (null != tAnimationClip && tAnimationClip.name == clip) {
//Debug.LogError("0" + tAnimationClip.length); return tAnimationClip.length; } } Debug.LogError("0");
return 0f;
}}