IEnumerator CycleColors() { while (true) { if (cycleColorsEnabled) { // Alternate between colors blinkBit = !blinkBit; Color currentColor = Color.yellow; Color darkerColor = Color.blue; if (hexa.lastHighlightedTileIndex >= 0) { // get one color from current tile currentColor = hexa.GetTileColor(hexa.lastHighlightedTileIndex, true); // make second color darker darkerColor = currentColor; darkerColor.r *= 0.8f; darkerColor.g *= 0.8f; darkerColor.b *= 0.8f; } blinkColor = blinkBit ? darkerColor : currentColor; // Change all cells with same color than selected cell to red and start animation hexa.SetTileColor(currentTerritoryTiles, blinkColor, true); } yield return(new WaitForSeconds(0.3f)); } }
void Start() { // Gets the script for the "Hexasphere" gameobject hexa = Hexasphere.GetInstance("Hexasphere"); hexa.OnTileClick += TileClick; hexa.OnTileMouseOver += TileMouseOver; // Color North in red int ti = hexa.GetTileAtPos(new Vector3(0, 50, 55)); hexa.SetTileColor(ti, Color.red); // Color opposite tile (South) in blue ti = hexa.GetTileAtPolarOpposite(ti); hexa.SetTileColor(ti, Color.blue); // Color opposite tile (Horizon) in green ti = hexa.GetTileAtPos(new Vector3(0, 0, 5)); hexa.SetTileColor(ti, Color.green); }
void OnSceneGUI() { if (hexa == null || Application.isPlaying || !hexa.enableGridEditor) { return; } Event e = Event.current; bool gridHit = hexa.CheckRay(HandleUtility.GUIPointToWorldRay(e.mousePosition)); if (tileHighlightedIndex != hexa.lastHighlightedTileIndex) { tileHighlightedIndex = hexa.lastHighlightedTileIndex; SceneView.RepaintAll(); } int count = tileSelectedIndices.Count; for (int k = 0; k < count; k++) { int idx = tileSelectedIndices [k]; Vector3 pos = hexa.GetTileCenter(idx); Handles.color = colorSelection; Handles.DrawSolidDisc(pos, hexa.tiles [idx].center, HandleUtility.GetHandleSize(pos) * 0.075f); } if (tileHighlightedIndex < 0) { return; } bool redraw = false; if ((e.type == EventType.MouseDown && e.isMouse && e.button == 0) || e.shift) { if (gridHit && e.type == EventType.MouseDown) { e.Use(); } if (!e.shift && tileSelectedIndices.Contains(tileHighlightedIndex)) { tileSelectedIndices.Remove(tileHighlightedIndex); } else { if (!e.control) { tileSelectedIndices.Clear(); } tileSelectedIndices.Add(tileHighlightedIndex); if (textureMode > 0) { hexa.SetTileTexture(tileHighlightedIndex, textureMode, Color.white); redraw = true; } if (!e.shift) { tileColor = hexa.GetTileColor(tileHighlightedIndex); if (tileColor.a == 0) { tileColor = Color.white; } tileTextureIndex = hexa.GetTileTextureIndex(tileHighlightedIndex); } tileTag = hexa.GetTileTag(tileHighlightedIndex); tileTagInt = hexa.GetTileTagInt(tileHighlightedIndex); EditorUtility.SetDirty(target); } } if (e.shift) { if (e.keyCode == KeyCode.S) { if (tileTextureIndex == 0) { hexa.SetTileColor(tileHighlightedIndex, tileColor); } else { hexa.SetTileTexture(tileHighlightedIndex, tileTextureIndex, tileColor, false); } redraw = true; e.Use(); } else if (e.keyCode == KeyCode.C) { hexa.ClearTile(tileHighlightedIndex); redraw = true; e.Use(); } } if (redraw) { SceneView.RepaintAll(); } if (gridHit) { Selection.activeGameObject = hexa.transform.gameObject; } }
void OnGUI() { if (avoidGUI) { return; } GUI.Label(new Rect(10, 10, 220, 30), divisionsText); divisions = (int)GUI.HorizontalSlider(new Rect(10, 30, 220, 30), divisions, 2, 100); if (divisions != hexa.numDivisions) { hexa.numDivisions = divisions; divisionsText = "Divisions (" + hexa.tiles.Length + " tiles)"; } GUI.Label(new Rect(10, 60, 220, 30), "Divisions"); bool wireframe = GUI.Toggle(new Rect(10, 80, 220, 20), hexa.style == STYLE.Wireframe, "Wireframe"); if (wireframe) { hexa.style = STYLE.Wireframe; } bool shaded = GUI.Toggle(new Rect(10, 100, 220, 20), hexa.style == STYLE.Shaded, "Shaded"); if (shaded) { hexa.style = STYLE.Shaded; } bool shadedWireframe = GUI.Toggle(new Rect(10, 120, 220, 20), hexa.style == STYLE.ShadedWireframe, "Shaded + Wireframe"); if (shadedWireframe) { hexa.style = STYLE.ShadedWireframe; } if (GUI.Button(new Rect(10, 155, 220, 30), "Paint Mode")) { if (selectMode != DEMO_MODE.Paint) { selectMode = DEMO_MODE.Paint; } else { selectMode = DEMO_MODE.Idle; } } bool prevPaintColor = paintInColor; paintInColor = GUI.Toggle(new Rect(10, 190, 200, 20), paintInColor, "Color"); paintInColor = !GUI.Toggle(new Rect(10, 210, 200, 20), !paintInColor, "Texture"); if (prevPaintColor != paintInColor) { selectMode = DEMO_MODE.Paint; } if (GUI.Button(new Rect(10, 240, 100, 30), "Colorize")) { RandomColors(); } if (GUI.Button(new Rect(120, 240, 110, 30), "Extrusion")) { if (hexa.extruded) { hexa.extruded = false; RandomColors(); } else { RandomExtrusion(); } } if (GUI.Button(new Rect(10, 280, 220, 30), "Random Obstacles")) { RandomObstacles(); } if (GUI.Button(new Rect(10, 320, 220, 30), "Clear Tiles")) { ClearTiles(); } if (GUI.Button(new Rect(10, 360, 100, 30), "Random Path")) { RandomPath(); } if (GUI.Button(new Rect(120, 360, 110, 30), "Custom Path")) { selectMode = DEMO_MODE.PathFind_StartTile; } if (GUI.Button(new Rect(10, 400, 220, 30), "Load Heightmap")) { if (divisions < 50) { Debug.Log("Hint: increase hexasphere divisions for heightmap sample."); } hexa.extrudeMultiplier = 0.1f; hexa.ApplyHeightMap(heightMap, waterMask); } if (labelStyle == null) { labelStyle = new GUIStyle(GUI.skin.label); labelStyle.normal.textColor = Color.yellow; } switch (selectMode) { case DEMO_MODE.Paint: GUI.Label(new Rect(10, 440, 220, 30), "Click to paint a tile.", labelStyle); break; case DEMO_MODE.PathFind_StartTile: GUI.Label(new Rect(10, 440, 220, 30), "Click to select starting tile.", labelStyle); break; case DEMO_MODE.PathFind_EndTile: GUI.Label(new Rect(10, 440, 220, 30), "Click to finish path.", labelStyle); break; } if (hexa.lastHighlightedTileIndex >= 0) { GUI.Label(new Rect(10, 460, 220, 30), "Highlighted Tile # = " + hexa.lastHighlightedTileIndex.ToString(), labelStyle); } if (Input.GetKeyDown(KeyCode.S)) { hexa.SetTileColor(hexa.lastHighlightedTileIndex, Color.white); } if (GUI.Button(new Rect(Screen.width - 230, 10, 220, 30), "Spawn Objects")) { SpawnObjects(); } if (GUI.Button(new Rect(Screen.width - 230, 50, 220, 30), "Spawn Texts")) { SpawnTexts(); } if (GUI.Button(new Rect(Screen.width - 230, 90, 220, 30), "Parent Sprite")) { ParentSprite(); } }