コード例 #1
0
 public TerrainManager(TerrainSettings s)
 {
     Pool      = new TerrainPool();
     VertexGen = new VertexGenerator(s);
     settings  = s;
     InstantiateTerrainObject();
 }
コード例 #2
0
 public TerrainManager(Settings s)
 {
     Pool = new TerrainPool();
     VertexGen = new VertexGenerator(s);
     settings = s;
     InstantiateTerrainObject();
 }
コード例 #3
0
 public TerrainManager(Settings s, Transform parentTransform)
 {
     Pool                 = new TerrainPool();
     VertexGen            = new VertexGenerator(s);
     settings             = s;
     this.parentTransform = parentTransform;
     InstantiateTerrainObject(s.TerrainManagerName);
 }
コード例 #4
0
        public void CreateCorner(VertexGenerator vg, TerrainPiece previousTerrain, TerrainPiece currentTerrain, Transform newParent)
        {
            //Our plane is made up of the last top and bottom verts of the previous mesh, and the first top and bottom verts of the current mesh
            List <Vector3> topVerticies    = GetCornerVerts(previousTerrain, currentTerrain, MeshPiece.Plane.Front, true);
            List <Vector3> bottomVerticies = GetCornerVerts(previousTerrain, currentTerrain, MeshPiece.Plane.Front, false);

            //Create our front mesh piece
            MeshPiece meshPiece = new MeshPiece(vg, MeshPiece.Plane.Front, settings);

            meshPiece.CreateCorner(topVerticies, bottomVerticies);

            //The first mesh could be null if we are below the minimum verticies we need to create a plane
            if (meshPiece.MeshObject != null)
            {
                TransformHelpers th = new TransformHelpers();

                //Now we've created the front of our mesh
                InstantiateTerrainObject(0f, newParent);
                MeshPieces.Add(meshPiece);

                //Add detail mesh
                if (settings.DrawDetailMeshRenderer)
                {
                    MeshPiece meshPieceDetail = new MeshPiece(vg, MeshPiece.Plane.Detail, settings);
                    topVerticies    = GetCornerVerts(previousTerrain, currentTerrain, MeshPiece.Plane.Detail, true);
                    bottomVerticies = GetCornerVerts(previousTerrain, currentTerrain, MeshPiece.Plane.Detail, false);
                    meshPieceDetail.CreateCorner(topVerticies, bottomVerticies);
                    MeshPieces.Add(meshPieceDetail);
                }

                if (settings.DrawTopMeshCollider || settings.DrawTopMeshRenderer)
                {
                    //Create the verticies for the top of our mesh, and add that too
                    MeshPiece meshPieceTop = new MeshPiece(vg, MeshPiece.Plane.Top, settings);

                    //Use the top verts as our bottom z row
                    bottomVerticies = th.CopyList(topVerticies);
                    Vector3 firstBottomVertex = topVerticies[0];

                    //Then shift the top verts into the z plane
                    topVerticies = th.MoveStartVertex(topVerticies, firstBottomVertex, new Vector3(firstBottomVertex.x, firstBottomVertex.y, firstBottomVertex.z + settings.TopPlaneHeight), false);
                    meshPieceTop.CreateCorner(topVerticies, bottomVerticies);
                    if (settings.TopPhysicsMaterial2D != null)
                    {
                        meshPieceTop.edgeCollider.sharedMaterial = settings.TopPhysicsMaterial2D; // assign Physics Material if any
                    }
                    if (settings.TerrainLayer != 0)
                    {
                        meshPieceTop.MeshObject.layer = settings.TerrainLayer; // assign Layer if any
                    }
                    MeshPieces.Add(meshPieceTop);
                }

                //Just to tidy up the heirarchy
                ParentMeshesToTerrainObject();
            }
        }
