uGuiのフェードイン/フェードアウトの方法を説明していきます。Spliteのフェードイン/フェードアウトについてはこちらをご覧ください。
Canvas Group
フェードさせたいGameObjectにCanvas GroupをAdd Componentします。
Code
SceneFade.csを作成して適当なGameObjectにAdd Componentします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
using UnityEngine; using System.Collections; using UnityEngine.UI; public class SceneFade : MonoBehaviour { private GameObject preSceneObj; private GameObject nextSceneObj; public void SceneNext( GameObject preObj, GameObject nextObj ){ preSceneObj = preObj; nextSceneObj = nextObj; nextObj.SetActive (true); nextObj.GetComponent<CanvasGroup>().alpha = 0.0f; iTween.ValueTo(gameObject, iTween.Hash( "from",1.0f, "to",0.0f, "time",0.5f, "easetype","easeOutCubic", "onUpdate","FadeUpdate", "oncomplete", "FadeComplete" ) ); } private void FadeUpdate(float fade){ preSceneObj.GetComponent<CanvasGroup>().alpha = fade; nextSceneObj.GetComponent<CanvasGroup>().alpha = 1.0f - fade; } private void FadeComplete(){ preSceneObj.SetActive (false); preSceneObj.GetComponent<CanvasGroup>().alpha = 1.0f; } } |
呼び出し側はこんな感じで
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
using UnityEngine; using System.Collections; public class MainManager : MonoBehaviour { public SceneFade fade; public GameObject preObj; public GameObject nextObj; // Use this for initialization void Start () { fade.SceneNext (preObj, nextObj); } // Update is called once per frame void Update () { } } |
コメントを残す