private bool DoBuildingConstructionHasACost(PreviewBuilding cBuilding)
        {
            Vector2Int coords = TileSystem.Instance.WorldToCoords(cBuilding.Building.transform.position);

            GameObject tile = TileSystem.Instance.GetTile(coords);

            return((tile == null) ||
                   (TileSystem.Instance.IsTileFree(coords) && !TileSystem.Instance.DoTileContainsEntityOfID(coords, EntityID)));
        }
        void AddConstructionBuilding()
        {
            var building = ObjectPooler.Instance.SpawnFromPool(EntityData.Prefab, Vector3.zero, Quaternion.identity, true);

            building.GetComponent <Entity>().Team = Team.Player;

            var constructionBuilding = new PreviewBuilding(building, EntityID, EntityData);

            _previewBuildings.Add(constructionBuilding);
        }
Esempio n. 3
0
        protected override void OnCurrentBuildingSet(string entityID, EntityData buildingData)
        {
            var building = ObjectPooler.Instance.SpawnFromPool(buildingData.Prefab, Vector3.zero, Quaternion.identity, true);

            building.GetComponent <Entity>().Team = Team.Player;

            Assert.IsNotNull(building, "Building out of ObjectPooler is null.");

            _constructionBuilding = new PreviewBuilding(building, entityID, buildingData);

            UpdateConstructionBuildingPosition();
        }
        private void ConstructBuilding(PreviewBuilding cBuilding)
        {
            GameObject building         = cBuilding.Building;
            Vector3    buildingPosition = building.transform.position;

            TileSystem tileSystem = TileSystem.Instance;

            // don't make construction unsuccessful because building on the same entiy
            if (tileSystem.GetTile(buildingPosition) != null && tileSystem.DoTileContainsEntityOfID(buildingPosition, EntityID))
            {
                // destroy, but don't interupt construction
                cBuilding.Destroy();
                return;
            }

            const TileFlag condition           = TileFlag.Free | TileFlag.Visible;
            bool           tileSetSuccessfully = tileSystem.TrySetTile(building, EntityData.TileSize, condition, EntityID);

            if (tileSetSuccessfully)
            {
                cBuilding.SetConstructionAsFinish(Team.Player);
                _constructionAchievedBuilding.Add(cBuilding);
            }
        }
 private bool IsConstructionBuildingAchieved(PreviewBuilding cBuilding)
 {
     return(_constructionAchievedBuilding != null && _constructionAchievedBuilding.Contains(cBuilding));
 }