Exemple #1
0
 public void AddAction(
     Action action,
     MonoBehaviourEventType triggerCallbackType,
     MonoBehaviourEventType unregisterCallbackType)
 {
     AddAction(action, triggerCallbackType);
     RemoveAction(action, unregisterCallbackType);
 }
Exemple #2
0
 public static void AutoTrigger(
     GameObject target,
     Action action,
     MonoBehaviourEventType triggerCallbackType,
     MonoBehaviourEventType unregisterMoment)
 {
     GetOrCreate(target, out MonoHooksManagerMB monoHookManager);
     monoHookManager.AddAction(action, triggerCallbackType, unregisterMoment);
 }
Exemple #3
0
        void TryChange(
            MonoBehaviourEventType eventType)
        {
            if (this.eventType != eventType)
            {
                return;
            }

            DoChange();
        }
Exemple #4
0
        public void RemoveAction(Action action, MonoBehaviourEventType monoCallbackType)
        {
            if (!TryGetMonoHook(
                    monoCallbackType,
                    false,
                    out IMonoHook monoHook))
            {
                return;
            }

            monoHook.Unsubscribe(action);
        }
Exemple #5
0
        public void AddAction(Action action, MonoBehaviourEventType monoCallbackType)
        {
            if (!_gameObject)
            {
                action.Invoke();
                return;
            }

            if (!TryGetMonoHook(
                    monoCallbackType,
                    true,
                    out IMonoHook monoHook))
            {
                return;
            }

            monoHook.Subscribe(action);
        }
Exemple #6
0
        private bool TryGetMonoHook(
            MonoBehaviourEventType monoCallbackType,
            bool shouldAddIfMissing,
            out IMonoHook monoHook)
        {
            monoHook = default;

            if (monoCallbackType == MonoBehaviourEventType.None)
            {
                return(false);
            }

            if (_hooks.TryGetValue(monoCallbackType, out monoHook))
            {
                return(true);
            }

            if (!CallbackAndHookTypeRelation.TryGetValue(monoCallbackType, out Type monoHookType))
            {
                return(false);
            }

            if (!shouldAddIfMissing)
            {
                return(false);
            }

            if (_gameObject.TryGetComponent(monoHookType, out Component component))
            {
                monoHook = component as IMonoHook;
            }
            else
            {
                monoHook = _gameObject.AddComponent(monoHookType) as IMonoHook;
            }

            _hooks.Add(monoCallbackType, monoHook);

            return(true);
        }