本文整理汇总了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();
}
示例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);
}
示例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);
}
}
}
}
示例4: Awake
/// <summary>
/// Initialized the components
/// </summary>
void Awake()
{
this.isoObj = GetComponent<IsoObject>();
this.collider = GetComponent<MeshCollider>();
collider.sharedMesh = createMesh();
deltaSize = isoObj.Size;
}
示例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();
}
}
示例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();
}
示例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>();
}
}
示例8: Start
void Start()
{
collider=GetComponent<MeshCollider>();
startRot=transform.rotation;
rbody=GetComponent<Rigidbody>();
startPos=transform.position;
}
示例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;
}
示例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;
}
示例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();
}
示例12: Awake
// Use this for initialization
void Awake()
{
rMesh = gameObject.GetComponent<MeshRenderer>();
fMesh = gameObject.GetComponent<MeshFilter>();
cMesh = gameObject.GetComponent<MeshCollider>();
mesh = new Mesh();
}
示例13: Awake
void Awake () {
anim = GetComponent<Animator>();
SFX = GetComponent<AudioSource>();
health = startingHealth;
meshCollider = GetComponent<MeshCollider>();
meshCollider.enabled = false;
}
示例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>();
}
示例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>();
}