static public int Expand(IntPtr l) { try{ if (matchType(l, 2, typeof(float))) { UnityEngine.Bounds self = (UnityEngine.Bounds)checkSelf(l); System.Single a1; checkType(l, 2, out a1); self.Expand(a1); setBack(l, self); return(0); } else if (matchType(l, 2, typeof(UnityEngine.Vector3))) { UnityEngine.Bounds self = (UnityEngine.Bounds)checkSelf(l); UnityEngine.Vector3 a1; checkType(l, 2, out a1); self.Expand(a1); setBack(l, self); return(0); } LuaDLL.luaL_error(l, "No matched override function to call"); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
// 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; }
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 ) ); } }
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; }
static bool Bounds_Expand__Single(JSVCall vc, int argc) { int len = argc; if (len == 1) { System.Single arg0 = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg); UnityEngine.Bounds argThis = (UnityEngine.Bounds)vc.csObj; argThis.Expand(arg0); JSMgr.changeJSObj(vc.jsObjID, argThis); } return(true); }
static bool Bounds_Expand__Vector3(JSVCall vc, int argc) { int len = argc; if (len == 1) { UnityEngine.Vector3 arg0 = (UnityEngine.Vector3)JSApi.getVector3S((int)JSApi.GetType.Arg); UnityEngine.Bounds argThis = (UnityEngine.Bounds)vc.csObj; argThis.Expand(arg0); JSMgr.changeJSObj(vc.jsObjID, argThis); } return(true); }
// 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); }
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; } } }
/** * 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; }
// Update is called once per frame void Update() { climbingBounds = torsoCollider.bounds;//sets the height detection ray boundaries to the boundry of the torso collider-Frantz climbingBounds.Expand (rayDisFromtorso);// expands the boundry to set height detection ray further away from player-Frantz // Check if facing right or left and set boxHCheck accordingly -Steve if(player.transform.localScale.x > 0f) boxHcheck = new Vector2 (climbingBounds.max.x, climbingBounds.max.y);// sets where the height detection ray's orign will be-Frantz else boxHcheck = new Vector2 (climbingBounds.min.x, climbingBounds.max.y);// sets where the height detection ray's orign will be-Frantz touchingBox = Physics2D.OverlapCircle (boxCheck.position, detectionRadius, whatIsBox);// checks if player is touching a box-Frantz boxHeightCheck= Physics2D.Raycast( boxHcheck, new Vector2 (0,-1),Mathf.Infinity,whatIsBox);//Makes a ray to detect if there is a box infront of the player and its distance between the rays origin and the top of the box-Frantz groundHeightCheck = Physics2D.Raycast (boxHcheck, new Vector2 (0, -1), Mathf.Infinity, whatIsGround);//Makes a ray to detect if there is a ground underneath of the player and its distance between the rays origin and the ground-Frantz actualBoxHeight = groundHeightCheck.distance - boxHeightCheck.distance;// finds the actual box height by finding the difference between ( distance of the ray origin to the box) - (distance of the ray origin to the ground); -Frantz Debug.DrawRay(boxHcheck, new Vector2 (0, -2), Color.red, .5f, true);//just draws the ray so we can see it-Frantz //if player is touching the box and the box is smaller then 2, the player is able to climb it-Frantz // 2 is just for the purposes of the prototype, I feel like it will change when we scale everything -Frantz if ((touchingBox && actualBoxHeight <= 2)) canClimb = true; else canClimb = false; }
private Mesh GenerateStarMesh(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(); var weights = new SGT_WeightedRandom(100); for (var i = 0; i < StarVariantCount; i++) { var ssv = GetStarVariant(i); weights.Add(i, ssv != null ? ssv.SpawnProbability : 1.0f); } 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 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; }
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"); }
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 (); #if ASTARDEBUG Console.WriteLine ("Recast Graph -- Building Contours"); #endif VoxelContourSet cset = new VoxelContourSet (); vox.BuildContours (contourMaxError,1,cset,Voxelize.RC_CONTOUR_TESS_WALL_EDGES); #if ASTARDEBUG Console.WriteLine ("Recast Graph -- Building Poly Mesh"); #endif VoxelMesh mesh; vox.BuildPolyMesh (cset,3,out mesh); #if ASTARDEBUG Console.WriteLine ("Recast Graph -- Building Nodes"); #endif //Vector3[] vertices = new Vector3[mesh.verts.Length]; AstarProfiler.StartProfile ("Build Nodes"); //matrix = Matrix4x4.TRS (vox.voxelOffset,Quaternion.identity,Int3.Precision*vox.cellScale); //Position the vertices correctly in the world for (int i=0;i<mesh.verts.Length;i++) { //Note the multiplication is Scalar multiplication of vectors mesh.verts[i] = ((mesh.verts[i]*Int3.Precision) * vox.cellScale) + (Int3)vox.voxelOffset; //Debug.DrawRay (matrix.MultiplyPoint3x4(vertices[i]),Vector3.up,Color.red); } #if ASTARDEBUG Console.WriteLine ("Recast Graph -- Generating Nodes"); #endif //NavMeshGraph.GenerateNodes (this,vertices,mesh.tris, out _vectorVertices, out _vertices); /*NavmeshTile prevTile = tiles[x + z*tileXCount]; if (prevTile != null) { for (int i=0;i<prevTile.nodes.Length;i++) { prevTile.nodes[i].v0 = -1; prevTile.nodes[i].v1 = -1; prevTile.nodes[i].v2 = -1; } }*/ NavmeshTile tile = CreateTile (vox, mesh, x,z); tiles[tile.x + tile.z*tileXCount] = tile; AstarProfiler.EndProfile ("Build Nodes"); #if ASTARDEBUG Console.WriteLine ("Recast Graph -- Done"); #endif AstarProfiler.EndProfile ("Build Tile"); }
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(); }
/** 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; } } } }
// 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; }
//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; } }
/** * Expands a Bounds object using both a velocity vector and an offset. */ public static Bounds ExpandBounds(this Bounds b, Vector3 velocity, float offset) { Bounds expanded = new Bounds(b.center,b.size); expanded.Expand(offset); expanded.Encapsulate(velocity + b.max); expanded.Encapsulate(velocity + b.min); return expanded; }
/// <summary> /// Recalculate shrinked the bounds /// </summary> public void UpdateInnerBounds() { bounds = box.bounds; // * 2 so it's shrink skinWidth by each side bounds.Expand (skinWidth * -2); }
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 System.Console.WriteLine("Recast Graph -- Building Nodes"); #endif //Vector3[] vertices = new Vector3[mesh.verts.Length]; AstarProfiler.StartProfile("Build Nodes"); // Debug code //matrix = Matrix4x4.TRS (vox.voxelOffset,Quaternion.identity,Int3.Precision*vox.cellScale); //Position the vertices correctly in the world for (int i = 0; i < mesh.verts.Length; i++) { //Note the multiplication is Scalar multiplication of vectors mesh.verts[i] = ((mesh.verts[i]*Int3.Precision) * vox.cellScale) + (Int3)vox.voxelOffset; // Debug code //Debug.DrawRay (matrix.MultiplyPoint3x4(vertices[i]),Vector3.up,Color.red); } #if ASTARDEBUG System.Console.WriteLine("Recast Graph -- Generating Nodes"); #endif NavmeshTile tile = CreateTile(vox, mesh, x, z); tiles[tile.x + tile.z*tileXCount] = tile; AstarProfiler.EndProfile("Build Nodes"); #if ASTARDEBUG System.Console.WriteLine("Recast Graph -- Done"); #endif AstarProfiler.EndProfile("Build Tile"); }
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; }
public void onDrawGizmos( Vector3 basePosition ) { Gizmos.color = new Color( 0f, 0.5f, 0.6f ); var bounds = new Bounds( basePosition, new Vector3( width, 10f ) ); var lineWidth = Camera.main.orthographicSize; bounds.center = new Vector3( bounds.center.x, basePosition.y, bounds.center.z ); bounds.Expand( new Vector3( 0f, lineWidth - bounds.size.y ) ); Gizmos.DrawLine( bounds.min, bounds.min + new Vector3( 0f, bounds.size.y ) ); Gizmos.DrawLine( bounds.max, bounds.max - new Vector3( 0f, bounds.size.y ) ); if( dualForwardFocusType == DualForwardFocusType.ThresholdBased ) { bounds.Expand( new Vector3( dualForwardFocusThresholdExtents, 1f ) ); Gizmos.color = Color.blue; Gizmos.DrawLine( bounds.min, bounds.min + new Vector3( 0f, bounds.size.y ) ); Gizmos.DrawLine( bounds.max, bounds.max - new Vector3( 0f, bounds.size.y ) ); } }
/// <summary> /// Update the collision boundaries. /// </summary> private void UpdateBounds() { m_Bounds = m_Collider.bounds; m_Bounds.Expand(m_Indenting * -2f); float minX = m_Bounds.min.x; float maxX = m_Bounds.max.x; float minY = m_Bounds.min.y; float maxY = m_Bounds.max.y; float minZ = m_Bounds.min.z; float maxZ = m_Bounds.max.z; m_BottomUpperLeft = new Vector3(minX, minY, maxZ); m_TopUpperLeft = new Vector3(minX, maxY, maxZ); m_FrontUpperLeft = new Vector3(minX, maxY, minZ); m_BackUpperLeft = new Vector3(minX, maxY, maxZ); m_RightUpperLeft = new Vector3(maxX, maxY, minZ); m_LeftUpperLeft = m_TopUpperLeft; }
private void LayoutHierachyNodes(List<HierachyNode> nodes, Rect sizeRect) { Bounds bounds = new Bounds(); for (int i = 0; i < nodes.Count; i++) { for (int k = i + 1; k < nodes.Count; k++) { if (nodes[i].pos.y == nodes[k].pos.y) { nodes[i].pos.x -= this.hierachySpread.x * 0.5f; nodes[k].pos.x = nodes[i].pos.x + this.hierachySpread.x; } } bounds.Encapsulate(nodes[i].pos); } bounds.Expand((Vector3) this.hierachySpread); this.hierachyRect = new Rect(0f, 0f, bounds.size.x, bounds.size.y); this.hierachyRect.width = Mathf.Max(this.hierachyRect.width, this.hierachyView.width); Vector3 vector3 = new Vector3((this.hierachyRect.xMax + this.hierachyRect.xMin) * 0.5f, (this.hierachyRect.yMax + this.hierachyRect.yMin) * 0.5f, 0f); vector3.y += 8f; for (int j = 0; j < nodes.Count; j++) { HierachyNode local1 = nodes[j]; local1.pos -= bounds.center; nodes[j].pos.x += vector3.x; nodes[j].pos.y += vector3.y; nodes[j].rect = new Rect(nodes[j].pos.x - (this.hierachyNodeSize.x * 0.5f), nodes[j].pos.y - (this.hierachyNodeSize.y * 0.5f), this.hierachyNodeSize.x, this.hierachyNodeSize.y); } }
// Frame Selects the curve to be completely visible public void FrameSelected(Rect rect) { if (animationCurve.length == 0) return; // Compute bounds from keyframes Vector3 pos = new Vector3 (animationCurve[0].time, animationCurve[0].value, 0); Bounds bounds = new Bounds(pos, Vector3.zero); for (int i=0;i<animationCurve.length;i++) { pos = new Vector3 (animationCurve[i].time, animationCurve[i].value, 0); bounds.Encapsulate(pos); } // With 50 pixel extra bounds if (animationCurve.length != 1) bounds.Expand(Mathf.Max(50 * bounds.size.magnitude / rect.width, 0.0001F)); // Single keyframe have a 1 unit extra bounds else bounds.Expand(Mathf.Max(1, 0.0001F)); // Calculate scale & translate from bounds m_Scale.x = Mathf.Min(rect.width / bounds.size.x, rect.height / bounds.size.y); m_Scale.y = -m_Scale.x; m_Translation.x = -bounds.min.x * m_Scale.x; m_Translation.y = rect.height - bounds.min.y * m_Scale.y; }