Exemplo n.º 1
0
 private void FollowGround(TerrainGen terrain)
 {
     transform.position = new Vector3(transform.position.x, 0f, transform.position.z);
     Vector3[] verts = mesh.vertices;
     for (int i = 0; i < verts.Length; i++)
     {
         verts[i].y = terrain.GetHeightAt(transform.localToWorldMatrix.MultiplyPoint(verts[i])) + .2f;
     }
     mesh.vertices = verts;
     mesh.RecalculateNormals();
     mesh.RecalculateBounds();
 }
Exemplo n.º 2
0
        public static Chunk Create(TerrainGen generator, Vector2i chunkPos, Vector2 size)
        {
            GameObject go = new GameObject("Chunk");

            go.transform.SetParent(generator.transform);
            Chunk chk = go.AddComponent <Chunk>();

            chk.generator = generator;
            chk.size      = size;
            chk.ChunkPos  = chunkPos;
            chk.Init();
            return(chk);
        }
Exemplo n.º 3
0
        private void CreateRoads(float width, float subdivDistance, TerrainGen terrain)
        {
            if (junctions.Count < 2)
            {
                return;
            }
            Junction prevJunc = junctions[0];

            for (int i = 1; i < junctions.Count; i++)
            {
                prevJunc.CreateRoadTo(junctions[i], width, true, subdivDistance, terrain);
                prevJunc = junctions[i];
            }
        }
Exemplo n.º 4
0
        public static Road CreateNew(Transform parent, Junction j1, Junction j2, float width, bool followGround, float subdivDistance, TerrainGen terrain)
        {
            GameObject go = new GameObject();

            go.name = "Road";
            go.transform.SetParent(parent, false);
            Road road = go.AddComponent <Road>();

            road.Junction1 = j1;
            road.Junction2 = j2;
            road.width     = width;
            road.ComputePositioning();
            road.subdivs = 2;
            if (followGround)
            {
                road.subdivs = GetSubdivisions(Vector3.Distance(j1.transform.position, j2.transform.position), subdivDistance);
            }
            road.GenerateMesh();
            if (followGround)
            {
                road.FollowGround(terrain);
            }
            return(road);
        }
Exemplo n.º 5
0
 public void CreateHighway(float width, float subdivDistance, TerrainGen terrain)
 {
     CreateJunctions();
     CreateRoads(width, subdivDistance, terrain);
     RoadCreated = true;
 }
Exemplo n.º 6
0
        public void CreateRoadTo(Junction junc, float width, bool followGround, float subdivDistance, TerrainGen terrain)
        {
            Road road = Road.CreateNew(transform.parent, this, junc, width, followGround, subdivDistance, terrain);

            roads.Add(road);
        }
Exemplo n.º 7
0
 private void Awake()
 {
     terrainGen         = GetComponent <TerrainGen>();
     terrainGen.townGen = this;
     terrainGen.OnTerrainGenCompleteEvent += OnTerrainGenComplete;
 }
Exemplo n.º 8
0
 public void Init(TerrainGen gen, FinishCallback fc, AnimationCurve contToAmp)
 {
     generator           = gen;
     callback            = fc;
     continentToAmpCurve = new AnimationCurve(contToAmp.keys);
 }