統一+アニメーション・ステート・マシン

コードは以下の通りであります:

System.Collectionsを使用しました。
System.Collections.Genericを使用しました。
UnityEngineを使用しました。

パブリッククラスARModeAnimationController:MonoBehaviour { 
    公共アニメーターanimatorTemp。
    公共アニメーターOtherAnimatorTemp。
    公共int型のClickNumber。
    プライベートダブルT1; 
    プライベートダブルT2; 
    公共BOOL isCurrentAnimator。
    パブリックブールisCanPlayOpen =はtrue。
    公共のゲームオブジェクト[] HideGameObject。
    公共のゲームオブジェクト[] HideSteam。
    公共int型isOnlyUIAnimation = 0; 
	公共BOOL isELE。
    //を使用し、この初期化
    ボイド開始()
    { 
        // animatorTemp = GetComponent <アニメーター>(); 
        OnARHideGameobject(HideGameObject、真の);
        OnARHideGameobject(HideSteam、偽); 
        isCanPlayOpenは真=。
    } 
    公共ボイドOnHideGameobject(BOOL石出)
    { 
        foreachの(HideGameObjectにおけるVARアイテム)
        { 
            Debug.LogError( "非表示")。
            item.SetActive(石出)。
        } 
    } 
    公共ボイドOnARHideGameobject(ゲームオブジェクト[] hideObject、BOOL石出)
    { 
        foreachの(hideObjectにおけるVARアイテム)
        { 
            //Debug.LogError("hide」)。
            item.SetActive(石出)。
        } 
    }  
    //双击播放动画
    公共ボイドOnDoubleClickPlayAnimation()
    {
        IF(Input.GetMouseButtonDown(0))
        { 
            線光線= ARGlobalData.ARCameraInstance.ScreenPointToRay(Input.mousePosition)。
            RaycastHit hitInfo; 
            IF(Physics.Raycast(光線)hitInfoアウト)
            { 
                IF(hitInfo.collider.gameObject.layer == 8)
                { 
                    (hitInfo.collider.gameObject.tag == "モード")であれば
                    { 
                        T2 = Time.realtimeSinceStartup。
                        IF(T2 - T1 <0.3)
                        {  
                            IF(isCanPlayOpen)
                            { 
                                Debug.LogError( "ダブルクリック")。

                                PlayAnimation(); 
                                ClickNumber ++; 
                            } 
                            //Debug.LogError("click「)。
                        } 
                        T1 = T2。
                    } 
                } 
            } 
        } 
        // IF(isCurrentAnimator)
        // { 
        // Debug.LogError( "現在の" + GetClipLength(animatorTemp、 "オープン"))。
        // AnimatorStateInfo情報= animatorTemp.GetCurrentAnimatorStateInfo(0); 
        // Debug.LogError( "info.no​​rmalizedTime" + info.no​​rmalizedTime)。

        // IF(info.no​​rmalizedTime> = 1F)
        // { 
        // Debug.LogError( "哈哈哈" + info.no​​rmalizedTime)。
        //} 
        //} 
    } 
    //更新は、フレームごとに一度呼び出され
    ボイド更新()
    { 
        // OnPlayAnimation()。
        OnDoubleClickPlayAnimation(); 
    } 
    //单击播放动画
    プライベートボイドOnPlayAnimation()
    { 
        IF(Input.GetMouseButtonDown(0))
        { 
            線光線= ARGlobalData.ARCameraInstance.ScreenPointToRay(Input.mousePosition)。
            RaycastHit hitInfo; 
            (Physics.Raycast hitInfoアウト(線))であれば
            {
                IF(hitInfo.collider.gameObject.layer == 8)
            animatorTemp.SetBool( "IsTake001"、偽);
                { 
                    (hitInfo.collider.gameObject.tag == "モード")であれば
                    { 
                        PlayAnimation()。
                        ClickNumber ++; 
                        Debug.LogError( "クリック")。
                    } 
                } 
            } 
        } 

    } 
    プライベートボイドPlayAnimation()
    { 
        IF(ClickNumber%2 == 0)
        { 

            animatorTemp.SetBool( "のIsOpen"、TRUE)。
            Debug.LogError(GetClipLength(animatorTemp、 "開きます")); 
        } 
        {
            animatorTemp.SetBool( "のIsOpen"、偽の); 
            animatorTemp.SetBool( "IsTake001"、偽); 
            isCurrentAnimatorは真=。

        } 
    } 
    公共ボイドOnClickUIPlayAnimation(BOOL isPlay)
    { 
        (isOnlyUIAnimation == - 1)であれば
        { 
			(isELE!)なら
			、{ 
				///2018.9.11蒸汽箭头动画和设备一体
				isCurrentAnimator = TRUE。

				animatorTemp.SetBool( "IsTake001"、isPlay)。
				animatorTemp.SetBool( "IsNewState"、isPlay!)。
			} 
			{  
				isCurrentAnimator = TRUE。
				animatorTemp.SetBool( "IsTake001"、isPlay)。
				animatorTemp.SetBool( "IsNewState"、isPlay!)。 
				animatorTemp.SetBool( "IsAroundClose"、DisplayRID!); 

			} 

        } 
        そうIF(isOnlyUIAnimation == 1)
        { 
            ///個々の項目に2018年9月11日蒸気矢印アニメーション
            isCurrentAnimator = TRUE。
            OtherAnimatorTemp.SetBool( "IsSteam"、DisplayRID); 
            //OtherAnimator.SetBool("IsNewState」、DisplayRID);! 
        } 


        /////2018.9.11蒸気アニメーション装置と一体的に矢印
        //// = isCurrentAnimator真であり; 

        // //animatorTemp.SetBool("IsTake001 "isplay); 
        ////animatorTemp.SetBool("IsNewState"、isplay);! 
        ///// 2018.9。別の項目に11のアニメーション矢印スチーム
        // isCurrentAnimator =はtrue。 
        、isPlay)//OtherAnimatorTemp.SetBool("IsSteam"。 
        ////OtherAnimator.SetBool("IsNewState"、DisplayRID);! 
    } 

    //現在のアニメーション・ステート・マシンムービークリップのデュレーションを取得
    公共フロートGetClipLengthを(アニメーターアニメーター、文字列クリップ)
    { 
        IF(アニメーター== NULL || String.IsNullOrEmpty(クリップ)|| animator.runtimeAnimatorController == NULL)
        { 
            Debug.LogError( "0"); 
            戻り0F; 
        } 
        RuntimeAnimatorController AC = animator.runtimeAnimatorController; 
        AnimationClip [] = ac.animationClips tAnimationClipS; 
        IF(== NULL || tAnimationClipS.Length tAnimationClipS <= 0)
        { 
            Debug.LogError( "0" );

            0F返します。 
        }
        AnimationClip tAnimationClip; 
        用(INT tCounter = 0、TLEN = tAnimationClipS.Length; tCounter <TLEN; tCounter ++)
        { 
            tAnimationClip = ac.animationClips [tCounter]。
            IF(ヌル= tAnimationClip && tAnimationClip.name ==クリップ!)
            { 

                //Debug.LogError("0" + tAnimationClip.length)。
                tAnimationClip.lengthを返します。
            } 
        } 
        Debug.LogError( "0")。

        0F返します。

    } 
}

  

