private void UpdateAttributeChoices() { string[] foundChoices = HexTypes.GetCompatibleAttrributes(hexType); attributeChoices = new string[foundChoices.Length + 1]; attributeChoices[0] = "None"; for (int i = 0; i < foundChoices.Length; ++i) { attributeChoices[i + 1] = foundChoices[i]; } }
public void ModifyType(HexTypes type) { switch (type) { case HexTypes.Hard: { Harden(); } break; case HexTypes.Enemy: { BecomeAnEnemy(); } break; case HexTypes.Hexposed: { ChangeState(HexStates.Full); } break; } }
void OnGUI() { //GUI.color = Color.grey; GUILayout.Window (0, menuWindowRect, MenuWindow, "", menuWindowStyle); hexes = GameObject.Find ("Hex Types").GetComponent<HexTypeScript> (); if(loadButton == true){ GUILayout.Window (1,new Rect(240,100,130,20), LevelLoad, ""); } //GameObject hex = hexes.hex; //var mats = hexes.mats; //mats = hexes.mats; GUI.Label (new Rect (10, 10, 100, 40), "HEIGHT:", labelStyle); GUI.Label (new Rect (10, 60, 100, 40), "WIDTH:", labelStyle); GUI.TextArea (new Rect (115, 10, 50, 40), height.ToString (), numStyle); GUI.TextArea (new Rect (115, 60, 50, 40), width.ToString (), numStyle); if (GUI.Button (new Rect (170, 12, 30, 15), "+")) { height++; } if (GUI.Button (new Rect (170, 33, 30, 15), "-")) { height--; } if (GUI.Button (new Rect (210, 12, 30, 15), "+X")) { height += 10; } if (GUI.Button (new Rect (210, 33, 30, 15), "-X")) { height -= 10; } if (GUI.Button (new Rect (170, 62, 30, 15), "+")) { width++; } if (GUI.Button (new Rect (170, 83, 30, 15), "-")) { width--; } if (GUI.Button (new Rect (210, 62, 30, 15), "+X")) { width += 10; } if (GUI.Button (new Rect (210, 83, 30, 15), "-X")) { width -= 10; } if (!newMap){ if(GUI.Button (new Rect (250, 20, 60, 70), "Create\n Map")){ newMap = true; GraphMap (); } } else{ levelName = GUI.TextArea (new Rect(10, 120, 200, 20), levelName); if(GUI.Button(new Rect(220, 120, 20, 20), "...")){ levelBtn = !levelBtn; } if(levelBtn){ /*Rect loadRect = new Rect(250, 120, 120, 10); Rect loadViewRect = new Rect(0, 0, 0, 20 * levels.Length); loadPosition = GUI.BeginScrollView(loadRect, loadPosition, loadViewRect); foreach(string level in levels){ if(GUILayout.Button (level)){ levelName = level; levelBtn = !levelBtn; } } GUI.EndScrollView ();*/ } if(GUI.Button (new Rect(20, 150, 80, 30), "Save Grid")){ Save (); } if(GUI.Button (new Rect(120, 150, 80, 30), "Load Grid")){ Load (); } if(GUI.Button (new Rect (250, 20, 60, 70), "Update\n Map")){ GraphMap (); } if (!raiseGround){ if (GUI.Button (new Rect( Screen.width - 300, 10, 80, 80), arrowUp)) { raiseGround = !raiseGround; lowerGround = false; paintTool = false; } } if (raiseGround){ isPainting = true; if (GUI.Button (new Rect( Screen.width - 300, 10, 80, 80), arrowUpPressed)){ raiseGround = !raiseGround; } } if (lowerGround){ isPainting = true; if (GUI.Button (new Rect( Screen.width - 215, 10, 80, 80), arrowDownPressed)){ lowerGround = !lowerGround; } } if (!lowerGround){ if (GUI.Button (new Rect( Screen.width - 215, 10, 80, 80), arrowDown)){ lowerGround = !lowerGround; raiseGround = false; paintTool = false; } } paintTool = GUI.Toggle (new Rect( Screen.width - 125, 10, 20, 20), paintTool, ""); if (paintTool){ isPainting = true; raiseGround = false; lowerGround = false; orePaintTool = false; } largeCursor = GUI.Toggle (new Rect(Screen.width - 127, 40, 30, 30), largeCursor, ""); //Material Painter Button, flip on Y if (GUI.Button (new Rect(Screen.width - 100, 10, 80, 80), painter.btn)){ painterBtn = !painterBtn; } if (painterBtn){ Rect scrollRect = new Rect(Screen.width - 100, 100, 100, 300); Rect scrollViewRect = new Rect(0, 0, 0, 75 * hexGroup.hexes.Length); scrollPosition = GUI.BeginScrollView (scrollRect, scrollPosition, scrollViewRect);//(scrollPosition, GUILayout.Width(100), GUILayout.Height(350)); for (int i = 0; i < hexGroup.hexes.Length; i++){ //if (GUILayout.Button (hexGroup.hexes[i].btn, GUILayout.Width (70), GUILayout.Height (70))){ if (GUILayout.Button (hexGroup.hexes[i].btn, emptyButtons, GUILayout.Width (70), GUILayout.Height (70))){ painter = hexGroup.hexes[i]; painterBtn = false; painterIndex = i; } } GUI.EndScrollView(); } orePaintTool = GUI.Toggle (new Rect (Screen.width - 270, 100, 15, 15), orePaintTool, ""); if (orePaintTool){ isPainting = true; raiseGround = false; lowerGround = false; paintTool = false; } if(GUI.Button (new Rect(Screen.width - 252.5f, 100, 70, 70), orePainter, emptyButtons)){ orePaintMenu = !orePaintMenu; } if (orePaintMenu){ Array.Resize (ref oreBools, oreTextures.Length); float originX = (float)(Screen.width - 252.5f + 35.0f); float originY = 100.0f + 35.0f; //circleMenu (90, 180, oreTextures.Length, new Vector3(originX, originY, 0f), 70f, oreTextures); float minRange = 0f; float maxRange = 180f; float size = 55f; int num = oreBools.Length; float spread = (maxRange - minRange) / (num - 1); float r = size + (size / 2); float R1; float R2; for( int i = 0; i < num; i++ ){ R1 = (float)((r * Math.Cos((Math.PI / 180)*(minRange + (spread * i))) + originX) - (size / 2)); R2 = (float)((r * Math.Sin((Math.PI / 180)*(minRange + (spread * i))) + originY) - (size / 2)); oreBools[i] = GUI.Button (new Rect( R1, R2, size, size), oreTextures[i], emptyButtons); if ( oreBools[i] ){ orePaintMenu = false; orePaint = i; orePainter = oreTextures [orePaint]; } } } if(GUI.Button (new Rect (Screen.width / 2 - 75, 10, 70, 70), "Player\nStart")){ pStart = GameObject.CreatePrimitive(PrimitiveType.Cylinder); pStart.transform.localScale = new Vector3(2f, 0.1f, 2f); } if(GUI.Button (new Rect (Screen.width / 2 + 5, 10, 70, 70), "Enemy\nStart")){ } /* border.SetPosition (0, new Vector3(0.1f, 1f, 0f)); border.SetPosition (1, new Vector3(width * hexW - 0.6f, 1f, 0f)); border.SetPosition (2, new Vector3(width * hexW - 0.6f, 1f, height * hexH - hexH)); border.SetPosition (3, new Vector3(0.1f, 1f, height * hexH - hexH)); border.SetPosition (4, new Vector3(0.1f, 1f, 0f)); */ } }
void Awake() { border = GetComponent<LineRenderer> (); painter = hexGroup.hexes [0]; scrollPosition = new Vector2 (Screen.width - 100, 100); var path = new DirectoryInfo (Application.persistentDataPath); var levelFiles = path.GetFiles(); foreach (FileInfo file in levelFiles) { if(file.Name.Contains(".hex")){//".hex")){ Array.Resize (ref levels, levels.Length + 1); levels[levels.Length - 1] = file.Name.Remove(file.Name.Length - 4); //Debug.Log (levels[levels.Length - 1]); } } menuWindowRect = new Rect(0, 0, Screen.width, 50); orePainter = oreTextures [orePaint]; }
public void GenerateMap() { if (mapWasGenerated) { Debug.LogError("Someone's trying to regenerate the map!"); } mapCentre = mapZone.transform.position; hexes = new Hex[numberOfColumns, numberOfRows]; Transform myTransform = transform; Bounds zoneBounds = mapZone.bounds; List <Hex> realHexesList = new List <Hex>(32); lowHexesTransforms = new List <Transform>(32); Wall[] walls = FindObjectsOfType <Wall>(); for (int column = 0; column < numberOfColumns; column++) { for (int row = 0; row < numberOfRows; row++) { Vector3 hexPosition = Hex.PositionInWorld(column, row); bool hexIsInBounds = zoneBounds.Contains(hexPosition); /* (hexPosition.x >= bounds.min.x && * hexPosition.x <= bounds.max.x && * hexPosition.z >= bounds.min.z && * hexPosition.z <= bounds.max.z);*/ if (hexIsInBounds) { HexTypes modifiedType = HexTypes.Floor; for (int i = 0; i < walls.Length; i++) { Bounds wallBounds = walls[i].collider.bounds; if (wallBounds.Contains(hexPosition)) { modifiedType = walls[i].hexType; break; } } //Find Mat ushort bestMatIndex; { Color32 bestColour = GetBackgroundColourFromBounds(hexPosition, zoneBounds, backGroundTexture); if (useDynamicColours) { ushort?index = FindClosestDynamicMaterial(bestColour); if (index == null) { Material mat = new Material(dynamicColourMat); mat.color = bestColour; dynamicHexColouredMaterials.Add(mat); bestMatIndex = (ushort)(dynamicHexColouredMaterials.Count - 1); } else { bestMatIndex = (ushort)index; } } else { bestMatIndex = FindClosestMaterialIndex(bestColour); } } byte bestFailureMatIndex; { Color32 bestColour = GetBackgroundColourFromBounds(hexPosition, zoneBounds, FailureTexture); byte?index = FindClosestFailureDynamicMaterial(bestColour); if (index == null) { Material mat = new Material(dynamicColourMat); mat.color = bestColour; dynamicFailureColouredMaterials.Add(mat); bestFailureMatIndex = (byte)(dynamicFailureColouredMaterials.Count - 1); } else { bestFailureMatIndex = (byte)index; } } Hex hex = Instantiate(hexPreFab); hex.transform.parent = myTransform; hex.Construct(bestMatIndex, bestFailureMatIndex); hex.transform.position = hexPosition; if (modifiedType != HexTypes.Floor) { hex.ModifyType(modifiedType); } else if (generateRandomThings) { if (Random.Range(0, bombGenerationChance) == 0) { HexBomb hexBomb = Instantiate (hexBombPreFab, hexPosition, Quaternion.identity); hexBomb.hex = hex; } else if (Random.Range(0, hardHexGenerationChance) == 0) { hex.ModifyType(HexTypes.Hard); } else if (Random.Range(0, enemyHexGenerationChance) == 0) { hex.ModifyType(HexTypes.Enemy); } } hexes[column, row] = hex; realHexesList.Add(hex); if (hex.State == HexStates.Empty && hex.Specialty == HexSpecialties.None) { lowHexesTransforms.Add(hex.transform); } } //Material hexMaterial = GetMaterialForHex(hex); //hexComponent.GetComponentInChildren<MeshRenderer>().material = hexMaterial; //hexComponent.SetHex(hex); /* if (hexComponent.GetComponentInChildren<TMPro.TextMeshPro>()) * { * hexComponent.GetComponentInChildren<TMPro.TextMeshPro>().text = column + "," + row; * }*/ // if(column == 0 && row == 0) /* { * GameObject hexModel = Instantiate(hexModelPreFab, hex.PositionInWorld(), Quaternion.identity); * hexModel.transform.parent = transform; * }*/ // hexComponent.GetComponentInChildren<TMPro.TextMeshPro>().enabled=false; } } //Nesssary stuff for (int column = 0; column < numberOfColumns; column++) { for (int row = 0; row < numberOfRows; row++) { if (hexes[column, row] != null) { Hex hex = hexes[column, row]; hex.SetNeighbours(column, row); /*bool isFillable = (hex.State == HexStates.Empty); * hex.fillMark = isFillable ? UNFILLED : FILLED;*/ } } } //FloodFillMapIsClear = true; realHexes = realHexesList.ToArray(); Debug.Log("Hexes Count: " + realHexes.Length); for (int i = 0; i < walls.Length; i++) { Destroy(walls[i].gameObject);////0; } Destroy(mapZone.gameObject); #region irrelevant //StaticBatchingUtility.Combine(gameObject); //waterHexMesh = Instantiate(combineableMeshPreFab, transform.position, Quaternion.identity,transform); /*mildClimateHexMeshes = new CombineableMesh[mildClimateMaterials.Length]; * for (int i = 0; i < mildClimateHexMeshes.Length; i++) * { * mildClimateHexMeshes[i] = Instantiate(combineableMeshPreFab, transform.position, Quaternion.identity, transform); * } * * for (int i = 0; i < mildClimateHexMeshes.Length; i++) * { * mildClimateHexMeshes[i].CombineMeshes(mildClimateMaterials[i]); * }*/ #endregion HexBomb[] bombs = FindObjectsOfType <HexBomb>(); for (int i = 0; i < bombs.Length; i++) { HexBomb bomb = bombs[i]; Vector3 bombPosition = bomb.transform.position; Hex hexAtPosition = GetHex(Hex.GetHexCoordinates(bombPosition)); if (hexAtPosition != null) { bomb.transform.position = new Vector3 (hexAtPosition.transform.position.x, bombPosition.y, hexAtPosition.transform.position.z); bomb.hex = hexAtPosition; //TODO: not elegant at allllkl } } mapWasGenerated = true; }
public void SetSelectedObject(GameObject objectIn) { currentlySelectedObject = objectIn; currentHexType = objectIn.GetComponent <Hex>().getType(); }