public void PlaceBuilding(string objectName, Tile t) { if (buildingPrototypes.ContainsKey(objectName) == false) { Debug.LogError("Wrong object type: " + objectName); return; } Building building = buildingPrototypes [objectName]; if (building is CommonBuilding) { building = CommonBuilding.SpawnObject(buildingPrototypes [objectName] as CommonBuilding, t); } else { building = UniqueBuilding.SpawnObject(buildingPrototypes [objectName] as UniqueBuilding, t); } Debug.Log("Built object name: " + objectName); if (buildingCreated != null) { buildingCreated(building); } else //FIXME Event is null after loading. All info loaded except OnBuildingCreated Method { Debug.LogError("BuildingCreatedEvent is Null"); MapManager.Instance.OnBuildingCreated(building); } }
public CommonBuilding(CommonBuilding other) { this.objectName = other.objectName; this.Width = other.Width; this.Height = other.Height; this.color = other.color; this.tile = other.tile; }
void OnTriggerStay2D(Collider2D other) { if (other.tag == "commonBuilding") { CommonBuilding cb = other.GetComponent <CommonBuilding>(); Vector3 pos = GetComponent <Transform>().position; cb.addCollidingTile(pos); } else if (other.tag == "uniqueBuilding") { UniqueBuilding ub = other.GetComponent <UniqueBuilding>(); Vector3 pos = GetComponent <Transform>().position; ub.addCollidingTile(pos); } }
static public CommonBuilding SpawnObject(CommonBuilding selected, Tile tile) { if (selected.placementValidation(tile) == false) { Debug.Log("Not valid."); return(null); } CommonBuilding obj = new CommonBuilding(selected); obj.tile = tile; if (!tile.PlaceObject(obj)) { return(null); } MapManager.Instance.map.buildings.Add(obj); return(obj); }