コード例 #1
0
    public void Explosion()
    {
        Transform explosion = Instantiate(ExplosionPrefab);

        explosion.position = GridCoordinates.ToPosition(coordinates) + new Vector3(0, CentreElevation * GridMetrics.elevationStep, 0);
        Destroy(explosion.gameObject, 10);
    }
コード例 #2
0
 public void CreatePrefab(Vector3 position, GridHash hash)
 {
     position      = GridCoordinates.ToPosition(foundations[0].coordinates) + Vector3.up * height * GridMetrics.elevationStep;
     buildingModel = Instantiate(prefabBuilding);
     buildingModel.localPosition = position;
     if (randomRotation)
     {
         buildingModel.localRotation = buildingModel.localRotation * Quaternion.Euler(0, 90 * Mathf.Round(hash.b * 4), 0);
     }
     if (hasColorVariants)
     {
         Renderer[] renderers   = buildingModel.GetComponentsInChildren <Renderer>();
         Color      randomColor = pallet.colorPallet[UnityEngine.Random.Range(0, pallet.colorPallet.Length)];
         foreach (Renderer r in renderers)
         {
             foreach (Material m in r.materials)
             {
                 if (m.name == "Company (Instance)")
                 {
                     m.color = randomColor;
                 }
             }
         }
     }
 }
コード例 #3
0
 void MoveEditorPointer(SquareCell cell, GridDirection vertex)
 {
     if (activeMode == EditMode.color || activeMode == EditMode.rivers || activeMode == EditMode.roads ||
         activeMode == EditMode.water_level || activeMode == EditMode.building || activeMode == EditMode.trees ||
         activeMode == EditMode.rocks || activeMode == EditMode.mast || activeMode == EditMode.lighthouse || activeMode == EditMode.industry || activeMode == EditMode.town)
     {
         pointerLocation = GridCoordinates.ToPosition(cell.coordinates) + Vector3.up * cell.CentreElevation * GridMetrics.elevationStep;
     }
     if (activeMode == EditMode.elevation)
     {
         pointerLocation = GridCoordinates.ToPosition(cell.coordinates) + GridMetrics.GetEdge(vertex) + Vector3.up * (int)cell.GridElevations[vertex] * GridMetrics.elevationStep;
     }
 }
コード例 #4
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;
         }
     }
 }