public void OnDrawGizmos(bool selected) { this.gizmoDrawing = true; Gizmos.color = new Color(0.615f, 1f, 0.06f, selected ? 1f : 0.7f); MovementPlane movementPlane = (RVOSimulator.active != null) ? RVOSimulator.active.movementPlane : MovementPlane.XZ; Vector3 vector = (movementPlane == MovementPlane.XZ) ? Vector3.up : (-Vector3.forward); if (this.gizmoVerts == null || this.AreGizmosDirty() || this._obstacleMode != this.obstacleMode) { this._obstacleMode = this.obstacleMode; if (this.gizmoVerts == null) { this.gizmoVerts = new List <Vector3[]>(); } else { this.gizmoVerts.Clear(); } this.CreateObstacles(); } Matrix4x4 matrix = this.GetMatrix(); for (int i = 0; i < this.gizmoVerts.Count; i++) { Vector3[] array = this.gizmoVerts[i]; int j = 0; int num = array.Length - 1; while (j < array.Length) { Gizmos.DrawLine(matrix.MultiplyPoint3x4(array[j]), matrix.MultiplyPoint3x4(array[num])); num = j++; } if (selected) { int k = 0; int num2 = array.Length - 1; while (k < array.Length) { Vector3 vector2 = matrix.MultiplyPoint3x4(array[num2]); Vector3 vector3 = matrix.MultiplyPoint3x4(array[k]); if (movementPlane != MovementPlane.XY) { Gizmos.DrawLine(vector2 + vector * this.Height, vector3 + vector * this.Height); Gizmos.DrawLine(vector2, vector2 + vector * this.Height); } Vector3 vector4 = (vector2 + vector3) * 0.5f; Vector3 normalized = (vector3 - vector2).normalized; if (!(normalized == Vector3.zero)) { Vector3 vector5 = Vector3.Cross(vector, normalized); Gizmos.DrawLine(vector4, vector4 + vector5); Gizmos.DrawLine(vector4 + vector5, vector4 + vector5 * 0.5f + normalized * 0.5f); Gizmos.DrawLine(vector4 + vector5, vector4 + vector5 * 0.5f - normalized * 0.5f); } num2 = k++; } } } this.gizmoDrawing = false; }
public JobBuild BuildJob(NativeArray <float3> agentPositions, NativeArray <float> agentSpeeds, NativeArray <float> agentRadii, int numAgents, MovementPlane movementPlane) { if (numAgents >= MaxAgents) { throw new System.Exception("Too many agents. Cannot have more than " + MaxAgents); } Reserve(numAgents); this.numAgents = numAgents; this.movementPlane = movementPlane; return(new JobBuild { agents = agents, agentPositions = agentPositions, agentSpeeds = agentSpeeds, agentRadii = agentRadii, outMaxSpeeds = maxSpeeds, outMaxRadius = maxRadius, outArea = nodeAreas, outAgentRadii = this.agentRadii, // Will be copied. These are copied so that the quadtree remains in a valid state even after new agents have been added/removed. This is important for the QueryArea method which may be called at any time. outAgentPositions = this.agentPositions, // Will be copied outBoundingBox = boundingBoxBuffer, outChildPointers = childPointers, numAgents = numAgents, movementPlane = movementPlane, }); }
public void setActivePlanes(MovementPlane activePlanes) { clearSelection(); xyAxisBox.Enabled = (activePlanes & MovementPlane.XY) == MovementPlane.XY; xzAxisBox.Enabled = (activePlanes & MovementPlane.XZ) == MovementPlane.XZ; yzAxisBox.Enabled = (activePlanes & MovementPlane.YZ) == MovementPlane.YZ; }
static int InnerNodeCountUpperBound(int numAgents, MovementPlane movementPlane) { // Every LeafSize number of nodes can cause a split at most MaxDepth // number of times. Each split needs 4 (or 8) units of space. // Round the value up by adding LeafSize-1 to the numerator. // This is an upper bound. Most likely the tree will contain significantly fewer nodes. return(((movementPlane == MovementPlane.Arbitrary ? 8 : 4) * MaxDepth * numAgents + LeafSize - 1) / LeafSize); }
public void setActivePlanes(MovementAxis axes, MovementPlane planes) { foreach (MovableObjectTools currentTools in movableObjects) { currentTools.setActiveAxes(axes); currentTools.setActivePlanes(planes); } }
// Use this for initialization void Start() { currentTrackElement = CreateTrack(StartingTrackPrefab); AutoFlanschAll(currentTrackElement, 5); MovementPlaneInstance = Instantiate(MovementPlanePrefab); MovementPlaneInstance.transform.position = currentTrackElement.BeginFlanschPoints[0].transform.position; MovementPlaneInstance.transform.rotation = currentTrackElement.BeginFlanschPoints[0].transform.rotation; MovementPlaneInstance.StartMovementPath(currentTrackElement, NextTrackElement); }
// Token: 0x06002856 RID: 10326 RVA: 0x001B75C8 File Offset: 0x001B57C8 public Simulator(int workers, bool doubleBuffering, MovementPlane movementPlane) { this.workers = new Simulator.Worker[workers]; this.doubleBuffering = doubleBuffering; this.DesiredDeltaTime = 1f; this.movementPlane = movementPlane; this.Quadtree = new RVOQuadtree(); for (int i = 0; i < workers; i++) { this.workers[i] = new Simulator.Worker(this); } this.agents = new List <Agent>(); this.obstacles = new List <ObstacleVertex>(); }
public static MovementPlane.Movement[] TruncateRoute(MovementPlane.Movement[] truncatedRoute, int newMovementCost, bool removeLastMove) { List<MovementPlane.Movement> newRoute = new List<MovementPlane.Movement>(); MovementPlane.Movement[] finalNewRoute = null; int moveCost = 0; for (int i = 0; i < truncatedRoute.Length; i++) { if (truncatedRoute[i].xMovement != 0 && truncatedRoute[i].yMovement != 0) moveCost += 3; else moveCost += 2; if (moveCost <= newMovementCost) newRoute.Add(truncatedRoute[i]); else { break; } } if (removeLastMove) { finalNewRoute = new MovementPlane.Movement[newRoute.Count - 1]; for (int j = 0; j < finalNewRoute.Length; j++) { finalNewRoute[j] = newRoute[j]; } } else { finalNewRoute = new MovementPlane.Movement[newRoute.Count]; finalNewRoute = newRoute.ToArray(); } return finalNewRoute; }
bool SetupMovement(MovementPlane.Movement move, MovementPlane.Movement[] route, int movesFound, int xPos, int yPos, int movePointsLeft, int maxMoves, bool unitsBlock) { int moveCost = 0; bool foundMove = false; bool crossingDiagonal = false; if(move.xMovement != 0 && move.yMovement != 0) { for (int i = 0; i < movesFound; i++) { int X = possibleMoves[i].GetComponent<MovementPlane>().PresentTile.GetComponent<BasicTile>().XPosition, Y = possibleMoves[i].GetComponent<MovementPlane>().PresentTile.GetComponent<BasicTile>().YPosition; if (((xPos + move.xMovement == X && yPos == Y) || (xPos == X && yPos + move.yMovement == Y)) && DiagonalsCrossing(move, possibleMoves[i].GetComponent<MovementPlane>().Route[possibleMoves[i].GetComponent<MovementPlane>().Route.Length - 1])) { crossingDiagonal = true; } } } if (!(xPos + move.xMovement < grid.xSize && xPos + move.xMovement >= 0 && yPos + move.yMovement < grid.ySize && yPos + move.yMovement >= 0)) return foundMove; else if (crossingDiagonal) return foundMove; else if (grid.Grid(xPos + move.xMovement, yPos + move.yMovement).GetComponent<BasicTile>().Accessible(grid.Grid(xPos, yPos).GetComponent<BasicTile>(), unitsBlock, team)) { foundMove = true; moveCost = MovementPlane.RouteMoveCost(route); if (move.xMovement != 0 && move.yMovement != 0) moveCost += 3; else moveCost += 2; if (moveCost <= maxMoves) { possibleMoves[movesFound] = Instantiate(movementPlane); MovementPlane.Movement[] newRoute = new MovementPlane.Movement[route.Length + 1]; for (int i = 0; i < route.Length; i++) { newRoute[i] = route[i]; } newRoute[route.Length] = move; possibleMoves[movesFound].GetComponent<MovementPlane>().AssignMovementPlaneValues(grid.Grid(xPos + move.xMovement, yPos + move.yMovement), true, false, this, newRoute, moveCost); possibleMoves[movesFound].name = "Move " + (xPos + move.xMovement) + " " + (yPos + move.yMovement); possibleMoves[movesFound].name += " costs " + possibleMoves[movesFound].GetComponent<MovementPlane>().MovementCost; foundMove = true; } else { foundMove = false; //MovementPlane.PrintRoute(route); } } if(grid.Grid(xPos + move.xMovement, yPos + move.yMovement).GetComponent<BasicTile>().IsOccupied) { objectsWithinRange.Add(grid.Grid(xPos + move.xMovement, yPos + move.yMovement).GetComponent<BasicTile>().CharacterStepping); } return foundMove; }
/*IEnumerator NewFindMovesCorout(int xPos, int yPos, MovementPlane.Movement[] route, int movesFound, int movementPointsLeft, int maxMoves, bool unitsBlock) { bool[] knownTiles = { true, true, true, true, true, true, true, true }; bool[] reachedEndOfLine = { false, false, false, false, false, false, false, false }; int endedLines = 0; int movesFoundThisRound = 0; parsedMoves++; int[] straightMoves = new int[8]; MovementPlane.Movement[] directions = new MovementPlane.Movement[8]; directions[4].xMovement = 1; directions[4].yMovement = 0; directions[0].xMovement = 1; directions[0].yMovement = 1; directions[5].xMovement = 0; directions[5].yMovement = 1; directions[1].xMovement = -1; directions[1].yMovement = 1; directions[6].xMovement = -1; directions[6].yMovement = 0; directions[2].xMovement = -1; directions[2].yMovement = -1; directions[7].xMovement = 0; directions[7].yMovement = -1; directions[3].xMovement = 1; directions[3].yMovement = -1; for (int i = 0; i < straightMoves.Length; i++) { straightMoves[i] = 1; } int initXPos = presentTile.GetComponent<BasicTile>().XPosition, initYPos = presentTile.GetComponent<BasicTile>().YPosition; while (endedLines < 8) { for (int j = 0; j <= 7; j++) { if (!reachedEndOfLine[j]) { for (int i = 0; i < movesFound; i++) { int X = possibleMoves[i].GetComponent<MovementPlane>().presentTile.GetComponent<BasicTile>().XPosition, Y = possibleMoves[i].GetComponent<MovementPlane>().presentTile.GetComponent<BasicTile>().YPosition, newXPos = xPos, newYPos = yPos; newXPos += straightMoves[j] * directions[j].xMovement; newYPos += straightMoves[j] * directions[j].yMovement; if ((newXPos == initXPos && newYPos == initYPos) || (newXPos == X && newYPos == Y)) { knownTiles[j] = false; } } if (knownTiles[j]) { MovementPlane.Movement[] newRoute = new MovementPlane.Movement[route.Length + straightMoves[j] - 1]; int newXPos = xPos, newYPos = yPos; for (int k = 0; k < route.Length; k++) { newRoute[k] = route[k]; } for (int k = 0; k < straightMoves[j] - 1; k++) { newRoute[route.Length + k] = directions[j]; } newXPos += (straightMoves[j] - 1) * directions[j].xMovement; newYPos += (straightMoves[j] - 1) * directions[j].yMovement; if (SetupMovement(directions[j], newRoute, movesFound, newXPos, newYPos, movementPointsLeft, maxMoves, unitsBlock)) { yield return new WaitForSeconds(0.2f); straightMoves[j]++; movesFound++; movesFoundThisRound++; } else { reachedEndOfLine[j] = true; endedLines++; } } else { reachedEndOfLine[j] = true; endedLines++; } } } } if (possibleMoves[parsedMoves - 1] != null) { int X = possibleMoves[parsedMoves - 1].GetComponent<MovementPlane>().presentTile.GetComponent<BasicTile>().XPosition, Y = possibleMoves[parsedMoves - 1].GetComponent<MovementPlane>().presentTile.GetComponent<BasicTile>().YPosition, movePointsLeft = maxMovementPoints - possibleMoves[parsedMoves - 1].GetComponent<MovementPlane>().movementCost; MovementPlane.Movement[] moveRoute = possibleMoves[parsedMoves - 1].GetComponent<MovementPlane>().route; StartCoroutine(NewFindMovesCorout(X, Y, moveRoute, movesFound, movePointsLeft, maxMoves, unitsBlock)); } yield break; } */ bool DiagonalsCrossing(MovementPlane.Movement move1, MovementPlane.Movement move2) { bool crossing = false; if ((move1.xMovement != 0 && move1.yMovement != 0) || (move2.xMovement != 0 && move2.yMovement != 0)) { if ((move1.xMovement == move2.xMovement && move1.yMovement == -move2.yMovement) || (move1.yMovement == move2.yMovement && move1.xMovement == -move2.xMovement)) { crossing = true; } } return crossing; }
public IEnumerator FollowRoute(MovementPlane.Movement[] route) { animatedMesh.Play("Armature|Walk_blocking"); for(int i = 0; i < route.Length; i++) { float moveProgress = 0f; int X = presentTile.GetComponent<BasicTile>().XPosition, Y = presentTile.GetComponent<BasicTile>().YPosition; nextTile = grid.Grid(X + route[i].xMovement, Y + route[i].yMovement); while(moveProgress <= 1f) { orientation = route[i].orientation; transform.localPosition = CalculateMovement(moveProgress); moveProgress += Time.deltaTime * speed; yield return null; } presentTile.GetComponent<BasicTile>().IsOccupied = false; presentTile.GetComponent<BasicTile>().CharacterStepping = null; presentTile = nextTile; presentTile.GetComponent<BasicTile>().IsOccupied = true; presentTile.GetComponent<BasicTile>().CharacterStepping = this; nextTile = null; moveProgress = 0f; } isMoving = false; movementPoints -= MovementPlane.RouteMoveCost(route); FinishedMoving(); animatedMesh.Play("Armature|WAIT01.001"); yield break; }
public void FindMoves(int xPos, int yPos, MovementPlane.Movement[] route, int movesFound, int movementPointsLeft, int maxMoves, bool unitsBlock) { bool[] knownTiles = { true, true, true, true, true, true, true, true }; bool[] reachedEndOfLine = { false, false, false, false, false, false, false, false }; int endedLines = 0; int movesFoundThisRound = 0; parsedMoves++; int[] straightMoves = new int[8]; MovementPlane.Movement[] directions = new MovementPlane.Movement[8]; directions[0] = new MovementPlane.Movement(1, 0); directions[4] = new MovementPlane.Movement(1, 1); directions[1] = new MovementPlane.Movement(0, 1); directions[5] = new MovementPlane.Movement(-1, 1); directions[2] = new MovementPlane.Movement(-1, 0); directions[6] = new MovementPlane.Movement(-1, -1); directions[3] = new MovementPlane.Movement(0, -1); directions[7] = new MovementPlane.Movement(1, -1); for (int i = 0; i < straightMoves.Length; i++) { straightMoves[i] = 1; } int initXPos = presentTile.GetComponent<BasicTile>().XPosition, initYPos = presentTile.GetComponent<BasicTile>().YPosition; while (endedLines < 8) { for (int j = 0; j <= 7; j++) { if (!reachedEndOfLine[j]) { for (int i = 0; i < movesFound; i++) { int X = possibleMoves[i].GetComponent<MovementPlane>().PresentTile.GetComponent<BasicTile>().XPosition, Y = possibleMoves[i].GetComponent<MovementPlane>().PresentTile.GetComponent<BasicTile>().YPosition, newXPos = xPos, newYPos = yPos; newXPos += straightMoves[j] * directions[j].xMovement; newYPos += straightMoves[j] * directions[j].yMovement; if ((newXPos == initXPos && newYPos == initYPos) || (newXPos == X && newYPos == Y)) { knownTiles[j] = false; } } if (knownTiles[j]) { MovementPlane.Movement[] newRoute = new MovementPlane.Movement[route.Length + straightMoves[j] - 1]; int newXPos = xPos, newYPos = yPos; for (int k = 0; k < route.Length; k++) { newRoute[k] = route[k]; } for (int k = 0; k < straightMoves[j] - 1; k++) { newRoute[route.Length + k] = directions[j]; } newXPos += (straightMoves[j] - 1) * directions[j].xMovement; newYPos += (straightMoves[j] - 1) * directions[j].yMovement; if (SetupMovement(directions[j], newRoute, movesFound, newXPos, newYPos, movementPointsLeft, maxMoves, unitsBlock)) { //yield return new WaitForSeconds(0.1f); straightMoves[j]++; movesFound++; movesFoundThisRound++; } else { reachedEndOfLine[j] = true; endedLines++; } } else { reachedEndOfLine[j] = true; endedLines++; } } } } if (possibleMoves[parsedMoves - 1] != null) { int X = possibleMoves[parsedMoves - 1].GetComponent<MovementPlane>().PresentTile.GetComponent<BasicTile>().XPosition, Y = possibleMoves[parsedMoves - 1].GetComponent<MovementPlane>().PresentTile.GetComponent<BasicTile>().YPosition, movePointsLeft = maxMoves - possibleMoves[parsedMoves - 1].GetComponent<MovementPlane>().MovementCost; MovementPlane.Movement[] moveRoute = possibleMoves[parsedMoves - 1].GetComponent<MovementPlane>().Route; FindMoves(X, Y, moveRoute, movesFound, movePointsLeft, maxMoves, unitsBlock); } return; }
public void setActivePlanes(MovementPlane activePlanes) { moveTool.setActivePlanes(activePlanes); }