示例#1
0
    public static void DoEvent(EventBase e)
    {
        PauseTimer();

        e.InitializeEvent();
        Current.EventCanvas.SetActive(true);
        Current.EventCanvas.transform.FindChildren("Text").GetComponent <Text>().text = e.Text;

        var optionArea = Current.EventCanvas.transform.FindChildren("OptionArea");

        foreach (var a in e.GetGlobalActions())
        {
            var obj = Instantiate(Current.UIEventButton);
            obj.transform.SetParent(optionArea, false);
            var button = obj.GetComponent <Button>();
            obj.GetComponentInChildren <Text>().text = a.Text;

            var onGlob = a.OnGlobal;
            button.onClick.AddListener(() => onGlob());
        }

        foreach (var c in GetAliveCharacters())
        {
            var name = Instantiate(Current.UIEventText);
            name.transform.SetParent(optionArea, false);
            name.GetComponent <Text>().text = c.Name;

            var actions = e.GetPossibleActions(c);
            foreach (var a in actions)
            {
                var obj = Instantiate(Current.UIEventButton);
                obj.transform.SetParent(optionArea, false);
                var button = obj.GetComponent <Button>();
                obj.GetComponentInChildren <Text>().text = a.Text;

                if (a.OnCharacter != null)
                {
                    var onChar = a.OnCharacter;
                    var child  = c;
                    button.onClick.AddListener(() => onChar(child));
                }
                else if (a.OnItem != null)
                {
                    var onItem = a.OnItem;
                    var item   = a.EventItem;
                    button.onClick.AddListener(() => onItem(item));
                }
                else
                {
                    Destroy(obj);
                }
            }
        }
    }