public virtual void ResetTriggerSettings()
        {
            if (debugMode)
            {
                Debug.Log("Reset Trigger Settings");
            }

            // reset player gravity and collision
            EnablePlayerGravityAndCollision();
            // reset the Animator parameter ActionState back to 0
            ResetActionState();
            // reset the CameraState to the Default state
            tpInput.ResetCameraState();
            // reset canTriggerAction so you can trigger another action
            //canTriggerAction = false;
            if (triggerAction != null && actions.ContainsKey(triggerAction._collider))
            {
                actions.Remove(triggerAction._collider);
            }
            triggerAction = null;
            // reset triggerActionOnce so you can trigger again
            //  triggerActionOnce = false;
            doingAction   = false;
            actionStarted = false;
        }
        protected virtual void Update()
        {
            if (!mainCamera)
            {
                mainCamera = Camera.main;
            }
            if (!mainCamera)
            {
                return;
            }

            CheckForTriggerAction();
            AnimationBehaviour();
            colliders.Clear();
            foreach (var key in actions.Keys)
            {
                colliders.Add(key);
            }
            if (!doingAction && triggerAction && !isLockTriggerEvents)
            {
                if (timeInTrigger <= 0)
                {
                    actions.Clear();
                    triggerAction = null;
                }
                else
                {
                    timeInTrigger -= Time.deltaTime;
                }
            }
        }
        protected virtual void CheckForTriggerAction(Collider other)
        {
            var _triggerAction = other.GetComponent <vTriggerGenericAction>();

            if (!_triggerAction)
            {
                return;
            }

            var dist = Vector3.Distance(transform.forward, _triggerAction.transform.forward);

            if (!_triggerAction.activeFromForward || dist <= 0.8f)
            {
                triggerAction    = _triggerAction;
                canTriggerAction = true;
                triggerAction.OnPlayerEnter.Invoke();
            }
            else
            {
                if (triggerAction != null)
                {
                    triggerAction.OnPlayerExit.Invoke();
                }
                canTriggerAction = false;
            }
        }
Example #4
0
        protected vTriggerGenericAction GetNearAction()
        {
            if (isLockTriggerEvents || _doingAction || playingAnimation)
            {
                return(null);
            }
            float distance = Mathf.Infinity;
            vTriggerGenericAction _targetAction = null;

            foreach (var key in actions.Keys)
            {
                if (key)
                {
                    var screenP = mainCamera ? mainCamera.WorldToScreenPoint(key.transform.position) : screenCenter;
                    if (mainCamera)
                    {
                        bool isValid = actions[key].enabled && actions[key].gameObject.activeInHierarchy && (!actions[key].activeFromForward && (screenP - screenCenter).magnitude < distance || IsInForward(actions[key].transform, actions[key].forwardAngle) && (screenP - screenCenter).magnitude < distance);
                        if (isValid)
                        {
                            distance = (screenP - screenCenter).magnitude;
                            if (_targetAction && _targetAction != actions[key])
                            {
                                _targetAction.OnPlayerExit.Invoke(gameObject);
                                _targetAction = actions[key];
                            }
                            else if (_targetAction == null)
                            {
                                _targetAction = actions[key];
                            }
                        }
                        else
                        {
                            actions[key].OnPlayerExit.Invoke(gameObject);
                            OnExitTriggerAction.Invoke();
                        }
                    }
                    else
                    {
                        if (!_targetAction)
                        {
                            _targetAction = actions[key];
                        }
                        else
                        {
                            actions[key].OnPlayerExit.Invoke(gameObject);
                            OnExitTriggerAction.Invoke();
                        }
                    }
                }
                else
                {
                    actions.Remove(key);
                    return(null);
                }
            }

            return(_targetAction);
        }
        public virtual IEnumerator DestroyDelay(vTriggerGenericAction triggerAction)
        {
            var _triggerAction = triggerAction;

            yield return(new WaitForSeconds(_triggerAction.destroyDelay));

            ResetPlayerSettings();
            Destroy(_triggerAction.gameObject);
        }
Example #6
0
        public virtual IEnumerator DestroyDelay(vTriggerGenericAction triggerAction)
        {
            var _triggerAction = triggerAction;

            yield return(new WaitForSeconds(_triggerAction.destroyDelay));

            if (isLocalPlayer)
            {
                CmdDestroy(_triggerAction.gameObject);
            }
        }
Example #7
0
        public virtual IEnumerator DestroyActionDelay(vTriggerGenericAction triggerAction)
        {
            var _triggerAction = triggerAction;

            yield return(new WaitForSeconds(_triggerAction.destroyDelay));

            if (_triggerAction != null && _triggerAction.gameObject != null)
            {
                Destroy(_triggerAction.gameObject);
            }
            DebugAction("Destroy Trigger ");
        }
        public override void OnActionEnter(Collider other)
        {
            if (isLockTriggerEvents)
            {
                return;
            }

            if (other != null && other.gameObject.CompareTag(actionTag) && !actions.ContainsKey(other))
            {
                vTriggerGenericAction _triggerAction = other.GetComponent <vTriggerGenericAction>();
                if (_triggerAction && _triggerAction.enabled)
                {
                    actions.Add(other, _triggerAction);
                }
            }
        }