System.Collectionsを使用して、UnityEngineを使用して、System.Collections.Genericを使用しました。
パブリッククラスARModeAnimationController:MonoBehaviour {公共アニメーターanimatorTemp。公共アニメーターOtherAnimatorTemp。公共int型のClickNumber。プライベートダブルT1; プライベートダブルT2; 公共BOOL isCurrentAnimator。パブリックブールisCanPlayOpen =はtrue。公共のゲームオブジェクト[] HideGameObject。公共のゲームオブジェクト[] HideSteam。公共int型のisOnlyUIAnimation = 0;公共BOOL isELE。//を使用し、この初期ボイド開始()のために{// animatorTemp = GetComponent <アニメーター>(); OnARHideGameobject(HideGameObject、真の); OnARHideGameobject(HideSteam、偽); isCanPlayOpenは真=。}公共ボイドOnHideGameobject(BOOL石出){foreachの(HideGameObjectにおけるVARアイテム){Debug.LogError( "非表示")。item.SetActive(石出)。}}公共ボイドOnARHideGameobject(ゲームオブジェクト[] hideObject、BOOL石出){foreachの(hideObjectにおけるVARアイテム){//Debug.LogError("hide」)。item.SetActive(石出)。}} //双击播放动画公共ボイドOnDoubleClickPlayAnimation(){IF(Input.GetMouseButtonDown(0)){線光線= ARGlobalData.ARCameraInstance.ScreenPointToRay(Input.mousePosition)。RaycastHit hitInfo; IF(Physics.Raycast(光線)hitInfoアウト){IF(hitInfo.collider.gameObject.layer == 8){(hitInfo.collider.gameObject.tag == "モード")であれば{T2 = Time.realtimeSinceStartup。IF(T2 - T1 <0。
                                PlayAnimation(); ClickNumber ++; } //Debug.LogError("click「)。} T1 = T2。}}}} // IF(isCurrentAnimator)// {// Debug.LogError( "現在の" + GetClipLength(animatorTemp、 "オープン"))。// AnimatorStateInfo情報= animatorTemp.GetCurrentAnimatorStateInfo(0); // Debug.LogError( "info.no​​rmalizedTime" + info.no​​rmalizedTime)。
        // IF(info.no​​rmalizedTime> = 1F)// {// Debug.LogError( "哈哈哈" + info.no​​rmalizedTime)。// //}}} //更新は、フレーム空隙更新(){// OnPlayAnimation()ごとに一度呼び出されます。OnDoubleClickPlayAnimation(); } //单击播放动画プライベートボイドOnPlayAnimation(){IF(Input.GetMouseButtonDown(0)){線光線= ARGlobalData.ARCameraInstance.ScreenPointToRay(Input.mousePosition)。RaycastHit hitInfo; IF(Physics.Raycast(光線、hitInfoアウト)){IF(hitInfo.collider.gameObject.layer == 8){IF(hitInfo.collider.gameObject.tag == "モード"){PlayAnimation()。ClickNumber ++; デバッグ。logError( "クリック")。}}}}
    }プライベートボイドPlayAnimation(){IF(ClickNumber%2 == 0){
            animatorTemp.SetBool( "のIsOpen"、TRUE)。animatorTemp.SetBool( "IsTake001"、偽); Debug.LogError(GetClipLength(animatorTemp、 "開きます")); }他{animatorTemp.SetBool( "のIsOpen"、偽)。animatorTemp.SetBool( "IsTake001"、偽); isCurrentAnimatorは真=。
        }}公共ボイドOnClickUIPlayAnimation(BOOL isPlay){(isOnlyUIAnimation == - 1)であれば{(isELE!)なら、{///2018.9.11蒸汽箭头动画和设备一体isCurrentAnimator = TRUE。
animatorTemp.SetBool( "IsTake001"、isPlay) ; animatorTemp.SetBool( "IsNewState"、isPlay!);}他{isCurrentAnimator = TRUE; animatorTemp.SetBool( "IsTake001"、isPlay); animatorTemp.SetBool( "IsNewState" ,! DisplayRID);! animatorTemp.SetBool( "IsAroundClose"、DisplayRID);
}
        }そうIF(isOnlyUIAnimation == 1)isCurrentAnimator = trueの個々の項目に{/// 2018年9月11日蒸気矢印アニメーション; OtherAnimatorTemp.SetBool( "IsSteam "、 DisplayRID); //OtherAnimator.SetBool("IsNewState」、DisplayRID);!}

        /////2018.9.11蒸気矢印アニメーション装置と一体//// isCurrentAnimator = TRUE。
        ////animatorTemp.SetBool("IsTake001 "isPlay); ////animatorTemp.SetBool("IsNewState" 、isPlay);! ///// 2018年9月11日蒸気導入矢印は// isCurrentAnimator =真別アニメーションを投影します; //OtherAnimatorTemp.SetBool("IsSteam "DisplayRID); ////OtherAnimator.SetBool("IsNewState"、DisplayRID);!}
    //現在のアニメーション状態マシンムービークリップ期間公共フロートGetClipLength(アニメーターアニメーターを得ます文字列クリップ){IF(ヌル==アニメーター|| string.IsNullOrEmpty(クリップ)||ヌル== animator.runtimeAnimatorController){Debug.LogError( "0");戻り0F;} RuntimeAnimatorController AC = animator.runtimeAnimatorController; AnimationClip [ ] tAnimationClipS = ac.animationClips; IF(ヌル == tAnimationClipS || tAnimationClipS.Length <= 0){Debug.LogError( "0")。
            0F返します。} AnimationClip tAnimationClip。用(INT tCounter = 0、TLEN = tAnimationClipS.Length; tCounter <TLEN; tCounter ++){tAnimationClip = ac.animationClips [tCounter]。IF(ヌル= tAnimationClip && tAnimationClip.name ==クリップ!){
                //Debug.LogError("0" + tAnimationClip.length)。tAnimationClip.lengthを返します。}} Debug.LogError( "0")。
        0F返します。
    }}

 

おすすめ

転載: www.cnblogs.com/WalkingSnail/p/11833902.html
おすすめ