コード例 #5
0
ファイル: TerrainPiece.cs プロジェクト: gallib2/surfer-boy
        public void Create(VertexGenerator vg, Vector3 origin)
        {
            //Track the angle we are currenlty on
            TerrainAngle = vg.CurrentTerrainRule.Angle;

            //Create the front mesh and populate our key verts for the front plane
            MeshPiece mp = new MeshPiece(vg, MeshPiece.Plane.Front, settings);

            mp.PopulateKeyVerticies(MeshPiece.Plane.Front);

            //Now create the mesh
            mp.Create(origin, TerrainAngle);


            //The first mesh could be null if we are below the minimum verticies we need to create a plane
            if (mp.MeshObject != null)
            {
                //Create a placeholder object for our mesh pieces
                InstantiateTerrainObject();

                //if (meshCollider == null) {
                //    meshCollider = TerrainObject.AddComponent<MeshCollider>();
                //    meshCollider.convex = true;
                //}

                if (terrainCollider == null)
                {
                    terrainCollider          = TerrainObject.AddComponent <TerrainCollider>();
                    terrainCollider.material = new PhysicMaterial();
                }

                //And add the front plane mesh piece to our list of meshes in the terrain piece
                MeshPieces.Add(mp);


                if (settings.DrawDetailMeshRenderer)
                {
                    MeshPiece mpDetail = new MeshPiece(vg, MeshPiece.Plane.Detail, settings);
                    mpDetail.Create(origin + settings.DetailPlaneOffset, TerrainAngle, mp.KeyTopVerticies);
                    MeshPieces.Add(mpDetail);
                }



                if (settings.DrawTopMeshCollider || settings.DrawTopMeshRenderer)
                {
                    MeshPiece mpTop = new MeshPiece(vg, MeshPiece.Plane.Top, settings);
                    mpTop.Create(mp.StartTopMesh, TerrainAngle, mp.KeyTopVerticies);
                    MeshPieces.Add(mpTop);
                }



                //Just to tidy up the heirarchy
                ParentMeshesToTerrainObject();
            }
        }
コード例 #6
0
        public void Create(VertexGenerator vg, Vector3 origin)
        {

            //Track the angle we are currenlty on          
            TerrainAngle = vg.CurrentTerrainRule.Angle;

            //Create the front mesh and populate our key verts for the front plane
            MeshPiece mp = new MeshPiece(vg, MeshPiece.Plane.Front, settings);
            mp.PopulateKeyVerticies(MeshPiece.Plane.Front);            
            
            //Now create the mesh
            mp.Create(origin, TerrainAngle);
          
			
			//The first mesh could be null if we are below the minimum verticies we need to create a plane
			if (mp.MeshObject != null){
				
                //Create a placeholder object for our mesh pieces
				InstantiateTerrainObject();	
			
                //And add the front plane mesh piece to our list of meshes in the terrain piece
			  	MeshPieces.Add(mp);


                if (settings.DrawDetailMeshRenderer)
                {
                    MeshPiece mpDetail = new MeshPiece(vg, MeshPiece.Plane.Detail, settings);
                    mpDetail.Create(origin + settings.DetailPlaneOffset, TerrainAngle, mp.KeyTopVerticies);
                    MeshPieces.Add(mpDetail);
                }



                if (settings.DrawTopMeshCollider || settings.DrawTopMeshRenderer)
                {
                    MeshPiece mpTop = new MeshPiece(vg, MeshPiece.Plane.Top, settings);
                    mpTop.Create(mp.StartTopMesh, TerrainAngle, mp.KeyTopVerticies);
                    MeshPieces.Add(mpTop);
                }
      
                  
				
				
	            //Just to tidy up the heirarchy
	            ParentMeshesToTerrainObject();
					
			}
        }
