/// <summary> /// Virtual method that is used to destroy the module. This method /// destroys the GameObject the module is attached to and returns /// a reference to the prefab used to create the module, if any. /// </summary> public virtual GameObject DestroyModule() { GameObject prefab = this._prefab; this._core = null; this.ammoStore = null; this.activator = null; this.modifier = null; this.targeter = null; this._prefab = null; GameObject.Destroy(gameObject); return(prefab); }
private void Update() { foreach (var pedestrian in this.Pedestrians) { pedestrian.Update(); } Vector3 testMouseClickPosition; if (TargeterComponent.GetGoalPosition(out testMouseClickPosition)) { this.mouseClickPosition = testMouseClickPosition; Actuator.SetGoalPosition(this.mouseClickPosition); DecomposerComponent.Initialize(this.mouseClickPosition); this.startPosition = this.character.KinematicData.position; currentSmoothedSolution = null; } if (this.character.KinematicData.Arrived) { //NOTE: stops the char from going forward before it flips back this.character.KinematicData.velocity = Vector3.zero; return; } // Path recalculation for the car actuator if (currentSmoothedSolution != null) { float distanceToPath = (character.KinematicData.position - currentSmoothedSolution.GetPosition((Actuator.GetMovement() as DynamicFollowPath).CurrentParam)).sqrMagnitude; if (distanceToPath > 400 && DecomposerComponent.Initialize(this.mouseClickPosition)) // 400 = 20^2 { Debug.Log("searching"); this.startPosition = this.character.KinematicData.position; Actuator.SetGoalPosition(this.mouseClickPosition); this.CalculatePath = true; currentSmoothedSolution = null; currentSolution = null; } } if (this.CalculatePath) { //Debug.Log("CALCULATE PATH"); DecomposerComponent.CalculatePath(out this.currentSolution); } if (this.currentSolution != null && (this.currentSmoothedSolution == null || DecomposerComponent.InNewLocalPath(this.currentSmoothedSolution) || this.violation)) { //Debug.Log("NEW LINE"); this.currentSmoothedSolution = DecomposerComponent.SmoothPath(this.currentSolution); Actuator.SetPath(currentSmoothedSolution); } if (this.currentSmoothedSolution == null) { return; } GlobalPath actuatorPath = null; GlobalPath pathToFollow = currentSmoothedSolution; violation = false; for (int i = 0; i < ITERATIONS_LIMIT; i++) { actuatorPath = Actuator.GetPath(pathToFollow); foreach (IConstraint constraint in PathConstraints) { Vector3 suggestedPosition; violation = constraint.WillViolate(actuatorPath, out suggestedPosition); if (violation) { pathToFollow = new GlobalPath(); pathToFollow.LocalPaths.Add(new LineSegmentPath(character.KinematicData.position, suggestedPosition)); //Debug.Log("Path collision violation"); break; } } if (violation) { continue; } // restrições de output foreach (IConstraint constraint in MovementConstraints) { Vector3 suggestedPosition; violation = constraint.WillViolate(actuatorPath, out suggestedPosition); if (violation) { pathToFollow = new GlobalPath(); pathToFollow.LocalPaths.Add(new LineSegmentPath(character.KinematicData.position, suggestedPosition)); //Debug.Log("Movement collision violation"); break; } } if (!violation) { break; } } Debug.DrawLine(this.character.KinematicData.position, actuatorPath.LocalPaths[0].EndPosition, Color.black); //NOTE: setting new legal path for the actuator and clearing auxiliary variable if (!violation) { Actuator.SetPath(actuatorPath); actuatorPath = null; } character.MovementOutput = Actuator.GetOutput(actuatorPath, character); this.character.Update(); }