RequestPath() public static method

public static RequestPath ( Vector2 pathStart, Vector2 pathEnd, bool>.Action callback ) : void
pathStart Vector2
pathEnd Vector2
callback bool>.Action
return void
Beispiel #1
0
    IEnumerator UpdatePath()
    {
        if (Time.timeSinceLevelLoad < .3f)
        {
            yield return(new WaitForSeconds(.3f));
        }

        PathRequestManager goCurrentAStar = GameObject.FindGameObjectWithTag("A*").GetComponent <PathRequestManager>();

        goCurrentAStar.RequestPath(transform.position, target.position, OnPathFound);

        float   sqrMoveThreshold = pathUpdateMoveThreshold * pathUpdateMoveThreshold;
        Vector2 targetPosOld     = target.position;

        while (true)
        {
            yield return(new WaitForSeconds(minPathUpdateTime));

            if (((Vector2)target.position - targetPosOld).sqrMagnitude > sqrMoveThreshold)
            {
                goCurrentAStar.RequestPath(transform.position, target.position, OnPathFound);
                targetPosOld = target.position;
            }
        }
    }
Beispiel #2
0
 void Start()
 {
     m_Collider        = GetComponent <CapsuleCollider>();
     m_Collider.radius = 1.3f;
     manager.RequestPath(transform.position, target.position, OnPathFound);
     rb = GetComponent <Rigidbody>();
 }
Beispiel #3
0
 void Start()
 {
     target = GameObject.Find("TownHallTile(Clone)");
     PathRequestManager.RequestPath(transform.position, target.transform.position, OnPathFound);
     cannotAttack = false;
     animator     = GetComponent <Animator>();
 }
Beispiel #4
0
    public IEnumerator updatePath()
    {
        if (Time.timeSinceLevelLoad < 0.3f)
        {
            yield return(new WaitForSeconds(0.3f));
        }
        // PathRequestManager.RequestPath(transform.position, target.position, OnPathFound);
        if (transform != null && target != null)
        {
            PathRequest pr = new PathRequest(transform.position, target.position, OnPathFound);
            PathRequestManager.RequestPath(pr);
        }
        float   sqrMoveThreshold = pathUpdateMoveThreshold * pathUpdateMoveThreshold;
        Vector3 targetOldPos     = Vector3.zero;

        if (target != null)
        {
            targetOldPos = target.position;
        }
        while (isKeepUpdatetingPath)
        {
            yield return(new WaitForSeconds(minPathUpdateTime));

            if (target != null)
            {
                if ((target.position - targetOldPos).sqrMagnitude > sqrMoveThreshold)
                {
                    PathRequestManager.RequestPath(new PathRequest(transform.position, target.position, OnPathFound));
                    targetOldPos = target.position;
                }
            }
        }
    }
Beispiel #5
0
 private void Update()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         PathRequestManager.RequestPath(transform.position, target.position, OnPathFound);
     }
 }
Beispiel #6
0
    void Start()
    {
        getSpawnpoint = GameObject.Find("Pathfinding");
        target        = getSpawnpoint.GetComponent <SpawnMinion2>().bot2Waypoints[0];

        PathRequestManager.RequestPath(transform.position, target.transform.position, OnPathFound);
    }
Beispiel #7
0
    private IEnumerator UpdatePath()
    {
        if (Time.timeSinceLevelLoad < 0.3f)
        {
            yield return(new WaitForSeconds(0.3f));
        }

        PathRequestManager.RequestPath(new PathRequest(transform.position, enemyMaster.myTarget.position, OnPathFound));
        float   sqrMoveThreshold = pathUpdateMoveThreshold * pathUpdateMoveThreshold;
        Vector3 targetPosOld     = enemyMaster.myTarget.position;

        while (true)
        {
            yield return(new WaitForSeconds(minPathUpdateTime));

            if (enemyMaster.myTarget == null)
            {
                break;
            }

            if ((enemyMaster.myTarget.position - targetPosOld).sqrMagnitude > sqrMoveThreshold)
            {
                PathRequestManager.RequestPath(new PathRequest(transform.position, enemyMaster.myTarget.position, OnPathFound));
                targetPosOld = enemyMaster.myTarget.position;
            }
        }
    }
