コード例 #1
0
        public static ISubscribe ToSub(this Button btn, IScope sd)
        {
            Warn.IsTrue(btn.gameObject.activeInHierarchy, $"Button on {SetActiveScopeApi.Path(btn.gameObject)} - should be active");
            var(pub, sub) = sd.PubSub();
            var onClick = btn.onClick;

            onClick.AddListener(_Next);
            sd.Subscribe(() => onClick.RemoveListener(_Next));
            return(sub);

            void _Next() => pub.Publish();
        }
コード例 #2
0
        public static void Register(this EventTrigger et, EventTriggerType type, Action <PointerEventData> callback, IScope sd)
        {
            // todo warn in couldn't raycast
            Warn.IsTrue(et.gameObject.activeInHierarchy, $"EventTrigger on {SetActiveScopeApi.Path(et.gameObject)} - should be active");

            var item = Ctor();

            et.triggers.Add(item);
            sd.Subscribe(Dispose);

            EventTrigger.Entry Ctor()
            {
                var entry = new EventTrigger.Entry()
                {
                    eventID  = type,
                    callback = new EventTrigger.TriggerEvent()
                };

                entry.callback.AddListener(Callb);
                sd.Subscribe(() => entry.callback.RemoveListener(Callb));
                return(entry);
            }

            void Callb(BaseEventData arg0)
            {
                if (arg0 is PointerEventData p)
                {
                    callback.Invoke(p);
                }
            }

            void Dispose()
            {
                et.triggers.Remove(item);
            }
        }