コード例 #1
0
    void Update()
    {
        if (Network.isServer && nodeGridInitialised)
        {
            if (findPath)
            {
                if (Mathf.RoundToInt(this.transform.position.x) < nodeGrid.GetLength(0) && Mathf.RoundToInt(this.transform.position.y) < nodeGrid.GetLength(0) && Mathf.RoundToInt(this.transform.position.z) < nodeGrid.GetLength(0))
                {
                    if (reset)
                    {
                        startNode = nodeGrid[Mathf.RoundToInt(this.transform.position.x), Mathf.RoundToInt(this.transform.position.y), Mathf.RoundToInt(this.transform.position.z)];
                        if (openList != null && closedList != null)
                        {
                            for (int i = 0; i < openList.Count; i++)
                            {
                                openList[i].parentNode = null;
                            }
                            for (int i = 0; i < closedList.Count; i++)
                            {
                                closedList[i].parentNode = null;
                            }
                            startNode = path[1];
                        }
                        path       = new List <Node>();
                        openList   = new List <Node>();
                        closedList = new List <Node>();

                        checkingNode = startNode;
                        CalculateAllHeuristics();

                        levelcreator = GameObject.FindGameObjectWithTag("levelSettings");
                        level        = levelcreator.GetComponent <Copy_LevelCreator>();
                        grid         = level.getGrid();
                        reset        = false;
                    }
                    int j = 0;
                    while (j < (1.7 / Time.deltaTime))
                    {
                        if (foundTarget == false)
                        {
                            FindPath();
                        }

                        if (foundTarget == true)
                        {
                            if (tracedBack == false)
                            {
                                TraceBackPath();
                                reset = true;
                            }
                        }
                        j++;
                    }
                }
            }
        }
    }