Beispiel #8
0
    private IEnumerator UpdatePath()
    {
        float   squareMoveThreshold = pathUpdateMoveThreshold * pathUpdateMoveThreshold;
        Vector3 targetOldPos        = unit.Target.position;

        PathRequestManager.RequestPath(new PathRequest(transform.position, unit.Target.position, gameObject, OnPathFound));

        float timeSinceUpdate = 0f;

        while (true)
        {
            if (Time.timeSinceLevelLoad < 2f)
            {
                yield return(new WaitForSeconds(2f));
            }
            yield return(new WaitForSeconds(minPathUpdateTime));

            if (unit.Target == null)
            {
                continue;
            }
            timeSinceUpdate += Time.deltaTime;
            if ((unit.Target.position - targetOldPos).sqrMagnitude > squareMoveThreshold || timeSinceUpdate > 0.5f || requirePathUpdate)
            {
                requirePathUpdate = false;
                PathRequestManager.RequestPath(new PathRequest(transform.position, unit.Target.position, gameObject, OnPathFound));
                targetOldPos = unit.Target.position;
            }
        }
    }
    private void UpdateARImage(ARTrackedImage trackedImage)
    {
        // Display the name of the tracked image in the canvas
        //imageTrackedText.text = trackedImage.referenceImage.name;
        Seeker   = arObjects["Plusieurs"].transform.Find("Seeker").gameObject;
        Target_1 = arObjects["Plusieurs"].transform.Find("Target_1").gameObject;
        Target_2 = arObjects["Plusieurs"].transform.Find("Target_2").gameObject;

        // Assign and Place Game Object
        if (trackedImage.referenceImage.name == "Plusieurs")
        {
            PathRequestManager.RequestPath(Seeker.transform.position, Target_1.transform.position, OnPathFound);
            PathRequestManager.RequestPath(Seeker.transform.position, Target_2.transform.position, OnPathFound);
        }
        else if (trackedImage.referenceImage.name == "Remplie")
        {
            PathRequestManager.RequestPath(Seeker.transform.position, Target_1.transform.position, OnPathFound);
        }
        else
        {
        }


        AssignGameObject("Plusieurs", trackedImage.transform.position);


        Debug.Log($"trackedImage.referenceImage.name: {trackedImage.referenceImage.name}");
    }
Beispiel #10
0
    IEnumerator UpdatePath()
    {
        if (Time.timeSinceLevelLoad < 0.3f)
        {
            yield return(new WaitForSeconds(0.3f));
        }

        //PathRequestManager.RequestPath(transform.position, target.position, OnPathFound);
        PathRequestManager.RequestPath(new PathRequest(transform.position, target.position, OnPathFound));

        float   sqrMovethreshold = patUpdateMoveThreshold * patUpdateMoveThreshold;
        Vector3 targetPosOld     = target.position;

        while (true)
        {
            yield return(new WaitForSeconds(minPathUpdateTime));

            if ((target.position - targetPosOld).sqrMagnitude > sqrMovethreshold)
            {
                //PathRequestManager.RequestPath(transform.position, target.position, OnPathFound);
                PathRequestManager.RequestPath(new PathRequest(transform.position, target.position, OnPathFound));
                targetPosOld = target.position;
            }
        }
    }
Beispiel #11
0
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         PathRequestManager.RequestPath(transform.position, target.position, OnPathFound);
     }
 }
Beispiel #12
0
    public object TargetMoreNear()
    {
        float      nearestTargetDistance = Mathf.Infinity;
        GameObject currentMinDist        = null;

        foreach (GameObject player in GameObject.FindGameObjectsWithTag(Tags.player))
        {
            if (!player.GetComponent <PlayerController>().downed)
            {
                PathRequestManager.RequestPath(new PathRequest(transform.position, player.transform.position, delegate(Vector3[] waypoints, bool pathSuccessful) {
                    if (pathSuccessful)
                    {
                        float tmpDistance = PathRequestManager.DistanceFromTarget(waypoints, transform.position, targetIndex = 0);
                        if (tmpDistance < nearestTargetDistance)
                        {
                            nearestTargetDistance = tmpDistance;
                            currentMinDist        = player;
                            target      = currentMinDist.transform;
                            targetFound = true;
                        }
                    }
                }));
            }
        }

        if (target != null)
        {
            targetFound = true;
        }

        /*anim.SetBool("TargetDead", false);
         * RpcSetAnimBool("TargetDead", false);*/
        return(null);
    }
