Пример #1
0
        void Update()
        {
            tileSizeText.text           = TileSize.ToString("F1");
            EstimateAggressionText.text = EstimateAggression.ToString("F2");

            Path path = FastPath.FindPathImmediate(Start, End);

            if (path.ValidPath)
            {
                InvalidPathIndicator.gameObject.SetActive(false);
            }
            else
            {
                InvalidPathIndicator.gameObject.SetActive(true);
            }

            if (DrawMap)
            {
                FastPath.DrawMapInEditor(FastPath.DefaultMap);
            }
            if (DrawPath)
            {
                path.DrawPath();
            }
            RaycastHit hit;

            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
            {
                if (hit.collider.tag != "Enemy")               // && (hit.collider.tag != "NonWalkable" || hit.collider.gameObject == Obstacle.gameObject))
                {
                    Obstacle.transform.position = new Vector3(hit.point.x, enemyY, hit.point.z);

                    Path p = FastPath.FindPathImmediate(Start, End, FastPath.IndexesBetween(FastPath.DefaultMap, Obstacle.bounds.min, Obstacle.bounds.max));

                    if (p.ValidPath)
                    {
                        ObstacleRenderer.material.color = Color.green;
                        if (Input.GetMouseButtonDown(0))
                        {
                            GameObject instance = (GameObject)Object.Instantiate(Obstacle.gameObject, new Vector3(hit.point.x, enemyY, hit.point.z), Quaternion.identity);
                            instance.GetComponent <MeshRenderer>().material = new Material(ObstacleRenderer.material);
                            FastPath.Update(FastPath.DefaultMap, FastPath.IndexesBetween(FastPath.DefaultMap, Obstacle.bounds.min, Obstacle.bounds.max));
                        }
                    }
                    else
                    {
                        ObstacleRenderer.material.color = Color.red;
                    }
                    if (DrawPath)
                    {
                        p.DrawPath();
                    }
                }
                else
                {
                    ObstacleRenderer.material.color = Color.red;
                }
            }
        }
Пример #2
0
        private void FindPath()
        {
            path = null;
            Vector3 startPos = new Vector3(transform.position.x, Controller.Instance.EnemyY, transform.position.z);

            System.DateTime start = System.DateTime.Now;

            // This lines actually finds the path. If findImmediate is true it finds it immediately otherwise it puts it in ther que.
            path = findImmediate ? FastPath.FindPathImmediate(startPos, Controller.Instance.EndPosition) : new Path(transform.position, Controller.Instance.EndPosition);

            lastPathTime = (System.DateTime.Now - start).TotalMilliseconds;

            currentIndex = 1;
        }
Пример #3
0
 public void Regen()
 {
     FastPath.DefaultMap = FastPath.Generate(config);             // Generates the map which contains nodes (walkalbe/non-walkable points).	Path will be found based on this map.
     totalNodes.text     = (FastPath.DefaultMap.TilesX * FastPath.DefaultMap.TilesX).ToString();
 }