當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。