public virtual void DeleteTileAspects(Vector2Int _placeVector2Int)
        {
            PlacedObject_WorldTile currentTileObject = _grid.GetGridObject(_placeVector2Int.x, _placeVector2Int.y).GetPlacedObject();

            Pathfinding.Instance.GetNode(_placeVector2Int.x, _placeVector2Int.y).SetIsWalkable(true);
            currentTileObject.DeleteAspects();
        }
 public WorldTileObject(Grid <WorldTileObject> grid, int x, int y)
 {
     this._grid   = grid;
     this.x       = x;
     this.y       = y;
     placedObject = null;
 }
Exemplo n.º 3
0
        public static PlacedObject_WorldTile Create(Transform _worldTileParent, List <TileAspect> _startingAspects, Vector3 worldPosition, Vector2Int origin, PlacedWorldTileTypeSO.Dir dir, PlacedWorldTileTypeSO _placedWorldTileTypeSO)
        {
            Transform placedObjectTransform = Instantiate(_placedWorldTileTypeSO.prefab, worldPosition, Quaternion.Euler(0, _placedWorldTileTypeSO.GetRotationAngle(dir), 0), _worldTileParent);

            PlacedObject_WorldTile placedObject = placedObjectTransform.GetComponent <PlacedObject_WorldTile>();

            placedObject.SetupTile(_placedWorldTileTypeSO, origin, dir);
            placedObject.SetTileAspects(_startingAspects);

            return(placedObject);
        }
        public virtual void SetTileAspect(TileAspect _tileAspect, Vector2Int _placeVector2Int, int _loopPathIndex)
        {
            PlacedObject_WorldTile currentTileObject = _grid.GetGridObject(_placeVector2Int.x, _placeVector2Int.y).GetPlacedObject();

            List <TileAspect> newAspects = new List <TileAspect>();

            newAspects.Add(LoopPathAspect);

            Pathfinding.Instance.GetNode(_placeVector2Int.x, _placeVector2Int.y).SetIsWalkable(false);
            currentTileObject.AddTileAspects(newAspects, _loopPathIndex);
        }
        public virtual void SetTileAspect(TileAspect _tileAspect, Vector2Int _placeVector2Int)
        {
            PlacedObject_WorldTile currentTileObject = _grid.GetGridObject(_placeVector2Int.x, _placeVector2Int.y).GetPlacedObject();

            List <TileAspect> newAspects = new List <TileAspect>();

            newAspects.Add(LoopPathAspect);

            if (!currentTileObject.MyAspects.Contains(LoopPathAspect))
            {
                currentTileObject.SetTileAspects(newAspects);
                Pathfinding.Instance.GetNode(_placeVector2Int.x, _placeVector2Int.y).SetIsWalkable(false);
            }
        }
        protected virtual List <Vector2Int> AddLoopPathNodes(List <PathNode> _pathNodes, List <Vector2Int> _allPathNodes)
        {
            for (int i = 0; i < _pathNodes.Count; i++)
            {
                Vector2Int toAdd = new Vector2Int(_pathNodes[i].x, _pathNodes[i].y);
                if (!_allPathNodes.Contains(toAdd))
                {
                    _allPathNodes.Add(toAdd);
                    PlacedObject_WorldTile currentTileObject = _grid.GetGridObject(toAdd.x, toAdd.y).GetPlacedObject();
                    Thing nodeThing = currentTileObject.GetComponent <Thing>();
                    loopPathTileSet.Items.Add(nodeThing);
                }
            }

            return(_allPathNodes);
        }
        public virtual void DeleteTileAspects(Vector3 _placePosition)
        {
            _grid.GetXY(_placePosition, out int x, out int z);

            if (x > DB.GridWidth || z > DB.GridHeight)
            {
                return;
            }

            Vector2Int _placedObjectOrigin = new Vector2Int(x, z);

            PlacedObject_WorldTile currentTileObject = _grid.GetGridObject(_placePosition).GetPlacedObject();

            Pathfinding.Instance.GetNode(x, z).SetIsWalkable(true);
            currentTileObject.DeleteAspects();
        }
        public virtual void DeleteAllTileAspects()
        {
            //for (int x = 0; x < DB.GridWidth; x++)
            //{
            //    for (int y = 0; y < DB.GridHeight; y++)
            //    {
            //        DeleteTileAspects(new Vector2Int(x, y));
            //        Pathfinding.Instance.GetNode(x, y).SetIsWalkable(true);
            //    }
            //}

            for (int i = 0; i < tileRuntimeSet.Items.Count; i++)
            {
                PlacedObject_WorldTile worldTile = tileRuntimeSet.Items[i].GetComponent <PlacedObject_WorldTile>();
                worldTile.DeleteAspects();
            }

            Pathfinding.Instance.SetAllWalkable(true);
        }
        public virtual void PlaceWorldTile(Vector3 _placePosition)
        {
            _grid.GetXY(_placePosition, out int x, out int z);

            Vector2Int _placedObjectOrigin = new Vector2Int(x, z);

            List <Vector2Int> gridPositionList = placedWorldTileTypeSO.GetGridPositionList(_placedObjectOrigin, dir);
            bool canBuild = true;

            foreach (Vector2Int gridPosition in gridPositionList)
            {
                if (!_grid.GetGridObject(gridPosition.x, gridPosition.y).CanBuild())
                {
                    canBuild = false;
                    break;
                }
            }

            if (canBuild)
            {
                Vector2Int rotationOffset            = placedWorldTileTypeSO.GetRotationOffset(dir);
                Vector3    placedObjectWorldPosition = _grid.GetWorldPosition(x, z) + new Vector3(rotationOffset.x, rotationOffset.y) * _grid.GetCellSize();

                PlacedObject_WorldTile placedObject = PlacedObject_WorldTile.Create(WorldTileParent, StartingAspects, placedObjectWorldPosition, _placedObjectOrigin, dir, placedWorldTileTypeSO);
                placedObject.transform.rotation = Quaternion.Euler(0, 0, -placedWorldTileTypeSO.GetRotationAngle(dir));

                foreach (Vector2Int gridPosition in gridPositionList)
                {
                    _grid.GetGridObject(gridPosition.x, gridPosition.y).SetPlacedObject(placedObject);
                }

                //OnObjectPlaced?.Invoke(this, EventArgs.Empty);

                //DeselectObjectType();
            }
            else
            {
                // Cannot build here
                UtilsClass.CreateWorldTextPopup("Cannot Build Here!", _placePosition);
            }
        }
        public virtual void SetTileAspect(TileAspect _tileAspect, Vector3 _placePosition)
        {
            _grid.GetXY(_placePosition, out int x, out int z);

            if (x > DB.GridWidth || z > DB.GridHeight)
            {
                return;
            }

            Vector2Int _placedObjectOrigin = new Vector2Int(x, z);

            PlacedObject_WorldTile currentTileObject = _grid.GetGridObject(_placePosition).GetPlacedObject();

            List <TileAspect> newAspects = new List <TileAspect>();

            newAspects.Add(LoopPathAspect);

            if (!currentTileObject.MyAspects.Contains(LoopPathAspect))
            {
                currentTileObject.SetTileAspects(newAspects);
                Pathfinding.Instance.GetNode(x, z).SetIsWalkable(false);
            }
        }
 public void ClearPlacedObject()
 {
     placedObject = null;
     _grid.TriggerGridObjectChanged(x, y);
 }
 public void SetPlacedObject(PlacedObject_WorldTile placedObject)
 {
     this.placedObject = placedObject;
     _grid.TriggerGridObjectChanged(x, y);
 }