public static BuildingConstruction Create(Vector3 position, BuildingTypeSO buildingType) { buildingCache = Instantiate(Resources.Load <Transform>(typeof(BuildingConstruction).Name), position, Quaternion.identity).GetComponent <BuildingConstruction>(); buildingCache.Setup(buildingType); return(buildingCache); }
public void SetActiveBuildingType(BuildingTypeSO buildingType) { activeBuildingType = buildingType; OnActiveBuildingTypeChanged?.Invoke(this, new OnActiveBuildingTypeChangedEventArgs { activeBuildingType = activeBuildingType }); }
private void Start() { cam = Camera.main; buildingTypeList = Resources.Load <BuildingTypeListSO>(nameof(BuildingTypeListSO)); buildingType = buildingTypeList.List[0]; }
void Awake() { EventManager.instance.onModeChanged += ResetLastClickedTile; instance = this; gridWidth = MapSizeController.mapSize; gridHeight = MapSizeController.mapSize; grid = new GridXZ(gridWidth, gridHeight, cellSize, Vector3.zero); // Create ground visual float groundSizeX = gridWidth * cellSize; float groundSizeY = gridHeight * cellSize; ground = Instantiate(groundVisualPrefab, new Vector3(groundSizeX / 2, -0.5f, groundSizeY / 2), Quaternion.identity); ground.localScale = new Vector3(groundSizeX, 1, groundSizeY); selectedBuildingSO = null; currentBuildingRotation = BuildingTypeSO.Direction.Down; float spawnChance = 0.05f; // The spawning chance of the trees when the game starts for (int i = 0; i < gridWidth; i++) { for (int j = 0; j < gridHeight; j++) { float randFloat = Random.Range(0f, 1f); if (randFloat < spawnChance) { spawnTree(i, j); } } } }
private void Awake() { timeMax = 1f; buildingType = GetComponent <BuildingTypeHolder>().buildingType; timeMax = buildingType.resGeneratorDt.timerMax; }
public void Setup() { GameObject buildings = new GameObject(); GameObject empty = new GameObject(); GameObject help = new GameObject(); buildings.name = "Buildings"; gameManager = help.AddComponent <GameManager>(); eventManager = help.AddComponent <EventManager>(); timeManager = help.AddComponent <TimeManager>(); empty.AddComponent <Attraction>(); gameManager.testMode = true; grid = new GridXZ(1, 1, 3, Vector3.zero); wcObject = ScriptableObject.CreateInstance <BuildingTypeSO>(); wcObject.type = BuildingTypeSO.Type.Attraction; wcObject.capacity = 1; wcObject.price = 150; wcObject.sellMultiplier = 0.5f; wcObject.baseIncome = 10; wcObject.breakChance = 0.2f; wcObject.width = 1; wcObject.height = 1; wcObject.prefab = empty.transform; wcObject.preview = empty.transform; wcObject.buildingName = "Toilet"; wcObject.uiPrefab = empty.transform; }
private void Start() { mainCamera = Camera.main; buildingTypeList = Resources.Load <BuildingTypeListSO>(typeof(BuildingTypeListSO).Name); buildingType = buildingTypeList.list[0]; }
void RefreshVisual() { if (visual != null) { Destroy(visual.gameObject); visual = null; } buildingType = buildingSystem.GetSelectedBuildingType(); if (buildingType != null) { visual = Instantiate(buildingType.preview, Vector3.zero, Quaternion.identity); visual.parent = transform; visual.localPosition = Vector3.zero; visual.localEulerAngles = Vector3.zero; } else { if (visual != null) { Destroy(visual.gameObject); } } }
private void Start() { mainCamera = Camera.main; buildingTypeList = Resources.Load <BuldingTypeListSO>("BuildingTypeSO"); buildingType = buildingTypeList.list[0]; }
public void Teardown() { Object.Destroy(gameManager); Object.Destroy(eventManager); Object.Destroy(timeManager); grid = null; wcObject = null; }
public void ChangeActiveBuilding(BuildingTypeSO newType) { activeBuildingType = newType; OnActiveBuildingTypeChange?.Invoke(this, new OnActiveBuildingTypeChangeArgs { activeBuildingType = newType }); }
private void Start() { buildingType = GetComponent <BuildingTypeHolder>().buildingType; healthSystem = GetComponent <HealthSystem>(); healthSystem.SetHealthAmountMax(buildingType.healthAmountMax, true); healthSystem.OnDie += HealthSystem_OnDied; healthSystem.OnDamage += HealthSystem_OnDamage; healthSystem.OnHealed += HealthSystem_OnHealed; }
void Start() { _buildingType = GetComponent <BuildingTypeHolder>().buildingType; _healthSystem = GetComponent <HealthSystem>(); _healthSystem.SetHealthAmountMax(_buildingType.healthAmountMax, true); _healthSystem.OnDamaged += HealthSystem_OnDamaged; _healthSystem.OnHealed += HealthSystem_OnHealed; _healthSystem.OnDied += HealthSystem_OnDied; }
public static BuildingConstruction Create(Vector3 position, BuildingTypeSO buildingType) { Transform buildingConstructionTransform = Instantiate(GameAssets.Instance.pfBuildingConstruction, position, Quaternion.identity); BuildingConstruction buildingConstruction = buildingConstructionTransform.GetComponent <BuildingConstruction>(); buildingConstruction.SetupBuildingType(buildingType); return(buildingConstruction); }
public bool ChangeSelectedType(BuildingTypeSO buildingTypeSO) { if (this.money >= buildingTypeSO.price) { buildingSystem.SetSelectedBuildingType(buildingTypeSO); return(true); } return(false); }
private void Setup(BuildingTypeSO building) { buildingType = building; constructionTimerMax = building.construcionTimerMax; constructionTimer = building.construcionTimerMax; colli.offset = building.prefab.GetComponent <BoxCollider2D>().offset; colli.size = building.prefab.GetComponent <BoxCollider2D>().size; spriteRenderer.sprite = building.sprite; typeHolder.buildingType = building; }
private void Start() { buildingType = GetComponent <BuildingTypeHolder>().buildingType; healthSystem = GetComponent <HealthSystem>(); healthSystem.SetHealthAmountMax(buildingType.healthAmountMax, true); healthSystem.OnDie += CallHealthSystemOnDie; }
public static BuildingConstruction Create(Vector3 position, BuildingTypeSO buildingType) { Transform pfBuildingConstruction = Resources.Load <Transform>("pfBuidlingConstruction"); Transform buildingConstructionTrasnform = Instantiate(pfBuildingConstruction, position, Quaternion.identity); BuildingConstruction buildingConstruction = buildingConstructionTrasnform.GetComponent <BuildingConstruction>(); buildingConstruction.SetBuildingType(buildingType); return(buildingConstruction); }
private void Awake() { transform.Find("button").GetComponent <Button>().onClick.AddListener(() => { BuildingTypeSO buildingType = building.GetComponent <BuildingTypeHolder>().buildingType; foreach (ResourceAmount resourceAmount in buildingType.constructionResourceCostArray) { ResourceManager.Instance.AddResource(resourceAmount.resourcetype, Mathf.FloorToInt(resourceAmount.amount * .6f)); } Destroy(building.gameObject); }); }
public void SetActiveBuildingType(BuildingTypeSO buildingType) { activeBuildingType = buildingType; if (buildingType != null) { onBuildingModeChange?.Invoke(buildingType.sprite); } else { onBuildingModeChange?.Invoke(null); } }
private void SetBuildingType(BuildingTypeSO buildingType) { this.buildingType = buildingType; constructionTimerMax = buildingType.constructionTimerMax; constructionTimer = constructionTimerMax; spriteRenderer.sprite = buildingType.sprite; boxCollider2D.offset = buildingType.prefab.GetComponent <BoxCollider2D>().offset; boxCollider2D.size = buildingType.prefab.GetComponent <BoxCollider2D>().size; buildingTypeHolder.buildingType = buildingType; }
private void GetNextBuilding() { var currentIndex = _buildingTypeList.buildingTypeList.IndexOf(_buildingType); if (currentIndex + 1 < _buildingTypeList.buildingTypeList.Count) { _buildingType = _buildingTypeList.buildingTypeList[currentIndex + 1]; } else { _buildingType = _buildingTypeList.buildingTypeList[0]; } }
private void InstanceOnOnActiveBuildingTypeChange(object sender, BuildingManager.OnActiveBuildingTypeChangeEventArgs e) { BuildingTypeSO buildingType = e.ActiveBuildingType; if (buildingType == null) { Hide(); } else { Show(buildingType.sprite); } }
public void MakeNewBuilding(BuildingTypeSO buildingType) { ResAmount buyResAmount = null; for (int i = 0; i < buildingType.buildResCostArr.Length; i++) { buyResAmount = buildingType.buildResCostArr[i]; int curResoruce = ResourceManager.Instance.GetResourceAmount(buyResAmount.resourceType); ResourceManager.Instance.SetResourceAmount(buyResAmount.resourceType, curResoruce - buyResAmount.amount); } Instantiate(activeBuildingType.prefab, curMousePos, Quaternion.identity); }
bool CanSpawnBuilding(BuildingTypeSO buildingType, Vector3 position, out string errorMessage) { BoxCollider2D boxCollider2D = buildingType.prefab.GetComponent <BoxCollider2D>(); Collider2D[] collider2DArray = Physics2D.OverlapBoxAll(position + (Vector3)boxCollider2D.offset, boxCollider2D.size, 0); bool isAreaClear = collider2DArray.Length == 0; if (!isAreaClear) { errorMessage = "Area is not clear!"; return(false); } collider2DArray = Physics2D.OverlapCircleAll(position, buildingType.minConstructionRadius); foreach (Collider2D col in collider2DArray) { // Colliders inside the construction radius BuildingTypeHolder buildingTypeHolder = col.GetComponent <BuildingTypeHolder>(); if (buildingTypeHolder != null) { if (buildingTypeHolder.buildingType == buildingType) { //There's already a building of this type within the construction radius! errorMessage = "Too close ot another building of the same type!"; return(false); } } } float maxConstructionRadius = 25f; collider2DArray = Physics2D.OverlapCircleAll(position, maxConstructionRadius); foreach (Collider2D col in collider2DArray) { // Colliders inside the construction radius BuildingTypeHolder buildingTypeHolder = col.GetComponent <BuildingTypeHolder>(); if (buildingTypeHolder != null) { // It's a building! errorMessage = ""; return(true); } } errorMessage = "Too far from any other building!"; return(false); }
void SetBuildingType(BuildingTypeSO buildingType) { _buildingType = buildingType; _constructionTimerMax = buildingType.constructionTimerMax; _constructionTimer = _constructionTimerMax; _spriteRenderer.sprite = buildingType.sprite; _boxCollider2D.offset = buildingType.prefab.GetComponent <BoxCollider2D>().offset; _boxCollider2D.size = buildingType.prefab.GetComponent <BoxCollider2D>().size; _buildingTypeHolder.buildingType = buildingType; }
private bool CanBuy(BuildingTypeSO buildingType) { ResAmount buyResAmount = null; for (int i = 0; i < buildingType.buildResCostArr.Length; i++) { buyResAmount = buildingType.buildResCostArr[i]; if (buyResAmount.amount > ResourceManager.Instance.GetResourceAmount(buyResAmount.resourceType)) { return(false); } } return(true); }
public void Setup() { gridWidth = 5; gridHeight = 5; cellSize = 3f; vector = Vector3.zero; grid = new GridXZ(gridWidth, gridHeight, cellSize, vector); roadSO = ScriptableObject.CreateInstance <BuildingTypeSO>(); roadSO.buildingName = "roadX"; roadSO.type = BuildingTypeSO.Type.Road; testObject = new GameObject(); baseRoad = testObject.AddComponent <Road>(); baseRoad.Type = roadSO; }
private bool CanSpawnBuilding(BuildingTypeSO buildingType, Vector3 position, out string errorMessage) { // for null - return false if (buildingType == null) { errorMessage = "Unknown Error"; return(false); } // Get colliders colliderCache = buildingType.prefab.GetComponent <BoxCollider2D>(); collidersCache = Physics2D.OverlapBoxAll(position + (Vector3)colliderCache.offset, colliderCache.size, 0); // If something under building -> false if (collidersCache.Length > 0) { errorMessage = "Area is not clear!"; return(false); } // Check if the same building in nearby collidersCache = Physics2D.OverlapCircleAll(position, buildingType.minConstrctionRadius); foreach (var collider in collidersCache) { if (collider.TryGetComponent(out buildingTypeHolderCache)) { if (buildingTypeHolderCache.buildingType == buildingType) { errorMessage = "Too close to another building of the same type!"; return(false); } } } // Check if there is ANY building in nearby collidersCache = Physics2D.OverlapCircleAll(position, maxConstrctionRadius); foreach (var collider in collidersCache) { if (collider.TryGetComponent(out buildingTypeHolderCache)) { // All requirements were fulfilled errorMessage = string.Empty; return(true); } } // No building around errorMessage = "Too far from any other building!"; return(false); }
private void Update() { if (Input.GetMouseButtonDown(0)) { Instantiate(buildingType.prefab, GetMouseWorldPosition(), Quaternion.identity); } if (Input.GetKeyDown(KeyCode.T)) { buildingType = buildingTypeList.list[0]; } if (Input.GetKeyDown(KeyCode.Y)) { buildingType = buildingTypeList.list[1]; } }