示例#1
0
    public bool ShouldUpdate()
    {
        if (InputSystem.Instance.lastNormalizedTouch.y == 0f &&
            InputSystem.Instance.lastNormalizedTouch.x == 0f)
        {
            if (controller == null)
            {
                controller = FindObjectOfType(typeof(GamePlayerThirdPersonController)) as GamePlayerThirdPersonController;
                if (controller != null)
                {
                    if (controller.verticalInput == 0f &&
                        controller.horizontalInput == 0f &&
                        controller.moveSpeed == 0f)
                    {
                        return(true);
                    }
                }
                else
                {
                    return(true);
                }
            }

            return(true);
        }
        grabbed = null;
        return(false);
    }
    public virtual void NavigateToDestination()
    {
        if (agent != null)
        {
            if (agentState == GamePlayerNavMeshAgentState.STOP)
            {
                agent.destination = gameObject.transform.position;
                return;
            }

            Vector3 targetPosition = transform.position;
            float   distance       = 0f;

            if (targetFollow == null)
            {
                // look for main player types
                GamePlayerThirdPersonController gamePlayerThirdPersonController =
                    FindObjectOfType(typeof(GamePlayerThirdPersonController)) as GamePlayerThirdPersonController;
                if (gamePlayerThirdPersonController != null)
                {
                    targetFollow = gamePlayerThirdPersonController.gameObject.transform;
                }
            }

            if (targetFollow != null)
            {
                distance = Vector3.Distance(agent.destination, targetFollow.position);

                if (followType == GamePlayerFollowAgentType.RangedPursue)
                {
                    if (distance <= targetAttractRange ||
                        distance <= agentDistance)
                    {
                        targetPosition = targetFollow.position;
                    }
                    else if (distance > targetLimitRange)
                    {
                        targetPosition = transform.position;
                    }
                }
                else if (followType == GamePlayerFollowAgentType.AlwaysPursue)
                {
                    targetPosition = targetFollow.position;
                }

                if (distance < agentDistance)
                {
                    transform.LookAt(targetPosition);
                }
            }

            if (agent.enabled)
            {
                agent.destination = targetPosition;
            }
        }
    }