コード例 #7
0
        public void Create(VertexGenerator vg, Vector3 origin, Transform newParent)
        {
            //Track the angle we are currenlty on
            TerrainAngle = vg.CurrentTerrainRule.Angle;

            //Create the front mesh and populate our key verts for the front plane
            MeshPiece mp = new MeshPiece(vg, MeshPiece.Plane.Front, settings);

            mp.PopulateKeyVerticies(MeshPiece.Plane.Front);

            //Now create the mesh
            mp.Create(origin, TerrainAngle);

            //The first mesh could be null if we are below the minimum verticies we need to create a plane
            if (mp.MeshObject != null)
            {
                //Create a placeholder object for our mesh pieces
                InstantiateTerrainObject(origin.x, newParent);

                //And add the front plane mesh piece to our list of meshes in the terrain piece
                MeshPieces.Add(mp);

                if (settings.DrawDetailMeshRenderer)
                {
                    MeshPiece mpDetail = new MeshPiece(vg, MeshPiece.Plane.Detail, settings);
                    mpDetail.Create(origin + settings.DetailPlaneOffset, TerrainAngle, mp.KeyTopVerticies);
                    MeshPieces.Add(mpDetail);
                }

                if (settings.DrawTopMeshCollider || settings.DrawTopMeshRenderer)
                {
                    MeshPiece mpTop = new MeshPiece(vg, MeshPiece.Plane.Top, settings);
                    mpTop.Create(mp.StartTopMesh, TerrainAngle, mp.KeyTopVerticies);
                    if (settings.TopPhysicsMaterial2D != null)
                    {
                        mpTop.edgeCollider.sharedMaterial = settings.TopPhysicsMaterial2D; // assign Physics Material if any
                    }
                    if (settings.TerrainLayer != 0)
                    {
                        mpTop.MeshObject.layer = settings.TerrainLayer; // assign Layer if any
                    }
                    MeshPieces.Add(mpTop);
                }
                //Just to tidy up the heirarchy
                ParentMeshesToTerrainObject();
            }
        }
コード例 #8
0
 public MeshPiece(VertexGenerator vg, Plane planeType, Settings s)
 {
     this.vg   = vg;
     PlaneType = planeType;
     settings  = s;
 }
コード例 #9
0
 public MeshPiece(VertexGenerator vg, Plane planeType, Settings s)
 {
     this.vg = vg;
     PlaneType = planeType;
     settings = s;
 }
コード例 #10
0
ファイル: TerrainPiece.cs プロジェクト: eiseneker/ghost-game
        public void CreateCorner(VertexGenerator vg, TerrainPiece previousTerrain, TerrainPiece currentTerrain)
        {
            //Our plane is made up of the last top and bottom verts of the previous mesh, and the first top and bottom verts of the current mesh
            List<Vector3> topVerticies = GetCornerVerts(previousTerrain, currentTerrain, MeshPiece.Plane.Front, true);
            List<Vector3> bottomVerticies = GetCornerVerts(previousTerrain, currentTerrain, MeshPiece.Plane.Front, false);

            //Create our front mesh piece
            MeshPiece meshPiece = new MeshPiece(vg, MeshPiece.Plane.Front, settings);
            meshPiece.CreateCorner(topVerticies, bottomVerticies);

            //The first mesh could be null if we are below the minimum verticies we need to create a plane
            if (meshPiece.MeshObject != null)
            {
                TransformHelpers th = new TransformHelpers();

                //Now we've created the front of our mesh
                InstantiateTerrainObject();
                MeshPieces.Add(meshPiece);

                //Add detail mesh

                if (settings.DrawDetailMeshRenderer)
                {
                    MeshPiece meshPieceDetail = new MeshPiece(vg, MeshPiece.Plane.Detail, settings);
                    topVerticies = GetCornerVerts(previousTerrain, currentTerrain, MeshPiece.Plane.Detail, true);
                    bottomVerticies = GetCornerVerts(previousTerrain, currentTerrain, MeshPiece.Plane.Detail, false);
                    meshPieceDetail.CreateCorner(topVerticies, bottomVerticies);
                    MeshPieces.Add(meshPieceDetail);
                }

                if (settings.DrawTopMeshCollider || settings.DrawTopMeshRenderer)
                {
                    //Create the verticies for the top of our mesh, and add that too
                    MeshPiece meshPieceTop = new MeshPiece(vg, MeshPiece.Plane.Top, settings);

                    //Use the top verts as our bottom z row
                    bottomVerticies = th.CopyList(topVerticies);
                    Vector3 firstBottomVertex = topVerticies[0];

                    //Then shift the top verts into the z plane
                    topVerticies = th.MoveStartVertex(topVerticies, firstBottomVertex, new Vector3(firstBottomVertex.x, firstBottomVertex.y, firstBottomVertex.z + settings.TopPlaneHeight), false);
                    meshPieceTop.CreateCorner(topVerticies, bottomVerticies);
                    MeshPieces.Add(meshPieceTop);
                }

                //Just to tidy up the heirarchy
                ParentMeshesToTerrainObject();

            }
        }