当前位置: 首页>>代码示例>>C#>>正文


C# UnityEngine.MeshCollider类代码示例

本文整理汇总了C#中UnityEngine.MeshCollider的典型用法代码示例。如果您正苦于以下问题:C# MeshCollider类的具体用法?C# MeshCollider怎么用?C# MeshCollider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MeshCollider类属于UnityEngine命名空间,在下文中一共展示了MeshCollider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

    void Start()
    {
        filter = gameObject.GetComponent<MeshFilter>();
        coll = gameObject.GetComponent<MeshCollider>();

        //past here is just to set up an example chunk
        blocks = new Block[chunkSize, chunkSize, chunkSize];

        for (int x = 0; x < chunkSize; x++)
        {
            for (int y = 0; y < chunkSize; y++)
            {
                for (int z = 0; z < chunkSize; z++)
                {
                    blocks[x, y, z] = new BlockAir();
                }
            }
        }

        blocks[1, 1, 1] = new Block();
        blocks[1, 2, 1] = new Block();
        blocks[1, 2, 2] = new Block();
        blocks[2, 2, 2] = new Block();

        UpdateChunk();
    }
开发者ID:billy1234,项目名称:TerrainGenMaster,代码行数:26,代码来源:Chunk.cs

示例2: Start

	// Use this for initialization
	void Start () {
		mesh = GetComponent<MeshFilter> ().mesh;
		meshC = GetComponent<MeshCollider> ();
		vertices = mesh.vertices;
		fireballs = GameObject.FindGameObjectsWithTag("Fireball");
		Debug.Log (vertices.Length);
	}
开发者ID:kkiniaes,项目名称:Fire-On-Ice,代码行数:8,代码来源:Island.cs

示例3: Start

    // Use this for initialization
    void Start()
    {
        hmul = 1F / hardness;
        mf = GetComponent<MeshFilter> ();
        mc = GetComponent<MeshCollider> ();
        verts = mf.mesh.vertices;
        tris = mf.mesh.triangles;
        //mf.mesh.SetIndices (tris, MeshTopology.LineStrip, 0);

        connections = new VertexConnection[verts.Length];
        for (int i = 0; i < verts.Length; i++) {
            Vector3 P1 = verts [i];
            VertexConnection VC1 = connections [i];
            for (int n = i+1; n < verts.Length; n++) {
                if (P1 == verts [n]) {
                    var VC2 = connections [n];
                    if (VC2 == null)
                        VC2 = connections [n] = new VertexConnection ();
                    if (VC1 == null)
                        VC1 = connections [i] = new VertexConnection ();
                    VC1.connections.Add (n);
                    VC2.connections.Add (i);
                }
            }
        }
    }
开发者ID:00yoshi,项目名称:Test,代码行数:27,代码来源:DamageMesh.cs

示例4: Awake

 /// <summary>
 /// Initialized the components
 /// </summary>
 void Awake()
 {
     this.isoObj = GetComponent<IsoObject>();
     this.collider = GetComponent<MeshCollider>();
     collider.sharedMesh = createMesh();
     deltaSize = isoObj.Size;
 }
开发者ID:FrankieAvocado,项目名称:UnityHarmsDealer,代码行数:10,代码来源:IsoCollider.cs

示例5: GenerateMesh

    public void GenerateMesh(int[,] map, float squareSize)
    {
        if(wallCollider == null)
        {
            wallCollider = walls.gameObject.AddComponent<MeshCollider> ();
        }
        outlines.Clear();
        checkedVertices.Clear ();
        triangleDictionary.Clear();

        squareGrid = new SquareGrid(map, squareSize);

        vertices = new List<Vector3>();
        triangles = new List<int>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for(int y =0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x,y]);
            }
        }

        Mesh mesh = new Mesh();
        cave.mesh = mesh;
        mesh.vertices = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.RecalculateNormals();

        if(!is2D) {
            CreateWallMesh();
        }
    }
开发者ID:AshKatchem,项目名称:GameTest,代码行数:33,代码来源:MeshGen.cs

