Пример #1
0
        public static void UpdateEvent(Enums.GameEventType t1, Enums.GameEventType t2, Enums.GameEventType t3)
        {
            Button btnEvent1 = GameObject.Find("SubCanvasChooseEvent/BtnEvent1").GetComponent <Button>();
            Button btnEvent2 = GameObject.Find("SubCanvasChooseEvent/BtnEvent2").GetComponent <Button>();
            Button btnEvent3 = GameObject.Find("SubCanvasChooseEvent/BtnEvent3").GetComponent <Button>();
            Text   text      = GameObject.Find("SubCanvasChooseEvent/TxtDesc").GetComponent <Text>();

            text.text = "";

            btnEvent1.image.sprite = SpriteHelper.GetEventSprite(t1);
            btnEvent2.image.sprite = SpriteHelper.GetEventSprite(t2);
            btnEvent3.image.sprite = SpriteHelper.GetEventSprite(t3);

            btnEvent1.image.color = ColorHelper.GetEventColor(t1);
            btnEvent2.image.color = ColorHelper.GetEventColor(t2);
            btnEvent3.image.color = ColorHelper.GetEventColor(t3);

            EventTrigger trigger = btnEvent1.gameObject.GetComponent <EventTrigger>();

            if (trigger == null)
            {
                trigger = btnEvent1.gameObject.AddComponent <EventTrigger>();
            }
            trigger.triggers.Clear();
            EventTrigger.Entry entry = new EventTrigger.Entry();
            entry.eventID  = EventTriggerType.PointerEnter;
            entry.callback = new EventTrigger.TriggerEvent();
            entry.callback.AddListener((eventdata) =>
            {
                var e     = GameInfo.EventList.FirstOrDefault(x => x.Type == t1);
                text.text = e.Description;
            });
            trigger.triggers.Add(entry);
            btnEvent1.onClick.RemoveAllListeners();
            btnEvent1.onClick.AddListener(() =>
            {
                ChooseEvent(t1);
            });

            EventTrigger trigger2 = btnEvent2.gameObject.GetComponent <EventTrigger>();

            if (trigger2 == null)
            {
                trigger2 = btnEvent2.gameObject.AddComponent <EventTrigger>();
            }
            trigger2.triggers.Clear();
            EventTrigger.Entry entry2 = new EventTrigger.Entry();
            entry2.eventID  = EventTriggerType.PointerEnter;
            entry2.callback = new EventTrigger.TriggerEvent();
            entry2.callback.AddListener((eventdata) =>
            {
                var e     = GameInfo.EventList.FirstOrDefault(x => x.Type == t2);
                text.text = e.Description;
            });
            trigger2.triggers.Add(entry2);
            btnEvent2.onClick.RemoveAllListeners();
            btnEvent2.onClick.AddListener(() =>
            {
                ChooseEvent(t2);
            });

            EventTrigger trigger3 = btnEvent3.gameObject.GetComponent <EventTrigger>();

            if (trigger3 == null)
            {
                trigger3 = btnEvent3.gameObject.AddComponent <EventTrigger>();
            }
            trigger3.triggers.Clear();
            EventTrigger.Entry entry3 = new EventTrigger.Entry();
            entry3.eventID  = EventTriggerType.PointerEnter;
            entry3.callback = new EventTrigger.TriggerEvent();
            entry3.callback.AddListener((eventdata) =>
            {
                var e     = GameInfo.EventList.FirstOrDefault(x => x.Type == t3);
                text.text = e.Description;
            });
            trigger3.triggers.Add(entry3);
            btnEvent3.onClick.RemoveAllListeners();
            btnEvent3.onClick.AddListener(() =>
            {
                ChooseEvent(t3);
            });
        }