本文整理汇总了C#中Voxel类的典型用法代码示例。如果您正苦于以下问题:C# Voxel类的具体用法?C# Voxel怎么用?C# Voxel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Voxel类属于命名空间,在下文中一共展示了Voxel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public void Initialize(int resolution, float size)
{
this.m_resolution = resolution;
m_gridSize = size;
m_voxelSize = size / resolution;
m_voxels = new Voxel[resolution * resolution];
m_voxelMaterials = new Material[m_voxels.Length];
for (int i = 0, y = 0; y < resolution; y++)
{
for (int x = 0; x < resolution; x++, i++)
{
CreateVoxel(i, x, y);
}
}
m_dummyX = new Voxel();
m_dummyY = new Voxel();
m_dummyT = new Voxel();
//offset the grid to center it inside the screen
Vector3 gridPosition = new Vector3(-0.5f * size, -0.5f * size, 0);
this.transform.localPosition = gridPosition;
GetComponent<MeshFilter>().mesh = m_mesh = new Mesh();
m_mesh.name = "VoxelGrid Mesh";
m_vertices = new List<Vector3>();
m_triangles = new List<int>();
Refresh();
}
示例2: Add
public static VoxelCommand Add(Voxel voxel)
{
VoxelCommand cmd = new VoxelCommand ();
cmd._type = Type.Add;
cmd._voxel = voxel;
return cmd;
}
示例3: detector_Collided
void detector_Collided(Volume collisonObject, Voxel voxel, Vector3 worldPosition)
{
// If the bullet hits an invader and is owned by the player, explode and destroy the invader - and deactivate the bullet
if (collisonObject.name == "Invader" && Owner is InvadersPlayerShip)
{
collisonObject.Destruct(3f, true);
Destroy(collisonObject.gameObject);
gameObject.SetActive(false);
}
// If we hit a shield, just explode and deactivate the bullet
if (collisonObject.name == "Shield")
{
exploder.ExplosionRadius = 1f;
exploder.Explode();
gameObject.SetActive(false);
}
// If we hit the player ship
if (collisonObject.name == "Player Ship")
{
collisonObject.Destruct(3f, true);
collisonObject.GetComponent<InvadersPlayerShip>().Die();
gameObject.SetActive(false);
}
}
示例4: GetDataFromString
static Voxel[] GetDataFromString(int width, int height, int depth, string dataString)
{
string[] layers = dataString.Split ('-');
int size = height * depth * width;
Voxel[] data = new Voxel[size];
int c = 0;
foreach (string layer in layers) {
string[] lines = layer.Split ('\n');
foreach (string line in lines) {
string row = line.Trim ();
for (int i = 0; i < row.Length; i++) {
Voxel v = new Voxel();
int j;
if (int.TryParse (row [i] + "", out j)) {
v.id = (byte)j;
} else {
v.id = 0;
}
// cut in the middle of processing
if (c == size) {
return data;
}
data [c++] = v;
}
}
}
if (c != size) {
throw new Exception ("insuficient voxel data");
}
return data;
}
示例5: DetectVoxels
void DetectVoxels ()
{
if (currentVoxel == null)
currentVoxel = new Voxel ();
}
示例6: RemoveVoxelAnimation
public void RemoveVoxelAnimation(bool hasPreviousBlock, Voxel voxel, Action finishCallback)
{
if (_animDic.ContainsKey(voxel.Pos))
{
AnimTuple anim = _animDic[voxel.Pos];
anim.Trans.GetComponent<MeshRenderer>().material.color = voxel.Color;
anim.Trans.GetComponent<DummyBehavior>().StopAllCoroutines();
anim.Cor = anim.Trans.GetComponent<DummyBehavior>().StartCoroutine(RemoveVoxelAnimationCor(voxel.Pos, anim.Trans, () =>
{
finishCallback();
}));
}
else
{
if (hasPreviousBlock)
{
AnimTuple anim = new AnimTuple();
_animDic[voxel.Pos] = anim;
anim.Trans = CreateAnimTransform(voxel);
anim.Trans.localScale = Vector3.one;
anim.Cor = anim.Trans.GetComponent<DummyBehavior>().StartCoroutine(RemoveVoxelAnimationCor(voxel.Pos, anim.Trans, () =>
{
finishCallback();
}));
}
}
}
示例7: InstantiateVoxels
public void InstantiateVoxels(int startx, int starty, int startz, int width, int height, int depth)
{
Width = width;
Height = height;
Depth = depth;
Voxels = new Voxel[Width, Height, Depth];
float voxelSize = VoxelWorld.Inst.PhysicalVoxelSize;
float halfVoxel = voxelSize * 0.5f;
for (int x = 0; x < Width; ++x)
{
for (int y = 0; y < Height; ++y)
{
for (int z = 0; z < Depth; ++z)
{
IntVec3 pos = new IntVec3(startx + x, starty + y, startz + z);
BoxCollider collider = gameObject.AddComponent<BoxCollider>();
collider.center = new Vector3(pos.X + halfVoxel, pos.Y + halfVoxel, pos.Z + halfVoxel);
collider.size = new Vector3(voxelSize, voxelSize, voxelSize);
Voxel voxel = new Voxel(this, VoxelType.Air, pos, collider);
Voxels[x, y, z] = voxel;
ColliderToVoxel[collider] = voxel;
}
}
}
}
示例8: Add
public void Add(Voxel voxel)
{
voxel.position -= this.Position;
if (Voxels[(int)voxel.position.X, (int)voxel.position.Y, (int)voxel.position.Z] != null) return;
//if (!inChunk(voxel.position)) return;
//this.Remove(voxel);
Voxels[(int)voxel.position.X, (int)voxel.position.Y, (int)voxel.position.Z] = voxel;
if (((int)voxel.position.X + 1 < this.Size.X && Voxels[(int)voxel.position.X + 1, (int)voxel.position.Y, (int)voxel.position.Z] == null) || (int)voxel.position.X == this.Size.X - 1)
vertices.AddRange(Face.getFace( Face.Facing.Right, voxel.position, voxel.color));
if (((int)voxel.position.X - 1 >= 0 && Voxels[(int)voxel.position.X - 1, (int)voxel.position.Y, (int)voxel.position.Z] == null) || (int)voxel.position.X == 0)
vertices.AddRange(Face.getFace( Face.Facing.Left, voxel.position, voxel.color));
if (((int)voxel.position.Y + 1 < this.Size.Y && Voxels[(int)voxel.position.X, (int)voxel.position.Y + 1, (int)voxel.position.Z] == null) || (int)voxel.position.Y == this.Size.Y - 1)
vertices.AddRange(Face.getFace( Face.Facing.Up, voxel.position, voxel.color));
if (((int)voxel.position.Y - 1 >= 0 && Voxels[(int)voxel.position.X, (int)voxel.position.Y - 1, (int)voxel.position.Z] == null) || (int)voxel.position.Y == 0)
vertices.AddRange(Face.getFace( Face.Facing.Down, voxel.position, voxel.color));
if (((int)voxel.position.Z + 1 < this.Size.Z && Voxels[(int)voxel.position.X, (int)voxel.position.Y, (int)voxel.position.Z + 1] == null) || (int)voxel.position.Z == this.Size.Z - 1)
vertices.AddRange(Face.getFace( Face.Facing.Forward, voxel.position, voxel.color));
if (((int)voxel.position.Z - 1 >= 0 && Voxels[(int)voxel.position.X, (int)voxel.position.Y, (int)voxel.position.Z - 1] == null) || (int)voxel.position.Z == 0)
vertices.AddRange(Face.getFace( Face.Facing.Backward, voxel.position, voxel.color));
this.Build();
}
示例9: GetNeighbours
public static Voxel[] GetNeighbours(Point3 worldCoord)
{
Voxel[] neighbours = new Voxel[6];
for (int i=0; i<checkSides.Length; i++) {
neighbours[i] = ChunkManager.GetBlock(worldCoord + checkSides[i]);
}
return neighbours;
}
示例10: AddVoxel
public void AddVoxel(Voxel voxel)
{
_voxelAnimation.AddVoxelAnimation(_voxelData.HasVoxelAtPos(voxel.Pos), voxel, () =>
{
_voxelData.AddVoxel(voxel);
_voxelRenderer.RenderMesh(_voxelData);
});
}
示例11: detector_Collided
private void detector_Collided(Volume collisonObject, Voxel voxel, Vector3 worldPosition)
{
if (collisonObject.name.StartsWith("Plane") && Owner is ShmupChopper)
{
collisonObject.GetComponent<ShmupPlane>().Die();
gameObject.SetActive(false);
}
}
示例12: Set
public void Set(int x, int y, int z, Voxel voxel)
{
if (voxels.GetLength(0) < x ||
voxels.GetLength(1) < y ||
voxels.GetLength(2) < z) {
return;
}
voxels[x, y, z] = voxel;
}
示例13: SeralizeVoxel
// TODO: Cache all the binary formatters
public static byte[] SeralizeVoxel(Voxel voxel)
{
BinaryFormatter formatter = new BinaryFormatter();
using (MemoryStream stream = new MemoryStream())
{
formatter.Serialize(stream, voxel);
return stream.ToArray();
}
}
示例14: BecomeYDummyOf
public void BecomeYDummyOf (Voxel voxel, float offset) {
state = voxel.state;
position = voxel.position;
xEdgePosition = voxel.xEdgePosition;
yEdgePosition = voxel.yEdgePosition;
position.y += offset;
xEdgePosition.y += offset;
yEdgePosition.y += offset;
}
示例15: Apply
public override Voxel.State Apply(int x, int y, Voxel.State voxel)
{
x -= centerX;
y -= centerY;
if (x * x + y * y <= sqrRadius)
{
return fillType;
}
return voxel;
}