示例6: Awake

		// Use this for initialization
		protected void Awake()
		{
			Filter = gameObject.GetComponent<MeshFilter>();
			Coll = gameObject.GetComponent<MeshCollider>();

			//past here is just to set up an example chunk
			//Blocks = new VoxBlock[ChunkSize, ChunkSize, ChunkSize];

			for (var x = 0; x < World.ChunkSize; x++)
			{
				for (var y = 0; y < World.ChunkSize; y++)
				{
					for (var z = 0; z < World.ChunkSize; z++)
					{
						Blocks[x, y, z] = new Block(Color.white) { BlockType = VoxBlockType.Empty };
					}
				}
			}

			//Blocks[1, 14, 1] = new VoxBlock();

			//Blocks[3, 5, 2] = new VoxBlock();
			//Blocks[4, 5, 2] = new VoxBlock();


			//UpdateChunk();

		}
开发者ID:Quixotic7,项目名称:VR-Vox,代码行数:29,代码来源:Chunk.cs

示例7: Start

 // Use this for initialization
 void Start()
 {
     // check this node for mReferenceCollider
     if (mReferenceCollider == null) {
         mReferenceCollider = this.GetComponent<BoxCollider>();
     }
     if (mReferenceCollider == null) {
         mReferenceCollider = this.GetComponent<SphereCollider>();
     }
     if (mReferenceCollider == null) {
         mReferenceCollider = this.GetComponent<CapsuleCollider>(); // unlikely.
     }
     // check the parent node for mReferenceCollider
     if (mReferenceCollider == null) {
         mReferenceCollider = this.transform.parent.GetComponent<BoxCollider>();
     }
     if (mReferenceCollider == null) {
         mReferenceCollider = this.transform.parent.GetComponent<SphereCollider>();
     }
     if (mReferenceCollider == null) {
         mReferenceCollider = this.transform.parent.GetComponent<CapsuleCollider>(); // unlikely.
     }
     if (mMeshCollider == null) {
         mMeshCollider = this.GetComponent<MeshCollider>();
     }
 }
开发者ID:C453,项目名称:Valdemar,代码行数:27,代码来源:AlphaMeshColliderCopyColliderEnabled.cs

示例8: Start

 void Start()
 {
     collider=GetComponent<MeshCollider>();
     startRot=transform.rotation;
     rbody=GetComponent<Rigidbody>();
     startPos=transform.position;
 }
开发者ID:drfuzzyness,项目名称:WearHax-OlivMatt,代码行数:7,代码来源:AddForce.cs

示例9: BuildMesh

	private void BuildMesh (MeshFilter mf, MeshRenderer mr, MeshCollider mc, int i, int j) {
		Mesh mesh = new Mesh();
		mesh.Clear();
		
		// the vertices of our new mesh, separated into two groups
		Vector3[] inner = new Vector3[grid.smoothness + 1]; // the inner vertices (closer to the centre)
		Vector3[] outer = new Vector3[grid.smoothness + 1]; // the outer vertices

		// vertices must be given in local space
		Transform trnsfrm = mf.gameObject.transform;
		
		// the amount of vertices depends on how much the grid is smoothed
		for (int k = 0; k < grid.smoothness + 1; k++) {
			// rad is the current distance from the centre, sctr is the current sector and i * (1.0f / grid.smoothness) is the fraction inside the current sector
			inner[k] = trnsfrm.InverseTransformPoint(grid.GridToWorld(new Vector3(i, j + k * (1.0f / grid.smoothness), 0)));
			outer[k] = trnsfrm.InverseTransformPoint(grid.GridToWorld(new Vector3(i + 1, j + k * (1.0f / grid.smoothness), 0)));
		}
		
		//this is wher the actual vertices go
		Vector3[] vertices = new Vector3[2 * (grid.smoothness + 1)];
		// copy the sorted vertices into the new array
		inner.CopyTo(vertices, 0);
		// for each inner vertex its outer counterpart has the same index plus grid.smoothness + 1, this will be relevant later
		outer.CopyTo(vertices, grid.smoothness + 1);
		// assign them as the vertices of the mesh
		mesh.vertices = vertices;
		
		// now we have to assign the triangles
		int[] triangles = new int[6 * grid.smoothness]; // for each smoothing step we need two triangles and each triangle is three indices
		int counter = 0; // keeps track of the current index
		for (int k = 0; k < grid.smoothness; k++) {
			// triangles are assigned in a clockwise fashion
			triangles[counter] = k;
			triangles[counter+1] = k + (grid.smoothness + 1) + 1;
			triangles[counter+2] = k + (grid.smoothness + 1);
			
			triangles[counter+3] = k + 1;
			triangles[counter+4] = k + (grid.smoothness + 1) + 1;
			triangles[counter+5] = k;

			counter += 6; // increment the counter for the nex six indices
		}
		mesh.triangles = triangles;
		
		// add some dummy UVs to keep the shader happy or else it complains, but they are not used in this example
		Vector2[] uvs = new Vector2[vertices.Length];
        for (int k = 0; k < uvs.Length; k++) {
            uvs[k] = new Vector2(vertices[k].x, vertices[k].y);
        }
        mesh.uv = uvs;
		
		// the usual cleanup
		mesh.RecalculateNormals();
		mesh.RecalculateBounds();
		mesh.Optimize();
		
		// assign the mesh  to the mesh filter and mesh collider
		mf.mesh = mesh;
		mc.sharedMesh = mesh;
	}
