本文整理汇总了C#中UnityEngine.Bounds.Expand方法的典型用法代码示例。如果您正苦于以下问题:C# Bounds.Expand方法的具体用法?C# Bounds.Expand怎么用?C# Bounds.Expand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Bounds
的用法示例。
在下文中一共展示了Bounds.Expand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
// Update is called once per frame
void Update()
{
var cameraSize =
camera.ScreenToWorldPoint(Camera.main.pixelWidth * Vector3.right + Camera.main.pixelHeight * Vector3.up)
- camera.ScreenToWorldPoint(Vector3.zero);
cameraSize.z = 0;
var cameraBounds = new Bounds(camera.transform.position, cameraSize);
cameraBounds.Expand(1f);
var pos = transform.position;
var y = Mathf.Lerp(pos.y, t.position.y, 10 * Time.deltaTime);
if(y > HorizontalRestriction.y)
{
y = HorizontalRestriction.y;
}
else if (y < HorizontalRestriction.x)
{
y = HorizontalRestriction.x;
}
pos.y = y;
pos.x = t.position.x;
transform.position = pos + Offset;
}
示例2: onDrawGizmos
public void onDrawGizmos( Vector3 basePosition )
{
Gizmos.color = new Color( 1f, 0f, 0.6f );
var hasHorizontal = ( axis & CameraAxis.Horizontal ) == CameraAxis.Horizontal;
var hasVertical = ( axis & CameraAxis.Vertical ) == CameraAxis.Vertical;
var hasBothAxis = hasHorizontal && hasVertical;
var bounds = new Bounds( basePosition, new Vector3( width, height ) );
var lineWidth = Camera.main.orthographicSize;
// expand our bounds to have larger lines if we only have a single axis
if( hasVertical && !hasBothAxis )
{
bounds.Expand( new Vector3( lineWidth - bounds.size.x, 0f ) );
}
if( hasHorizontal && !hasBothAxis )
{
bounds.Expand( new Vector3( 0f, lineWidth - bounds.size.y ) );
}
if( hasVertical || hasBothAxis )
{
Gizmos.DrawLine( bounds.min, bounds.min + new Vector3( bounds.size.x, 0f ) );
Gizmos.DrawLine( bounds.max, bounds.max - new Vector3( bounds.size.x, 0f ) );
}
if( hasHorizontal || hasBothAxis )
{
Gizmos.DrawLine( bounds.min, bounds.min + new Vector3( 0f, bounds.size.y ) );
Gizmos.DrawLine( bounds.max, bounds.max - new Vector3( 0f, bounds.size.y ) );
}
}
示例3: Move
public Vector2 Move(float deltaX, float deltaY)
{
//Update bounds
m_BoundsWithSkin = m_BoxCollider.bounds;
m_BoundsWithSkin.Expand(-2.0f * m_SkinWidth);
m_IsGrounded = false;
m_IsGoingUpSlope = false;
Vector2 deltaMovement = new Vector2(deltaX * Time.deltaTime, deltaY * Time.deltaTime);
//Move horizontally
HandleHorizontalMovement(ref deltaMovement);
//Move vertically
HandleVerticalMovement(ref deltaMovement);
//Do the actual movement in world space
transform.Translate(new Vector3(deltaMovement.x, deltaMovement.y, 0.0f), Space.World);
//Return the current velocity
Vector2 velocity = new Vector2(0.0f, 0.0f);
if (Time.deltaTime > 0.0f)
velocity = deltaMovement / Time.deltaTime;
return velocity;
}
示例4: Start
// Use this for initialization
void Start()
{
var mesh = model.sharedMesh;
positions = mesh.vertices;
normals = mesh.normals;
var mat = model.renderer.sharedMaterial;
var tex = (Texture2D)mat.mainTexture;
colors = System.Array.ConvertAll(mesh.uv, (uv) => tex.GetPixelBilinear(uv.x, uv.y));
_tree = new KdTree();
_tree.build(positions, Enumerable.Range(0, mesh.vertexCount).ToArray());
_bounds = model.renderer.bounds;
_bounds.Expand(2f * coloringDist);
}
示例5: ApplyForce
public void ApplyForce(Transform transObj, float maxForce = 1, float radius = 0)
{
//radius = 0;
//Debug.Log("Cube hit!");
var b = new Bounds(FinalPosition, transform.localScale);
b.Expand(radius * 2);
// Why does radius need to be multiplied by 2?
//var falloffBounds =new Bounds( new Bounds(FinalPosition, transform.localScale + (Vector3.one * Falloff) + (Vector3.one * radius * 2));
var falloffBounds = new Bounds(FinalPosition, transform.localScale);
falloffBounds.Expand(radius * 2 + Falloff * 2);
if (falloffBounds.Contains(transObj.position))
{
//Debug.Log("Object in falloff");
// inside the obstacle!
if (b.Contains(transObj.position))
{
//Debug.Log("Object has enter bounds!");
transObj.position = GetClosestBorderFromInsidePoint(b, transObj.position, 0.01f);
}
// in the fallout area
else
{
var falloutClosePoint = falloffBounds.ClosestPoint(transObj.position);
Helpers.DrawDebugPoint(falloutClosePoint, 1, Color.cyan);
var objClosePoint = b.ClosestPoint(transObj.position);
Helpers.DrawDebugPoint(objClosePoint, 1, Color.magenta);
Debug.DrawLine(falloutClosePoint, objClosePoint, Color.yellow);
var mag = (falloutClosePoint - objClosePoint).magnitude;
var frac = Mathf.Max(1 - mag / Falloff, 0);
//Debug.Log("mag = " + mag + " (" + frac + ")");
var forceVector = (falloutClosePoint - objClosePoint).normalized * frac * maxForce;
transObj.position += forceVector * Time.deltaTime;
}
}
}
示例6: GetCellsInsideBounds
/**
* Queries the grid structure to find cells completely or partially inside the supplied bounds.
* \param bounds bounds that we are interested to get intersecting cells for.
* \param boundsExpansion how much to expand the bounds before checking for cell overlap.
* \param boundsExpansion how many cells we can afford to check for overlap after the initial guess. If there are more than this, we will just return all cells.
* \return the list of cells that intersect or are completely inside the supplied bounds.
*/
public List<Cell> GetCellsInsideBounds(Bounds bounds, float boundsExpansion, int maxCellOverlap)
{
List<Cell> result;
bounds.Expand(boundsExpansion);
int mincellX = Mathf.FloorToInt(bounds.min.x / cellSize);
int maxcellX = Mathf.FloorToInt(bounds.max.x / cellSize);
int mincellY = Mathf.FloorToInt(bounds.min.y / cellSize);
int maxcellY = Mathf.FloorToInt(bounds.max.y / cellSize);
int mincellZ = Mathf.FloorToInt(bounds.min.z / cellSize);
int maxcellZ = Mathf.FloorToInt(bounds.max.z / cellSize);
int cellCount = (maxcellX-mincellX)*(maxcellY-mincellY)*(maxcellZ-mincellZ);
if (cellCount > maxCellOverlap) {
result = new List<Cell>(cells.Values);
return result;
}
// Give list an initial size equal to the upper bound of cells inside the bounds, to prevent size reallocations.
result = new List<Cell>(cellCount);
Vector3 cellpos = Vector3.zero;
Cell cell = null;
for (int x = mincellX ; x <= maxcellX; x++){
for (int y = mincellY ; y <= maxcellY; y++){
for (int z = mincellZ ; z <= maxcellZ; z++){
cellpos.Set(x,y,z);
int hash = ComputeCellHash(cellpos);
if (cells.TryGetValue(hash, out cell))
result.Add(cell);
}
}
}
return result;
}
示例7: UpdateAreaInit
public void UpdateAreaInit (GraphUpdateObject o) {
if (!o.updatePhysics) {
return;
}
if (!dynamic) {
throw new System.Exception ("Recast graph must be marked as dynamic to enable graph updates");
}
AstarProfiler.Reset ();
AstarProfiler.StartProfile ("UpdateAreaInit");
AstarProfiler.StartProfile ("CollectMeshes");
RelevantGraphSurface.UpdateAllPositions ();
List<ExtraMesh> extraMeshes;
Bounds b = o.bounds;
b.center -= forcedBounds.min;
//Calculate world bounds of all affected tiles
IntRect r = new IntRect (Mathf.FloorToInt (b.min.x / (tileSizeX*cellSize)), Mathf.FloorToInt (b.min.z / (tileSizeZ*cellSize)), Mathf.FloorToInt (b.max.x / (tileSizeX*cellSize)), Mathf.FloorToInt (b.max.z / (tileSizeZ*cellSize)));
//Clamp to bounds
r = IntRect.Intersection (r, new IntRect (0,0,tileXCount-1,tileZCount-1));
Bounds tileBounds = new Bounds();
Vector3 forcedBoundsMin = forcedBounds.min;
Vector3 forcedBoundsMax = forcedBounds.max;
float tcsx = tileSizeX*cellSize;
float tcsz = tileSizeZ*cellSize;
tileBounds.SetMinMax(new Vector3 (r.xmin*tcsx, 0, r.ymin*tcsz) + forcedBoundsMin,
new Vector3 ((r.xmax+1)*tcsx + forcedBoundsMin.x, forcedBoundsMax.y, (r.ymax+1)*tcsz + forcedBoundsMin.z)
);
int voxelCharacterRadius = Mathf.CeilToInt (characterRadius/cellSize);
int borderSize = voxelCharacterRadius + 3;
//Expand borderSize voxels on each side
tileBounds.Expand (new Vector3 (borderSize,0,borderSize)*cellSize*2);
Debug.DrawLine (tileBounds.min, tileBounds.max);
//Debug.Break ();
if (!CollectMeshes (out extraMeshes, tileBounds)) {
//return;
}
Voxelize vox = globalVox;
if (vox == null) {
//Create the voxelizer and set all settings
vox = new Voxelize (cellHeight, cellSize, walkableClimb, walkableHeight, maxSlope);
vox.maxEdgeLength = maxEdgeLength;
if (dynamic) globalVox = vox;
}
vox.inputExtraMeshes = extraMeshes;
AstarProfiler.EndProfile ("CollectMeshes");
AstarProfiler.EndProfile ("UpdateAreaInit");
}
示例8: BuildTileMesh
protected void BuildTileMesh (Voxelize vox, int x, int z) {
AstarProfiler.StartProfile ("Build Tile");
AstarProfiler.StartProfile ("Init");
//World size of tile
float tcsx = tileSizeX*cellSize;
float tcsz = tileSizeZ*cellSize;
int voxelCharacterRadius = Mathf.CeilToInt (characterRadius/cellSize);
Vector3 forcedBoundsMin = forcedBounds.min;
Vector3 forcedBoundsMax = forcedBounds.max;
Bounds bounds = new Bounds ();
bounds.SetMinMax(new Vector3 (x*tcsx, 0, z*tcsz) + forcedBoundsMin,
new Vector3 ((x+1)*tcsx + forcedBoundsMin.x, forcedBoundsMax.y, (z+1)*tcsz + forcedBoundsMin.z)
);
vox.borderSize = voxelCharacterRadius + 3;
//Expand borderSize voxels on each side
bounds.Expand (new Vector3 (vox.borderSize,0,vox.borderSize)*cellSize*2);
vox.forcedBounds = bounds;
vox.width = tileSizeX + vox.borderSize*2;
vox.depth = tileSizeZ + vox.borderSize*2;
if (!useTiles && relevantGraphSurfaceMode == RelevantGraphSurfaceMode.OnlyForCompletelyInsideTile) {
// This best reflects what the user would actually want
vox.relevantGraphSurfaceMode = RelevantGraphSurfaceMode.RequireForAll;
} else {
vox.relevantGraphSurfaceMode = relevantGraphSurfaceMode;
}
vox.minRegionSize = Mathf.RoundToInt(minRegionSize / (cellSize*cellSize));
#if ASTARDEBUG
Debug.Log ("Building Tile " + x+","+z);
Console.WriteLine ("Recast Graph -- Voxelizing");
#endif
AstarProfiler.EndProfile ("Init");
//Init voxelizer
vox.Init ();
vox.CollectMeshes ();
vox.VoxelizeInput ();
AstarProfiler.StartProfile ("Filter Ledges");
if (importMode) {
if (System.IO.File.Exists(Application.dataPath+"/tile."+x+"."+z)) {
System.IO.FileStream fs = System.IO.File.OpenRead (Application.dataPath+"/tile."+x+"."+z);
byte[] bytes = new byte[fs.Length];
fs.Read (bytes,0,(int)fs.Length);
VoxelArea tmpVox = new VoxelArea(vox.width,vox.depth);
Pathfinding.Voxels.VoxelSerializeUtility.DeserializeVoxelAreaData (bytes,tmpVox);
Pathfinding.Voxels.VoxelSerializeUtility.MergeVoxelAreaData(tmpVox,vox.voxelArea,vox.voxelWalkableClimb);
}
}
if (exportMode) {
System.IO.FileStream fs = System.IO.File.Create(Application.dataPath+"/tile."+x+"."+z);
byte[] bytes = Pathfinding.Voxels.VoxelSerializeUtility.SerializeVoxelAreaData(vox.voxelArea);
fs.Write(bytes,0,bytes.Length);
fs.Close();
}
vox.FilterLedges (vox.voxelWalkableHeight, vox.voxelWalkableClimb, vox.cellSize, vox.cellHeight, vox.forcedBounds.min);
AstarProfiler.EndProfile ("Filter Ledges");
AstarProfiler.StartProfile ("Filter Low Height Spans");
vox.FilterLowHeightSpans (vox.voxelWalkableHeight, vox.cellSize, vox.cellHeight, vox.forcedBounds.min);
AstarProfiler.EndProfile ("Filter Low Height Spans");
vox.BuildCompactField ();
vox.BuildVoxelConnections ();
#if ASTARDEBUG
Console.WriteLine ("Recast Graph -- Eroding");
#endif
vox.ErodeWalkableArea (voxelCharacterRadius);
#if ASTARDEBUG
Console.WriteLine ("Recast Graph -- Building Distance Field");
#endif
vox.BuildDistanceField ();
#if ASTARDEBUG
Console.WriteLine ("Recast Graph -- Building Regions");
#endif
vox.BuildRegions ();
//.........这里部分代码省略.........
示例9: DrawGraph
private void DrawGraph(ILayoutAlgorithm layout, Rect drawingArea, NodeConstraints nodeConstraints)
{
// add border, except on right-hand side where the legend will provide necessary padding
drawingArea = new Rect(drawingArea.x + k_BorderSize,
drawingArea.y + k_BorderSize,
drawingArea.width - k_BorderSize,
drawingArea.height - k_BorderSize * 2);
var b = new Bounds(Vector3.zero, Vector3.zero);
foreach (var c in layout.vertices)
{
b.Encapsulate(new Vector3(c.position.x, c.position.y, 0.0f));
}
// Increase b by maximum node size (since b is measured between node centers)
b.Expand(new Vector3(nodeConstraints.maximumNormalizedNodeSize, nodeConstraints.maximumNormalizedNodeSize, 0));
var scale = new Vector2(drawingArea.width / b.size.x, drawingArea.height / b.size.y);
var offset = new Vector2(-b.min.x, -b.min.y);
Vector2 nodeSize = ComputeNodeSize(scale, nodeConstraints);
GUI.BeginGroup(drawingArea);
foreach (var e in layout.edges)
{
Vector2 v0 = ScaleVertex(layout.vertices[e.source].position, offset, scale);
Vector2 v1 = ScaleVertex(layout.vertices[e.destination].position, offset, scale);
DrawEdge(v0, v1, layout.vertices[e.source].propagatedWeight);
}
int index = 0;
foreach (var v in layout.vertices)
{
DrawNode(v, ScaleVertex(v.position, offset, scale) - nodeSize / 2, nodeSize, index.ToString());
index++;
}
GUI.EndGroup();
}
示例10: ScheduleUpdate
/** Requests an update to all tiles which touch the specified bounds */
public void ScheduleUpdate ( Bounds bounds ) {
if (graph == null) {
// If no graph has been set, use the first graph available
if (AstarPath.active != null) {
SetGraph (AstarPath.active.astarData.recastGraph);
}
if (graph == null) {
Debug.LogError ("Received tile update request (from RecastTileUpdate), but no RecastGraph could be found to handle it");
return;
}
}
// Make sure that tiles which do not strictly
// contain this bounds object but which still
// might need to be updated are actually updated
int voxelCharacterRadius = Mathf.CeilToInt (graph.characterRadius/graph.cellSize);
int borderSize = voxelCharacterRadius + 3;
// Expand borderSize voxels on each side
bounds.Expand (new Vector3 (borderSize,0,borderSize)*graph.cellSize*2);
var touching = graph.GetTouchingTiles (bounds);
if (touching.Width * touching.Height > 0) {
if (!anyDirtyTiles) {
earliestDirty = Time.time;
anyDirtyTiles = true;
}
for ( int z = touching.ymin; z <= touching.ymax; z++ ) {
for ( int x = touching.xmin; x <= touching.xmax; x++ ) {
dirtyTiles[z*graph.tileXCount + x] = true;
}
}
}
}
示例11: Update
// Update is called once per frame
void Update()
{
// If we don't have an object to scroll, we don't scroll at all
if (skipUpdate || scrollable == null || camera == null || spriteBounds.size == Vector3.zero)
return;
var cameraSize =
camera.ScreenToWorldPoint(Camera.main.pixelWidth * Vector3.right + Camera.main.pixelHeight * Vector3.up)
- camera.ScreenToWorldPoint(Vector3.zero);
cameraSize.z = 0;
var cameraBounds = new Bounds(camera.transform.position, cameraSize);
cameraBounds.Expand(1f);
DestroyIfOutside(GetComponentsInChildren<SpriteRenderer>(), cameraBounds);
objs.ForEach(obj => GameObject.Destroy(obj));
var b = AddBounds(from Transform child in transform select child, new Bounds(transform.position, Vector3.zero));
//var spawnPosition = Vector3.zero;
switch (Direction)
{
case ScrollDirection.Left:
break;
case ScrollDirection.Right:
//spawnPosition = b.max;
//transform.Translate(-Vector2.right * parallax * Time.deltaTime);
//if (spawnPosition.x > cameraBounds.max.x)
// return;
if (spriteBounds.size.x == 0)
return;
for (float x = b.max.x; x < cameraBounds.max.x; x += spriteBounds.size.x)
{
var spawnPosition = new Vector2(x + spriteBounds.size.x / 2, scrollable.transform.position.y);
var obj = GameObject.Instantiate(scrollable);
obj.transform.position = spawnPosition;
obj.transform.parent = transform;
var pos = obj.transform.localPosition;
pos.y = spawnPosition.y;
obj.transform.localPosition = pos;
}
for (float x = b.min.x; x > cameraBounds.min.x; x -= spriteBounds.size.x)
{
var spawnPosition = new Vector2(x - spriteBounds.size.x / 2, scrollable.transform.position.y);
var obj = GameObject.Instantiate(scrollable);
obj.transform.position = spawnPosition;
obj.transform.parent = transform;
var pos = obj.transform.localPosition;
pos.y = spawnPosition.y;
obj.transform.localPosition = pos;
}
//spawnPosition.x += spriteBounds.size.x / 2 - 0.1f;
//spawnPosition.y = scrollable.transform.position.y;
//spawnPosition.z = 0;
break;
case ScrollDirection.Up:
break;
case ScrollDirection.Down:
if (spriteBounds.size.y == 0)
return;
for (float y = cameraBounds.min.y; y > cameraBounds.min.y; y -= spriteBounds.size.y)
{
var spawnPosition = new Vector2(scrollable.transform.position.x, y + spriteBounds.size.y / 2);
var obj = GameObject.Instantiate(scrollable);
obj.transform.position = spawnPosition;
obj.transform.parent = transform;
var pos = obj.transform.localPosition;
pos.x = spawnPosition.x;
obj.transform.localPosition = pos;
}
break;
}
//var spawn = GameObject.Instantiate(scrollable);
//spawn.transform.position = spawnPosition;
//spawn.transform.parent = transform;
}
示例12: Start
//private Bounds cameraBounds = new Bounds();
// Use this for initialization
void Start()
{
if (scrollable == null || camera == null)
return;
var cameraSize =
camera.ScreenToWorldPoint(Camera.main.pixelWidth * Vector3.right + Camera.main.pixelHeight * Vector3.up)
- camera.ScreenToWorldPoint(Vector3.zero);
cameraSize.z = 0;
var cameraBounds = new Bounds(camera.transform.position, cameraSize);
cameraBounds.Expand(1f);
var transforms = new List<Transform>(from Transform t in scrollable.transform select t);
transforms.Add(scrollable.transform);
spriteBounds = AddBounds(transforms, new Bounds());
if (spriteBounds.size == Vector3.zero)
return;
switch (Direction)
{
case ScrollDirection.Left:
break;
case ScrollDirection.Right:
if (spriteBounds.size.x == 0)
return;
for (float x = cameraBounds.min.x; x < cameraBounds.max.x; x += spriteBounds.size.x)
{
var spawnPosition = new Vector2(x + spriteBounds.size.x / 2, scrollable.transform.position.y);
var obj = GameObject.Instantiate(scrollable);
obj.transform.position = spawnPosition;
obj.transform.parent = transform;
var pos = obj.transform.localPosition;
pos.y = spawnPosition.y;
obj.transform.localPosition = pos;
}
break;
case ScrollDirection.Up:
break;
case ScrollDirection.Down:
if (spriteBounds.size.y == 0)
return;
for (float y = cameraBounds.min.y; y > cameraBounds.min.y; y -= spriteBounds.size.y)
{
var spawnPosition = new Vector2(scrollable.transform.position.x, y + spriteBounds.size.y / 2);
var obj = GameObject.Instantiate(scrollable);
obj.transform.position = spawnPosition;
obj.transform.parent = transform;
var pos = obj.transform.localPosition;
pos.x = spawnPosition.x;
obj.transform.localPosition = pos;
}
break;
default:
break;
}
}
示例13: BuildTileMesh
protected void BuildTileMesh (Voxelize vox, int x, int z) {
AstarProfiler.StartProfile("Build Tile");
AstarProfiler.StartProfile("Init");
//World size of tile
float tcsx = tileSizeX*cellSize;
float tcsz = tileSizeZ*cellSize;
int voxelCharacterRadius = Mathf.CeilToInt(characterRadius/cellSize);
Vector3 forcedBoundsMin = forcedBounds.min;
Vector3 forcedBoundsMax = forcedBounds.max;
var bounds = new Bounds();
bounds.SetMinMax(new Vector3(x*tcsx, 0, z*tcsz) + forcedBoundsMin,
new Vector3((x+1)*tcsx + forcedBoundsMin.x, forcedBoundsMax.y, (z+1)*tcsz + forcedBoundsMin.z)
);
vox.borderSize = voxelCharacterRadius + 3;
//Expand borderSize voxels on each side
bounds.Expand(new Vector3(vox.borderSize, 0, vox.borderSize)*cellSize*2);
vox.forcedBounds = bounds;
vox.width = tileSizeX + vox.borderSize*2;
vox.depth = tileSizeZ + vox.borderSize*2;
if (!useTiles && relevantGraphSurfaceMode == RelevantGraphSurfaceMode.OnlyForCompletelyInsideTile) {
// This best reflects what the user would actually want
vox.relevantGraphSurfaceMode = RelevantGraphSurfaceMode.RequireForAll;
} else {
vox.relevantGraphSurfaceMode = relevantGraphSurfaceMode;
}
vox.minRegionSize = Mathf.RoundToInt(minRegionSize / (cellSize*cellSize));
#if ASTARDEBUG
Debug.Log("Building Tile " + x+","+z);
System.Console.WriteLine("Recast Graph -- Voxelizing");
#endif
AstarProfiler.EndProfile("Init");
//Init voxelizer
vox.Init();
vox.CollectMeshes();
vox.VoxelizeInput();
AstarProfiler.StartProfile("Filter Ledges");
vox.FilterLedges(vox.voxelWalkableHeight, vox.voxelWalkableClimb, vox.cellSize, vox.cellHeight, vox.forcedBounds.min);
AstarProfiler.EndProfile("Filter Ledges");
AstarProfiler.StartProfile("Filter Low Height Spans");
vox.FilterLowHeightSpans(vox.voxelWalkableHeight, vox.cellSize, vox.cellHeight, vox.forcedBounds.min);
AstarProfiler.EndProfile("Filter Low Height Spans");
vox.BuildCompactField();
vox.BuildVoxelConnections();
#if ASTARDEBUG
System.Console.WriteLine("Recast Graph -- Eroding");
#endif
vox.ErodeWalkableArea(voxelCharacterRadius);
#if ASTARDEBUG
System.Console.WriteLine("Recast Graph -- Building Distance Field");
#endif
vox.BuildDistanceField();
#if ASTARDEBUG
System.Console.WriteLine("Recast Graph -- Building Regions");
#endif
vox.BuildRegions();
#if ASTARDEBUG
System.Console.WriteLine("Recast Graph -- Building Contours");
#endif
var cset = new VoxelContourSet();
vox.BuildContours(contourMaxError, 1, cset, Voxelize.RC_CONTOUR_TESS_WALL_EDGES);
#if ASTARDEBUG
System.Console.WriteLine("Recast Graph -- Building Poly Mesh");
#endif
VoxelMesh mesh;
vox.BuildPolyMesh(cset, 3, out mesh);
#if ASTARDEBUG
//.........这里部分代码省略.........
示例14: GenerateStarMesh
private Mesh GenerateStarMesh(int starOffset, int starCount)
{
var positions = new Vector3[starCount * 4];
var indices = new int[starCount * 6];
var uv0s = new Vector2[starCount * 4];
var uv1s = new Vector2[starCount * 4];
var normals = new Vector3[starCount * 4];
var colours = new Color[starCount * 4];
var bounds = new Bounds();
for (var i = 0; i < starCount; i++)
{
var i0 = i * 6;
var i1 = i0 + 1;
var i2 = i1 + 1;
var i3 = i2 + 1;
var i4 = i3 + 1;
var i5 = i4 + 1;
var v0 = i * 4;
var v1 = v0 + 1;
var v2 = v1 + 1;
var v3 = v2 + 1;
// Index data
indices[i0] = v0;
indices[i1] = v1;
indices[i2] = v2;
indices[i3] = v3;
indices[i4] = v2;
indices[i5] = v1;
// Calculate star values
var starData = GenerateStar();
var midRadius = (starData.RadiusMin + starData.RadiusMax) * 0.5f;
var pulseRadius = (starData.RadiusMax - starData.RadiusMin) * 0.5f;
var position = starData.Position;
var colour = new Color(starData.RadiusPulseRate, starData.RadiusPulseOffset, 0.0f);
var uv0 = starData.Variant.Coords;
var uv1 = new Vector2(midRadius, pulseRadius);
var right = SGT_Helper.Rotate(Vector2.right * SGT_Helper.InscribedBox, starData.Angle);
var up = SGT_Helper.Rotate(Vector2.up * SGT_Helper.InscribedBox, starData.Angle);
bounds.Encapsulate(position);
// Write star values into vertex data
positions[v0] = position;
positions[v1] = position;
positions[v2] = position;
positions[v3] = position;
normals[v0] = SGT_Helper.NewVector3(-right + up, 0.0f);
normals[v1] = SGT_Helper.NewVector3( right + up, 0.0f);
normals[v2] = SGT_Helper.NewVector3(-right - up, 0.0f);
normals[v3] = SGT_Helper.NewVector3( right - up, 0.0f);
colours[v0] = colour;
colours[v1] = colour;
colours[v2] = colour;
colours[v3] = colour;
uv0s[v0] = uv0[0];
uv0s[v1] = uv0[1];
uv0s[v2] = uv0[2];
uv0s[v3] = uv0[3];
uv1s[v0] = uv1;
uv1s[v1] = uv1;
uv1s[v2] = uv1;
uv1s[v3] = uv1;
}
bounds.Expand(starRadiusMax);
var starMesh = new Mesh();
starMesh.hideFlags = HideFlags.DontSave;
starMesh.name = "Starfield";
starMesh.bounds = bounds;
starMesh.vertices = positions;
starMesh.normals = normals;
starMesh.colors = colours;
starMesh.uv = uv0s;
starMesh.uv1 = uv1s;
starMesh.triangles = indices;
return starMesh;
}
示例15: GenerateStarMesh
//.........这里部分代码省略.........
{
var i0 = i * 6;
var i1 = i0 + 1;
var i2 = i1 + 1;
var i3 = i2 + 1;
var i4 = i3 + 1;
var i5 = i4 + 1;
var v0 = i * 4;
var v1 = v0 + 1;
var v2 = v1 + 1;
var v3 = v2 + 1;
// Index data
indices[i0] = v0;
indices[i1] = v1;
indices[i2] = v2;
indices[i3] = v3;
indices[i4] = v2;
indices[i5] = v1;
// Calculate star values
var position = GeneratePosition();
var index = weights.RandomIndex;
var po = packer.GetOutput(index);
var ssv = GetStarVariant(index);
float baseRadius, minRadius, maxRadius;
if (ssv != null && ssv.Custom == true)
{
baseRadius = Random.Range(ssv.CustomRadiusMin, ssv.CustomRadiusMax);
minRadius = Mathf.Max(baseRadius - ssv.CustomPulseRadiusMax, ssv.CustomRadiusMin);
maxRadius = Mathf.Min(baseRadius + ssv.CustomPulseRadiusMax, ssv.CustomRadiusMax);
}
else
{
baseRadius = Random.Range(starRadiusMin, starRadiusMax);
minRadius = Mathf.Max(baseRadius - starPulseRadiusMax, starRadiusMin);
maxRadius = Mathf.Min(baseRadius + starPulseRadiusMax, starRadiusMax);
}
var midRadius = (minRadius + maxRadius) * 0.5f;
var pulseRadius = (maxRadius - minRadius) * 0.5f;
var pulseRate = Random.Range(0.0f, 1.0f);
var pulseOffset = Random.Range(0.0f, 1.0f);
var colour = new Color(pulseRate, pulseOffset, 0.0f);
var uv1 = new Vector2(midRadius, pulseRadius);
var rollAngle = Random.Range(-Mathf.PI, Mathf.PI);
var right = SGT_Helper.Rotate(Vector2.right * SGT_Helper.InscribedBox, rollAngle);
var up = SGT_Helper.Rotate(Vector2.up * SGT_Helper.InscribedBox, rollAngle);
bounds.Encapsulate(position);
// Write star values into vertex data
positions[v0] = position;
positions[v1] = position;
positions[v2] = position;
positions[v3] = position;
normals[v0] = SGT_Helper.NewVector3(-right + up, 0.0f);
normals[v1] = SGT_Helper.NewVector3( right + up, 0.0f);
normals[v2] = SGT_Helper.NewVector3(-right - up, 0.0f);
normals[v3] = SGT_Helper.NewVector3( right - up, 0.0f);
colours[v0] = colour;
colours[v1] = colour;
colours[v2] = colour;
colours[v3] = colour;
if (po != null)
{
uv0s[v0] = po.UvTopLeft;
uv0s[v1] = po.UvTopRight;
uv0s[v2] = po.UvBottomLeft;
uv0s[v3] = po.UvBottomRight;
}
uv1s[v0] = uv1;
uv1s[v1] = uv1;
uv1s[v2] = uv1;
uv1s[v3] = uv1;
}
bounds.Expand(starRadiusMax);
var starMesh = new Mesh();
starMesh.name = "Starfield";
starMesh.bounds = bounds;
starMesh.vertices = positions;
starMesh.normals = normals;
starMesh.colors = colours;
starMesh.uv = uv0s;
starMesh.uv2 = uv1s;
starMesh.triangles = indices;
return starMesh;
}