Exemplo n.º 1
0
 public virtual void OnDestroy()
 {
     AStarGridManager.UnregisterGrid(this);
     connectionNodes = null;
     Nodes           = null;
     searchGrid      = null;
     obstacles.Clear();
     hashObstacles.Clear();
     obstructedIndexes.Clear();
 }
Exemplo n.º 2
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;
        }