开发者ID:Gapti,项目名称:ClashOfClanRIP,代码行数:60,代码来源:ConstructPolarBlocks.cs

示例10: pStart

 private void pStart()
 {
     _collider = (MeshCollider)gameObject.collider;
         //this sets the collider mesh to equal the objects mesh filter.
         //May not be required if you aren't using 2D Toolkit
         _collider.sharedMesh = gameObject.GetComponent<MeshFilter>().sharedMesh;
 }
开发者ID:phil-me-up,项目名称:Rain-one--Mesh-Sensor,代码行数:7,代码来源:MeshSensor.cs

示例11: DuplicateOldChunk

	public void DuplicateOldChunk(string ChunkData)
	{
		meshCollider = GetComponent<MeshCollider>();
		map = new byte[width, width, width];
		int iter = 0;
		for (int x = 0; x < width; x++)
		{
			for (int z = 0; z < width; z++)
			{
				//make the bottom layer of the chunk all solid blocks
				if(ChunkData[iter] == '0')
					map[x,0,z]=0;
				else
					map[x,0,z]=1;
				iter++;
				//make the second layer of the chunk random
				if(ChunkData[iter] == '0')
					map[x,1,z]=0;
				else
					map[x,1,z]=1;
				iter++;
			}
		}
		mesh = new Mesh();
		GetComponent<MeshFilter>().mesh = mesh;
		Regenerate();
	}
开发者ID:Panamax,项目名称:UncleCraft,代码行数:27,代码来源:Chunk.cs

示例12: Awake

 // Use this for initialization
 void Awake()
 {
     rMesh = gameObject.GetComponent<MeshRenderer>();
     fMesh = gameObject.GetComponent<MeshFilter>();
     cMesh = gameObject.GetComponent<MeshCollider>();
     mesh = new Mesh();
 }
开发者ID:kristafervale,项目名称:MapEditor,代码行数:8,代码来源:cell_c.cs

示例13: Awake

	void Awake () {
		anim = GetComponent<Animator>();
		SFX = GetComponent<AudioSource>();
		health = startingHealth;
		meshCollider = GetComponent<MeshCollider>();
		meshCollider.enabled = false;
	}
开发者ID:gitter-badger,项目名称:Citadel,代码行数:7,代码来源:EnemyHealth.cs

示例14: Start

    // Use this for initialization
    void Start()
    {
        world = GameObject.FindWithTag("world").GetComponent("World") as World;

        displayBlock = new BlockSelect();
        filter = gameObject.GetComponent<MeshFilter>();
        coll = gameObject.GetComponent<MeshCollider>();
    }
开发者ID:TwoClunkers,项目名称:Clunk-Genesis,代码行数:9,代码来源:SelectedCube+(copy).cs

示例15: Start

    void Start()
	{
		if (DataManager == null) 
			DataManager = GetManager.GetDataManager ();	// need a better way to do this, keep references in a static object..!
		HasInitialLoad = false;
        filter = gameObject.GetComponent<MeshFilter>();
        coll = gameObject.GetComponent<MeshCollider>();
    }
开发者ID:Deus0,项目名称:Zeltex,代码行数:8,代码来源:Chunk.cs


注:本文中的UnityEngine.MeshCollider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。