본문 바로가기

정리 카테고리/실습_과제

Uinty_게임 시작부분




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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Title : MonoBehaviour
{
 
    private UI.UITitle uiTitle;
    private UI.UIloginPopup uiloginPopup;
    private UIRoot uiRoot;
    private UISprite dim;
    private UIPanel dimPanel;
    public void Init(UnityEngine.Object obj0, UnityEngine.Object obj1, UnityEngine.Object obj2)
    {
        this.uiRoot = GameObject.FindObjectOfType<UIRoot>();
        this.dimPanel = GameObject.Find("dim_sp").GetComponent<UIPanel>();
        var prefab = Instantiate(obj0) as GameObject;
        prefab.transform.parent = this.uiRoot.transform;
        prefab.transform.localScale = Vector3.one;
 
 
        var prefab2 = Instantiate(obj1) as GameObject;
        this.uiTitle = prefab2.GetComponent<UI.UITitle>();
        this.uiTitle.transform.parent = this.uiRoot.transform;
        this.uiTitle.transform.localScale = Vector3.one;
 
        prefab2 = Instantiate(obj2) as GameObject;
        this.uiloginPopup = prefab2.GetComponent<UI.UIloginPopup>();
        this.uiloginPopup.gameObject.SetActive(false);
        this.uiloginPopup.transform.parent = this.uiRoot.transform;
        this.uiloginPopup.transform.localScale = Vector3.one;
 
        this.UITitleAddEventListener();
 
        dim = GameObject.Find("dim").GetComponent<UISprite>();
        StartCoroutine(HideDimSprite(dim, () => {
            Debug.Log("로고보여줘");
            Debug.Log(dim.alpha);
            StartCoroutine(ShowDimSprite(dim, 1.5f, () => {
 
                prefab.SetActive(false);
 
                StartCoroutine(HideDimSprite(dim, () =>
                {
                    Debug.Log("게임을 보여줘");
                    this.dimPanel.gameObject.SetActive(false);
                    dim.alpha = 1;
                }));
 
            }));
        }));
 
 
    }
    private void UITitleAddEventListener()
    {
        this.uiTitle.btnStart.onClick.Add(new EventDelegate(() =>
        {
            Debug.Log("로그인 팝업 열기 ");
            this.uiloginPopup.gameObject.SetActive(true);
        }));
 
        this.uiloginPopup.btnlogin.onClick.Add(new EventDelegate(() =>
        {
            Debug.Log("로그인");
            this.dimPanel.gameObject.SetActive(true);
            
            StartCoroutine(HideDimSprite(dim, () =>
            {
                Debug.Log("게임을 보여줘");
 
            }));
            // app.ChangeScene("Stage");
        }));
 
        this.uiloginPopup.btnClose.onClick.Add(new EventDelegate(() =>
        {
            Debug.Log("로그인 팝업 닫기");
            this.uiloginPopup.gameObject.SetActive(false);
        }));
    }
 
 
    IEnumerator HideDimSprite(UISprite dimSprite, System.Action onComplete)
    {
        while (true)
        {
 
            if (dimSprite.alpha <= 0) { dimSprite.alpha = 0break; }
            dimSprite.alpha -= 0.05f;
            yield return null;
 
        }
        onComplete();
    }
    IEnumerator ShowDimSprite(UISprite dimSprite, float duration, System.Action onComplete)
    {
        yield return new WaitForSeconds(duration);
        while (true)
        {
 
            if (dimSprite.alpha >= 1) { dimSprite.alpha = 1break; }
            dimSprite.alpha += 0.05f;
            yield return null;
 
        }
        onComplete();
    }
 
    private void Start()
    {
 
    }
}
 
cs




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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
 
public class App : MonoBehaviour {
 
 
    private void Start()
    {
        //리소스 로드
 
 
 
        //씬 로드
        StartCoroutine(this.ChangeScene("Title",() => {
            //씬 로드가 끝나면 호출되는 내용
            Debug.Log("Title 로드 끝");
            var title = GameObject.FindObjectOfType<Title>();
 
 
            title.Init(Resources.Load("UI/Logo"),Resources.Load("UI/UI_Title"), Resources.Load("UI/UI_LoginPopup"));
 
        }));
        
    }
 
 
    IEnumerator ChangeScene(string sceneName,System.Action onComplete)
    {
        var asyncOper = SceneManager.LoadSceneAsync(sceneName);
        yield return new WaitUntil(() => asyncOper.isDone);
        onComplete();
    }
}
 
cs