/// Loads the build option buttons private void loadBuildOptions() { Builder builder = GameStateManager.Instance.SelectedCell.Selectable as Builder; GameStateManager.Instance.SelectedBuildOption = ""; if (builder != null) { for (int i = 0; i < this.buttons.Count; i++) { Destroy(this.buttons[i].gameObject); } this.buttons.Clear(); string[] buildOptions = builder.BuildOptionLabels; for (int i = 0; i < buildOptions.Length; i++) { int g = i; BuildButton buildButton = Instantiate(this.buildButtonPrefab) as BuildButton; UnitRecipe recipe = builder.BuildOptions[g]; GameObject buildOptionWrapper = buildButton.SetButton(builder.Faction, () => this.onSelectBuildOption(g.ToString(), builder), builder.BuildOptions[g]); this.buttons.Add(buildOptionWrapper); buildOptionWrapper.transform.SetParent(this.buttonsParent, false); } } }
private void OnSwitchEditBuild(BuildButton buildButton) { if (buildButton == CurrentEditBuildButton) { return; } if (IsReadOnly) { return; } if (CurrentEditBuildButton) { CurrentEditBuildButton.IsEdit = false; SelectBuildManager.Instance.OnSaveBuildInfo(CurrentEditBuildButton.BuildInfo); } CurrentEditBuildButton = buildButton; CurrentEditBuildButton.IsEdit = true; SelectCardsByBuildInfo(buildButton.BuildInfo); RefreshCoinLifeEnergy(); RefreshDrawCardNum(); AudioManager.Instance.SoundPlay("sfx/SwitchBuild"); if (SelectBuildManager.Instance.CurrentGameMode == SelectBuildManager.GameMode.Online) { OnlineManager.Instance.CurrentOnlineBuildID = buildButton.BuildInfo.BuildID; } }
virtual public string TriggerEnter(BuildButton selectedBuildButton) { // Debug.Log("HexTile.TriggerEnter" + selectedBuildButton.nextTile); GameObject tile = gameObject; mat = tile.GetComponent <Renderer>().material; tile.GetComponent <Renderer>().material = TileManager.Get().selectMat; // NuclearAHexTile.AddTile(tile); if (selectedBuildButton != null) { Building b = selectedBuildButton.building; Debug.Log("space " + space); Debug.Log("space needed " + b.space); if (!HasSpace(b)) { tile.GetComponent <Renderer>().material = TileManager.Get().fullMat; return("No hay espacio suficiente para el edificio"); } if (!AllowsBuilding(b)) { tile.GetComponent <Renderer>().material = TileManager.Get().NotAllowedMat; return("No estan los recursos para poner este edificio aqui"); } // Debug.Log("selectedBuildButton.TriggerEnter" + selectedBuildButton.nextTile); AddBuilding(b, buildings.Count); // Debug.Log("selectedBuildButton.TriggerEnter" + selectedBuildButton.nextTile); // selectedBuildButton.nextTile.AddTileLocal(tile); } return(null); }
public void HighlightThird() { First.Highlight(false); Second.Highlight(false); Third.Highlight(true); Highlighted = Third; }
void OnEnable() { First.Highlight(true); Second.Highlight(false); Third.Highlight(false); Highlighted = First; }
public void HighlightFirst() { First.Highlight(true); Second.Highlight(false); Third.Highlight(false); Highlighted = First; }
public void OnBuildButtonDoubleClickToSelect(BuildButton buildButton) { if (IsReadOnly) { return; } if (CurrentSelectedBuildButton) { CurrentSelectedBuildButton.IsSelected = false; } CurrentSelectedBuildButton = buildButton; CurrentSelectedBuildButton.IsSelected = true; }
private void ClearAllBuilds() { while (AllMyBuildsContainer.childCount > 1) { BuildButton bb = AllMyBuildsContainer.GetChild(0).GetComponent <BuildButton>(); if (bb != null) { bb.PoolRecycle(); } } CurrentBuildButtons.Clear(); }
public void Init(Builder builder) { foreach (Tower t in builder.towerShop) { BuildButton button = Instantiate(buildButtonPrefab, buildPanelTransform); button.Init(t); if (t.Price > player.Money) { button.GetComponent <Button>().interactable = false; } } CancelButton cancel = Instantiate(CancelButtonPrefab, buildPanelTransform); }
void firstButtons() { Debug.Log("Button location detected at: " + buttonLocation + " Spawner at: " + buttonSpawner.transform.position); buttonLocation = buttonSpawner.transform.position; foreach (GameObject currentRoomPrefab in roomPrefabArray) { GameObject button = Instantiate(buttonPrefab, buttonLocation, Quaternion.identity) as GameObject; button.transform.SetParent(buttonsParent.transform, false); buildButton = button.GetComponent <BuildButton> (); buildButton.roomPrefab = currentRoomPrefab; buttonLocation.y -= 250.0079f; } ButtonInitialize = true; }
private BuildButton GenerateNewBuildButton(BuildInfo m_BuildInfo) { BuildButton newBuildButton = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.BuildButton].AllocateGameObject <BuildButton>(AllMyBuildsContainer); newBuildButton.Initialize(m_BuildInfo); CreateNewBuildButton.transform.parent.SetAsLastSibling(); OnMouseClick bbc = newBuildButton.Button.GetComponent <OnMouseClick>(); bbc.ResetListeners(); bbc.LeftClick.AddListener(delegate { OnSwitchEditBuild(newBuildButton); }); bbc.RightClick.AddListener(delegate { OnRightClickBuildButtonToRename(newBuildButton.BuildInfo); }); bbc.LeftDoubleClick.AddListener(delegate { OnBuildButtonDoubleClickToSelect(newBuildButton); }); return(newBuildButton); }
public void OnTriggerEnter(Collider other) { // other.gameObject.GetComponent<Renderer>().material = world.desertMat; Debug.Log("Coll all "); HexTile hexTile = other.gameObject.GetComponent <HexTile>(); // BuildButton selectedBuildButton = BuildManager.Get().selectedBuildButton; // other.gameObject.GetComponent<BuildButton>(); BuildButton selectedBuildButton = other.gameObject.GetComponent <BuildButton>(); // Debug.Log("BuildBtn " + selectedBuildButton); WorldRotatorButton selectedRotatorButton = other.gameObject.GetComponent <WorldRotatorButton>(); if (hexTile != null) { Debug.Log("Coll world " + BuildManager.Get().GetSelectedBuilding()); hexTile.TriggerEnter(BuildManager.Get().GetSelectedBuilding()); // hexTile.TriggerEnter(other.gameObject, BuildManager.Get().GetSelectedBuilding()); } else if (selectedBuildButton != null) { selectedBuildButton.SetSelected(true); Debug.Log("Coll board " + selectedBuildButton); // GameObject o = selectedBuildButton.nextTile.Get3dObject(); // Debug.Log("Coll board 1 " + o); /* * if (o != null) * { * Debug.Log("Going nuckear " ); * * o.SetActive(true); * carryObject = o; * * o.transform.position = gameObject.transform.position;// new Vector3(x, y, z); * * }*/ // show it in the hand } else if (selectedRotatorButton != null) { } else { Debug.Log("Coll Qui! "); Application.Quit(); } }
public void OnCreateNewBuildButton(BuildInfo buildInfo) { BuildButton newBuildButton = GenerateNewBuildButton(buildInfo); CurrentBuildButtons.Add(buildInfo.BuildID, newBuildButton); OnSwitchEditBuild(newBuildButton); if (CurrentSelectedBuildButton == null) { CurrentSelectedBuildButton = newBuildButton; CurrentSelectedBuildButton.IsSelected = true; ShowSliders(true); } CreateNewBuildButton.enabled = true; //解锁 DeleteBuildButton.enabled = true; }
private void Update() { if (isLocalPlayer) { if (Input.GetMouseButtonUp(0) && selectionHighlight.enabled && MultiplayerController.Instance.IsGameInitialized) { wasShiftPressedOnActualTest = Input.GetKey(KeyCode.LeftShift); CmdTestSelection(startSelectionPosition, selectionHighlight.transform.localScale, wasShiftPressedOnActualTest); selectionHighlight.enabled = false; } if (CheckIfIsInSelectionArea() && !player.Commander.IsSelectingBuildingPlace && MultiplayerController.Instance.IsGameInitialized) { if (Input.GetMouseButtonDown(0)) { selectionHighlight.enabled = true; startSelectionPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); selectionHighlight.transform.position = startSelectionPosition; } if (Input.GetMouseButton(0)) { selectionHighlight.transform.localScale = new Vector3(Camera.main.ScreenToWorldPoint(Input.mousePosition).x - startSelectionPosition.x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y - startSelectionPosition.y, 1f); } } if (MultiplayerController.Instance.IsGameInitialized) { RaycastHit2D underMouseCursorInfo = GetWhatIsUnderMouseCursor(); if (underMouseCursorInfo.collider != null && underMouseCursorInfo.collider.GetComponent <TrainingButton>()) { TrainingButton buttonUnderMouse = underMouseCursorInfo.collider.GetComponent <TrainingButton>(); Unit unitToViewCost = Units.Instance.UnitsList.Find(item => item.UnitType == buttonUnderMouse.UnitType); CostGUI.Instance.ShowCostGUI(unitToViewCost.GoldCost, unitToViewCost.LumberCost, unitToViewCost.FoodCost); } else if (underMouseCursorInfo.collider != null && underMouseCursorInfo.collider.GetComponent <BuildButton>()) { BuildButton buttonUnderMouse = underMouseCursorInfo.collider.GetComponent <BuildButton>(); Building buildingToViewCost = Buildings.Instance.BuildingsList.Find(item => item.BuildingType == buttonUnderMouse.BuildingType); CostGUI.Instance.ShowCostGUI(buildingToViewCost.GoldCost, buildingToViewCost.LumberCost, 0); } else if (CostGUI.Instance.IsVisible) { CostGUI.Instance.HideCostGUI(); } } } }
public void Init(BuildingPlot plot) { buttonContainerTransform = transform.Find("ButtonContainer"); plot.onDestroyed += OnPlotDestroyed; for (int i = 0; i < System.Enum.GetValues(typeof(BuildButton.Type)).Length; i++) { GameObject buildButtonGO = Instantiate(buildButtonPrefab, Vector3.zero, Quaternion.identity, buttonContainerTransform); BuildButton btn = buildButtonGO.GetComponent <BuildButton> (); btn.Init((BuildButton.Type)i); btn.button.onClick.AddListener(() => { if (onBuildButtonClicked != null) { onBuildButtonClicked(btn, plot); } }); buttons.Add(btn); } }
public void OnBlockClick(Block block) { CurrentBlock = block; BuildingPanel.SetActive(true); if (block.Building != null) { DestroyButton.SetActive(true); BuildButton.SetActive(false); TabsHolder.SetActive(false); } else { DestroyButton.SetActive(false); BuildButton.SetActive(true); TabsHolder.SetActive(true); } CurrentBlock.transform.position += Vector3.up / 2; }
public void Initialize(EnvironmentTile firstPosition) { facilitiesTypes = GameTiles.instance.GetFacilitiesTypes(); foreach (FacilitiesTileType type in facilitiesTypes.tileTypes) { // can't build cities if (type.Name == "City") { continue; } // create a button for this facility and add it to the parent object // instantiate new button GameObject button = Instantiate(buttonTemplate) as GameObject; button.SetActive(true); BuildButton btnScript = button.GetComponent <BuildButton>(); // change the icon of the button // get all sliced tiles from our tileset Sprite[] tileSprites = Resources.LoadAll <Sprite>(facilitiesTileset.name); Sprite matchingSprite = tileSprites[0]; // find the sprite foreach (Sprite sprite in tileSprites) { if (sprite.name == type.SpriteName) { matchingSprite = sprite; break; } } btnScript.SetImage(matchingSprite); btnScript.SetType(type); btnScript.Enable(type.IsBuildable(firstPosition)); // set parent of the button with the parent of the button template's parent // (our content object) button.transform.SetParent(buttonTemplate.transform.parent, false); buttons.Add(button); } }
public void NewButtons() { buttonLocation = buttonSpawner.transform.position; Debug.Log("Button location detected at: " + buttonLocation + " Spawner at: " + buttonSpawner.transform.position); GameObject[] existingButtons = GameObject.FindGameObjectsWithTag("BuildButton"); Debug.Log("Existing Buttons are" + existingButtons); foreach (GameObject currentButton in existingButtons) { Destroy(currentButton); } foreach (GameObject currentRoomPrefab in roomPrefabArray) { GameObject button = Instantiate(buttonPrefab, buttonLocation, Quaternion.identity) as GameObject; buildButton = button.GetComponent <BuildButton> (); buildButton.roomPrefab = currentRoomPrefab; button.transform.SetParent(buttonsParent.transform, false); buttonLocation.y -= 250.0079f; } }
// Start is called before the first frame update void Start() { s_buildManager = this; selectedBuildButton = null; buildButtons = new BuildButton[9]; index = 0; buildInfo = info.gameObject; buildInfo.SetActive(false); CreateButton(-0.3f, -0.3f, nuclearAMat, new NuclearA()); CreateButton(0f, -0.3f, nuclearBMat, new NuclearB()); CreateButton(0.3f, -0.3f, nuclearCMat, new NuclearC()); // CreateButton(-0.3f, 0f, renewAMat, new RenewA()); CreateButton(0f, 0f, renewBMat, new RenewB()); CreateButton(0.3f, 0f, renewCMat, new RenewC()); CreateButton(-0.3f, 0.3f, coalAMat, new CoalA()); CreateButton(0f, 0.3f, coalBMat, new CoalB()); CreateButton(0.3f, 0.3f, coalCMat, new CoalC()); }
public void ToggleLeft() { if (Highlighted == First) { First.Highlight(false); Third.Highlight(true); Highlighted = Third; } else if (Highlighted == Second) { Second.Highlight(false); First.Highlight(true); Highlighted = First; } else if (Highlighted == Third) { Third.Highlight(false); Second.Highlight(true); Highlighted = Second; } }
void CreateButton(float x, float y, Material m, Building building) { GameObject nuclearA = Instantiate(menuButton, new Vector3(x, y, -0.5f), Quaternion.EulerRotation(0, 0, 0)); GameObject nuclear2A = Instantiate(menuButton, new Vector3(x, y, -0.5f), Quaternion.EulerRotation(0, 0, 0)); nuclearA.SetActive(true); nuclear2A.SetActive(true); nuclearA.transform.transform.SetParent(spawnPoint.transform, false); nuclear2A.transform.transform.SetParent(spawnPoint.transform, false); BoxCollider c = nuclear2A.AddComponent <BoxCollider>(); c.isTrigger = true; BuildButton b = nuclear2A.AddComponent <BuildButton>(); buildButtons[index++] = b; nuclearA.GetComponent <Renderer>().material = m; b.Init(building.GetPrice(), building.GetUnlockEpoch(), building, selectedMat, m, nuclear2A); b.SetLock(true); // nuclearA.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f); }
public void OnDeleteBuildButton(int buildID) { if (CurrentBuildButtons.ContainsKey(buildID)) { BuildButton deleteBuildButton = CurrentBuildButtons[buildID]; int siblingIndex = deleteBuildButton.transform.GetSiblingIndex(); int newEditBuildButtonSiblingIndex = 0; if (siblingIndex > AllMyBuildsContainer.childCount - 3) { newEditBuildButtonSiblingIndex = AllMyBuildsContainer.childCount - 3; } else { newEditBuildButtonSiblingIndex = siblingIndex; } bool isSelected = deleteBuildButton.IsSelected; deleteBuildButton.PoolRecycle(); CurrentBuildButtons.Remove(buildID); if (newEditBuildButtonSiblingIndex < 0 || AllMyBuildsContainer.childCount == 1) { CurrentEditBuildButton = null; CurrentSelectedBuildButton = null; UnSelectAllCard(SelectCardMethods.DeleteBuild); ShowSliders(false); AudioManager.Instance.SoundPlay("sfx/SwitchBuild"); return; } BuildButton nextCurrentEditBuildButton = AllMyBuildsContainer.GetChild(newEditBuildButtonSiblingIndex).GetComponent <BuildButton>(); OnSwitchEditBuild(nextCurrentEditBuildButton); if (isSelected) { nextCurrentEditBuildButton.IsSelected = true; CurrentSelectedBuildButton = nextCurrentEditBuildButton; } } }
public void InitBuildButtons(SortedDictionary <int, BuildInfo> buildInfos) { ClearAllBuilds(); foreach (KeyValuePair <int, BuildInfo> kv in buildInfos) { BuildButton newBuildButton = GenerateNewBuildButton(kv.Value); CurrentBuildButtons.Add(kv.Key, newBuildButton); newBuildButton.transform.SetParent(AllMyBuildsContainer.transform); } CreateNewBuildButton.transform.parent.SetAsLastSibling(); if (CurrentBuildButtons.Count != 0) { CurrentEditBuildButton = AllMyBuildsContainer.transform.GetChild(0).GetComponent <BuildButton>(); CurrentEditBuildButton.IsEdit = true; CurrentSelectedBuildButton = CurrentEditBuildButton; CurrentSelectedBuildButton.IsSelected = true; SelectCardsByBuildInfo(CurrentEditBuildButton.BuildInfo); } }
public void UpdateButtons(EnvironmentTile tile) { // if there is no tile there is nothing that can be built if (tile != null) { // check which facilities can be built on the specified tile foreach (GameObject button in buttons) { BuildButton buildButton = button.GetComponent <BuildButton>(); var type = buildButton.GetTileType(); // hide/show buttons according to if they are buildable on this tile buildButton.Enable(type.IsBuildable(tile)); } lastTileClicked = tile; } else { Debug.Log("There is no tile here!"); } }
private void StructureAdded(StructureManager manager, Structure structure) { if (ButtonManager[structure.Position] != null) { ButtonManager.RemoveButton(ButtonManager[structure.Position]); } ButtonManager.AddButton(new StructureButton(GameSettings, structure), structure.Position); if (!(structure is Construction)) { foreach (var adjacentHexagonNode in structure.Position.GetAccessibleAdjacentHexagonNodes(HexagonManager)) { var p1 = adjacentHexagonNode.Position1; var p2 = adjacentHexagonNode.Position2; var p3 = adjacentHexagonNode.Position3; if (HexagonManager.GetHexagonAtPosition(p1) == null) { HexagonManager.RevealHexagonAt(p1); } if (HexagonManager.GetHexagonAtPosition(p2) == null) { HexagonManager.RevealHexagonAt(p2); } if (HexagonManager.GetHexagonAtPosition(p3) == null) { HexagonManager.RevealHexagonAt(p3); } if (StructureManager[adjacentHexagonNode] == null && ButtonManager[adjacentHexagonNode] == null) { var button = new BuildButton(GameSettings, adjacentHexagonNode); ButtonManager.AddButton(button, adjacentHexagonNode); } /*if (!EdgeManager.ContainsEdge(structure.Position, adjacentHexagonNode)) * EdgeManager.AddEdge(structure.Position, adjacentHexagonNode);*/ } } }
// Use this for initialization void Start() { ItemTypes = FindObjectOfType <Main>().PlayerIsBody ? BodyItemTypes : SoulItemTypes; int buttonRow = 0; int buttonColumn = 0; int paddings = 0; foreach (TileItemType type in ItemTypes) { if (type == TileItemType.NONE) { buttonRow++; buttonColumn = 0; paddings++; } else { if (buttonColumn >= maxItemsPerRow) { buttonRow++; buttonColumn = 0; } int x = buttonColumn * 75; int y = buttonRow * 85 + 25 * paddings; GameObject btnObject = Instantiate <GameObject>(ButtonPrefab, ButtonContainer); BuildButton btn = btnObject.GetComponent <BuildButton>(); btn.transform.localPosition = new Vector3(x, -y); btn.ItemType = type; btn.UpdateDisplay(); buttonColumn++; } } }
public void SetSelectedBuilding(BuildButton b) { selectedBuildButton = b; buildInfo.SetActive(b != null); }
private void ConstructionMenuRequested(BuildButton buildButton, MenuLayer menuLayer) { BuildMenu.TargetNode = buildButton.HexagonNode; menuLayer.DisplayMenu(BuildMenu); }
void OnBuildButtonClicked(BuildButton btn, BuildingPlot plot) { Debug.Log("Clicked building button: " + btn.type); UnselectBuildingPlot(); plot.ChooseBuilding(btn.type); }