public void Awake() { RB = GetComponent <Rigidbody>(); Controller = GetComponent <IAgentController>(); if (UnitySolver) { RB.centerOfMass = CenterOfMass; foreach (var axle in Axles) { axle.Left.ConfigureVehicleSubsteps(5f, 30, 10); axle.Right.ConfigureVehicleSubsteps(5f, 30, 10); axle.Left.wheelDampingRate = 1f; axle.Right.wheelDampingRate = 1f; } } var modelVars = new Dictionary <string, uint>(); for (int i = 0; i < FMUData.modelVariables.Count; i++) { modelVars.Add(FMUData.modelVariables[i].name, FMUData.modelVariables[i].valueReference); } fmu = new FMU(FMUData.modelName, FMUData.modelName, FMUData.GUID, modelVars, FMUData.Path, false); Init(); }
public override IEnumerator Apply(ITriggerAgent agent) { if (Loader.IsInScenarioEditor) { Debug.LogWarning( $"Visual Scenario Editor does not support the {GetType().Name}."); yield break; } var egos = SimulatorManager.Instance.AgentManager.ActiveAgents; IAgentController collisionEgo = null; var lowestTTC = TimeToCollisionLimit; foreach (var ego in egos) { var controller = ego.AgentGO.GetComponentInChildren <IAgentController>(); var ttc = CalculateTTC(controller, agent, agent.MovementSpeed); if (ttc >= lowestTTC || ttc < 0.0f) { continue; } lowestTTC = ttc; collisionEgo = controller; } yield return(agent.StartCoroutine(Apply(lowestTTC, collisionEgo, agent))); }
IEnumerator WaitToDodge(IAgentController aC, bool isLeft) { isWaitingToDodge = true; float elapsedTime = 0f; while (elapsedTime < 5f) { if (aC.AgentGameObject.GetComponent <Rigidbody>().velocity.magnitude > 0.01f) { isWaitingToDodge = false; yield break; } elapsedTime += Time.fixedDeltaTime; yield return(new WaitForFixedUpdate()); } if (!isLeft) { SetDodge(true); } else { SetDodge(false); } isWaitingToDodge = false; }
protected override void Initialize() { Controller = GetComponentInParent <IAgentController>(); Dynamics = GetComponentInParent <IVehicleDynamics>(); Actions = GetComponentInParent <VehicleActions>(); Debug.Assert(Dynamics != null); Debug.Assert(SimulatorManager.Instance != null); Controls = new KeyboardControlInputs(); Controls.VehicleKeyboard.Direction.started += DirectionStarted; Controls.VehicleKeyboard.Direction.performed += DirectionPerformed; Controls.VehicleKeyboard.Direction.canceled += DirectionCanceled; Controls.VehicleKeyboard.ShiftFirst.performed += ShiftFirstPerformed; Controls.VehicleKeyboard.ShiftReverse.performed += ShiftReversePerformed; Controls.VehicleKeyboard.ParkingBrake.performed += ParkingBrakePerformed; Controls.VehicleKeyboard.Ignition.performed += IgnitionPerformed; Controls.VehicleKeyboard.HeadLights.performed += HeadLightsPerformed; Controls.VehicleKeyboard.IndicatorLeft.performed += IndicatorLeftPerformed; Controls.VehicleKeyboard.IndicatorRight.performed += IndicatorRightPerformed; Controls.VehicleKeyboard.IndicatorHazard.performed += IndicatorHazardPerformed; Controls.VehicleKeyboard.FogLights.performed += FogLightsPerformed; Controls.VehicleKeyboard.InteriorLight.performed += InteriorLightPerformed; Controls.Enable(); }
void Awake() { _health = GetComponent <Health>(); _explosions = GameObject.FindGameObjectWithTag(GameTags.GameController).GetComponent <ExplosionManager>(); controller = Instantiate(behaviour, transform).GetComponent <IAgentController>(); _player = GameObject.FindGameObjectWithTag(GameTags.Player).GetComponent <Player>(); }
protected override void Initialize() { Controller = GetComponentInParent <IAgentController>(); Dynamics = GetComponentInParent <IVehicleDynamics>(); Actions = GetComponentInParent <VehicleActions>(); Debug.Assert(Dynamics != null); Debug.Assert(SimulatorManager.Instance != null); Controls = new WheelControlSensorInput(); Controls.VehicleWheel.Accel.performed += AccelPerformed; Controls.VehicleWheel.Accel.canceled += AccelCanceled; Controls.VehicleWheel.Brake.performed += BrakePerformed; Controls.VehicleWheel.Brake.canceled += BrakeCanceled; Controls.VehicleWheel.Steer.performed += SteerPerformed; Controls.VehicleWheel.ButtonA.performed += ButtonA; Controls.VehicleWheel.ButtonB.performed += ButtonB; Controls.VehicleWheel.ButtonX.performed += ButtonX; Controls.VehicleWheel.ButtonY.performed += ButtonY; Controls.VehicleWheel.ButtonRB.performed += ButtonRB; Controls.VehicleWheel.ButtonLB.performed += ButtonLB; Controls.VehicleWheel.ButtonSelect.performed += ButtonSelect; Controls.VehicleWheel.ButtonStart.performed += ButtonStart; Controls.VehicleWheel.ButtonRSB.performed += ButtonRSB; Controls.VehicleWheel.ButtonLSB.performed += ButtonLSB; Controls.VehicleWheel.ButtonCenter.performed += ButtonCenter; Controls.VehicleWheel.DPad.performed += DPad; Controls.Enable(); }
void Start() { var agent = GetComponent <IAgent>(); if (agent != null) { _controller = agent.controller; } }
public override void Init() { Dynamics = GetComponent <IVehicleDynamics>(); Actions = GetComponent <VehicleActions>(); Controller = GetComponent <IAgentController>(); Inputs.AddRange(GetComponentsInChildren <IVehicleInputs>()); InitialPosition = transform.position; InitialRotation = transform.rotation; }
public static async Task <AgentRecord> CreateTestAgent(this IAgentController container, int index) { var agentRecord = new AgentRecord { Id = $"Agent.{index}", State = AgentState.Running, }; await container.Register(agentRecord, CancellationToken.None); return(agentRecord); }
void Start() { var agent = GetComponent <IAgent>(); if (agent != null) { _controller = agent.controller; } if (_controller == null) { throw new System.Exception(); } }
public void Awake() { RB = GetComponent <Rigidbody>(); Controller = GetComponent <IAgentController>(); RB.centerOfMass = CenterOfMass; NumberOfDrivingWheels = Axles.Where(a => a.Motor).Count() * 2; TractionControlAdjustedMaxTorque = MaxMotorTorque - (TractionControlAmount * MaxMotorTorque); foreach (var axle in Axles) { axle.Left.ConfigureVehicleSubsteps(5f, 30, 10); axle.Right.ConfigureVehicleSubsteps(5f, 30, 10); axle.Left.wheelDampingRate = WheelDamping; axle.Right.wheelDampingRate = WheelDamping; } }
private float CalculateTTC(IAgentController ego, ITriggerAgent agent) { //Calculate intersection point, return infinity if vehicles won't intersect var egoTransform = ego.AgentGameObject.transform; if (!GetLineIntersection(egoTransform.position, egoTransform.forward, agent.AgentTransform.position, agent.AgentTransform.forward, out var intersection)) { return(float.PositiveInfinity); } var egoDistance = Distance2D(egoTransform.position, intersection); var npcDistance = Distance2D(agent.AgentTransform.position, intersection); var egoTimeToIntersection = CalculateTimeForAccelerated(ego.Velocity.magnitude, ego.Acceleration.magnitude, egoDistance); var npcTimeToIntersection = CalculateTimeForAccelerated(agent.MovementSpeed, agent.Acceleration.magnitude, npcDistance); //If npc will reach intersection quicker, ttc will be positive //If agent cannot reach collision point before ego, ttc will be negative return(egoTimeToIntersection - npcTimeToIntersection); }
protected override void Initialize() { Controller = GetComponentInParent <IAgentController>(); activeRT = new RenderTexture(Width, Height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear) { dimension = TextureDimension.Tex2D, antiAliasing = 1, useMipMap = false, useDynamicScale = false, wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Bilinear }; activeRT.Create(); Camera = GetComponentInChildren <Camera>(); Camera.targetTexture = activeRT; Camera.fieldOfView = FieldOfView; Camera.nearClipPlane = MinDistance; Camera.farClipPlane = MaxDistance; Camera.gameObject.GetComponent <HDAdditionalCameraData>().hasPersistentHistory = true; passId = new ShaderTagId("SimulatorSegmentationPass"); SegmentationCamera.fieldOfView = FieldOfView; SegmentationCamera.nearClipPlane = MinDistance; SegmentationCamera.farClipPlane = DetectionRange; SegmentationCamera.gameObject.GetComponent <HDAdditionalCameraData>().customRender += OnSegmentationRender; SegmentationCamera.gameObject.GetComponent <HDAdditionalCameraData>().hasPersistentHistory = true; renderTarget = SensorRenderTarget.Create2D(Width, Height, GraphicsFormat.R8G8B8A8_UNorm); SegmentationCamera.targetTexture = renderTarget; minX = new ComputeBuffer(256, sizeof(uint)); maxX = new ComputeBuffer(256, sizeof(uint)); minY = new ComputeBuffer(256, sizeof(uint)); maxY = new ComputeBuffer(256, sizeof(uint)); AAWireBoxes = gameObject.AddComponent <AAWireBox>(); AAWireBoxes.Camera = Camera; AAWireBoxes.IgnoreUpdates = true; }
public ActorAgent(IActorRef actorTextOutput, Agent ag, IActorRef actorSolarSystem) { _actorTextOutput = actorTextOutput; _actorSolarSystem = actorSolarSystem; _agent = ag; _tickCompleteCmd = new MessageEngineAgCompletedCommand(_agent.AgentId); AgentControllerState stateForAgent = new AgentControllerState(ag); switch (_agent.Type) { //case AgentTypeEnum.Trader: // _agentC = new AgentTraderController(ag, _actorTextOutput); // break; default: _agentC = new AgentDefaultController(stateForAgent, _actorSolarSystem, _actorTextOutput); break; } Receive <MessageTick>(msg => receiveDefaultTick(msg)); }
public override IEnumerator Apply(ITriggerAgent agent) { var lowestTTC = TimeToCollisionLimit; var egos = SimulatorManager.Instance.AgentManager.ActiveAgents; IAgentController collisionEgo = null; foreach (var ego in egos) { var controller = ego.AgentGO.GetComponentInChildren <IAgentController>(); var ttc = CalculateTTC(controller, agent); if (ttc >= lowestTTC || ttc < 0.0f) { continue; } lowestTTC = ttc; collisionEgo = controller; } //If there is no collision detected don't wait if (lowestTTC >= TimeToCollisionLimit || collisionEgo == null) { yield break; } //Agent will adjust waiting time while waiting do { yield return(null); lowestTTC = CalculateTTC(collisionEgo, agent); //Check if TTC is valid, for example ego did not change the direction if (lowestTTC >= TimeToCollisionLimit) { yield break; } } while (lowestTTC > 0.0f); }
public ActorAgent(IActorRef actorTextOutput, Agent ag, IActorRef actorSolarSystem) { _actorTextOutput = actorTextOutput; _actorSolarSystem = actorSolarSystem; _agent = ag; _tickCompleteCmd = new MessageEngineAgCompletedCommand(_agent.AgentId); AgentControllerState stateForAgent = new AgentControllerState(ag); switch(_agent.Type) { //case AgentTypeEnum.Trader: // _agentC = new AgentTraderController(ag, _actorTextOutput); // break; default: _agentC = new AgentDefaultController(stateForAgent, _actorTextOutput); break; } Receive<MessageTick>(msg => receiveDefaultTick(msg)); Receive<MessageShipResponse>(msg => receiveShipResponse(msg)); Receive<MessageAgentDestinationReached>(msg => receiveShipDestinationReached(msg)); }
public void Process(IAgentController controller) { throw new NotImplementedException("Error message dla IAgentController"); }
private void Start() { _controller = GetComponentInParent <IAgent>().controller; _sfx = GameObject.FindGameObjectWithTag(GameTags.Audio).GetComponent <SFXManager>(); }
private void Awake() { LastControlUpdate = SimulatorManager.Instance.CurrentTime; Controller = GetComponentInParent <IAgentController>(); Dynamics = GetComponentInParent <IVehicleDynamics>(); }
private void Awake() { Dynamics = GetComponentInParent <IVehicleDynamics>(); Controller = GetComponentInParent <IAgentController>(); Lane = GetComponentInParent <VehicleLane>(); }
private void Start() { _controller = GetComponentInParent <IAgent>().controller; }
public BalanceActivity(IAgentController agentController) { agentController.VerifyNotNull(nameof(agentController)); _agentController = agentController; }
public void Process(IAgentController controller) { controller.SendKeepAlive(ClientId); }
public AgentInterpreter(IAgentController controller) { GameController = controller; }
public void Process(IAgentController controller) { controller.SendMessageToGameMaster(Serialize()); }
protected override void Initialize() { Dynamics = GetComponentInParent <IVehicleDynamics>(); Controller = GetComponentInParent <IAgentController>(); }