Пример #1
0
        void DoRaycast()
        {
            if (_agent == null)
            {
                return;
            }

            UnityEngine.AI.NavMeshHit _NavMeshHit;
            bool _reachedBeforeTargetPosition = _agent.Raycast(targetPosition.Value, out _NavMeshHit);

            reachedBeforeTargetPosition.Value = _reachedBeforeTargetPosition;

            position.Value = _NavMeshHit.position;
            normal.Value   = _NavMeshHit.normal;
            distance.Value = _NavMeshHit.distance;
            mask.Value     = _NavMeshHit.mask;
            hit.Value      = _NavMeshHit.hit;

            if (_reachedBeforeTargetPosition)
            {
                if (!FsmEvent.IsNullOrEmpty(reachedBeforeTargetPositionEvent))
                {
                    Fsm.Event(reachedBeforeTargetPositionEvent);
                }
            }
            else
            {
                if (!FsmEvent.IsNullOrEmpty(reachedAfterTargetPositionEvent))
                {
                    Fsm.Event(reachedAfterTargetPositionEvent);
                }
            }
        }
        public override Status Update()
        {
            // Get the renderer
            if (m_Agent == null || m_Agent.gameObject != gameObject.Value)
            {
                m_Agent = gameObject.Value != null?gameObject.Value.GetComponent <UnityEngine.AI.NavMeshAgent>() : null;
            }

            // Validate members?
            if (m_Agent == null || target.Value == null)
            {
                return(Status.Error);
            }

            // Calcaulate the delayed timer
            UnityEngine.AI.NavMeshHit hit;
            Vector3 targetPos  = target.transform.position;
            Vector3 currentPos = gameObject.transform.position;

            if (!m_Agent.Raycast(target.transform.position, out hit) && Vector3.Distance(currentPos, targetPos) < maxDistanceSight.Value && (Vector3.Dot(gameObject.transform.TransformDirection(localDirection.Value).normalized, (targetPos - currentPos).normalized) + 1f) * .5f >= 1f - maxAngleSight.Value)
            {
                // Send event?
                if (onSuccess.id != 0)
                {
                    owner.root.SendEvent(onSuccess.id);
                }

                return(Status.Success);
            }
            else
            {
                return(Status.Failure);
            }
        }