Example #9
0
        public virtual IEnumerator DestroyActionDelay(vTriggerGenericAction triggerAction)
        {
            var _triggerAction = triggerAction;

            yield return(new WaitForSeconds(_triggerAction.destroyDelay));

            if (_triggerAction != null && _triggerAction.gameObject != null)
            {
                OnExitTriggerAction.Invoke();
                Destroy(_triggerAction.gameObject);
            }

            if (debugMode)
            {
                Debug.Log($"<b>GenericAction: </b>Destroy Trigger ");
            }
        }
        protected virtual void CheckForTriggerAction()
        {
            if (actions.Count == 0 && !triggerAction || isLockTriggerEvents)
            {
                return;
            }
            vTriggerGenericAction _triggerAction = GetNearAction();

            if (!doingAction && triggerAction != _triggerAction)
            {
                triggerAction = _triggerAction;
                if (triggerAction)
                {
                    triggerAction.OnPlayerEnter.Invoke();
                }
            }

            TriggerActionInput();
        }
Example #11
0
 public override void OnActionExit(Collider other)
 {
     if (isLockTriggerEvents)
     {
         return;
     }
     if (other.gameObject.CompareTag(actionTag) && actions.ContainsKey(other) && (!_doingAction || other != triggerAction._collider))
     {
         vTriggerGenericAction action = actions[other];
         actions.Remove(other);
         action.OnPlayerExit.Invoke(gameObject);
         action.OnInvalidate.Invoke(gameObject);
         OnExitTriggerAction.Invoke();
         if (debugMode)
         {
             Debug.Log("<color=red>Exit of Trigger </color> " + other.gameObject, other.gameObject);
         }
     }
 }
Example #12
0
        public virtual void ResetTriggerSettings()
        {
            DebugAction("Reset Trigger Settings ");

            // reset player gravity and collision
            EnablePlayerGravityAndCollision();
            // reset the Animator parameter ActionState back to 0
            ResetActionState();
            // reset the CameraState to the Default state
            tpInput.ResetCameraState();
            // remove the collider from the actions list
            if (triggerAction != null && actions.ContainsKey(triggerAction._collider))
            {
                actions.Remove(triggerAction._collider);
            }
            triggerAction = null;
            doingAction   = false;
            actionStarted = false;
        }
Example #13
0
 private void HandleColliders()
 {
     colliders.Clear();
     foreach (var key in actions.Keys)
     {
         colliders.Add(key);
     }
     if (!doingAction && triggerAction && !isLockTriggerEvents)
     {
         if (timeInTrigger <= 0)
         {
             actions.Clear();
             triggerAction = null;
         }
         else
         {
             timeInTrigger -= Time.deltaTime;
         }
     }
 }
Example #14
0
        public virtual void ResetTriggerSettings(bool removeTrigger = true)
        {
            if (debugMode)
            {
                Debug.Log($"<b>GenericAction: </b>Reset Trigger Settings ");
            }

            // reset player gravity and collision
            EnablePlayerGravityAndCollision();
            // reset the Animator parameter ActionState back to 0
            ResetActionState();
            // reset the CameraState to the Default state
            tpInput.ResetCameraState();
            // remove the collider from the actions list
            if (triggerAction != null && actions.ContainsKey(triggerAction._collider) && removeTrigger)
            {
                actions.Remove(triggerAction._collider);
            }
            triggerAction = null;
            doingAction   = false;
            actionStarted = false;
        }
Example #15
0
        public override void OnActionEnter(Collider other)
        {
            if (isLockTriggerEvents)
            {
                return;
            }

            if (other != null && other.gameObject.CompareTag(actionTag))
            {
                if (!actions.ContainsKey(other))
                {
                    vTriggerGenericAction _triggerAction = other.GetComponent <vTriggerGenericAction>();
                    if (_triggerAction && _triggerAction.enabled)
                    {
                        actions.Add(other, _triggerAction);
                        _triggerAction.OnPlayerEnter.Invoke(gameObject);
                        if (debugMode)
                        {
                            Debug.Log("<color=green>Enter in Trigger </color>" + other.gameObject, other.gameObject);
                        }
                    }
                }
            }
        }
Example #16
0
 internal ActionStorage(vTriggerGenericAction action)
 {
     this.action = action;
     action.OnValidate.AddListener((GameObject o) => { isValid = true; });
     action.OnInvalidate.AddListener((GameObject o) => { isValid = false; });
 }