public void AddAction( Action action, MonoBehaviourEventType triggerCallbackType, MonoBehaviourEventType unregisterCallbackType) { AddAction(action, triggerCallbackType); RemoveAction(action, unregisterCallbackType); }
public static void AutoTrigger( GameObject target, Action action, MonoBehaviourEventType triggerCallbackType, MonoBehaviourEventType unregisterMoment) { GetOrCreate(target, out MonoHooksManagerMB monoHookManager); monoHookManager.AddAction(action, triggerCallbackType, unregisterMoment); }
void TryChange( MonoBehaviourEventType eventType) { if (this.eventType != eventType) { return; } DoChange(); }
public void RemoveAction(Action action, MonoBehaviourEventType monoCallbackType) { if (!TryGetMonoHook( monoCallbackType, false, out IMonoHook monoHook)) { return; } monoHook.Unsubscribe(action); }
public void AddAction(Action action, MonoBehaviourEventType monoCallbackType) { if (!_gameObject) { action.Invoke(); return; } if (!TryGetMonoHook( monoCallbackType, true, out IMonoHook monoHook)) { return; } monoHook.Subscribe(action); }
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); }