Unityã®uGUIã§ãUIã®ã¢ãã¡ã¼ã·ã§ã³å¶å¾¡ã
ç®æ¬¡
Unityã®uGUIã§ãUIã®ã¢ãã¡ã¼ã·ã§ã³å¶å¾¡ã
Unityã®ã¢ãã¡ã¼ã·ã§ã³ã·ã¹ãã ã®Mecanimã¯ã2Dã§è¦ãå ´åã¯è¤éãªä¸ã«é¢åãªã®ã§ä½¿ãåæãå°ãæªãã§ãããã¾ã使ããªãã¯ãªãã§ãããããåã£ãUI表ç¾ãçµããã¨æã£ãæãæå¤ã¨ä½¿ããããããã¾ããã
ç¹ã«UIå ¨ä½ãåãããããªã¢ãã¡ã¼ã·ã§ã³ã®å ´åãåã¢ã¤ãã ã®åããåãããããAnimatorã¯ã¡ãã£ã¨ã ã便å©ããããã¾ããã
ã»ã»ã»åç´ãªUIæä½ã®å ´åãTween使ã£ãã»ãã楽ã ã¨æãã¾ãããAnimation使ãããããå°ã説æã楽ãªãã§ããã©ããããã°ã©ãçã«ã¯ã
[Unity][uGUI] uGUIã§NGUIã©ã¤ã¯ãªTween : West Hill éçºã¡ã¢
uGUIã§ã¢ãã¡ã¼ã·ã§ã³
Unityã®ã¢ãã¡ã¼ã·ã§ã³ã¯é常ã«å¼·åãªæ©è½ã§ãã座æ¨ãã¹ãã©ã¤ãã¿ã¤ãã ãã§ãªããã¹ã¯ãªããã®Inspectorããæä½åºæ¥ãfloatãboolãColorãæä½ãããã該å½ã®ãªãã¸ã§ã¯ããæã¤ã³ã³ãã¼ãã³ãã®ã¡ã½ãããå¼ã³åºãäºãã§ãã¾ããï¼intãenumã¨ãã£ãä¸éå¤ã®ãªãç©ã¯æä½åºæ¥ã¾ããï¼
ã¾ãåãªãã¸ã§ã¯ããæä½ããäºãå¯è½ã§ãååããä¸è´ããã°AnimationClipãä½ã£ãæã¨ã¯å ¨ãå¥ã®ãªãã¸ã§ã¯ãã使ãäºãã§ãã¾ãï¼ã©ã³ã¿ã¤ã ã®å·®æ¿ãã¯ãå·®ãæ¿ãæã«Rebindãããã¯GameObjectã®Active->Inactiveãå¿ è¦ï¼ãéãè¨ãã°ãåãååã®ãªãã¸ã§ã¯ããè¤æ°ããã¨ä¸æãåãã¾ããã(Unity 5ãããªãã¸ã§ã¯ããè¤è£½ããå ´ååæã«ãã³ããªã³ã°ãããã®ã¯ããã®ä»æ§ãé¢ä¿ããããããªãããªã¼ã¨æ¨æ¸¬ï¼
Â
ã¢ãã¡ã¼ã·ã§ã³ã®ã¹ã¤ããã¯ãåºæ¬çã«Animatorã«ãä»»ããã¾ããAnimatorã®ç¡é§ã«é«æ§è½ãªãã¬ã³ãæ©è½ãåUIã®ä½ç½®ãä¸æãæãã«ãã¬ã³ããã¦ããã¾ãã
åUIã®åããAnimationClipã§ä½æãã¦ãããå¾ã¯AnyStateããTriggerã§åã¹ãã¼ãã¸ããããã¯Intã§ã¹ãã¼ãçªå·ãæå®ãããããªæãã«ããã¨ãAnimatorControllerã®ãã©ã¡ã¼ã¿ãæ¸ãæããã ãã§UIãé·ç§»ãã¦ããã¾ãã
ããæ£ç´Animatorã®ãã©ã¡ã¼ã¿æå®ããããAnimator.CrossFadeã§ç´æ¥ã¹ãã¼ãæå®ãã¦ã¢ãã¡ã¼ã·ã§ã³åæ¿ããæ¹ã絶対ããã ã¨æãã®ã§ããã»ã»ã»ã¾ãã»ã»ã»ããããããããã¨ã§ã
ã¡ãªã¿ã«Triggerã§åããå ´åã¯uGUIã®EventSystemããæä½ã§ããã®ã§å°ã楽ã§ãã
ã¢ãã¡ã¼ã·ã§ã³ã®ä½ææé
ã¢ãã¡ã¼ã·ã§ã³ã®ä¸çªæã£åãæ©ãä½ãæ¹ã¯ãæçµçãªä½ç½®ã®ã¿ãä½æããã¢ãã¡ã¼ã·ã§ã³ã¯ãªãããã使ããã¨ã§ãã以åç´¹ä»ããã¨ããããã¼ã®ãªãã¢ãã¡ã¼ã·ã§ã³ãã¯åæãã©ã¡ã¼ã¿ã«ãGameObjectãActiveã«ãªã£ãæã®å¤ãã使ãäºãå©ç¨ãã¾ãã
ä¾ãã°TitleLogoãèµ·åæã«ä¸å¤®ã¸INããæãã®ã¢ãã¡ã¼ã·ã§ã³ãä½ãã¾ãã
 ç»é¢ã®æºå
ã¾ãã¯ç»é¢ãä½ãã¾ãããããªæãã§ããããã
Animatorã¨AnimationClipä½æ
次ã«CenterãªãAnimationClipã¨Animatorç»é²ãè¡ãã¾ããAnimationã§ã¯ãªãAnimatorã§ããã¿ã¤ãã«ãã´ã®ããTitleLogoãé¸æãAddComponentãã¿ã³ã§Animatorã追å ãã¾ãã
ã¤ãã§ã«Projectãã¥ã¼ã§AnimationãCenterãã¨AnimatorControllerãTitleLogoAnimatorControllerããä½æããTitleLogoAnimatorControllerãããã«ã¯ãªãã¯ã§éãã¦ä½æããCenterï¼Animationï¼ãç»é²ãã¾ãããã®å¾ãTitleLogoã®Animatorã«TitleLogoAnimatorControllerãç»é²ãã¾ãã
ãã¼ãã¬ã¼ã ã®ç»é²
次ã«Animationã¦ã£ã³ãã¦ãéããç¶æ ã§TitleLogoãé¸æãããçä¸ã®ä½ç½®ãããã¼ãã¬ã¼ã ã¨ãã¦ã¢ãã¡ã¼ã·ã§ã³ã«è¨å®ãã¾ããpivotãä¸å¤®ã»ã¢ã³ã«ã¼ãä¸å¤®ã¨è¨å®ãã¦ããã¾ããä»åã®ååã¯Centerã¨ãã«ãã¾ãããä½æ¥ã¯AddPropertyãæ¼ãç°¡åãªãä»äºã§ãã
ãªãAnimationClipãªã®ã§ããã¼ãã¬ã¼ã ã¨ã¢ãã¡ã¼ã·ã§ã³ã«ã¼ãã使ã£ãè¤éãªã¢ãã¡ã¼ã·ã§ã³ãå¶å¾¡ã§ãã¾ããã¾ããAnchored PositionãpivotãAnchorã¯xã¨yã®å¤ãæã¡ã¾ããããããæ¶ãã°x軸ãããã¯y軸ã®ã¿ã®ã¢ãã¡ã¼ã·ã§ã³ãä½ããã¨ãåºæ¥ã¾ãã
次ã«ä½ããã¼ãæã£ã¦ããªããä½ã£ãã ãã®AnimationClipãç¨æãã¾ããååã¯Neutralã¨ãã¾ããä½ã£ããAnimationControllerã«ç»é²ã
AnimationControllerã®è¨å®
å¾ã¯ã¢ãã¡ã¼ã·ã§ã³ãå¶å¾¡ããAnimationControllerãè¨å®ãã¾ããã¡ãªã¿ã«Animator.CrossFadeã§ã¢ãã¡ã¼ã·ã§ã³åæ¿ããå ´åã¯AnimationControllerã®è¨å®ä½æ¥ã¯ä¸è¦ã§ããAnimationControllerãåã¢ãã¡ã¼ã·ã§ã³ã¯ãªããæã£ã¦ããå± ãã°OKã
- ã¾ãåæ¿æ¡ä»¶ã®ãã©ã¡ã¼ã¿ãä½ãã¾ããä»åã¯Intã§IsCenterã
- 次ã«AnyStateããAnyStateå³ã¯ãªãã¯âMakeTransitionã§Centerã¨Neutralã«ç¢å°ãè²¼ãã¾ãã
- ç¢å°ãé¸æãã¦ãã¢ãã¡ã¼ã·ã§ã³åæ¿æ¡ä»¶ãè¨å®ãã¾ããIsCenterãTrueãªãCenterã¸ãIsCenterãFalseãªãNeutralã¸ã
- æå¾ã«ã¢ãã¡ã¼ã·ã§ã³åæ¿ã®é·ããæå®ãã¾ãã
é¢åãããã¨æãã¾ãããï¼ç§ãåæè¦ã§ãã
å¾ã¯ã¿ã¤ãã«ãã´ã®åæä½ç½®ãç»é¢å¤ã¸è¨å®ãã¾ãããã®éãPivotã¨Anchorãä¸æããã£ã¦ãããã¨ç°ãªãã¢ã¹ãã¯ãæ¯ã§ãã¡ããã¨ç»é¢å¤ã¸ç§»åãã¦ããã¾ãã
ï¼ã³ã¬ã®å ´åãç»é¢ç¯å²ã®ä¸ãTitleLogoã®ä¸çªä¸ã¨ãã¦ãã¾ãï¼
å¾ã¯ãã¬ã¤ããã°ãINããã¢ãã¡ã¼ã·ã§ã³ãä½ãã¾ããåæä½ç½®ãå¤æ´ãã¦ãæçµçã«ã¯ä¸å¤®ã«è¡ãæãã§ãã
AnimationControllerãã¹ã¯ãªããã§å¶å¾¡ãã
ãã®AnimationControllerãã¹ã¯ãªããããå¶å¾¡ããã®ã¯ãããªæãã§OKã§ããAnimatorControllerãæã¤ãã©ã¡ã¼ã¿ã交æãã¦ããã°ãå¾ã¯AnimationControllerãä½ã¨ããã¾ãã
using UnityEngine;
using System.Collections;
public class UIController : MonoBehaviour
{
    [SerializeField]
    Animator
        animator;
    void Update ()
    {
        if( Input.GetKeyDown(KeyCode.UpArrow))
            animator.SetBool("IsCenter", true);
        if( Input.GetKeyDown(KeyCode.DownArrow))
            animator.SetBool("IsCenter", false);
    }
}
CrossFadeã§ããï¼AnimationControllerã§ã¢ãã¡ã¼ã·ã§ã³å¶å¾¡ããªãï¼å ´åã¯ãããªæãã§å¶å¾¡ãã¾ããã¢ãã¡ã¼ã·ã§ã³ç§»åå ã«åAnimationStateãæå®ãã¾ãã
using UnityEngine;
using System.Collections;
public class UIController : MonoBehaviour
{
    [SerializeField]
    Animator
        animator;
    void Update ()
    {
        if( Input.GetKeyDown(KeyCode.UpArrow))
            animator.CrossFade("Center", 0.3f);
        if( Input.GetKeyDown(KeyCode.DownArrow))
            animator.CrossFade("Neutral", 1f);
    }
}
ææ³
ãªãä»åç´¹ä»ããNeutralã使ãæ¹æ³ã¯Animatorãæã¤ãªãã¸ã§ã¯ããéã¢ã¯ãã£ãã«ããéã¯æ³¨æãå¿ è¦ã§ãã詳細ã¯Unityã®GameObjectãéã¢ã¯ãã£ãã«ããã¨Animatorããªã»ãããããæåããã®å¯¾å¦æ³ ã«ã対çã¨ãã¦ã¯ãåæ座æ¨ãè¨æ¶ãã¦ããéã¢ã¯ãã£ãæã«æ»ããã¨ãããNeutralã使ããåæ座æ¨ãæå®ããããããã¾ãã
 ã©ã¤ã»ã³ã¹
ç»åã«ã¦ããã£ã¡ãã2Dã使ãã¾ããã
ããããã¦ããã£ã¡ããã©ã¤ã»ã³ã¹ã®ã¢ã¤ã³ã³ã¯èæ¯é»ä¸è²ã ã¨ä½ãæªéçã§ãããä¸å¿Î±ééçããã¦ã³ãã¼ããã¼ã¸ã«ç½®ãã¦ãã£ãã®ã§ãããããã°ã®ãã¼ãã§èªåçã«ã¢ã¦ãã©ã¤ã³ä»ãã¡ãã£ã¦æ®å¿µãªæãã«ã
é¢é£æ å ±
[Unity][uGUI] uGUIã§NGUIã©ã¤ã¯ãªTween : West Hill éçºã¡ã¢
tomtc123/ugui-Tween-Tool · GitHub
Unityã®AnimatorControllerã«AnimationClipãå èµãã - ãã©ã·ã¥ã¼ã«ããã°
DATA DOWNLOAD-å©ç¨è¦ç´ | UNITY-CHAN! OFFICIAL WEBSITEï¼ç»åã¢ã»ããï¼
Unityã®æ°GUIãUGUIã®ã¤ãã³ãå¶å¾¡ã«ã¤ã㦠- ãã©ã·ã¥ã¼ã«ããã°
Â