Example #1
0
 void EditCell(SquareCell cell, Vector3 hitpoint)
 {
     if (activeMode == EditMode.color)
     {
         cell.Tile = activeTileMaterial.GetClone;
     }
     else if (activeMode == EditMode.elevation)
     {
         GridDirection vertex = squareGrid.GetVertex(hitpoint);
         if (Input.GetMouseButton(0) && (stopWatch.ElapsedMilliseconds > 500f || freshClick))
         {
             cell.ChangeVertexElevation(vertex, 1);
             if (!allowCliffs)
             {
                 if (cell.GetNeighbor(vertex))
                 {
                     cell.GetNeighbor(vertex).ChangeVertexElevation(vertex.Opposite(), 1);
                 }
                 if (cell.GetNeighbor(vertex.Next()))
                 {
                     cell.GetNeighbor(vertex.Next()).ChangeVertexElevation(vertex.Previous2(), 1);
                 }
                 if (cell.GetNeighbor(vertex.Previous()))
                 {
                     cell.GetNeighbor(vertex.Previous()).ChangeVertexElevation(vertex.Next2(), 1);
                 }
             }
             stopWatch.Reset();
             stopWatch.Start();
         }
         if (Input.GetMouseButton(1) && (stopWatch.ElapsedMilliseconds > 500f || freshClick))
         {
             cell.ChangeVertexElevation(vertex, -1);
             if (!allowCliffs)
             {
                 if (cell.GetNeighbor(vertex))
                 {
                     cell.GetNeighbor(vertex).ChangeVertexElevation(vertex.Opposite(), -1);
                 }
                 if (cell.GetNeighbor(vertex.Next()))
                 {
                     cell.GetNeighbor(vertex.Next()).ChangeVertexElevation(vertex.Previous2(), -1);
                 }
                 if (cell.GetNeighbor(vertex.Previous()))
                 {
                     cell.GetNeighbor(vertex.Previous()).ChangeVertexElevation(vertex.Next2(), -1);
                 }
             }
             stopWatch.Reset();
             stopWatch.Start();
         }
     }
     else if (activeMode == EditMode.rivers)
     {
         if (Input.GetMouseButton(1))
         {
             cell.RemoveRivers();
             Explosion(cell);
         }
         else if (isDrag)
         {
             SquareCell otherCell = cell.GetNeighbor(dragDirection.Opposite()); // work with brushes
             if (otherCell)
             {
                 otherCell.SetOutgoingRiver(dragDirection);
             }
         }
     }
     else if (activeMode == EditMode.roads)
     {
         float fracX = hitpoint.x - Mathf.Floor(hitpoint.x);
         float fracZ = hitpoint.z - Mathf.Floor(hitpoint.z);
         if (fracX > 0.25f && fracX < 0.75f || fracZ > 0.25f && fracZ < 0.75f)
         {
             GridDirection edge = squareGrid.GetEdge(hitpoint);
             if (Input.GetMouseButton(1))
             {
                 cell.RemoveRoad(edge);
                 Explosion(cell);
             }
             else
             {
                 cell.AddRoad(edge);
             }
         }
     }
     else if (activeMode == EditMode.water_level)
     {
         if (Input.GetMouseButton(0) && freshClick)
         {
             cell.WaterLevel++;
         }
         else if (Input.GetMouseButton(1) && freshClick)
         {
             cell.WaterLevel--;
         }
     }
     else if (activeMode == EditMode.building)
     {
         if (Input.GetMouseButton(0) && freshClick)
         {
             cell.UrbanLevel++;
         }
         if (Input.GetMouseButton(1) && freshClick)
         {
             cell.UrbanLevel = 0;
             Explosion(cell);
         }
     }
     else if (activeMode == EditMode.trees)
     {
         if (Input.GetMouseButton(0) && freshClick)
         {
             cell.PlantLevel++;
         }
         if (Input.GetMouseButton(1) && freshClick)
         {
             cell.PlantLevel = 0;
             Explosion(cell);
         }
     }
     else if (activeMode == EditMode.rocks)
     {
         if (Input.GetMouseButton(0) && freshClick)
         {
             cell.ScenaryObject = 1;
         }
         if (Input.GetMouseButton(1) && freshClick)
         {
             cell.ScenaryObject = 0;
             Explosion(cell);
         }
     }
     else if (activeMode == EditMode.mast)
     {
         if (Input.GetMouseButton(0) && freshClick)
         {
             cell.ScenaryObject = 2;
         }
         if (Input.GetMouseButton(1) && freshClick)
         {
             cell.ScenaryObject = 0;
             Explosion(cell);
         }
     }
     else if (activeMode == EditMode.lighthouse)
     {
         if (Input.GetMouseButton(0) && freshClick)
         {
             cell.ScenaryObject = 3;
         }
         if (Input.GetMouseButton(1) && freshClick)
         {
             cell.ScenaryObject = 0;
             Explosion(cell);
         }
     }
     else if (activeMode == EditMode.industry)
     {
         if (Input.GetMouseButton(0) && freshClick)
         {
             cell.Industry = (int)activeIndustry + 1;
         }
         if (Input.GetMouseButton(1) && freshClick)
         {
             cell.Industry = 0;
             Explosion(cell);
         }
     }
     else if (activeMode == EditMode.town)
     {
         if (cell.Town == null)
         {
             GameObject  town    = Instantiate(townPrefab);
             TownManager manager = town.GetComponent <TownManager>();
             town.transform.position = GridCoordinates.ToPosition(cell.coordinates) + new Vector3(0, cell.CentreElevation * GridMetrics.elevationStep, 0);
             manager.Init(cell);
             cell.Town = manager;
         }
     }
 }