本文整理汇总了C#中UnityEngine.Bounds.SetMinMax方法的典型用法代码示例。如果您正苦于以下问题:C# Bounds.SetMinMax方法的具体用法?C# Bounds.SetMinMax怎么用?C# Bounds.SetMinMax使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Bounds
的用法示例。
在下文中一共展示了Bounds.SetMinMax方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBounds
public static Bounds GetBounds(Renderer r)
{
if (r is SkinnedMeshRenderer) {
SkinnedMeshRenderer smr = r as SkinnedMeshRenderer;
Mesh mesh = smr.sharedMesh;
Vector3[] vertices = mesh.vertices;
if (vertices.Length <= 0) {
return r.bounds;
}
int idx = 0;
Vector3 min, max;
min = max = r.transform.TransformPoint (vertices [idx++]);
for (int i = idx; i < vertices.Length; i++) {
Vector3 v = vertices [i];
Vector3 V = r.transform.TransformPoint (v);
for (int n = 0; n < 3; n++) {
if (V [n] > max [n])
max [n] = V [n];
if (V [n] < min [n])
min [n] = V [n];
}
}
Bounds b = new Bounds ();;
b.SetMinMax (min, max);
return b;
} else {
return r.bounds;
}
}
示例2: GetBounds
// Compute bounding box
//
public Bounds GetBounds()
{
float xmin = Mathf.Infinity;
float ymin = Mathf.Infinity;
float xmax = -Mathf.Infinity;
float ymax = -Mathf.Infinity;
Point v;
float vx, vy;
for (int i = this.halfEdges.Count - 1; i >= 0; i--)
{
v = this.halfEdges[i].GetStartPoint();
vx = v.x;
vy = v.y;
if (vx < xmin) { xmin = vx; }
if (vy < ymin) { ymin = vy; }
if (vx > xmax) { xmax = vx; }
if (vy > ymax) { ymax = vy; }
// we dont need to take into account end point,
// since each end point matches a start point
}
// TODO: verify y
Bounds bounds = new Bounds();
bounds.SetMinMax(new Vector3(xmin, 0, xmax), new Vector3(ymin, 0, ymax));
return bounds;
}
示例3: Render
public void Render(Vector3 position, float pointGranularity, Color drawColor)
{
Bounds b = new Bounds();
b.SetMinMax(
position + new Vector3(0f, 5f, 0f),
position + new Vector3(_sizeX * pointGranularity, 5f, _sizeZ * pointGranularity));
Gizmos.color = drawColor;
Gizmos.DrawCube(b.center, b.size);
}
示例4: GetViewportBounds
protected Bounds GetViewportBounds(Vector3 screenPosition1, Vector3 screenPosition2) {
var v1 = Camera.main.ScreenToViewportPoint(screenPosition1);
var v2 = Camera.main.ScreenToViewportPoint(screenPosition2);
var min = Vector3.Min(v1, v2);
var max = Vector3.Max(v1, v2);
min.z = Camera.main.nearClipPlane;
max.z = Camera.main.farClipPlane;
var bounds = new Bounds();
bounds.SetMinMax(min, max);
return bounds;
}
示例5: GetViewportBounds
//This returns the boudns to detect units inside the rect.
public static Bounds GetViewportBounds( Camera camera, Vector3 screenPosition1, Vector3 screenPosition2 )
{
var v1 = camera.ScreenToViewportPoint( screenPosition1 );
var v2 = camera.ScreenToViewportPoint( screenPosition2 );
var min = Vector3.Min( v1, v2 );
var max = Vector3.Max( v1, v2 );
min.z = camera.nearClipPlane;
max.z = camera.farClipPlane;
var bounds = new Bounds();
bounds.SetMinMax( min, max );
return bounds;
}
示例6: Intersect
public static Bounds Intersect(this Bounds a, Bounds b)
{
float x1 = Mathf.Max(a.min.x, b.min.x);
float x2 = Mathf.Min(a.max.x, b.max.x);
float y1 = Mathf.Max(a.min.y, b.min.y);
float y2 = Mathf.Min(a.max.y, b.max.y);
var bounds = new Bounds();
if (x2 >= x1 && y2 >= y1)
{
bounds.SetMinMax(new Vector3(x1, y1, 0), new Vector3(x2, y2, 0));
}
return bounds;
}
示例7: GetViewportBounds
public static Bounds GetViewportBounds(Vector3 originViewportPoint, Camera currentCamera, Vector3 currentScreenPosition)
{
Vector3 v1 = originViewportPoint;
Vector3 v2 = currentCamera.ScreenToViewportPoint(currentScreenPosition);
Vector3 min = Vector3.Min(v1, v2);
Vector3 max = Vector3.Max(v1, v2);
min.z = currentCamera.nearClipPlane;
max.z = currentCamera.farClipPlane;
Bounds bounds = new Bounds();
bounds.SetMinMax(min, max);
return bounds;
}
示例8: BoundsOfPoints
public static Bounds BoundsOfPoints(IList<ScreenCoordinate> points)
{
float minX = 0.0f, minY = 0.0f, maxX = 0.0f, maxY = 0.0f;
foreach (ScreenCoordinate p in points) {
if (p.position.x < minX) { minX = p.position.x; }
if (p.position.x > maxX) { maxX = p.position.x; }
if (p.position.y < minY) { minY = p.position.y; }
if (p.position.y > maxY) { maxY = p.position.y; }
}
Bounds b = new Bounds();
b.SetMinMax(new Vector3(minX, minY), new Vector3(maxX, maxY));
return b;
}
示例9: initConfig
public void initConfig()
{
keyForward = KeyCode.W;
keyBack = KeyCode.S;
keyRight = KeyCode.D;
keyLeft = KeyCode.A;
keyUp = KeyCode.E;
keyDown = KeyCode.Q;
keyRun = KeyCode.Space;
keySneak = KeyCode.LeftControl;
keySwitchMode = KeyCode.Alpha5;
enableExperimentalEditorExtensionsCompatibility = true;
defaultCamera = true;
enforceBounds = true;
mouseWheelActive = true;
sensitivity = 14;
acceleration = 150;
friction = 10;
runMultiplier = 2;
sneakMultiplier = 0.3f;
mouseWheelAcceleration = 1.75f;
//vab = cfg.vab;
vab = new EditorConfig();
sph = new EditorConfig();
vab.initialPosition = new Vector3(-6.1f,17.7f, -1.9f);
vab.initialPitch = 16.386f;
vab.initialYaw = 72.536f;
Vector3 min = new Vector3(-28.8f, 0.8f, -22.5f);
Vector3 max = new Vector3(29.7f, 70f, 22.7f);
var result = new Bounds();
result.SetMinMax(min, max);
vab.bounds = result;
// sph = cfg.sph;
sph.initialPosition = new Vector3(-8.6f, 14.4f, 2.7f);
sph.initialPitch = 14.080f;
sph.initialYaw = 120.824f;
min = new Vector3(-43.2f, 1.4f, -56f);
max = new Vector3(43.0f, 30.3f, 56.0f);
result = new Bounds();
result.SetMinMax(min, max);
sph.bounds = result;
}
示例10: GetRendererBoundsInChildren
static Bounds GetRendererBoundsInChildren(Transform root, HashSet<Transform> ignoreItems, Transform transform, bool includeAllChildren) {
Vector3 vector3Min = new Vector3(float.MinValue, float.MinValue, float.MinValue);
Vector3 vector3Max = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
Vector3[] minMax = new Vector3[] {
vector3Max,
vector3Min
};
GetRendererBoundsInChildren( root.worldToLocalMatrix, minMax, ignoreItems, transform, includeAllChildren);
Bounds b = new Bounds();
if (minMax[0] != vector3Max && minMax[1] != vector3Min) {
b.SetMinMax(minMax[0], minMax[1]);
}
return b;
}
示例11: getBGLimits
public Bounds getBGLimits()
{
Bounds BGBounds = GameObject.Find(BGObjectTag).GetComponent<SpriteRenderer>().bounds;
Bounds BGBoundLimits = new Bounds();
Vector3 BGBoundsMin = new Vector3();
Vector3 BGBoundsMax = new Vector3();
if (BGBounds.min.x < 0)
{
BGBoundsMin.x = BGBounds.min.x + 1;
}
else
{
BGBoundsMin.x = BGBounds.min.x - 1;
}
if (BGBounds.max.x < 0)
{
BGBoundsMax.x = BGBounds.max.x + 1;
}
else
{
BGBoundsMax.x = BGBounds.max.x - 1;
}
if (BGBounds.min.y < 0)
{
BGBoundsMin.y = BGBounds.min.y + 1;
}
else
{
BGBoundsMin.y = BGBounds.min.y - 1;
}
if (BGBounds.max.y < 0)
{
BGBoundsMax.y = BGBounds.max.y + 1;
}
else
{
BGBoundsMax.y = BGBounds.max.y - 1;
}
BGBoundLimits.SetMinMax(BGBoundsMin, BGBoundsMax);
return BGBoundLimits;
}
示例12: CalculateBoundingBox
public static Bounds CalculateBoundingBox(GameObject aObj)
{
if (aObj == null) {
Debug.LogError("CalculateBoundingBox: object is null");
return new Bounds(Vector3.zero, Vector3.one);
}
Transform myTransform = aObj.transform;
Mesh mesh = null;
MeshFilter mF = aObj.GetComponent<MeshFilter>();
if (mF != null) mesh = mF.mesh;
else {
SkinnedMeshRenderer sMR = aObj.GetComponent<SkinnedMeshRenderer>();
if (sMR != null) mesh = sMR.sharedMesh;
}
if (mesh == null) {
Debug.LogError("CalculateBoundingBox: no mesh found on the given object");
return new Bounds(aObj.transform.position, Vector3.one);
}
Vector3[] vertices = mesh.vertices;
if (vertices.Length <=0) {
Debug.LogError("CalculateBoundingBox: mesh doesn't have vertices");
return new Bounds(aObj.transform.position, Vector3.one);
}
Vector3 min, max;
min = max = myTransform.TransformPoint(vertices[0]);
for (int i = 1; i < vertices.Length; i++) {
Vector3 V = myTransform.TransformPoint(vertices[i]);
for (int n = 0; n < 3; n++) {
if (V[n] > max[n]) max[n] = V[n];
if (V[n] < min[n]) min[n] = V[n];
}
}
Bounds B = new Bounds();
B.SetMinMax(min, max);
return B;
}
示例13: getBoundsOfTrackPiece
public Bounds getBoundsOfTrackPiece(MeshRenderer[] mrList)
{
Bounds trackBounds = new Bounds();
float minx = float.MaxValue;
float minz = float.MaxValue;
float maxx = float.MinValue;
float maxz = float.MinValue;
foreach (MeshRenderer mr in mrList)
{
if (minx > mr.bounds.min.x)
minx = mr.bounds.min.x;
if (maxx < mr.bounds.max.x)
maxx = mr.bounds.max.x;
if (minz > mr.bounds.min.z)
minz = mr.bounds.min.z;
if (maxz < mr.bounds.max.z)
maxz = mr.bounds.max.z;
}
trackBounds.SetMinMax(new Vector3(minx, 0, minz), new Vector3(maxx, 0, maxz));
return trackBounds;
}
示例14: FillMesh
Mesh FillMesh(Mesh mesh) {
Vector3 anchorOffset = Vector3.zero;
switch (anchor) {
case tk2dBaseSprite.Anchor.UpperLeft: anchorOffset = new Vector3(0, -size.y, 0); break;
case tk2dBaseSprite.Anchor.UpperCenter: anchorOffset = new Vector3(-size.x / 2, -size.y, 0); break;
case tk2dBaseSprite.Anchor.UpperRight: anchorOffset = new Vector3(-size.x, -size.y, 0); break;
case tk2dBaseSprite.Anchor.MiddleLeft: anchorOffset = new Vector3(0, -size.y / 2, 0); break;
case tk2dBaseSprite.Anchor.MiddleCenter: anchorOffset = new Vector3(-size.x / 2, -size.y / 2, 0); break;
case tk2dBaseSprite.Anchor.MiddleRight: anchorOffset = new Vector3(-size.x, -size.y / 2, 0); break;
case tk2dBaseSprite.Anchor.LowerLeft: anchorOffset = new Vector3(0, 0, 0); break;
case tk2dBaseSprite.Anchor.LowerCenter: anchorOffset = new Vector3(-size.x / 2, 0, 0); break;
case tk2dBaseSprite.Anchor.LowerRight: anchorOffset = new Vector3(-size.x, 0, 0); break;
}
Vector3[] positions = new Vector3[4] {
anchorOffset + new Vector3( 0, 0, -depth),
anchorOffset + new Vector3( size.x, 0, -depth),
anchorOffset + new Vector3( 0, size.y, -depth),
anchorOffset + new Vector3( size.x, size.y, -depth)
};
mesh.vertices = positions;
mesh.uv = uv;
mesh.triangles = indices;
// Recalculate bounds, and reset bounds center, i.e. determining draw order for
// transparent sprites
Bounds bounds = new Bounds();
bounds.SetMinMax(anchorOffset, anchorOffset + new Vector3(size.x, size.y, 0));
mesh.bounds = bounds;
return mesh;
}
示例15: Scan
public static void Scan(GameObject meshObject, float voxelSize)
{
Transform meshTransform = meshObject.transform;
Mesh mesh = null;
MeshFilter mF = meshObject.GetComponent<MeshFilter>();
if (mF != null)
mesh = mF.sharedMesh;
else
{
SkinnedMeshRenderer sMR = meshObject.GetComponent<SkinnedMeshRenderer>();
if (sMR != null)
mesh = sMR.sharedMesh;
}
if (mesh == null) return;
// bool addedCollider = false;
GameObject mcContainer = new GameObject("PVMCC");
mcContainer.transform.SetParent(meshObject.transform, false);
MeshCollider mc = mcContainer.AddComponent<MeshCollider>();
mc.sharedMesh = mesh;
GameObject mcContainerRev = new GameObject("PVMCCR");
mcContainerRev.transform.SetParent(meshObject.transform, false);
Mesh reverseMesh = (Mesh)UnityEngine.Object.Instantiate(mesh);
reverseMesh.triangles = mesh.triangles.Reverse().ToArray();
MeshCollider mcr = mcContainerRev.AddComponent<MeshCollider>();
mcr.sharedMesh = reverseMesh;
Vector3[] vertices = mesh.vertices;
if (vertices.Length <= 0) return;
Texture2D renderTex =null;
Color materialColor = Color.white;
Renderer rend = meshObject.GetComponent<Renderer>();
if (rend != null && rend.sharedMaterial != null && rend.sharedMaterial.mainTexture != null)
{
renderTex = (Texture2D)rend.sharedMaterial.mainTexture;
try
{
renderTex.GetPixel(0, 0);
}
catch (Exception)
{
string path = AssetDatabase.GetAssetPath(rend.sharedMaterial.mainTexture);
TextureImporter ti = (TextureImporter)TextureImporter.GetAtPath(path);
ti.isReadable = true;
AssetDatabase.ImportAsset(path);
ti.isReadable = false;
try
{
renderTex.GetPixel(0, 0);
}
catch (Exception)
{
renderTex = null;
}
}
}
else if (rend != null && rend.sharedMaterial != null)
{
materialColor = rend.sharedMaterial.color;
}
Vector3 min, max;
min = max = meshTransform.TransformPoint(vertices[0]);
for (int i = 1; i < vertices.Length; i++)
{
Vector3 V = meshTransform.TransformPoint(vertices[i]);
for (int n = 0; n < 3; n++)
{
if (V[n] > max[n])
max[n] = V[n];
if (V[n] < min[n])
min[n] = V[n];
}
vertices[i] = V;
}
vertices[0] = meshTransform.TransformPoint(vertices[0]);
Bounds bounds = new Bounds();
bounds.SetMinMax(min, max);
if (bounds.size.x <= 0f || bounds.size.y <= 0f || bounds.size.z <= 0f) return;
var newObject = Editor.Instantiate(EditorUtility.VoxelVolumePrefab, Vector3.zero, Quaternion.identity) as GameObject;
newObject.name = meshObject.name+" (Voxels)";
newObject.GetComponent<Volume>().Material = EditorUtility.PicaVoxelDiffuseMaterial;
newObject.GetComponent<Volume>().GenerateBasic(FillMode.None);
Volume voxelVolume = newObject.GetComponent<Volume>();
voxelVolume.XSize = (int)(bounds.size.x/voxelSize)+1;
voxelVolume.YSize = (int)(bounds.size.y / voxelSize)+1;
voxelVolume.ZSize = (int)(bounds.size.z / voxelSize)+1;
voxelVolume.Frames[0].XSize = voxelVolume.XSize;
voxelVolume.Frames[0].YSize = voxelVolume.YSize;
voxelVolume.Frames[0].ZSize = voxelVolume.ZSize;
voxelVolume.Frames[0].Voxels = new Voxel[voxelVolume.XSize * voxelVolume.YSize * voxelVolume.ZSize];
for (int i = 0; i < voxelVolume.Frames[0].Voxels.Length; i++) voxelVolume.Frames[0].Voxels[i].Value = 128;
//.........这里部分代码省略.........