public void UpdateDestroyBlockQueueUI() { for (var i = 0; i < _blocksToDestroy.Count; i++) { int3 blockWorldPos = _blocksToDestroy[i].c0; int3 block = _blocksToDestroy[i].c1; string text = (i).ToString(); if (i == 0) { text = ""; } if (i < blockUIs.Count) { Vector3 pos = Utils.CenterOfBlockWithWorldPos(blockWorldPos); blockUIs[i].gameObject.SetActive(true); blockUIs[i].Setup(pos, block, text); } else { BlockUI bUI = BlockUI.Create(blockWorldPos, block, text); blockUIs.Add(bUI); } } if (blockUIs.Count > _blocksToDestroy.Count) { var remains = blockUIs.GetRange(_blocksToDestroy.Count, blockUIs.Count - _blocksToDestroy.Count); foreach (var r in remains) { r.gameObject.SetActive(false); } } }
public void SetupUI(BlockUI blockUI) { blockId = blockUI.name; blockName.text = blockUI.name; blockImage.sprite = blockUI.sprite; name = blockUI.name; }
public static BlockUI Create(int3 blockWorldPos, int3 block, string text, bool isSelected = false) { Vector3 pos = Utils.CenterOfBlockWithWorldPos(blockWorldPos); Transform tr = Instantiate(GameAssets.i.pfBlockUI, pos, Quaternion.identity); BlockUI blockUI = tr.GetComponent<BlockUI>(); blockUI.Setup(pos, block, text, isSelected); return blockUI; }
public override void OnInspectorGUI() { BlockUI blockUI = (BlockUI)target; EditorGUILayout.LabelField("Size of the block:"); EditorGUILayout.BeginHorizontal(); blockUI.width = EditorGUILayout.IntField("Width", blockUI.width); blockUI.height = EditorGUILayout.IntField("Height", blockUI.height); EditorGUILayout.EndHorizontal(); base.OnInspectorGUI(); }
void OnGUI() { if (currentPathFinding != null && currentPathFinding.pathNodes.Count > 0) { Rect screenRect = new Rect(Screen.width - 160, 25, 150, 25 * (currentPathFinding.pathNodes.Count + 1)); GUILayout.BeginArea(screenRect); foreach (var node in currentPathFinding.pathNodes) { if (GUILayout.RepeatButton(String.Format("{0} {1} {2}", node.startValue, node.value, node.endValue))) { BlockUI bUI = blocksUI.Find(bui => bui.pos == node.pos); bUI.ToggleSelection(); } } clearAll = GUILayout.Toggle(clearAll, " Clear All"); GUILayout.EndArea(); } }
public static Dictionary <GameColor, BlockUI> CreateBlocks(ContentManager content) { Texture2D redBlockTexture = content.Load <Texture2D>("Blocks/Red"); Texture2D orangeBlockTexture = content.Load <Texture2D>("Blocks/Orange"); Texture2D yellowBlockTexture = content.Load <Texture2D>("Blocks/Yellow"); Texture2D greenTexture = content.Load <Texture2D>("Blocks/Green"); Texture2D blueBlockTexture = content.Load <Texture2D>("Blocks/Blue"); Texture2D cyanBlockTexture = content.Load <Texture2D>("Blocks/Cyan"); Texture2D magentaBlockTexture = content.Load <Texture2D>("Blocks/Magenta"); Texture2D blackBlockTexture = content.Load <Texture2D>("Blocks/Black"); Texture2D grayBlockTexture = content.Load <Texture2D>("Blocks/Gray"); Texture2D whiteBlockTexture = content.Load <Texture2D>("Blocks/White"); BlockUI redBlock = new BlockUI(redBlockTexture, GlobalData.Theme["LightRed"], GlobalData.Theme["Red"]); BlockUI orangeBlock = new BlockUI(orangeBlockTexture, GlobalData.Theme["LightOrange"], GlobalData.Theme["Orange"]); BlockUI yellowBlock = new BlockUI(yellowBlockTexture, GlobalData.Theme["LightYellow"], GlobalData.Theme["Yellow"]); BlockUI greenBlock = new BlockUI(yellowBlockTexture, GlobalData.Theme["LightGreen"], GlobalData.Theme["Green"]); BlockUI blueBlock = new BlockUI(blueBlockTexture, GlobalData.Theme["LightBlue"], GlobalData.Theme["Blue"]); BlockUI cyanBlock = new BlockUI(cyanBlockTexture, GlobalData.Theme["LightCyan"], GlobalData.Theme["Cyan"]); BlockUI magentaBlock = new BlockUI(magentaBlockTexture, GlobalData.Theme["LightMagenta"], GlobalData.Theme["Magenta"]); BlockUI blackBlock = new BlockUI(blackBlockTexture, GlobalData.Theme["Dark"], GlobalData.Theme["Black"]); BlockUI grayBlock = new BlockUI(grayBlockTexture, GlobalData.Theme["LightGray"], GlobalData.Theme["Gray"]); BlockUI whiteBlock = new BlockUI(whiteBlockTexture, GlobalData.Theme["Silver"], GlobalData.Theme["White"]); return(new Dictionary <GameColor, BlockUI>() { { GameColor.Red, redBlock }, { GameColor.Orange, orangeBlock }, { GameColor.Yellow, yellowBlock }, { GameColor.Green, greenBlock }, { GameColor.Blue, blueBlock }, { GameColor.Cyan, cyanBlock }, { GameColor.Magenta, magentaBlock }, { GameColor.Gray, grayBlock }, { GameColor.Black, blackBlock }, { GameColor.White, whiteBlock }, }); }
private void OnMouseDown() { if (EventSystem.current.IsPointerOverGameObject()) { return; } BlockUI blockUI = Canvas.FindObjectOfType <BlockUI>(); blockUI.setBlock(this); GameObject.FindObjectOfType <BlockUI>().BroadcastMessage("UIExit"); //display UI according to the Block's status if (this.isOwned) { if (this.isEmpty) { blockUI.SendMessage("OwnedBlockPanelEntry"); } else { blockUI.SendMessage("BuildingInfoPanelEntry"); } } else { if (this.isEmpty) { blockUI.SendMessage("EmptyBlockPanelEntry"); } else { blockUI.SendMessage("EmptyBlockPanelEntry"); } } }
private void SetupClientUIs() { if (Main.netMode == 2) { return; } //Activation of the UIs colorUI = new ColorUI(); hammerUI = new HammerUI(); blockUI = new BlockUI(); mossUI = new MossUI(); colorUI.Activate(); hammerUI.Activate(); blockUI.Activate(); mossUI.Activate(); colorUserInterface = new UserInterface(); hammerUserInterface = new UserInterface(); blockUserInterface = new UserInterface(); mossUserInterface = new UserInterface(); blockUserInterface.SetState(blockUI); colorUserInterface.SetState(colorUI); hammerUserInterface.SetState(hammerUI); mossUserInterface.SetState(mossUI); }
public void HandlePathFindingInput(Vector3 blockCenter, int3 block) { if (!didStartPathFinding) { didStartPathFinding = true; Vector3 pos = Utils.CentrifyPosition(new Vector3(transform.position.x, transform.position.y + 0.5f, transform.position.z)); currentPathFinding = new PathFinding(pos, blockCenter); if (isOnManualPathFinding) { var moves = currentPathFinding.OpenPossibleNewMoves(pos); RemoveFromBlocksUIIfExists(moves); foreach (var node in moves) { var bUI = BlockUI.Create(Utils.WorldBlockPosForCenter(node.pos), int3.zero, String.Format("{0}\n{1}\n{2}", node.startValue, node.value, node.endValue)); blocksUI.Add(bUI); } var sbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(pos), int3.zero, "Start"); sbUI.ToggleSelection(); blocksUI.Add(sbUI); var fbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(blockCenter), int3.zero, "Finish"); fbUI.ToggleSelection(); blocksUI.Add(fbUI); } else { StartCoroutine(currentPathFinding.BuildPathToTarget(() => { if (currentPathFinding.isClosed) { foreach (var bbbUI in blocksUI) { GameObject.Destroy(bbbUI.gameObject); } foreach (var node in currentPathFinding.pathNodes) { var bbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(node.pos), int3.zero, String.Format("{0}\n{1}\n{2}", node.startValue, node.value, node.endValue)); blocksUI.Add(bbUI); } var sbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(currentPathFinding.startPos), int3.zero, "Start"); sbUI.ToggleSelection(); blocksUI.Add(sbUI); var fbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(currentPathFinding.endPos), int3.zero, "Finish"); fbUI.ToggleSelection(); blocksUI.Add(fbUI); } else { var poppedBottom = currentBlockDestroying.PopBottomBlock(); selectionController.Deselect(); aiState.mode = AIStateMode.Idle; currentBlockDestroying.UpdateDestroyBlockQueueUI(); } })); } } else if (blocksUI.Find(b => b.pos.Equals(blockCenter)) != null) { var n = currentPathFinding.SuggestNextNode(); var bUI = blocksUI.Find(b => b.pos.Equals(n.pos)); bUI.ToggleSelection(); var moves = currentPathFinding.OpenPossibleNewMoves(bUI.pos, n); RemoveFromBlocksUIIfExists(moves); foreach (var node in moves) { var bbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(node.pos), int3.zero, String.Format("{0}\n{1}\n{2}", node.startValue, node.value, node.endValue)); blocksUI.Add(bbUI); } if (currentPathFinding.CheckIfEnd(n)) { foreach (var bbbUI in blocksUI) { GameObject.Destroy(bbbUI.gameObject); } foreach (var node in currentPathFinding.pathNodes) { var bbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(node.pos), int3.zero, String.Format("{0}\n{1}\n{2}", node.startValue, node.value, node.endValue)); blocksUI.Add(bbUI); } var sbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(currentPathFinding.startPos), int3.zero, "Start"); sbUI.ToggleSelection(); blocksUI.Add(sbUI); var fbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(currentPathFinding.endPos), int3.zero, "Finish"); fbUI.ToggleSelection(); blocksUI.Add(fbUI); } } else { didStartPathFinding = false; foreach (var bUI in blocksUI) { GameObject.Destroy(bUI.gameObject); } blocksUI = new List <BlockUI>(); } }
public void GenerateBlockUI() { blockUI = Resources.Load <BlockUI>("UIs/Blocks/" + blockId); }