본문 바로가기

Unity/Problems

대리자 본문은 대리자를 불러오기 전에 정의를 해주어야한다.

 

ButtonController.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
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class ButtonController : MonoBehaviour
{
    public List<Button> btnList;
    private bool[] arrIsBtnSelected;
 
    public CardBinder[] arrCardBinders;
    public Transform[] arrPivot;
 
    void Start()
    {
        this.init();
 
        for (int i = 0; i < this.btnList.Count; i++)
        {
            int captureInx = i;
 
            this.btnList[captureInx].onClick.AddListener(() =>
            {
                switch (captureInx)
                {
                    case 0:
                        {
                            this.arrIsBtnSelected[captureInx] = true;
                         
                            this.arrCardBinders[captureInx].OnFadeAwayComplete = (IsSelectComplete) =>
                            {
                                this.btnList[captureInx].interactable = false;
                                if (IsSelectComplete == true)
                                {
                                    this.CardSelectEventFx(captureInx);
                                }
                            };
 
                            this.arrCardBinders[captureInx].Init();
 
                            //Debug.LogFormat("Inx :: {0}", captureInx);
                            //Debug.LogFormat("bool :: {0}", this.arrIsbtnselected[captureInx]);
                            break;
                        }
                    case 1:
                        {
                            this.arrIsBtnSelected[captureInx] = true;
                          
                            
                            this.arrCardBinders[captureInx].OnFadeAwayComplete = (IsSelectComplete) =>
                            {
                                
                                this.btnList[captureInx].interactable = false;
 
                                if (IsSelectComplete == true)
                                {
                                    this.CardSelectEventFx(captureInx);
                                }
                            };
 
                            this.arrCardBinders[captureInx].Init();
                            //Debug.LogFormat("Inx :: {0}", captureInx);
                            //Debug.LogFormat("bool :: {0}", this.arrIsbtnselected[captureInx]);
                            break;
                        }
                    case 2:
                        {
                            this.arrIsBtnSelected[captureInx] = true;
                           
                            
                            this.arrCardBinders[captureInx].OnFadeAwayComplete = (IsSelectComplete) =>
                            {
                                this.btnList[captureInx].interactable = false;
 
                                if (IsSelectComplete == true)
                                {
                                    this.CardSelectEventFx(captureInx);
                                }
                            };
 
                            this.arrCardBinders[captureInx].Init();
                            //Debug.LogFormat("Inx :: {0}", captureInx);
                            //Debug.LogFormat("bool :: {0}", this.arrIsbtnselected[captureInx]);
                            break;
                        }
                    default:
                        Debug.LogFormat("이상한거 누르지마세요");
                        break;
                }
            });
        }
   }
 
    void init()
    {
        this.arrIsBtnSelected = new bool[3];
    }
 
    public void CardSelectEventFx(int index)
    {
        var cardSelectFx = Resources.Load<GameObject>("Fx/CardSelectFx");
        var fxGo = Instantiate<GameObject>(cardSelectFx);
        fxGo.transform.position = this.arrPivot[index].position;
    }
 
    // Update is called once per frame
    void Update()
    {
        
    }
}
 
 
 

CardBinder.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
37
38
39
40
41
42
43
44
45
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
 
public class CardBinder : MonoBehaviour
{
    public Animator anim;
    public UnityAction<bool> OnFadeAwayComplete;
 
    public bool IsSelectComplete;
 
    public void Init()
    {
        Debug.LogFormat("::Init");
        this.anim = this.gameObject.GetComponent<Animator>();
        this.FadeAway();
 
    }
 
    public void FadeAway()
    {
        this.anim.SetBool("isSelected"true);
 
        this.IsSelectComplete = true;
 
        this.OnFadeAwayComplete(this.IsSelectComplete);
 
    }
 
    void Update()
    {
        
    }
 
    
 
    //public void OnOpenCompleteCardEvent()
    //{
    //    Debug.Log("OnOpenCompleteCardEvent");
    //}
        
}
 
 
 

 

 

 

대리자 본문 Null Reference Exception 오류

 

문제의 부분

 

대리자 본문을 위로 옮겨 해결

 

대리자 본문은 Init하기 전에 미리 정의되어 있어야 한다.