###前提・実現したいこと
Unityの2DアニメーションでAnimatorControllerのAnimationClipでそれぞれのKeyframeが参照しているスプライトをスクリプト内で動的に変更したい。
###該当のソースコード
private static void FindSpriteFromAnimation(GameObject prefab, UnityEditor.Animations.AnimatorController animatorController) { IEnumerable<State> states = GetStates( animatorController ); IEnumerable<AnimationClip> clips = states .Select( state => state.motion as AnimationClip ) .Where( animationClip => animationClip != null ); IEnumerable<ObjectReferenceKeyframe> keyframes = clips.SelectMany( c => GetKeyframe( c ) ); //ここでkeyframseが参照しているそれぞれのスプライトを、任意のスプライトと差し替えたい } private static IEnumerable<UnityEditor.Animations.AnimatorState> GetStates(UnityEditor.Animations.AnimatorController animationController) { return animationController.layers.SelectMany( l => l.stateMachine.states.Select( s => s.state ) ); }
###試したこと
IEnumerable<ObjectReferenceKeyframe> keyframes = clips.SelectMany( c => GetKeyframe( c ) );
上記のkeyframesから現在参照されているスプライトを見ることは出来ました。
###補足情報(言語/FW/ツール等のバージョンなど)
Unity5.3.4
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/27 01:30