예제 #1
0
        public void Initialize(string titleText, string descriptionText, FinishQustionEnum finishQustionEnum, bool useFocusUp, params ButtonInfo[] buttonInfos)
        {
            this.finishQustionEnum = finishQustionEnum;
            gameObject.SetActive(true);
            transform.SetAsLastSibling();

            _isFirstFocusable = false;

            if (buttonInfos == null || dialogsIndexDictonary == null)
            {
                return;
            }

            if (titleContainer != null)
            {
                titleContainer.SetText(titleText);
            }

            if (descriptionContainer != null)
            {
                descriptionContainer.SetText(descriptionText);
            }

            int length = buttonInfos.Length;

            if (!dialogsIndexDictonary.TryGetValue(length, out _buttonsContainer))
            {
                return;
            }

            foreach (var pair in dialogsIndexDictonary)
            {
                pair.Value.gameObject.SetActive(pair.Key == length);
            }

            for (int index = 0; index < buttonInfos.Length; index++)
            {
                if (index >= _buttonsContainer.childCount)
                {
                    continue;
                }

                Transform child = _buttonsContainer.GetChild(index);

                if (child == null)
                {
                    continue;
                }

                Button      button      = child.GetComponent <Button>();
                TextManager textManager = child.GetComponentInChildren <TextManager>();


                if (button == null || textManager == null)
                {
                    continue;
                }

                ButtonInfo buttonInfo = buttonInfos[index];

                var auxEvent = buttonInfo.unityEvent;
                auxEvent.AddInHeadNotPersistantListener(DisableObject);

                ButtonClickedEvent buttonClickEvent = new ButtonClickedEvent();

                var auxList = auxEvent.UnityActions;
                foreach (var unityEvent in auxList)
                {
                    buttonClickEvent.AddListener(unityEvent);
                }
                button.onClick = buttonClickEvent;


                textManager.SetText(buttonInfo.text);

                if (buttonInfo.isFirstFocus || length == 1 || (!_isFirstFocusable && index == length - 1))
                {
                    FocusManager.SetFocus(button.gameObject);
                    _isFirstFocusable = true;
                }
            }
        }