ãUnityãAnimatorããã£ã¨æ¥½ã«ä½¿ãããç§ã®çºã®ãåçä¸ã®AnimationControllerã¨è¿½å AnimationClipãã¯ãã¹ãã§ã¼ãããæ¹æ³
ä»åã¯åçä¸ã®AnimationControllerã«ãå¥ã®ã¢ãã¡ã¼ã·ã§ã³ãæµãè¾¼ãæ¹æ³ãè¦ã¤ããã®ã§ããã¡ãã«ã¡ã¢ãã¾ãã
Â
- AnimationControllerã¨ããæ©è½
- Playable APIã¨AnimationControllerãèåï¼
- åçä¸ã®AnimationControllerã«å¥ã®AnimationClipããã§ã¼ããã¤ã¤åçãã
- æ¢ç¥ã®åé¡
- é¢é£
AnimationControllerã¨ããæ©è½
Unity 5ã®Mecanimã¯ã°ã©ãã£ã«ã«ãªã¢ãã¡ã¼ã·ã§ã³ã®å¶å¾¡ãæä¾ãã¦ããã¾ãããã®æ©è½ã®ãé°ã§ããç¨åº¦è¤éãªã¢ãã¡ã¼ã·ã§ã³ãããã°ã©ã ãè¨è¿°ãããã¨ãªãå¶å¾¡åºæ¥ããã¨ãå¯è½ã«ãªãã¾ããã
ãã®æ©è½ã®çå±ã¯ãã¢ãã¡ã¼ã·ã§ã³ãåçãããã£ã©ã¯ã¿ã¼å¨è¾ºã®å¤ããã©ã¡ã¼ã¿ã¨ãã¦æ¸¡ãã°ãAnimationControllerãæé©ãªã¢ãã¡ã¼ã·ã§ã³ãé¸æãã¦ããããã¨ããç©ã§ãã
ä¾ãã°ç¾å¨ã®ç§»åæ¹åãä¸ä¸ã®ç§»åé度ãåæ¹ã®å£ã®æç¡ãªã©ãç¶æ³ã«å¿ãã¦ã¢ãã¡ã¼ã·ã§ã³ãé¸æãã¦ãããâ¦ã¨ãã£ãæãã§ãã
ãã®è¾ºããèãããUnity 5å®è£
åã®ãã¢ãçºãã¦ã¿ãã¨ãMecanimã£ã¦ã¹ãã¼ããã·ã³ã§ã¯ãªãBlendTreeã主役ãªãã ãªï½ã¨æãã¦ã¾ãã Animator.SetFloatã¯dampTimeã使ç¨ãã¦æ¥æ¿ã«é·ç§»ããªãããã«ããã®ããã¤ã³ãã
ã¾ãBlendTreeã§ã¯å®è£
ãé¢åãªâé çªãä¼´ãã¢ãã¡ã¼ã·ã§ã³âã®è¡¨ç¾ããæ確ã«ç¶æ³ãç°ãªããã®ã¯ã¹ãã¼ããã·ã³ãå©ç¨ãããã¨ã§è¡¨ç¾ãããã¨ãã§ãã¾ãã
å人çã«ã¯ãâå¨å²ã®ç¶æ³ãã¹ãã£ãã¯çã®å¤ãè¦ã¦åããâ ã®ãBlendTreeãâãã¿ã³æä½ãç¹å¥ãªç¶æ³â ã«ããå¤åãåçé ã®ãããã®ã¯ã¹ãã¼ãåæ¿ããªï¼ã¨æãã¦ãã¾ãã
å¨å²ã®ç¶æ³ã¯StateMachineBehaviourã§åéããæããï¼StateMachineBehaviourã§ãã©ã¡ã¼ã¿ãæ´æ°ï¼
AnimationControllerã¯çªçºçãªã¢ãã¡ã¼ã·ã§ã³ãæãã¨è¤éåãã
ãããªæãã§ã¢ãã¡ã¼ã·ã§ã³ã表ç¾ããã®ãAnimationControllerãªã®ã§ãããå®é使ã£ã¦ã¿ãã¨é常ã«é¢åãªé¨åãå¤ãã¨æãã¾ãã
ããã¯å人çã«ã¯ãå®éã®ã²ã¼ã éçºã§ã¯ âçµäºå¾
ã¡ããçæçãªã¢ãã¡ã¼ã·ã§ã³â ã¨ãããã®ãé常ã«å¤ãçºããªã¨èãã¦ãã¾ããã¾ãå²ãè¾¼ã¿ã¢ãã¡ã¼ã·ã§ã³ãé常ã«å¤ãããã®è¾ºããå
¨ã¦ã¹ãã¼ããç¨æããã¨è¤éåãããªã¨ãã£ãå°è±¡ã§ãã
ãããã£ãåå¥ã®ã¢ãã¡ã¼ã·ã§ã³æ¯ã«Triggerã®ãã©ã¡ã¼ã¿ãå²ãå½ã¦ãã®ã¯ããªãè¦çã§ãããä¸ã¤ã®ã¹ãã¼ãã«å¯¾ãã¦å¤§éã®ç¢å°ãå¼ãããã®ã¯ç¾ããããã¾ããã*1
ãããå¼·å¼ã«è§£æ±ºããã®ãStateãä½ã£ã¦Animator.CrossFadeã¨ããã¢ããã¼ãã§ãã
äºåã«AnimationControllerã«ä½¿ç¨ããAnimationClipãäºåã«ç»é²ãã¦ããAnimationOverrideControllerã§ä¸æ¸ãããã¨ãã£ãã¢ããã¼ãã§ãã
ãã ããAnimationControllerã¯AnimationClipã®Stateãåçã«å¢ãããã¨ãåºæ¥ãªããããAnimationControllerã«äºåã«æ大æ°ã®AnimationClipãç»é²ãã¦ããå¿ è¦ãããã¾ããããã«Fadeã使ç¨ããå ´åãé·ç§»ã¯ãªãã¢ã«è¡ãããç¹ãã¹ãã¼ããå¤ãããã¨ããã©ã¼ãã³ã¹çã«åé¡ã«ãªãç¹ãæªããã¤ã³ãã§ãã
ããã使ãããããªãAnimation使ããï¼ãã¨ããã®ã¯å²ã¨ç´å¾ã®çç±ã§ãã
ä¸å¿ãåçã«AnimationClipãå·®ãæ¿ããäºã§å¹¾ã¤ãã®åé¡ã解決åºæ¥ãªãã¯ãªãã®ã§ãããã¾ãâ¦è²ã ã
ããã ãPlayable APIã使ãã
ã¨ãããã¨ã§ âPlayable APIã使ç¨ãã¦å ¨é¨ã¹ã¯ãªããã§ç®¡çãã¦ãã¾ãã" ã¨ããçµè«ã«è³ã訳ã§ãããå®éããããã£ã¦ããã¨Animatorã®ã·ã¼ã±ã³ã¹å¶å¾¡ãBlendTreeã®æ©è½ã欲ãããªã£ã¦ãã¾ãã
失ã£ã¦åãããã®å¤§åãã
ããããªãã°ãã¬ã³ãããããAnimationControllerã¨Playableãã
åºæ¬çãªç§»åã¯AnimationControllerãçªçºçãªåããPlayableAPIã§è³ãæãã§ãã
Playable APIã¨AnimationControllerãèåï¼
AnimationControllerã¨Playable APIãèåãã¦ã¿ã¾ãã
ãã®å ´åã®ãã¤ã³ãã¯ä»¥ä¸ã®äºã¤ã§ãã
- AnimationControllerãæ¢ã«åçä¸ã®Playable Graphã¯å¤æ´ã§ããªã
ï¼å¤æ´ãã¦ãå³åº§ã«å·»ãæ»ãããï¼ - AnimationPlayableOutputã®weightããã¬ã³ãçã決ãã
Â
ã¾ãã¯ã·ã³ãã«ã«åä½ã確èªãã¦ã¿ã
ãã®è¾ºããåæã«ãã¾ãæãç°¡åã«AnimationControllerã«AnimationClipPlayableããã¬ã³ããã¦ã¿ã¾ãã
ã³ã¼ãã¯ãããªæãã§ãã
ãã¤ã³ãã¯PlayableGraphãèªåã§ä½ã£ã¦ããç¹ã¨ãOutputã®ã¦ã§ã¤ã調æ´ã§ãã
å®ã¯ä»ã®å¹¾ã¤ãã®è¨äºã§ã¯é¢åãªã®ã§AnimationControllerããPlayableGraphãåå¾ãã¦ãã¾ããã稼åä¸ã®AnimationControllerã®PlayableGraphã¯å¤æ´ãã¦ãå³æ²»ãã¨ããå¦ãªåãããã¾ãããã®ããããããã£ãå½¢ã§åæããå ´åã«ã¯AnimationControllerã¨ã¯å¥ã«PlayableGraphãç¨æãã¾ããã
ãªããPlayableGraphãéæ¾ãå¿ããã¨ãææªã¨ãã£ã¿ãè½ã¡ã¾ãã
Â
ããä¸ã¤ã¯Outputã®ã¦ã§ã¤ã調æ´ã§ãã
ãã®å¦çã§AnimationControllerã¨Playableã®æ¯çãè¨å®ãã¦ãä¸æãæãã«åæåºæ¥ã¦ãã¾ãã
ãã®éãPlayableGraphçµç±ã§AnimationControllerãããã¯PlayableGraphã®åä½ãæ¢ãã¦ããã¨ãè²ã
ã¨å¹ççã§ãã
åææ¯çãã«ã¼ãã§æå®
ãã®å¦çãä½ã£ã¦ã¿ãéã«æ°ã¥ããæãã¬ã¡ãªããã®ä¸ã¤ããã¢ãã¡ã¼ã·ã§ã³ã®ãã¬ã³ãçãã«ã¼ãã§å¶å¾¡ã§ããç¹ã§ãã
åºæ¬çã«Mecanimã®ãã¬ã³ãã¯ãªãã¢ã«è¡ãããã®ã§ãããPlayableã§ã¦ã§ã¤ããç´ã§æå®ã§ãããã®ã¢ããã¼ãã§ã¯ãã«ã¼ããçµç±ãã¦ã¢ãã¡ã¼ã·ã§ã³ã®ãã¬ã³ãçãå¶å¾¡ãããã¨ãåºæ¥ãæãã§ãã
ä¾ãã°ãã¬ã³ãã®ä¸éã®æéãçãæå®ãã¦ããã°ããã¬ã³ãä¸ã«åºã¦ããéåæã®ããé¨åãããç¨åº¦è¦ããªãããã«ã§ããããããã¾ããã
ãã¤ã³ãã¯[SerializeField]ã§AnimationCurveãç·¨éå¯è½ã«ãã¦ãããAnimationCurve.Evaluateã§å¤ãè£æ£ãã¦ãããã¨ã§ãã
Â
ãããæ´»ç¨ãããªããAnimationClipãåç´ã«åå¾ããã®ã§ã¯ãªãScriptableObjectã®ãã©ã¡ã¼ã¿ã¨ä¸ç·ã«ãã¦ãâæå®ã¢ãã¡ã¼ã·ã§ã³ãªããã¬ã³ãã¯ããâ ã¿ããã«ããã¨æéã ãã©é¢ç½ãããªæ°é ãããã¾ãã
åçä¸ã®AnimationControllerã«å¥ã®AnimationClipããã§ã¼ããã¤ã¤åçãã
ãã¦ãä»åã®æ¬é¡ã§ãã
ããã¯è¦ããã«ãAnimationClipPlayableãåçã«ä½æã»ã¦ã§ã¤ãã調æ´ããã°è¡ãã¾ãã
Sampleã®Playããã¿ã³çµç±ã§å¼ã³åºãã¦ã¿ãã¨ããããªæãã®ãã¨ãã§ãã¾ãã
å®è¡æã«AnimationClipãæµãè¾¼ãäºãã§ããã®ã§ããã£ã©ã¯ã¿ã¼æ¯ã®ç¹æ®æãä»»æã®å ´æã§ã®ã¢ã¯ã·ã§ã³çã«ã使ããããããã¾ããã
ããAnimationClipPlayableåçä¸ã«ãã£ã³ã»ã«ãã¦AnimationClipPlayableãåçããã®ããã¬ã³ãããâ¦ã¨ãªãã¨ãAnimationMixerPlayableã使ç¨ããã®ãè¯ãããã§ãã
æªå®æã§ãããä¸å¿æ®ãã¦ããã¾ãããã*2
ä¸ã®Gifã¢ãã¡ã§ã¯ããã£ã©ã¯ã¿ã¼ã®ç§»åç³»ï¼å¨è¾ºç°å¢ã§åä½ãå¤ãããã®ï¼ã¯AnimationControllerãæ»æãªã©ã®ã¢ã¯ã·ã§ã³ã¯Playableã®å²ãè¾¼ã¿ã§è¡ã£ã¦ãã¾ãã
æ¢ç¥ã®åé¡
ã¢ããªã±ã¼ã·ã§ã³ãããã¯ã°ã©ã¦ã³ãã«åãã¨Playableã®ã¢ãã¡ã¼ã·ã§ã³ãæ¢ã¾ãåä½ã確èªãã¦ãã¾ãã
é¢é£
ä»åã®ããæ¹ã¯ãã³ã¬ãè¦ã¦æãã¤ãã¾ããã
ä»åã®å 容ã®çºå±å½¢
Â
ããã¡ãã£ã¨å®å®ãã¦ããããæé«ãªãã ãã©
*1:ãã£ã³ã»ã«ç³»ã¯ã¢ãã¡ã¼ã·ã§ã³çµäºå¾ ã¡ãã¦ãªããªãBlendTreeã¸
*2: ã¢ãã¡ã¼ã·ã§ã³ä¸ã«ä»ã®ã¢ãã¡ã¼ã·ã§ã³ãå²ãè¾¼ãã§ããã¬ã³ããã¦ããã¾ããããã¬ã³ãä¸ã«å²ãè¾¼ãã®ã¯æ¢ãã¾ãããï¼ç´æ