Beispiel #13
0
    IEnumerator UpdatePath()
    {
        if (Time.timeSinceLevelLoad < .3f)
        {
            yield return(new WaitForSeconds(.3f));
        }

        PathRequestManager.RequestPath(new PathRequest(transform.position, target.position, OnPathFound));

        float sqrMoveThreshold = pathUpdateMoveThreshold * pathUpdateMoveThreshold;

        Vector3[] targetsOldPosition = new Vector3[3];
        while (targetFound)
        {
            yield return(new WaitForSeconds(minPathUpdateTime));

            foreach (GameObject player in GameObject.FindGameObjectsWithTag(Tags.player))
            {
                if (target != null && (player.transform.position - targetsOldPosition[(int)player.GetComponent <PlayerAttacks>().playerType]).sqrMagnitude > sqrMoveThreshold)
                {
                    PathRequestManager.RequestPath(new PathRequest(transform.position, target.position, OnPathFound));
                    targetsOldPosition[(int)player.GetComponent <PlayerAttacks>().playerType] = player.transform.position;
                }
            }
        }
    }
Beispiel #14
0
    private void Patrol(StateController controller)
    {
        if ((controller.path == null || controller.currentTarget != controller.wayPointList[controller.currentWayPoint]))
        {
            controller.pathCompleted = false;
            PathRequestManager.RequestPath(new PathRequest(controller.transform.position, controller.wayPointList[controller.currentWayPoint].position, controller, OnPathFound));
        }

        if (!controller.pathCompleted)
        {
            return;
        }

        Vector3 direction = (controller.path[controller.currentPathPoint] - controller.transform.position).normalized;
        float   dist      = Vector3.Distance(controller.transform.position, controller.path[controller.currentPathPoint]);

        // Move enemy
        controller.rb.velocity = new Vector2((controller.isFacingRight ? 1 : -1) * controller.enemyStats.speed, controller.rb.velocity.y);
        //Handle Animation
        controller.anim.SetBool("Patrol", true);
        if (dist < nextPointDistance)
        {
            SoundManager.instance.RandomSfx(controller.transform, controller.audioClips.walkAudio);
            controller.currentPathPoint = (controller.currentPathPoint + 1) % controller.path.Length;
            // If we just hit the last path point, update the waypoint
            if (controller.currentPathPoint == 0)
            {
                controller.currentWayPoint = (controller.currentWayPoint + 1) % controller.wayPointList.Count;
            }
        }
    }
Beispiel #15
0
    void Hide()     // Checks if there are any hiding spaces in the vicinity. If so, it hides. Else, the task fails.
    {
        List <Transform> hidingSpaces = new List <Transform>();

        Vector3 halfExtends = new Vector3(3f, 1f, 3f);

        Collider[] cols = Physics.OverlapBox(transform.position, halfExtends, Quaternion.identity);
        foreach (Collider collider in cols)
        {
            if (collider.CompareTag("Obstacle"))
            {
                hidingSpaces.Add(collider.transform);
            }
        }

        if (hidingSpaces.Count > 0)
        {
            TileGrid grid = FindObjectOfType <TileGrid>();
            grid.isFleeing = true;
            PathRequestManager.RequestPath(transform.position, hidingSpaces[Random.Range(0, hidingSpaces.Count)].position, OnPathFound);
            grid.isFleeing = false;
            Task.current.Succeed();
        }
        else if (hidingSpaces.Count <= 0)
        {
            Task.current.Fail();
        }
    }
Beispiel #16
0
    void RequestPathHome()      // Requests a path to the Homebase.
    {
        GameObject[] homes = GameObject.FindGameObjectsWithTag("Home");

        PathRequestManager.RequestPath(transform.position, homes[Random.Range(0, homes.Length)].transform.position, OnPathFound);
        Task.current.Succeed();
    }
Beispiel #17
0
    // Update is called once per frame
    void Update()
    {
        //If there is no target, target the town hall
        if (target == null)
        {
            target = townBase;
            PathRequestManager.RequestPath(transform.position, target.transform.position, OnPathFound);
        }

        float targetDistance = Vector2.Distance(transform.position, target.transform.position);

        if (targetDistance <= range)
        {
            if (fireCountdown <= 0)
            {
                Shoot();
                fireCountdown = 1f / fireRate;
            }
            fireCountdown -= Time.deltaTime;
            return;
        }
        else if (targetDistance > range)
        {
            animator.SetBool("Attack", false);
            moveDirection = new Vector2(target.transform.position.x - transform.position.x, target.transform.position.y - transform.position.y);
            moveDirection.Normalize();
            GetComponent <Rigidbody2D>().velocity = moveDirection * movementSpeed;
        }
    }
 public void StartUp()
 {
     foreach (Vector2Int playerBase in GameHandle.instance.baseZone)
     {
         PathRequestManager.RequestPath(indexPos, playerBase, GameHandle.instance.currBoard, OnPathFound);
     }
 }
