Esempio n. 1
0
 public virtual void OnDestroy()
 {
     AStarGridManager.UnregisterGrid(this);
     connectionNodes = null;
     Nodes           = null;
     searchGrid      = null;
     obstacles.Clear();
     hashObstacles.Clear();
     obstructedIndexes.Clear();
 }
Esempio n. 2
0
        // Constructor
        public AsyncPathRequest(SearchGrid grid, Index start, Index end, PathRequestDelegate callback)
        {
            this.Grid     = grid;
            this.Start    = start;
            this.End      = end;
            this.Callback = callback;

            // Create a time stamp
            TimeStamp = DateTime.UtcNow.Ticks;
        }
Esempio n. 3
0
        public AsyncPathRequest(SearchGrid grid, Index start, Index end, DiagonalMode diagonal, BaseTraversal2D traversal2D, PathRequestDelegate callback)
        {
            this.Grid        = grid;
            this.Start       = start;
            this.End         = end;
            this.Diagonal    = diagonal;
            this.Callback    = callback;
            this.Traversal2D = traversal2D;

            // Create a time stamp
            TimeStamp = DateTime.UtcNow.Ticks;
        }
Esempio n. 4
0
        public virtual void Awake()
        {
            Ins         = this;
            PosFactionX = (gridX / 2);
            PosFactionY = (gridY / 2);
            AStarGridManager.RegisterGrid(this);
            Nodes = new Node[gridX, gridY];
            for (int i = 0; i < gridX; i++)
            {
                for (int j = 0; j < gridY; j++)
                {
                    GameObject obj = null;
                    if (NodePrefab != null)
                    {
                        obj      = Instantiate(NodePrefab, Const.VEC_FarawayPos, Quaternion.identity);
                        obj.name = string.Format("Node:{0},{1}", i, j);
                    }
                    else
                    {
                        obj = new GameObject(string.Format("Node:{0},{1}", i, j));
                        var temp = obj.AddComponent <Node>();
                        temp.IsWalkable = true;
                    }
                    obj.transform.localPosition = Const.VEC_FarawayPos;
                    obj.transform.rotation      = Quaternion.identity;
                    obj.transform.SetParent(transform);
                    if (Type == MapType.XY)
                    {
                        obj.transform.localPosition = new Vector3((i - PosFactionX) * nodeSpacing, (j - PosFactionY) * nodeSpacing);
                    }
                    else
                    {
                        obj.transform.localPosition = new Vector3((i - PosFactionX) * nodeSpacing, 0, (j - PosFactionY) * nodeSpacing);
                    }
                    Nodes[i, j]                 = obj.GetComponent <Node>();
                    Nodes[i, j].Index           = new Index(i, j);
                    Nodes[i, j].OnNodeSelected += OnNodeSelected;
                    if (showPreviewPath == true)
                    {
                        Nodes[i, j].OnNodeHover += OnNodeHover;
                    }
                }
            }

            searchGrid = new SearchGrid(Nodes);
            searchGrid.IsIndexObstacle = IsObstacle;
        }
Esempio n. 5
0
 // Constructor
 /// <summary>
 /// Default constructor.
 /// </summary>
 internal Path(SearchGrid grid)
 {
     this.grid = grid;
 }