public void OnObjectInteracted(IPlaceable placeable) { // If on placeable already placed item, then call "OnObjectInteracted" for that item. if (placeable.HavePlacedItem()) { IInteractible interactible = placeable.GetPlacedItem().GetComponent <IInteractible>(); OnObjectInteracted(interactible); return; } ItemType selectedItemType = UIManager.Instance.GetSelectedItemType(); if (selectedItemType == ItemType.None) { return; } InventoryItem invItem = inventory.GetItem(selectedItemType); if (invItem.count == 0) { return; } invItem.count--; Vector3 pos = placeable.GetItemPlacePos(); Item item = gameMap.SpawnItem(selectedItemType, pos); item.isInteractible = true; placeable.SetPlacedItem(item); UIManager.Instance.UpdateHUD(inventory); }
public void SpawnMap(Platform[] map, int mapWidth, int mapHeight, Action _onAllObsorbersActivated) { DestroyMap(); onAllObsorbersActivated = _onAllObsorbersActivated; foreach (Platform platform in map) { int columnIdx = platform.column - mapWidth / 2; int rowIdx = platform.row - mapHeight / 2; Vector3 pos = new Vector3(columnIdx * platformSize, 0f, -rowIdx * platformSize); GameObject platformGO = Instantiate(GetPlatformPrefab(platform.type), pos, Quaternion.identity, transform); // Place Item onto Platform. if (platform.itemData.type != ItemType.None) { IPlaceable placeable = platformGO.GetComponent <IPlaceable>(); if (placeable == null) { return; } Item item = Instantiate(GetItemPrefab(platform.itemData.type), pos, Quaternion.identity, transform); item.transform.forward = platform.itemData.direction; item.SetColor(platform.itemData.inputColors, platform.itemData.outputColors); if (platform.itemData.type == ItemType.LaserBeamer) { laserBeamers.Add((LaserBeamer)item); } else if (platform.itemData.type == ItemType.LaserAbsorber) { ((LaserObsorber)item).OnActiveStateChanged += OnObsorberActiveStateChanged; laserObsorbers.Add((LaserObsorber)item); } placeable.SetPlacedItem(item); } } // Spawn Lasers from LaserBeamers. foreach (LaserBeamer laserBeamer in laserBeamers) { Vector3 dir = laserBeamer.laserSpawnPos.forward; Vector3 pos = laserBeamer.laserSpawnPos.position; SpawnLaser(laserBeamer.laserColor, pos, dir, laserBeamer.GetComponent <IObstacle>(), null); } }