Beispiel #19
0
        IEnumerator UpdatePath()
        {
            if (Time.timeSinceLevelLoad < .3f)
            {
                yield return(new WaitForSeconds(.3f));
            }
            //target = aiController.target.transform;
            if (aiController != null)
            {
                if (aiController.target == null)
                {
                }
                //aiController.target = aiController.target;
            }

            PathRequestManager.RequestPath(new PathRequest(transform.position, aiController.target.transform.position, OnPathFound));
            float   sqrMoveThreshold = pathUpdateMoveThreshold * pathUpdateMoveThreshold;
            Vector3 targetPosOld     = aiController.target.transform.position;

            while (true)
            {
                yield return(new WaitForSeconds(minPathUpdateTime));

                if (aiController.target != null)
                {
                    if ((aiController.target.transform.position - targetPosOld).sqrMagnitude > sqrMoveThreshold)
                    {
                        PathRequestManager.RequestPath(new PathRequest(transform.position, aiController.target.transform.position, OnPathFound));
                        targetPosOld = aiController.target.transform.position;
                    }
                }
            }
        }
Beispiel #20
0
 public void WalkTo(Node destination, Action <bool> callbackWalking)
 {
     this.callbackWalking = callbackWalking;
     PathRequestManager.RequestPath(new PathRequest(aiNode, destination, OnPathFound));
     source = aiNode;
     des    = destination;
 }
Beispiel #21
0
    public void playerDetect()
    {
        Vector3 pos = this.transform.InverseTransformPoint(player.transform.position);

        if (hit.collider != null)
        {
            if (pursuingPlayer == true)
            {
                if (hit.collider.gameObject.tag == "Wall") //If player goes behind a wall
                {
                    //Debug.Log("Lost sight of player");
                    ResetStates();
                    goingToLastLoc = true;
                }
                else //Enemy sees player and updates last position
                {
                    playerLastPos = player.transform.position;
                    PathRequestManager.RequestPath(transform.position, playerLastPos, OnPathFound);
                }
            }
            else if (hit.collider.gameObject.tag == "Player" && pos.x > viewCone && Vector3.Distance(this.transform.position, player.transform.position) < 9) //detected
            {
                Debug.Log("ENEMY: " + "Detected player");
                playerLastPos = player.transform.position;
                //Debug.DrawRay(transform.position, player.transform.position - transform.position, Color.red);
                roaming        = false;
                pursuingPlayer = true;
                goingToLastLoc = false;
                PathRequestManager.RequestPath(transform.position, playerLastPos, OnPathFound);
            }
        }
    }
Beispiel #22
0
    //Функция обновления пути
    public IEnumerator UpdatePath()
    {
        if (Time.timeSinceLevelLoad < .3f)
        {
            yield return(new WaitForSeconds(.3f));
        }

        Vector3 targetPosOld     = Vector3.zero;
        float   sqrMoveThreshold = pathUpdateMoveThreshold * pathUpdateMoveThreshold;

        target = getTarget();
        PathRequestManager.RequestPath(new PathRequest(transform.position, target.position, OnPathFound));
        targetPosOld = target.position;

        while (true)
        {
            yield return(new WaitForSeconds(minPathUpdateTime));

            target = getTarget();
            if ((target != null) && (target.position - targetPosOld).sqrMagnitude > sqrMoveThreshold)
            {
                PathRequestManager.RequestPath(new PathRequest(transform.position, target.position, OnPathFound));
                targetPosOld = target.position;
            }
        }
    }
    public void OnPathFound(Vector3[] newPath, bool pathSuccessful)
    {
        if (pathSuccessful)
        {
            path        = newPath;
            targetIndex = 0;
            StopCoroutine("FollowPath");
            StartCoroutine("FollowPath");
        }

        else if (!pathSuccessful)
        {
            GameObject[] structures = GameObject.FindGameObjectsWithTag("Structure");
            float        dist       = 1000;
            for (int i = 0; i < structures.Length; i++)
            {
                if ((structures[i].transform.position - transform.position).magnitude < dist)
                {
                    target = structures[i];
                    dist   = (target.transform.position - transform.position).magnitude;
                }
            }
            PathRequestManager.RequestPath(transform.position, target.transform.position, OnPathFound);
        }
    }
