本文整理汇总了C#中Bounds类的典型用法代码示例。如果您正苦于以下问题:C# Bounds类的具体用法?C# Bounds怎么用?C# Bounds使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Bounds类属于命名空间,在下文中一共展示了Bounds类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Awake
// Use this for initialization
void Awake()
{
player = GameObject.FindGameObjectWithTag ("Player").transform;
playerOrgin = player.position;
path2 = new []{ new Vector3(10.0f,20.0f,40f), new Vector3(10f,10f,20f),
playerOrgin, new Vector3(0f,10f,-10f), new Vector3( 0f, -5f, -20f), new Vector3(10f,-10f,5f),
new Vector3(5f,5f,15f), new Vector3(0f,20f,20f)};
path3 = new []{ new Vector3(30.0f,6.0f,60f), new Vector3(9f,40f,40f),
new Vector3(15.2f,2f,20f), new Vector3(0f,0f,5f), new Vector3( 4f, 7f, -30f), new Vector3(16f,4f, 5f)};
path4 = new []{ new Vector3(20.0f,30.0f,60f), new Vector3(5f,70f,40f),
new Vector3(28.2f,21f,20f), new Vector3(0f,0f,5f), new Vector3( 4f, 7f, -30f), new Vector3(16f,4f, 5f)};
path5 = new []{ new Vector3(20.0f,30.0f,60f), new Vector3(5f,-70f,30f),
new Vector3(11.2f,16f,20f), new Vector3(0f,0f,5f), new Vector3( 4f, -17f, -30f), new Vector3(16f,4f, 5f)};
aiShip = FindObjectOfType <Rigidbody> ();
launcher = GetComponent<MLauncher> ();
path = path2;
target = path[0];
bound = new Bounds (path[0], new Vector3(1f,1f,1f));
}
开发者ID:CodeoGenic,项目名称:Asteroid_Rift,代码行数:26,代码来源:FollowPath.cs
示例2: Update
// Update is called once per frame
void Update()
{
// I.E We've moved somewhere.
if (HasShipMoved(20)) {
Bounds generateDistance = new Bounds (Ship.transform.position, Vector3.one * VIEW_DISTANCE);
foreach (ChunkObject c in StreamSource.GetObjects(generateDistance))
{
if (!LiveObjects.Exists(i => i.transform.position == c.Position))
{
GameObject GO = PhotonNetwork.InstantiateSceneObject(c.ChunkObjectType, c.Position, c.Rotation,0, null);
GO.transform.localScale = new Vector3(400,400,400);
LiveObjects.Add(GO);
GO.transform.parent = this.transform;
}
}
for (var i = LiveObjects.Count() - 1; i >= 0; i--) {
//Replace your Where(...)
var go = LiveObjects[i];
if (!generateDistance.Intersects(new Bounds(go.transform.position,new Vector3(3,3,3))))
continue;
Debug.Log ("Deleting" + LiveObjects[i].transform.position.ToString ());
GameObject reference = LiveObjects[i];
LiveObjects.RemoveAt(i);
PhotonNetwork.Destroy (reference);
//body of foreach loop goes here
}
oldShipPosition = Ship.transform.position;
}
}
开发者ID:jackgardner,项目名称:SpaceGame,代码行数:31,代码来源:WorldGenerator.cs
示例3: CalculateAbsoluteWidgetBounds
/// <summary>
/// Calculate the combined bounds of all widgets attached to the specified game object or its children (in world space).
/// </summary>
public static Bounds CalculateAbsoluteWidgetBounds(Transform trans)
{
UIWidget[] widgets = trans.GetComponentsInChildren<UIWidget>() as UIWidget[];
Bounds b = new Bounds(trans.transform.position, Vector3.zero);
bool first = true;
foreach (UIWidget w in widgets)
{
Vector2 size = w.relativeSize;
Vector2 offset = w.pivotOffset;
float x = (offset.x + 0.5f) * size.x;
float y = (offset.y - 0.5f) * size.y;
size *= 0.5f;
Transform wt = w.cachedTransform;
Vector3 v0 = wt.TransformPoint(new Vector3(x - size.x, y - size.y, 0f));
// 'Bounds' can never start off with nothing, apparently, and including the origin point is wrong.
if (first)
{
first = false;
b = new Bounds(v0, Vector3.zero);
}
else
{
b.Encapsulate(v0);
}
b.Encapsulate(wt.TransformPoint(new Vector3(x - size.x, y + size.y, 0f)));
b.Encapsulate(wt.TransformPoint(new Vector3(x + size.x, y - size.y, 0f)));
b.Encapsulate(wt.TransformPoint(new Vector3(x + size.x, y + size.y, 0f)));
}
return b;
}
开发者ID:quiker,项目名称:hexagon,代码行数:38,代码来源:NGUIMath.cs
示例4: DebugDrawCube
public static void DebugDrawCube(Vector3 center, Vector3 size, Color c)
{
/*
* 4-----5
* /| /|
* y 7-----6 |
* | | 0---|-1
* | |/ |/
* | 3-----2
* | z
* |/_______x
*/
Bounds bounds = new Bounds(center, size);
Vector3 p3 = bounds.min;
Vector3 p5 = bounds.max;
Vector3 p0 = new Vector3(p3.x, p3.y, p5.z);
Vector3 p1 = new Vector3(p5.x, p3.y, p5.z);
Vector3 p2 = new Vector3(p5.x, p3.y, p3.z);
Vector3 p4 = new Vector3(p3.x, p5.y, p5.z);
Vector3 p6 = new Vector3(p5.x, p5.y, p3.z);
Vector3 p7 = new Vector3(p3.x, p5.y, p3.z);
Debug.DrawLine(p0, p1, c);
Debug.DrawLine(p1, p2, c);
Debug.DrawLine(p2, p3, c);
Debug.DrawLine(p3, p0, c);
Debug.DrawLine(p4, p5, c);
Debug.DrawLine(p5, p6, c);
Debug.DrawLine(p6, p7, c);
Debug.DrawLine(p7, p4, c);
Debug.DrawLine(p0, p4, c);
Debug.DrawLine(p1, p5, c);
Debug.DrawLine(p2, p6, c);
Debug.DrawLine(p3, p7, c);
}
开发者ID:schmidtec,项目名称:voxel-terrain-unity,代码行数:34,代码来源:Display.cs
示例5: FitToChildren
static void FitToChildren()
{
foreach (GameObject rootGameObject in Selection.gameObjects)
{
if (!(rootGameObject.GetComponent<Collider>() is BoxCollider))
continue;
bool hasBounds = false;
Bounds bounds = new Bounds(Vector3.zero, Vector3.zero);
for (int i = 0; i < rootGameObject.transform.childCount; ++i)
{
Renderer childRenderer = rootGameObject.transform.GetChild(i).GetComponent<Renderer>();
if (childRenderer != null)
{
if (hasBounds)
{
bounds.Encapsulate(childRenderer.bounds);
}
else
{
bounds = childRenderer.bounds;
hasBounds = true;
}
}
}
BoxCollider collider = (BoxCollider)rootGameObject.GetComponent<Collider>();
collider.center = bounds.center - rootGameObject.transform.position;
collider.size = bounds.size;
}
}
开发者ID:romsahel,项目名称:explorative-platformer,代码行数:32,代码来源:ColliderToFit.cs
示例6: positionObjectWithRendererBoundsData
//for moving object based on gaze coordinates from tracker
//based on resolution of window
//receives object, renderer, bounds script, and data script
//returns vector3 position in world coordinates
public Vector3 positionObjectWithRendererBoundsData(GameObject theObject, Renderer theRenderer, Bounds theBounds, GazeDataManager theData) {
//verify the gaze data
if (theData.gazeCoords != null) {
//convert gaze coords to screen coords
Point2D screenCoords = DataUtilities.gazePointToWindowPoint(theData.gazeCoords);
//convert window coords to viewport coords
Point2D viewCoords = DataUtilities.windowPointToViewPoint(screenCoords);
Vector3 viewVector = new Vector3((float)viewCoords.X, (float)(viewCoords.Y), 0);
//check bounds
//use the object with the outermost bounds and a renderer to make the check
Vector3 boundsVector = theBounds.checkBoundsForRenderer(theRenderer, viewVector);
//convert viewport vector to world position vector
Vector3 worldPos = Camera.main.ViewportToWorldPoint(boundsVector);
worldPos.z = theObject.transform.position.z; //maintain z position for object
//return new world position
return worldPos;
}
//error
else {
//Debug.Log("[GazeMove] Null gaze data, " + theObject.name + " cannot be positioned");
return Vector3.zero;
}
} //end function
开发者ID:Ar2rZ,项目名称:tetbeams,代码行数:32,代码来源:GazeMove.cs
示例7: CalculateBounds
public void CalculateBounds()
{
selectionBounds = new Bounds(transform.position, Vector3.zero);
foreach(Renderer r in GetComponentsInChildren< Renderer >()) {
selectionBounds.Encapsulate(r.bounds);
}
}
开发者ID:devend711,项目名称:game-tutorial,代码行数:7,代码来源:WorldObject.cs
示例8: Start
private void Start()
{
if (this.template != null)
{
int num = 0;
Bounds bounds = new Bounds();
for (int i = 0; i < this.maxRows; i++)
{
for (int j = 0; j < this.maxColumns; j++)
{
GameObject obj2 = NGUITools.AddChild(base.gameObject, this.template);
obj2.transform.localPosition = new Vector3(this.padding + ((j + 0.5f) * this.spacing), -this.padding - ((i + 0.5f) * this.spacing), 0f);
UIStorageSlot component = obj2.GetComponent<UIStorageSlot>();
if (component != null)
{
component.storage = this;
component.slot = num;
}
bounds.Encapsulate(new Vector3((this.padding * 2f) + ((j + 1) * this.spacing), (-this.padding * 2f) - ((i + 1) * this.spacing), 0f));
if (++num >= this.maxItemCount)
{
if (this.background != null)
{
this.background.transform.localScale = bounds.size;
}
return;
}
}
}
if (this.background != null)
{
this.background.transform.localScale = bounds.size;
}
}
}
开发者ID:Lessica,项目名称:Something-of-SHIPWAR-GAMES,代码行数:35,代码来源:UIItemStorage.cs
示例9: CombineBoundsOfChildren
public static Bounds CombineBoundsOfChildren(GameObject go)
{
// Create an empty Bounds b
Bounds b = new Bounds(Vector3.zero, Vector3.zero);
// If this GameObject has a Renderer Component...
if (go.GetComponent<Renderer>() != null)
{
// Expand b to contain the Renderer's Bounds
b = BoundsUnion(b, go.GetComponent<Renderer>().bounds);
}
// If this GameObject has a Collider Component...
if (go.GetComponent<Collider>() != null)
{
// Expand b to contain the Collider's Bounds
b = BoundsUnion(b, go.GetComponent<Collider>().bounds);
}
// Iterate through each child of this gameObject.transform
foreach (Transform t in go.transform)
{
// Expand b to contain their Bounds as well
b = BoundsUnion(b, CombineBoundsOfChildren(t.gameObject));
}
return (b);
}
开发者ID:aalhamad7,项目名称:CSCI-3300-Group-3,代码行数:25,代码来源:Utils.cs
示例10: CollisionDectection
public static char CollisionDectection(Bounds moi, Bounds toi)
{
char sides;
Vector3 moiMax = moi.max;
Vector3 moiMin = moi.min;
Vector3 toiMax = toi.max;
Vector3 toiMin = toi.min;
//toiMax
Vector3 maxMinusMin = new Vector3(Mathf.Abs(moiMax.x - toiMin.x),Mathf.Abs(moiMax.y - toiMin.y),Mathf.Abs(moiMax.z - toiMin.z));
Vector3 minMinusMax = new Vector3(Mathf.Abs(moiMin.x - toiMax.x),Mathf.Abs(moiMin.y - toiMax.y),Mathf.Abs(moiMin.z - toiMax.z));
if(maxMinusMin.x <= maxMinusMin.y &&
maxMinusMin.x <= minMinusMax.y)
return 'r';
if(minMinusMax.x <= minMinusMax.y &&
minMinusMax.x <= maxMinusMin.y)
return 'l';
if(maxMinusMin.y <= minMinusMax.x &&
maxMinusMin.y <= maxMinusMin.x)
return 'u';
if(minMinusMax.y <= minMinusMax.x &&
minMinusMax.y <= maxMinusMin.x)
return 'd';
return 'n';
}
开发者ID:nburo,项目名称:TESTLOL_project,代码行数:29,代码来源:StaticTools.cs
示例11: GetBoundWithChildren
static bool GetBoundWithChildren( Transform parent, ref Bounds pBound, ref bool initBound )
{
Bounds bound = new Bounds();
bool didOne = false;
if( parent.gameObject.renderer != null )
{
bound = parent.gameObject.renderer.bounds;
if( initBound )
{
pBound.Encapsulate( bound.min );
pBound.Encapsulate( bound.max );
}
else
{
pBound.min = new Vector3( bound.min.x, bound.min.y, bound.min.z );
pBound.max = new Vector3( bound.max.x, bound.max.y, bound.max.z );
initBound = true;
}
didOne = true;
}
foreach( Transform child in parent )
{
if( GetBoundWithChildren( child, ref pBound, ref initBound ))
didOne = true;
}
return didOne;
}
开发者ID:pchernev,项目名称:Zombayo,代码行数:30,代码来源:GetBBox.cs
示例12: MaxBoundsExtent
private float m_ZoomAmountMultiplier = 2; // a multiplier for the FOV amount. The default of 2 makes the field of view twice as wide as required to fit the target.
#endregion Fields
#region Methods
public static float MaxBoundsExtent(Transform obj, bool includeEffects)
{
// get the maximum bounds extent of object, including all child renderers,
// but excluding particles and trails, for FOV zooming effect.
var renderers = obj.GetComponentsInChildren<Renderer>();
Bounds bounds = new Bounds();
bool initBounds = false;
foreach (Renderer r in renderers)
{
if (!((r is TrailRenderer) || (r is ParticleRenderer) || (r is ParticleSystemRenderer)))
{
if (!initBounds)
{
initBounds = true;
bounds = r.bounds;
}
else
{
bounds.Encapsulate(r.bounds);
}
}
}
float max = Mathf.Max(bounds.extents.x, bounds.extents.y, bounds.extents.z);
return max;
}
开发者ID:ankith8,项目名称:IH_PandaVSCritters,代码行数:33,代码来源:TargetFieldOfView.cs
示例13: InitializeInventory
// sets up the inventory with as many items
// as maxItemSlot. the background can be seen
// if it contains a UISprite.
void InitializeInventory()
{
int count = 0;
Bounds bound = new Bounds();
BackgroundSettings();
for(int y = 0; y < m_MaxRows; ++y)
{
for(int x = 0; x < m_MaxColumns; ++x)
{
GameObject go = NGUITools.AddChild(gameObject, m_Template);
UISprite sprite = go.GetComponent<UISprite> () as UISprite;
int width = sprite.width;
int height = sprite.height;
go.transform.localPosition = new Vector3 ( width * (x + 0.5f) * m_Spacing,
-(height * ( y + 0.5f ) * m_Padding),
0f);
InventoryItem slot = go.GetComponent<InventoryItem>();
if(slot != null)
{
slot.Slot = count;
}
InventoryData.AddSlot(go);
++count;
}
}
}
开发者ID:jonwa,项目名称:Project-Alix,代码行数:36,代码来源:Inventory.cs
示例14: CreateGrid
void CreateGrid() {
GameObject floorTiles = new GameObject("Floor Tiles"); // An object to store the tiles in the Hiearchy. Just for tidyness ;).
floorTiles.AddComponent<LevelInfo>(); // This should be done manually for the designed floors.
Bounds levelBounds = new Bounds();
int nrTiles = this.transform.childCount;
for (int i = 0; i < nrTiles; i++) {
Transform child = transform.GetChild(i);
if (child.GetComponent<Renderer>())
levelBounds.Encapsulate(child.GetComponent<Renderer>().bounds);
//TODO fixa så att det även funkar med cubeworld utan en tom box i dem
// else if (child.GetComponentInChildren<Renderer>())
// levelBounds.Encapsulate(child.GetComponent<Renderer>().bounds);
}
Vector3 size = levelBounds.size;
_gridManager.CreateGrid((int)size.x + 1, (int)size.z + 1);
for (int i = 0; i < nrTiles; i++) {
BaseTile tile = transform.GetChild(i).GetComponent<BaseTile>();
tile.Init(_gridManager);
_gridManager.AddTile(tile);
}
Object[] allUnits = Object.FindObjectsOfType<BaseUnit>();
for (int i = 0; i < allUnits.Length; i++) {
BaseUnit bu = allUnits[i] as BaseUnit;
bu.Init(_gridManager);
BaseTile tile = _gridManager.GetTile(bu.transform.position);
DebugAux.Assert(tile != null, "Can't have a unit placed on a non-tile " + bu);
BaseTile.TeleportTo(bu, null, tile);
}
}
开发者ID:Niklas83,项目名称:UnityGame1,代码行数:35,代码来源:Floor.cs
示例15: calculateWorldBounds
public static Bounds calculateWorldBounds(GameObject go)
{
if (null == go) { return new Bounds(Vector3.zero, Vector3.zero); }
Vector2 min = new Vector2(float.MaxValue, float.MaxValue);
Vector2 max = new Vector2(float.MinValue, float.MinValue);
Vector3 v;
RectTransform[] rts = go.GetComponentsInChildren<RectTransform>();
if (rts.Length == 0) return new Bounds(go.transform.position, Vector3.zero);
for (int i = 0, imax = rts.Length; i < imax; ++i)
{
RectTransform t = rts[i];
if (!t.gameObject.activeSelf) { continue; }
Vector3[] corners = new Vector3[4];
t.GetWorldCorners(corners);
for (int j = 0; j < 4; ++j)
{
v = corners[j];
if (v.x > max.x) max.x = v.x;
if (v.y > max.y) max.y = v.y;
if (v.x < min.x) min.x = v.x;
if (v.y < min.y) min.y = v.y;
}
}
Bounds b = new Bounds(min, Vector3.zero);
b.Encapsulate(max);
return b;
}
开发者ID:oathx,项目名称:Six,代码行数:35,代码来源:UGUIMath.cs
示例16: CheckOffscreen
void CheckOffscreen()
{
//if bounds are still tehir default value
if (bounds.size == Vector3.zero)
{
//then set them
bounds = Utils.CombineBoundsOfChildren(this.gameObject);
//Also find the diff between bounds.center & transform.position
boundsCenterOffset = bounds.center - transform.position;
}
//every time, update teh bounds to the ucrrent positon
bounds.center = transform.position + boundsCenterOffset;
//check to see wehether the bounds are completely offscreen
Vector3 off = Utils.ScreenBoundsCheck(bounds, BoundsTest.offScreen);
if (off != Vector3.zero)
{
//if this enemy has gone off the bottom edge of the screen
if (off.y < 0)
{
//then destroy it
Destroy(this.gameObject);
}
}
}
开发者ID:spacesnaill,项目名称:Space-SHMUP,代码行数:25,代码来源:Enemy.cs
示例17: DoUpdateGraphs
public void DoUpdateGraphs()
{
if (col == null) { return; }
isWaitingForUpdate = false;
Bounds newBounds = col.bounds;
//if (!simple) {
Bounds merged = newBounds;
merged.Encapsulate (prevBounds);
if (BoundsVolume (merged) < BoundsVolume (newBounds)+BoundsVolume(prevBounds)) {
AstarPath.active.UpdateGraphs (merged);
} else {
AstarPath.active.UpdateGraphs (prevBounds);
AstarPath.active.UpdateGraphs (newBounds);
}
/*} else {
GraphUpdateObject guo = new GraphUpdateObject (prevBounds);
guo.updatePhysics = false;
guo.modifyWalkability = true;
guo.setWalkability = true;
AstarPath.active.UpdateGraphs (guo);
}*/
prevBounds = newBounds;
}
开发者ID:shreshtabm,项目名称:Fight-for-Zion-Mobile-Game,代码行数:28,代码来源:DynamicGridObstacle.cs
示例18: CalculateBounds
public void CalculateBounds()
{
if (connectedBody == null)
{
_bodyBounds = new Bounds();
return;
}
AABB aabb_full = new AABB();
bool combine = false;
for (int i = 0; i < connectedBody.FixtureList.Count; i++)
{
for (int j = 0; j < connectedBody.FixtureList[i].Shape.ChildCount; j++)
{
AABB aabb;
connectedBody.FixtureList[i].Shape.ComputeAABB(out aabb, ref connectedBody.Xf, j);
if (!combine)
{
combine = true;
aabb_full = aabb;
}
else
{
aabb_full.Combine(ref aabb);
}
}
}
_bodyBounds = Bounds.FromAABB(ref aabb_full, to2dMode, GetSize());
}
开发者ID:Elideb,项目名称:FFWD,代码行数:28,代码来源:Collider.cs
示例19: DebugBounds
/// <summary>
/// - Debugs an axis-aligned bounding box.
/// </summary>
/// <param name='bounds'>
/// - The bounds to debug.
/// </param>
/// <param name='color'>
/// - The color of the bounds.
/// </param>
/// <param name='duration'>
/// - How long to draw the bounds.
/// </param>
/// <param name='depthTest'>
/// - Whether or not the bounds should be faded when behind other objects.
/// </param>
public static void DebugBounds(Bounds bounds, Color color, float duration, bool depthTest)
{
Vector3 center = bounds.center;
float x = bounds.extents.x;
float y = bounds.extents.y;
float z = bounds.extents.z;
Vector3 ruf = center+new Vector3(x,y,z);
Vector3 rub = center+new Vector3(x,y,-z);
Vector3 luf = center+new Vector3(-x,y,z);
Vector3 lub = center+new Vector3(-x,y,-z);
Vector3 rdf = center+new Vector3(x,-y,z);
Vector3 rdb = center+new Vector3(x,-y,-z);
Vector3 lfd = center+new Vector3(-x,-y,z);
Vector3 lbd = center+new Vector3(-x,-y,-z);
Debug.DrawLine(ruf, luf, color, duration, depthTest);
Debug.DrawLine(ruf, rub, color, duration, depthTest);
Debug.DrawLine(luf, lub, color, duration, depthTest);
Debug.DrawLine(rub, lub, color, duration, depthTest);
Debug.DrawLine(ruf, rdf, color, duration, depthTest);
Debug.DrawLine(rub, rdb, color, duration, depthTest);
Debug.DrawLine(luf, lfd, color, duration, depthTest);
Debug.DrawLine(lub, lbd, color, duration, depthTest);
Debug.DrawLine(rdf, lfd, color, duration, depthTest);
Debug.DrawLine(rdf, rdb, color, duration, depthTest);
Debug.DrawLine(lfd, lbd, color, duration, depthTest);
Debug.DrawLine(lbd, rdb, color, duration, depthTest);
}
开发者ID:DarkGizmo,项目名称:DryadConfiture,代码行数:48,代码来源:DebugExtension.cs
示例20: Query
public void Query(Vector3 pos, float radius, UKList<IUKSpatialObject> result)
{
var b = new Bounds(pos, Vector3.one * radius * 2f);
int minx = Mathf.FloorToInt(b.min.x / CELL_SIZE);
int miny = Mathf.FloorToInt(b.min.y / CELL_SIZE);
int minz = Mathf.FloorToInt(b.min.z / CELL_SIZE);
int maxx = Mathf.FloorToInt(b.max.x / CELL_SIZE);
int maxy = Mathf.FloorToInt(b.max.y / CELL_SIZE);
int maxz = Mathf.FloorToInt(b.max.z / CELL_SIZE);
for (int z = minz; z <= maxz; ++z) {
for (int y = miny; y <= maxy; ++y) {
for (int x = minx; x <= maxx; ++x) {
var h = CalculateHash(x,y,z);
if (spatialHashTable.ContainsKey(h)) {
var l = spatialHashTable[h];
foreach(var p in l) {
result.Add(p.Key);
}
}
}
}
}
}
开发者ID:hagish,项目名称:tektix,代码行数:26,代码来源:UKSpatialIndexHash.cs
注:本文中的Bounds类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论