LoginSignup
9
10

More than 5 years have passed since last update.

【Photon】Unity5でPhotonAnimatorViewを有効にする方法

Last updated at Posted at 2015-04-11

PUN 1.51で正式対応され、このエントリの修正は不要になりました!

Animatorの同期を行ってくれる便利なPhotonAnimatorViewですがUnity5ではEditor上での編集が無効化されており使えなくなっています( v1.50.3現在)。PhotonAnimatorView自体はUnity5でも動作しますので、今回はPhotonAnimatorViewEditorの方を編集してUnity4/Unity5の両方で使えるようにします。

以下、PhotonAnimatorViewEditorの書き換え方です。

4~6行目

変更前
#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
using UnityEditorInternal;
#endif

↓ #elseを追加し、その中でUnityEditor.AnimationsをUsingする。

変更後
#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
using UnityEditorInternal;
#else
using UnityEditor.Animations;
#endif

14~16行目

変更前
 #if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
    private AnimatorController m_Controller;
 #endif

↓ if節を削除する

変更後
    private AnimatorController m_Controller;

59~61行目

変更前
#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
        this.m_Controller = AnimatorController.GetEffectiveAnimatorController(this.m_Animator);
#endif

↓ #elseを追加して、AnimatorControllerの初期化方法を記述する。

変更後
#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
        this.m_Controller = AnimatorController.GetEffectiveAnimatorController(this.m_Animator);
#else
        this.m_Controller = m_Animator.runtimeAnimatorController as AnimatorController;
#endif

115~129行目

変更前
#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
        if (this.m_Controller == null)
        {
            return 0;
        }

        return this.m_Controller.parameterCount;
#else
        if( m_Animator == null )
        {
            return 0;
        }

        return m_Animator.parameters.Length;
#endif

↓ m_Animatorの部分を削除して、parametersの長さの取得方法をUnity4/5に対応した形で書き分ける。

変更後
        if (this.m_Controller == null)
        {
            return 0;
        }

#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
        return this.m_Controller.parameterCount;
#else  
        return this.m_Controller.parameters.Length;
#endif

134~154行目

変更前
#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
        for (int i = 0; i < this.m_Controller.parameterCount; ++i)
        {
            if (this.m_Controller.GetParameter(i).name == name)
            {
                return true;
            }
        }

        return false;
#else
        for( int i = 0; i < m_Animator.parameters.Length; ++i )
        {
            if( m_Animator.parameters[ i ].name == name )
            {
                return true;
            }
        }

        return false;
#endif

↓ m_Animatorの方を削除し、parameters要素のチェック方法をUnity4/5で書き分ける。

変更後
#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
        for (int i = 0; i < this.m_Controller.parameterCount; ++i)
        {
            if (this.m_Controller.GetParameter(i).name == name)
            {
                return true;
            }
        }

        return false;
#else
        return m_Controller.parameters.Any(t => t.name == name);
#endif

196~200行目

変更前
#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
            parameter = this.m_Controller.GetParameter(i);
#else
            parameter = m_Animator.parameters[ i ];
#endif

↓ #elseの中身を書き換える

変更後
#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
            parameter = this.m_Controller.GetParameter(i);
#else
            parameter = this.m_Controller.parameters[i];
#endif

以上でUnity5でもPhotonAnimatorViewが使えるようになります。

9
10
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
10