Beispiel #24
0
    // Goes from start to target by creating waypoints to the target //

    IEnumerator FollowPath()
    {
        Vector3 currentWaypoint = path[0];

        while (true)
        {
            if (transform.position == currentWaypoint)
            {
                targetIndex++;
                if (targetIndex >= path.Length)
                {
                    targetIndex = 0;
                    path        = null;
                    if (currWP < getSpawnpoint.GetComponent <SpawnMinion2>().bot2Waypoints.Length - 1)
                    {
                        currWP++;
                        targetIndex = 0;
                        target      = getSpawnpoint.GetComponent <SpawnMinion2>().bot2Waypoints[currWP];
                        if (gameObject != null)
                        {
                            PathRequestManager.RequestPath(transform.position, target.transform.position, OnPathFound);
                        }
                    }
                    yield break;
                }
                currentWaypoint = path[targetIndex];
            }

            transform.position = Vector3.MoveTowards(transform.position, currentWaypoint, speed * Time.deltaTime);
            yield return(null);
        }
    }
Beispiel #25
0
 public void GoToClick(Vector3 target)
 {
     if (!attacking)
     {
         PathRequestManager.RequestPath(transform.position, target, OnPathFound);
     }
 }
Beispiel #26
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(1) && selected)
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit, 1000))
            {
                targetIndex = 0;
                path        = null;
                PathRequestManager.RequestPath(accesableGroundType, transform.position, hit.point, OnPathFound);
            }
        }

        if (GetComponent <Renderer>().isVisible&& Input.GetMouseButton(0))
        {
            Vector3 cameraPos = Camera.main.WorldToScreenPoint(transform.position);
            cameraPos.y = MainCamera.InvertMouseY(cameraPos.y);
            selected    = MainCamera.selection.Contains(cameraPos);
        }

        if (selected)
        {
            GetComponent <Renderer>().material.color = Color.red;
        }
        else
        {
            GetComponent <Renderer>().material.color = Color.white;
        }
    }
Beispiel #27
0
 void Update()
 {
     if ((target.position - transform.position).magnitude > 3f)
     {
         PathRequestManager.RequestPath(transform.position, target.position, OnPathFound);
     }
 }
Beispiel #28
0
 //행위 메소드 공통된거 추가하기
 public virtual void Reaction(float value, Transform transform)
 {
     if (this.gameObject.layer == 7)                //몬스터가 맞았을때 플레이어를 확인하지 못한경우
     {
         if (attackRange.visibleTargets.Count <= 0) //플레이를 확인하지 못했을대
         {
             isRandomMove = false;
             findTarget   = true;
             StopCoroutine("Move");
             attackRange.visibleTargets.Add(transform);
             PathRequestManager.RequestPath(transform.position, transform.position, OnPathFound);
         }
     }
     if (Shield < value)
     {
         if (isAttack)
         {
             animator.SetTrigger("Reaction");
         }
         Hpbar.fillAmount = Health / maxHealth;
         if (Health > 0)
         {
             Health -= (value - Shield);
         }
         else
         {
             Death();
             StageManager.instance.StageEnd();
         }
     }
 }
Beispiel #29
0
    public IEnumerator RequestNewPathTo(Vector2 pos)
    {
        DebugExtension.DebugCircle(pos, Vector3.forward, Color.blue, 0.2f);

        Vector2 cam = Camera.main.transform.position;

        if (pos.x == -1000)
        {
            bool found = false;
            while (!found)
            {
                Target = Camera.main.ViewportToWorldPoint(new Vector3(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), 0));
                if (!PathRequestManager.VerifyLocation(Target))
                {
                    Debug.Log("Não é possivel chegar à posição de destino");
                }
                else
                {
                    found = true;
                }
            }
        }
        else
        {
            Target = pos;
        }
        PathRequestManager.RequestPath(new PathRequest(transform.position, Target, OnPathFound));

        yield return(new WaitForEndOfFrame());
    }
Beispiel #30
0
    IEnumerator UpdatePath()
    {
        if (Time.timeSinceLevelLoad < .5f)
        {
            yield return(new WaitForSeconds(.5f));
        }
        PathRequestManager.RequestPath(new PathRequest(transform.position, target.position, OnPathFound), ignoreUnwalkable);

        float   sqrMoveThreshold = pathUpdateMoveThreshold * pathUpdateMoveThreshold;
        Vector3 targetPosOld     = target.position;

        while (true)
        {
            yield return(new WaitForSeconds(minPathUpdateTime));

            if (target != null)
            {
                if ((target.position - targetPosOld).sqrMagnitude > sqrMoveThreshold)
                {
                    PathRequestManager.RequestPath(new PathRequest(transform.position, target.position, OnPathFound), ignoreUnwalkable);
                    targetPosOld = target.position;
                }
            }
        }
    }