private void CheckMove(GameObject go) { ClickBehaviour clickBehaviour = go.GetComponent <ClickBehaviour>(); if (!lastGo) { lastGo = go; counter++; clickBehaviour.hold = true; return; } if (Utilites.GetLocalNeighbourPositions(go).Contains(lastGo.transform.localPosition)) { lastGo = go; clickBehaviour.hold = !clickBehaviour.hold; counter++; } else { lastGo = null; counter = 0; Utilites.ResetButtonsState(buttons); } }
void Awake() { attachedDrag = GetComponent <DragBehaviour>(); attachedClick = GetComponent <ClickBehaviour>(); image = transform.GetChild(1).GetComponent <Image>(); highlight = GetComponent <Image>(); text = transform.GetChild(2).GetComponentInChildren <Text>(); costBanner = image.transform.GetChild(0).gameObject; typeBanner = transform.GetChild(3).GetComponent <Image>(); grayout = transform.GetChild(4).gameObject; }
private void Start() { ClickListener.ObjClicked += CheckMove; GameObject[] objects = GameObject.FindGameObjectsWithTag("Button"); foreach (var obj in objects) { ClickBehaviour clickBehaviour = obj.GetComponent <ClickBehaviour>(); buttons.Add(clickBehaviour); //Debug.Log($"{GetInvertedPosition(clickBehaviour.transform.position)} - {obj.name}"); } }
private void CheckClick(GameObject go) { var item = go.GetComponent <ClickBehaviour>(); curDice = item; if (lastDice == null) { lastDice = item; var diceI = dices.Find(diceItem => ReferenceEquals(diceItem, lastDice)); diceI.ToggleHold(); lastDiceIndex = dices.IndexOf(diceI); return; } int lastDiceValue = int.Parse(lastDice.name); lastDiceIndex = dices.IndexOf(lastDice); var moveTo = lastDiceIndex + lastDiceValue; if (moveTo >= dicesLength) { moveTo = Mathf.Abs(dicesLength - moveTo); } if (ReferenceEquals(curDice, dices[moveTo])) { curDice.ToggleHold(); lastDice = curDice; lastDiceIndex = dices.IndexOf(curDice); } else { lastDice = null; Utilites.ResetButtonsState(dices); } CheckWin(); }
void ClickHandler(ClickBehaviour cb) { switch (cb.name.ToLower()) { case "my-computer": cb.MouseDown.AddListener(() => { var go = Instantiate <GameObject>(Resources.Load <GameObject>("Prefabs/Windows/WindowContent")); go.name = "Computer"; var title = go.GetComponent <ContentPointer>().Title.GetComponent <Text>(); title.text = go.name; go.transform.SetParent(GameObject.Find("Window Container").transform); go.transform.localPosition = new Vector3(0f, 0f); }); break; case "32-32_orange": cb.MouseDown.AddListener(() => Assets.Scripts.Misc.Logging.Debug.Log($"ORANGE")); break; default: cb.MouseDown.AddListener(() => Assets.Scripts.Misc.Logging.Debug.Log($"Sprite {cb.name} was clicked")); break; } }
void OnGUI() { if (currentState == EditorState.Creation) { GUI.BeginGroup (new Rect (Screen.width / 2 - 100, Screen.height / 2 - 100, 200, 200)); GUI.Box (new Rect (0, 0, 200, 200), "Options"); GUI.Label (new Rect (10, 10, 180, 20), "Width"); width = GUI.TextField (new Rect (10, 40, 180, 20), width); GUI.Label (new Rect (10, 60, 180, 20), "Height"); height = GUI.TextField (new Rect (10, 90, 180, 20), height); GUI.Label (new Rect (10, 110, 180, 20), "Export To"); fileName = GUI.TextField (new Rect(10, 130, 180, 20), fileName); float testW = 0; float testH = 0; if (float.TryParse (width, out testW) && float.TryParse (height, out testH) && fileName != "") { if (GUI.Button (new Rect (40, 160, 120, 30), "Create Map")) { canvas = new GameObject ("Canvas"); MeshFilter newFilter = canvas.AddComponent<MeshFilter> (); newFilter.mesh = new Mesh (); float widthNum = float.Parse (width) / 2; float heightNum = float.Parse (height) / 2; newFilter.mesh.vertices = new Vector3[4] { new Vector3 (-widthNum, -heightNum, 0), new Vector3 (widthNum, -heightNum, 0), new Vector3 (widthNum, heightNum, 0), new Vector3 (-widthNum, heightNum, 0) }; newFilter.mesh.triangles = new int[6]{0,2,1,0,3,2}; newFilter.mesh.RecalculateNormals (); MeshRenderer newRenderer = canvas.AddComponent<MeshRenderer> (); newRenderer.material.shader = Shader.Find ("Sprites/Default"); newRenderer.material.color = Color.grey; canvas.AddComponent<MeshCollider> (); CanvasClick newClick = new CanvasClick(); newClick.parentCC = this; currentClick = newClick; CameraMove cameraMove = Camera.main.GetComponent<CameraMove>(); cameraMove.xBound = widthNum; cameraMove.yBound = heightNum; currentState = EditorState.Editing; } } GUI.EndGroup (); } else if (currentState == EditorState.Editing) { GUI.BeginGroup (new Rect (0, 0, 200, 150)); GUI.Box (new Rect (0, 0, 200, 150), "Options"); GUI.Label (new Rect (20, 30, 160, 20), "Node count: " + nodes.Count.ToString ()); GUI.Label (new Rect (20, 50, 160, 20), "Link count: " + links.Count.ToString ()); if (nodes.Count == 0) { if (GUI.Button (new Rect (40, 70, 120, 30), "Delete Canvas")) { GameObject.Destroy (canvas); } } else { if (GUI.Button (new Rect (40, 110, 120, 30), "Convert Countries")) { if(ConvertCountries ()) { foreach(CNode node in nodes) { Destroy (node.gameObject); } Destroy(canvas); currentClick = new CountryClick(); currentState = EditorState.Finalising; } } } GUI.EndGroup (); } else if (currentState == EditorState.Finalising) { int groupWidth = 100; GUI.BeginGroup(new Rect(0, 0, groupWidth*factions.Count + 50, 180)); for(int factionCount = 0; factionCount < factions.Count; factionCount++) { Faction faction = factions[factionCount]; GUI.Box( new Rect(groupWidth*factionCount, 0, groupWidth, 180), faction.factionName); if(factionCount != 0) { faction.factionName = GUI.TextField(new Rect(groupWidth*factionCount + 10, 20, groupWidth-20, 30), faction.factionName); } else { GUI.Label(new Rect(groupWidth*factionCount + 10, 20, groupWidth-20, 30), faction.factionName); } GUI.Label (new Rect(groupWidth*factionCount + 10, 60, groupWidth-20, 20), "Countries: " + faction.countries.Count.ToString()); faction.colorString = GUI.TextField(new Rect(groupWidth*factionCount + 10, 80, groupWidth-20, 20), faction.colorString); if(faction.colorString.Length == 6) { bool canParse = true; for(int i = 0; i < faction.colorString.Length; i += 2) { byte outByte; if(!byte.TryParse(faction.colorString.Substring(0,2), System.Globalization.NumberStyles.HexNumber, null, out outByte)) { canParse = false; } } if(canParse) { if(GUI.Button (new Rect(groupWidth*factionCount + 10, 110, groupWidth-20, 20), "Colour")) { faction.factionColor = MeshMaker.HexToColor(faction.colorString); faction.ColorCountries(); } } } if(factionCount != 0) { if(GUI.Button (new Rect(groupWidth*factionCount + 10, 140, groupWidth-20, 20), "Delete")) { factions.Remove (faction); while(faction.countries.Count != 0) { factions[0].AddCountry(faction.countries[0]); } factionCount--; } } } GUI.Box (new Rect(groupWidth*factions.Count, 50, 50, 50), ""); if(GUI.Button (new Rect(groupWidth*factions.Count, 50, 50, 50), "+")) { factions.Add (new Faction()); } GUI.EndGroup(); GUI.BeginGroup (new Rect(0, Screen.height - 90, 100, 90)); GUI.Box (new Rect(0, 0, 100, 90), "Final Conversion"); if(GUI.Button(new Rect(10, 30, 90, 30), "Convert")) { warningLabel = CanExportMap(); if(warningLabel == "") { ExportMap(); } } GUI.Label (new Rect(10, 70, 90, 20), warningLabel); GUI.EndGroup(); } }
void OnGUI() { if (currentState == EditorState.Creation) { GUI.BeginGroup(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 100, 200, 200)); GUI.Box(new Rect(0, 0, 200, 200), "Options"); GUI.Label(new Rect(10, 10, 180, 20), "Width"); width = GUI.TextField(new Rect(10, 40, 180, 20), width); GUI.Label(new Rect(10, 60, 180, 20), "Height"); height = GUI.TextField(new Rect(10, 90, 180, 20), height); GUI.Label(new Rect(10, 110, 180, 20), "Export To"); fileName = GUI.TextField(new Rect(10, 130, 180, 20), fileName); float testW = 0; float testH = 0; if (float.TryParse(width, out testW) && float.TryParse(height, out testH) && fileName != "") { if (GUI.Button(new Rect(40, 160, 120, 30), "Create Map")) { canvas = new GameObject("Canvas"); MeshFilter newFilter = canvas.AddComponent <MeshFilter> (); newFilter.mesh = new Mesh(); float widthNum = float.Parse(width) / 2; float heightNum = float.Parse(height) / 2; newFilter.mesh.vertices = new Vector3[4] { new Vector3(-widthNum, -heightNum, 0), new Vector3(widthNum, -heightNum, 0), new Vector3(widthNum, heightNum, 0), new Vector3(-widthNum, heightNum, 0) }; newFilter.mesh.triangles = new int[6] { 0, 2, 1, 0, 3, 2 }; newFilter.mesh.RecalculateNormals(); MeshRenderer newRenderer = canvas.AddComponent <MeshRenderer> (); newRenderer.material.shader = Shader.Find("Sprites/Default"); newRenderer.material.color = Color.grey; canvas.AddComponent <MeshCollider> (); CanvasClick newClick = new CanvasClick(); newClick.parentCC = this; currentClick = newClick; CameraMove cameraMove = Camera.main.GetComponent <CameraMove>(); cameraMove.xBound = widthNum; cameraMove.yBound = heightNum; currentState = EditorState.Editing; } } GUI.EndGroup(); } else if (currentState == EditorState.Editing) { GUI.BeginGroup(new Rect(0, 0, 200, 150)); GUI.Box(new Rect(0, 0, 200, 150), "Options"); GUI.Label(new Rect(20, 30, 160, 20), "Node count: " + nodes.Count.ToString()); GUI.Label(new Rect(20, 50, 160, 20), "Link count: " + links.Count.ToString()); if (nodes.Count == 0) { if (GUI.Button(new Rect(40, 70, 120, 30), "Delete Canvas")) { GameObject.Destroy(canvas); } } else { if (GUI.Button(new Rect(40, 110, 120, 30), "Convert Countries")) { if (ConvertCountries()) { foreach (CNode node in nodes) { Destroy(node.gameObject); } Destroy(canvas); currentClick = new CountryClick(); currentState = EditorState.Finalising; } } } GUI.EndGroup(); } else if (currentState == EditorState.Finalising) { int groupWidth = 100; GUI.BeginGroup(new Rect(0, 0, groupWidth * factions.Count + 50, 180)); for (int factionCount = 0; factionCount < factions.Count; factionCount++) { Faction faction = factions[factionCount]; GUI.Box(new Rect(groupWidth * factionCount, 0, groupWidth, 180), faction.factionName); if (factionCount != 0) { faction.factionName = GUI.TextField(new Rect(groupWidth * factionCount + 10, 20, groupWidth - 20, 30), faction.factionName); } else { GUI.Label(new Rect(groupWidth * factionCount + 10, 20, groupWidth - 20, 30), faction.factionName); } GUI.Label(new Rect(groupWidth * factionCount + 10, 60, groupWidth - 20, 20), "Countries: " + faction.countries.Count.ToString()); faction.colorString = GUI.TextField(new Rect(groupWidth * factionCount + 10, 80, groupWidth - 20, 20), faction.colorString); if (faction.colorString.Length == 6) { bool canParse = true; for (int i = 0; i < faction.colorString.Length; i += 2) { byte outByte; if (!byte.TryParse(faction.colorString.Substring(0, 2), System.Globalization.NumberStyles.HexNumber, null, out outByte)) { canParse = false; } } if (canParse) { if (GUI.Button(new Rect(groupWidth * factionCount + 10, 110, groupWidth - 20, 20), "Colour")) { faction.factionColor = MeshMaker.HexToColor(faction.colorString); faction.ColorCountries(); } } } if (factionCount != 0) { if (GUI.Button(new Rect(groupWidth * factionCount + 10, 140, groupWidth - 20, 20), "Delete")) { factions.Remove(faction); while (faction.countries.Count != 0) { factions[0].AddCountry(faction.countries[0]); } factionCount--; } } } GUI.Box(new Rect(groupWidth * factions.Count, 50, 50, 50), ""); if (GUI.Button(new Rect(groupWidth * factions.Count, 50, 50, 50), "+")) { factions.Add(new Faction()); } GUI.EndGroup(); GUI.BeginGroup(new Rect(0, Screen.height - 90, 100, 90)); GUI.Box(new Rect(0, 0, 100, 90), "Final Conversion"); if (GUI.Button(new Rect(10, 30, 90, 30), "Convert")) { warningLabel = CanExportMap(); if (warningLabel == "") { ExportMap(); } } GUI.Label(new Rect(10, 70, 90, 20), warningLabel); GUI.EndGroup(); } }
private void PlaceBallMillButton_Click(object sender, RoutedEventArgs e) { ToggleButton((Button) sender); _clickBehaviour = ClickBehaviour.PlaceBallMill; }
private void DebugButton_OnClick(object sender, RoutedEventArgs e) { ToggleButton((Button)sender); _clickBehaviour = ClickBehaviour.ToggleDebug; }
private void CleareButton_OnClick(object sender, RoutedEventArgs e) { ToggleButton((Button) sender); _clickBehaviour = ClickBehaviour.Clear; }
private void AddSteamButton_Click(object sender, RoutedEventArgs e) { ToggleButton((Button) sender); _clickBehaviour = ClickBehaviour.AddSteam; }
private void CheckClick(GameObject go) { ClickBehaviour clickBehaviour = go.GetComponent <ClickBehaviour>(); if (clickBehaviour.hold) { ResetTable(); return; } clickBehaviour.hold = true; if (!lastGo) { counter++; lastGo = go; return; } var goPos = go.transform.localPosition; var lastPos = lastGo.transform.localPosition; switch (lastGo.name) { case "D": if (lastPos.x == goPos.x && lastPos.y > goPos.y) { DoAction(go); } else { ResetTable(); } break; case "U": if (lastPos.x == goPos.x && lastPos.y < goPos.y) { DoAction(go); } else { ResetTable(); } break; case "R": if (lastPos.x < goPos.x && lastPos.y == goPos.y) { DoAction(go); } else { ResetTable(); } break; case "L": if (lastPos.x > goPos.x && lastPos.y == goPos.y) { DoAction(go); } else { ResetTable(); } break; case "Cross": ResetTable(); break; } CheckWin(); }