public void InitCharacters(UnitEntity[] units, BannerUnit bannerUnit) { for (int i = 0; i < units.Length; i++) { characterDisplays[i].Init(units[i]); } banner.Init(bannerUnit); }
protected void Init() { villagerList.AddRange(FindObjectsOfType <BaseVillager>()); cameraReference = Camera.main; controller = cameraReference.GetComponent <PlayerController>(); mainUI = Instantiate(Resources.Load("UI/MainUI")) as GameObject; woodText = mainUI.GetComponentsInChildren <Text>()[0]; stoneText = mainUI.GetComponentsInChildren <Text>()[1]; foodText = mainUI.GetComponentsInChildren <Text>()[2]; villagerText = mainUI.GetComponentsInChildren <Text>()[3]; questMenu = Instantiate(Resources.Load("UI/QuestMenuPanel")) as GameObject; characterMenu = Instantiate(Resources.Load("UI/CharacterMenuPanel")) as GameObject; characterScroll = characterMenu.GetComponentInChildren <CharacterDisplay>().gameObject; characterDisplay = characterScroll.GetComponent <CharacterDisplay>(); characterInfo = Instantiate(Resources.Load("UI/SelectedCharacterInfo")) as GameObject; buildingMenu = Instantiate(Resources.Load("UI/BuildingMenuPanel")) as GameObject; buildingPanel = buildingMenu.GetComponentInChildren <HorizontalLayoutGroup>().gameObject; buildingInfo = Instantiate(Resources.Load("UI/BuildingInfoPanel")) as GameObject; buildingDisplay = buildingInfo.GetComponentInChildren <BuildingDisplay>(); lossPanel = Instantiate(Resources.Load("UI/GameOverPanel")) as GameObject; inventoryPanel = Instantiate(Resources.Load("UI/InventoryPanel")) as GameObject; inventoryPanel.GetComponentInChildren <Dropdown>().onValueChanged.AddListener(delegate { inventoryReference.SortItems(inventoryPanel.GetComponentInChildren <Dropdown>().value); }); pauseMenu = Instantiate(Resources.Load("UI/PauseMenu")) as GameObject; if (!GetComponent <InventoryBase>()) { inventoryReference = gameObject.AddComponent <InventoryBase>(); } else { inventoryReference = GetComponent <InventoryBase>(); } if (!GetComponent <QuestManager>()) { questManager = gameObject.AddComponent <QuestManager>(); } else { questManager = GetComponent <QuestManager>(); } pauseMenu.GetComponentsInChildren <Button>()[0].onClick.AddListener(delegate { TogglePauseMenu(true); }); pauseMenu.GetComponentsInChildren <Button>()[1].onClick.AddListener(RestartGame); pauseMenu.GetComponentsInChildren <Button>()[2].onClick.AddListener(SaveQuit); questMenu.GetComponentInChildren <Button>().onClick.AddListener(delegate { ToggleQuestMenu(true); }); characterMenu.GetComponentInChildren <Button>().onClick.AddListener(ToggleCharacterMenu); //Incident Panel incidentPanel = Instantiate(Resources.Load("UI/AttackArrivalPanel")) as GameObject; //Loss Panel lossPanel.GetComponentsInChildren <Button>()[0].onClick.AddListener(RestartGame); lossPanel.GetComponentsInChildren <Button>()[1].onClick.AddListener(ReturnToMenu); //Build Menu buildingText = buildingMenu.transform.GetChild(1).gameObject; buildingText.GetComponentsInChildren <Button>()[0].onClick.AddListener(CreateBuilding); buildingText.GetComponentsInChildren <Button>()[1].onClick.AddListener(CloseBuildingMenu); buildingMenu.GetComponentsInChildren <Button>()[0].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingTownHall") as GameObject); }); buildingMenu.GetComponentsInChildren <Button>()[1].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingWall") as GameObject); }); buildingMenu.GetComponentsInChildren <Button>()[2].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingHouse") as GameObject); }); buildingMenu.GetComponentsInChildren <Button>()[3].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingFarm") as GameObject); }); buildingMenu.GetComponentsInChildren <Button>()[4].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingLumbercamp") as GameObject); }); buildingMenu.GetComponentsInChildren <Button>()[5].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingMiningcamp") as GameObject); }); buildingMenu.GetComponentsInChildren <Button>()[6].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingBarracks") as GameObject); }); buildingMenu.GetComponentsInChildren <Button>()[7].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingOutpost") as GameObject); }); buildingMenu.GetComponentsInChildren <Button>()[8].onClick.AddListener(delegate { SelectBuilding(Resources.Load("Buildings/BuildingBlacksmith") as GameObject); }); //Barracks Buttons buildingInfo.GetComponentsInChildren <Button>()[0].onClick.AddListener(delegate { AddingCharacter(0); }); buildingInfo.GetComponentsInChildren <Button>()[1].onClick.AddListener(delegate { AddingCharacter(1); }); buildingInfo.GetComponentsInChildren <Button>()[2].onClick.AddListener(delegate { AddingCharacter(2); }); buildingInfo.GetComponentsInChildren <Button>()[3].onClick.AddListener(delegate { AddingCharacter(3); }); //Blacksmith Buttons buildingInfo.GetComponentsInChildren <Button>()[4].onClick.AddListener(delegate { AddingCharacter(0); }); buildingInfo.GetComponentsInChildren <Button>()[5].onClick.AddListener(delegate { AddingCharacter(1); }); //Farm Buttons buildingInfo.GetComponentsInChildren <Button>()[7].onClick.AddListener(delegate { AddingCharacter(0); }); buildingInfo.GetComponentsInChildren <Button>()[8].onClick.AddListener(delegate { AddingCharacter(1); }); buildingInfo.GetComponentsInChildren <Button>()[9].onClick.AddListener(delegate { AddingCharacter(2); }); buildingInfo.GetComponentsInChildren <Button>()[10].onClick.AddListener(delegate { AddingCharacter(3); }); //Lumbermill Buttons buildingInfo.GetComponentsInChildren <Button>()[11].onClick.AddListener(delegate { AddingCharacter(0); }); buildingInfo.GetComponentsInChildren <Button>()[12].onClick.AddListener(delegate { AddingCharacter(1); }); buildingInfo.GetComponentsInChildren <Button>()[13].onClick.AddListener(delegate { AddingCharacter(2); }); buildingInfo.GetComponentsInChildren <Button>()[14].onClick.AddListener(delegate { AddingCharacter(3); }); //MiningCamp Buttons buildingInfo.GetComponentsInChildren <Button>()[15].onClick.AddListener(delegate { AddingCharacter(0); }); buildingInfo.GetComponentsInChildren <Button>()[16].onClick.AddListener(delegate { AddingCharacter(1); }); buildingInfo.GetComponentsInChildren <Button>()[17].onClick.AddListener(delegate { AddingCharacter(2); }); buildingInfo.GetComponentsInChildren <Button>()[18].onClick.AddListener(delegate { AddingCharacter(3); }); //Outpost Buttons buildingInfo.GetComponentsInChildren <Button>()[19].onClick.AddListener(delegate { AddingCharacter(0); }); buildingInfo.GetComponentsInChildren <Button>()[20].onClick.AddListener(delegate { AddingCharacter(1); }); //Townhall Buttons buildingInfo.GetComponentsInChildren <Button>()[21].onClick.AddListener(delegate { AddingCharacter(0); }); buildingInfo.GetComponentsInChildren <Button>()[22].onClick.AddListener(delegate { AddingCharacter(1); }); buildingInfo.GetComponentsInChildren <Button>()[23].onClick.AddListener(delegate { AddingCharacter(2); }); buildingInfo.GetComponentsInChildren <Button>()[24].onClick.AddListener(delegate { AddingCharacter(3); }); controller.Init(inventoryPanel, characterInfo, buildingInfo, this); characterDisplay.Init(this, characterMenu.GetComponentInChildren <Scrollbar>()); questManager.Init(questMenu, questMenu.GetComponentInChildren <HorizontalLayoutGroup>().gameObject); inventoryReference.Init(inventoryPanel, controller); buildingPanelPositionStart = buildingPanel.transform.position; buildingPanelPositionEnd = new Vector3(buildingPanel.transform.position.x - 570, buildingPanel.transform.position.y, buildingPanel.transform.position.z); buildingMenu.GetComponentInChildren <Scrollbar>().onValueChanged.AddListener(ScrollBuildingMenu); buildingDisplay.Init(); mainUI.GetComponentsInChildren <Button>()[0].onClick.AddListener(controller.OpenInventory); mainUI.GetComponentsInChildren <Button>()[1].onClick.AddListener(ToggleBuildingMenu); mainUI.GetComponentsInChildren <Button>()[2].onClick.AddListener(OpenQuestMenu); mainUI.GetComponentsInChildren <Button>()[3].onClick.AddListener(ToggleCharacterMenu); mainUI.GetComponentsInChildren <Button>()[4].onClick.AddListener(RestartGame); mainUI.GetComponentsInChildren <Button> () [5].onClick.AddListener(delegate { TogglePauseMenu(false); }); Debug.Log("Init Successful"); }