public void DeselectTile() { selectedObject = null; selectedIcon.transform.parent = null; selectedIcon.SetActive(false); if (taskActionBarInstance) { Destroy(taskActionBarInstance.gameObject); } if (buildingActionBarInstance) { Destroy(buildingActionBarInstance.gameObject); } if (wallActionBarInstance) { Destroy(wallActionBarInstance.gameObject); } if (factoryActionBarInstance) { Destroy(factoryActionBarInstance.gameObject); } if (haulableActionBarInstance) { Destroy(haulableActionBarInstance.gameObject); } }
// Called on events that should destroy the menu void DestroyMenus(TaskableBase taskable) { if (taskable == selectedObject) { DeselectTile(); } }
public void SelectTile(TaskableBase tile) { DeselectTile(); selectedObject = tile; selectedIcon.SetActive(true); selectedIcon.transform.parent = selectedObject.transform; selectedIcon.transform.position = selectedObject.transform.position; BuildingBase buildingObject = tile.GetComponent <BuildingBase>(); WallBase wallObject = tile.GetComponent <WallBase>(); HaulableBase haulObject = tile.GetComponent <HaulableBase>(); if (buildingObject) { if (buildingObject.currentTask) { taskActionBarInstance = Instantiate(taskActionBarPrefab, transform); taskActionBarInstance.Setup(buildingObject); } else { buildingActionBarInstance = Instantiate(buildingActionBarPrefab, transform); buildingActionBarInstance.Setup(buildingObject); FactoryBase factoryObject = buildingObject.GetComponent <FactoryBase>(); if (factoryObject) { factoryActionBarInstance = Instantiate(factoryActionBarPrefab, transform); factoryActionBarInstance.Setup(factoryObject); } } } else if (wallObject) { if (wallObject.currentTask) { taskActionBarInstance = Instantiate(taskActionBarPrefab, transform); taskActionBarInstance.Setup(wallObject); } else { wallActionBarInstance = Instantiate(wallActionBarPrefab, transform); wallActionBarInstance.Setup(wallObject); } } else if (haulObject) { if (haulObject.currentTask) { taskActionBarInstance = Instantiate(taskActionBarPrefab, transform); taskActionBarInstance.Setup(haulObject); } else { haulableActionBarInstance = Instantiate(haulableActionBarPrefab, transform); haulableActionBarInstance.Setup(haulObject); } } }
public void Setup(TaskableBase taskable) { this.taskable = taskable; prioritizeButton.onClick.AddListener(() => PrioritizeAction()); cancelButton.onClick.AddListener(() => CancelAction()); RefreshUI(); }
public static void TriggerEvent(string eventName, TaskableBase location) { TileEvent thisEvent = null; if (instance.tileEventDictionary.TryGetValue(eventName, out thisEvent)) { thisEvent.Invoke(location); } }
void CheckWallDestroyed(TaskableBase destroyedObject) { WallBase wall = destroyedObject.GetComponent <WallBase>(); if (wall) { if (TilemapManager.instance.wallTilemap.WorldToCell(wall.transform.position) == TilemapManager.instance.depositTilemap.WorldToCell(this.transform.position)) { DestroySelf(); } } }
public void CheckForNewSpawner(TaskableBase tileBase) { Vector3Int location = TilemapManager.instance.wallTilemap.WorldToCell(tileBase.transform.position); GameObject locObj = TilemapManager.instance.floorTilemap.GetInstantiatedObject(location); if (locObj) { EnemySpawner enemySpawner = locObj.GetComponent <EnemySpawner>(); if (enemySpawner) { spawnPoints.Add(enemySpawner); } } }
// Extends the camera bounds to include the given location void SetBounds(TaskableBase tileBase) { Vector3 location = tileBase.transform.position; if (location.x > topRight.x) { topRight = new Vector2(location.x, topRight.x); } if (location.y > topRight.y) { topRight = new Vector2(topRight.x, location.y); } if (location.x < bottomLeft.x) { bottomLeft = new Vector2(location.x, bottomLeft.y); } if (location.y < bottomLeft.y) { bottomLeft = new Vector2(bottomLeft.x, location.y); } }
public virtual void Setup(TaskableBase target) { this.target = target; this.transform.position = target.transform.position; EventManager.TriggerEvent("TaskCreated", target); }
// For now just triggers a full recheck of the path, could make this smarter though public void UpdatePath(TaskableBase tileBase) { triggerPathRefresh = true; }
// Called on events that should refresh the menu void RefreshMenus(TaskableBase taskable) { if (taskable && taskable == selectedObject) { if (taskable.currentTask) { // Create or update task action bar if (taskActionBarInstance) { taskActionBarInstance.RefreshUI(); } else { taskActionBarInstance = Instantiate(taskActionBarPrefab, transform); taskActionBarInstance.Setup(selectedObject); } // clean up building and wall action bars if (buildingActionBarInstance) { Destroy(buildingActionBarInstance.gameObject); } if (wallActionBarInstance) { Destroy(wallActionBarInstance.gameObject); } if (factoryActionBarInstance) { Destroy(factoryActionBarInstance.gameObject); } if (haulableActionBarInstance) { Destroy(haulableActionBarInstance.gameObject); } } else { // Clean up task action bar if (taskActionBarInstance) { Destroy(taskActionBarInstance.gameObject); } // refresh building and wall action bars BuildingBase buildingObject = taskable.GetComponent <BuildingBase>(); WallBase wallObject = taskable.GetComponent <WallBase>(); HaulableBase haulObject = taskable.GetComponent <HaulableBase>(); if (buildingObject) { if (buildingActionBarInstance) { buildingActionBarInstance.RefreshUI(); } else { buildingActionBarInstance = Instantiate(buildingActionBarPrefab, transform); buildingActionBarInstance.Setup(buildingObject); } FactoryBase factoryObject = buildingObject.GetComponent <FactoryBase>(); if (factoryObject) { if (factoryActionBarInstance) { factoryActionBarInstance.RefreshUI(); } else { factoryActionBarInstance = Instantiate(factoryActionBarPrefab, transform); factoryActionBarInstance.Setup(factoryObject); } } } else if (wallObject) { if (wallActionBarInstance) { wallActionBarInstance.RefreshUI(); } else { wallActionBarInstance = Instantiate(wallActionBarPrefab, transform); wallActionBarInstance.Setup(wallObject); } } else if (haulObject) { if (haulableActionBarInstance) { haulableActionBarInstance.RefreshUI(); } else { haulableActionBarInstance = Instantiate(haulableActionBarPrefab, transform); haulableActionBarInstance.Setup(haulObject); } } } } }
//////////////////// // BUILD TRACKING // //////////////////// void AddBuildingToList(TaskableBase newBuilding) { buildingList.Add(newBuilding.GetComponent <BuildingBase>()); }
void RemoveBuildingFromList(TaskableBase oldBuilding) { buildingList.Remove(oldBuilding.GetComponent <BuildingBase>()); }
public override void Setup(TaskableBase target) { base.Setup(target); owner = target.GetComponent <BuildingBase>(); }