/// <summary> /// Processes a trigger / collider exit event according to the current settings. /// </summary> /// <param name="collidingGameObject">The GameObject that we collided with</param> void ProcessExitEvents(GameAction.GameActionInvocationContext context) { if (ProcessExit && (!OnlyWhenLevelRunning || LevelManager.Instance.IsLevelRunning) && context.OtherGameObject.CompareTag(CollidingTag) && !_processingDisabled) { ProcessTriggerData(Exit, context); ExitOccurred(context); } }
/// <summary> /// Processes a trigger / collider stay event according to the current settings. /// </summary> /// <param name="collidingGameObject">The GameObject that we collided with</param> void ProcessStayEvents(GameAction.GameActionInvocationContext context) { if (ProcessWithin && (!OnlyWhenLevelRunning || LevelManager.Instance.IsLevelRunning) && context.OtherGameObject.CompareTag(CollidingTag) && Time.time > _lastWithinTime + RunInterval && !_processingDisabled) { _lastWithinTime = Time.time; ProcessTriggerData(Within, context); StayOccurred(context); } }
/// <summary> /// Processes a trigger / collider enter event according to the current settings. /// </summary> /// <param name="collidingGameObject">The GameObject that we collided with</param> void ProcessEnterEvents(GameAction.GameActionInvocationContext context) { if ((!OnlyWhenLevelRunning || LevelManager.Instance.IsLevelRunning) && context.OtherGameObject.CompareTag(CollidingTag) && Time.time > _lastTriggerTime + Interval && !_processingDisabled) { _lastTriggerTime = Time.time; _lastWithinTime = _lastTriggerTime; ProcessTriggerData(Enter, context); EnterOccurred(context); switch (DisableAfterUse) { case DisableAfterUseType.None: break; case DisableAfterUseType.ThisComponent: _processingDisabled = true; enabled = false; break; case DisableAfterUseType.GameObject: gameObject.SetActive(false); break; case DisableAfterUseType.Colliders: foreach (var siblingCollider in _siblingColliders) { siblingCollider.enabled = false; } foreach (var siblingCollider2D in _siblingColliders2D) { siblingCollider2D.enabled = false; } break; } } }
/// <summary> /// Perform the action /// </summary> /// <returns></returns> public static void ExecuteGameActions(IEnumerable <GameActionReference> actionReferences, bool isStart, GameAction.GameActionInvocationContext context) { foreach (var actionReference in actionReferences) { if (actionReference.IsReference) { if (actionReference.ScriptableObjectReference != null) { actionReference.ScriptableObjectReference.InvocationContext = context; actionReference.ScriptableObjectReference.ExecuteInternal(isStart); } } else { var action = actionReference.ScriptableObject; actionReference.ScriptableObject.InvocationContext = context; action.ExecuteInternal(isStart); } } }
/// <summary> /// Processing of any trigger data. /// </summary> /// <param name="triggerData"></param> /// <param name="collidingGameObject"></param> void ProcessTriggerData(TriggerData triggerData, GameAction.GameActionInvocationContext context) { GameActionHelper.ExecuteGameActions(triggerData.ActionReferences, false, context); triggerData.Callback.Invoke(context.OtherGameObject); }
/// <summary> /// Called when we have detected and processed a valid trigger / collider exit based upon other settings /// </summary> /// Override this in you custom base classes that you want to hook into the trigger system. /// <param name="collidingGameObject">The GameObject that we collided with</param> public virtual void ExitOccurred(GameAction.GameActionInvocationContext context) { }