예제 #1
0
 /// <summary>
 /// Applies a random extrusion to all tiles
 /// </summary>
 void RandomExtrusion()
 {
     hexa.extruded          = true;
     hexa.extrudeMultiplier = 0.05f;
     for (int k = 0; k < hexa.tiles.Length; k++)
     {
         float extrusionAmount = UnityEngine.Random.value;
         if (extrusionAmount > 0.015f)
         {
             hexa.SetTileExtrudeAmount(k, extrusionAmount);
             Color landColor = new Color(0, extrusionAmount, 0);
             hexa.SetTileColor(k, landColor);
         }
         else
         {
             hexa.SetTileExtrudeAmount(k, 0f);
             hexa.SetTileColor(k, new Color(0f, 0.411f, 0.58f));
         }
     }
     animateTileIndex = Random.Range(0, hexa.tiles.Length - 1);
     hexa.FlyTo(animateTileIndex, 2f);
 }
예제 #2
0
        void TileMouseOver(int tileIndex)
        {
            // Get color of current cell
            Color32 cellColor = hexa.GetTileColor(tileIndex, true);

            // If color is same, don't do anything
            if (cellColor.r == currentColor.r && cellColor.g == currentColor.g && cellColor.b == currentColor.b)
            {
                return;
            }

            // Clears temporary colors
            hexa.ClearTiles(true, false, false);

            // Reset extrusion
            hexa.ClearTilesExtrusion();

            // Select cell
            currentColor = cellColor;

            // If current cell is "sea", ignore and return
            if (currentColor.r == seaColor.r && currentColor.g == seaColor.g && currentColor.b == seaColor.b)
            {
                cycleColorsEnabled = false;
                return;
            }

            // Select tiles with same color
            currentTerritoryTiles.Clear();
            for (int k = 0; k < hexa.tiles.Length; k++)
            {
                if (hexa.GetTileColor(k, true) == currentColor)
                {
                    currentTerritoryTiles.Add(k);
                }
            }

            // Extrude tiles
            hexa.SetTileExtrudeAmount(currentTerritoryTiles, 0.5f);

            // Enable territory highlight color cycle
            cycleColorsEnabled = true;
            blinkBit           = false;
        }
예제 #3
0
        void Update()
        {
            // Updates extrusion amount for each tile; doing it this way for all tiles and every frame can be consuming, but this is an example
            float time = Time.time * 5f;

            for (int tileIndex = 0; tileIndex < hexa.tiles.Length; tileIndex++)
            {
                // directly get the center from the field value instead of calling GetTileCenter
                Vector3 pos = hexa.tiles [tileIndex].center;
                // distance from tile to epicenter
                float distance = 1.0f + (pos - epicenter).sqrMagnitude * 50f;
                // calculate wave
                float extrusionAmount = 0.5f + Mathf.Sin(-time + distance * 10f) * 0.5f / (distance * distance);
                // make average with previous value to smooth changes
                extrusionAmount = (extrusionAmount + hexa.tiles[tileIndex].extrudeAmount) * 0.5f;
                // Set new extrusion amount for this tile
                hexa.SetTileExtrudeAmount(tileIndex, extrusionAmount);
            }

            if (Time.time - lastQuakeTime > 10f)
            {
                NewQuake();
            }
        }