Ejemplo n.º 1
0
        private void Start()
        {
            AgentController = GetComponentInParent <AgentController>();

            dynamics = GetComponentInParent <VehicleDynamics>();
            actions  = GetComponentInParent <VehicleActions>();

            Debug.Assert(dynamics != null);
            Debug.Assert(actions != null);
            Debug.Assert(SimulatorManager.Instance != null);

            controls = SimulatorManager.Instance.controls;
            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;
        }
Ejemplo n.º 2
0
        private void Start()
        {
            AgentController = GetComponentInParent <AgentController>();

            dynamics = GetComponentInParent <VehicleDynamics>();
            actions  = GetComponentInParent <VehicleActions>();

            Debug.Assert(dynamics != null);
            Debug.Assert(actions != null);
            Debug.Assert(SimulatorManager.Instance != null);

            controls = SimulatorManager.Instance.controls;

            if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Linux && Application.isEditor)
            {
                // empty
            }
            else
            {
                controls.Vehicle.Direction.started         += DirectionStarted;
                controls.Vehicle.Direction.performed       += DirectionPerformed;
                controls.Vehicle.Direction.canceled        += DirectionCanceled;
                controls.Vehicle.ShiftFirst.performed      += ShiftFirstPerformed;
                controls.Vehicle.ShiftReverse.performed    += ShiftReversePerformed;
                controls.Vehicle.ParkingBrake.performed    += ParkingBrakePerformed;
                controls.Vehicle.Ignition.performed        += IgnitionPerformed;
                controls.Vehicle.HeadLights.performed      += HeadLightsPerformed;
                controls.Vehicle.IndicatorLeft.performed   += IndicatorLeftPerformed;
                controls.Vehicle.IndicatorRight.performed  += IndicatorRightPerformed;
                controls.Vehicle.IndicatorHazard.performed += IndicatorHazardPerformed;
                controls.Vehicle.FogLights.performed       += FogLightsPerformed;
                controls.Vehicle.InteriorLight.performed   += InteriorLightPerformed;
            }
        }
Ejemplo n.º 3
0
    private void Awake()
    {
        thisCamera = GetComponentInChildren <Camera>();

        controls = SimulatorManager.Instance.controls;
        controls.Camera.Direction.started            += ctx => directionInput = ctx.ReadValue <Vector2>();
        controls.Camera.Direction.performed          += ctx => directionInput = ctx.ReadValue <Vector2>();
        controls.Camera.Direction.canceled           += ctx => directionInput = Vector2.zero;
        controls.Camera.Elevation.started            += ctx => elevationInput = ctx.ReadValue <float>();
        controls.Camera.Elevation.performed          += ctx => elevationInput = ctx.ReadValue <float>();
        controls.Camera.Elevation.canceled           += ctx => elevationInput = 0f;
        controls.Camera.Zoom.started                 += ctx => zoomInput = ctx.ReadValue <float>();
        controls.Camera.Zoom.performed               += ctx => zoomInput = ctx.ReadValue <float>();
        controls.Camera.Zoom.canceled                += ctx => zoomInput = 0f;
        controls.Camera.Boost.performed              += ctx => boost = ctx.ReadValue <float>();
        controls.Camera.Boost.canceled               += ctx => boost = ctx.ReadValue <float>();
        controls.Camera.ToggleState.performed        += ctx => ToggleFreeCinematicState();
        controls.Camera.CinematicNewPath.performed   += ctx => GetCinematicFollowMapLane();
        controls.Camera.CinematicResetPath.performed += ctx => ResetCinematicMapLane();

        controls.Camera.MouseDelta.performed += ctx => mouseInput = ctx.ReadValue <Vector2>();
        controls.Camera.MouseDelta.canceled  += ctx => mouseInput = Vector2.zero;
        controls.Camera.MouseLeft.performed  += ctx => mouseLeft = ctx.ReadValue <float>();
        controls.Camera.MouseLeft.canceled   += ctx => mouseLeft = ctx.ReadValue <float>();
        controls.Camera.MouseRight.performed += ctx => mouseRight = ctx.ReadValue <float>();
        controls.Camera.MouseRight.canceled  += ctx => mouseRight = ctx.ReadValue <float>();

        //controls.Camera.MouseMiddle.performed += ctx => ResetFollowRotation();

        // TODO broken in package currently https://github.com/Unity-Technologies/InputSystem/issues/647
        //controls.Camera.MouseScroll.started += ctx => mouseScroll = ctx.ReadValue<Vector2>();
        //controls.Camera.MouseScroll.performed += ctx => mouseScroll = ctx.ReadValue<Vector2>();
        //controls.Camera.MouseScroll.canceled += ctx => mouseScroll = Vector2.zero;
    }
    private void Awake()
    {
        thisCamera = GetComponentInChildren <Camera>();

        controls = SimulatorManager.Instance.controls;

        if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Linux && Application.isEditor)
        {
            // empty
        }
        else
        {
            controls.Camera.Direction.started   += ctx => directionInput = ctx.ReadValue <Vector2>();
            controls.Camera.Direction.performed += ctx => directionInput = ctx.ReadValue <Vector2>();
            controls.Camera.Direction.canceled  += ctx => directionInput = Vector2.zero;
            controls.Camera.Elevation.started   += ctx => elevationInput = ctx.ReadValue <float>();
            controls.Camera.Elevation.performed += ctx => elevationInput = ctx.ReadValue <float>();
            controls.Camera.Elevation.canceled  += ctx => elevationInput = 0f;

            controls.Camera.Zoom.started   += ctx => zoomInput = ctx.ReadValue <float>();
            controls.Camera.Zoom.performed += ctx => zoomInput = ctx.ReadValue <float>();
            controls.Camera.Zoom.canceled  += ctx => zoomInput = 0f;

            controls.Camera.Boost.performed += ctx => boost = ctx.ReadValue <float>();
            controls.Camera.Boost.canceled  += ctx => boost = ctx.ReadValue <float>();

            controls.Camera.ToggleState.performed += ctx => SetFreeCameraState();
        }

        controls.Camera.MouseDelta.started   += ctx => mouseInput = ctx.ReadValue <Vector2>();
        controls.Camera.MouseDelta.performed += ctx => mouseInput = ctx.ReadValue <Vector2>();
        controls.Camera.MouseDelta.canceled  += ctx => mouseInput = Vector2.zero;

        controls.Camera.MouseLeft.performed  += ctx => mouseLeft = ctx.ReadValue <float>();
        controls.Camera.MouseLeft.canceled   += ctx => mouseLeft = ctx.ReadValue <float>();
        controls.Camera.MouseRight.performed += ctx => mouseRight = ctx.ReadValue <float>();
        controls.Camera.MouseRight.canceled  += ctx => mouseRight = ctx.ReadValue <float>();

        //controls.Camera.MouseMiddle.performed += ctx => ResetFollowRotation();

        // TODO broken in package currently https://github.com/Unity-Technologies/InputSystem/issues/647
        //controls.Camera.MouseScroll.started += ctx => mouseScroll = ctx.ReadValue<Vector2>();
        //controls.Camera.MouseScroll.performed += ctx => mouseScroll = ctx.ReadValue<Vector2>();
        //controls.Camera.MouseScroll.canceled += ctx => mouseScroll = Vector2.zero;
    }
Ejemplo n.º 5
0
    public void Init(int?seed = null)
    {
        if (ApiManager.Instance != null)
        {
            FixedUpdateManager = ApiManager.Instance;
            IsAPI = true;
        }
        else
        {
            FixedUpdateManager = Instance;
            IsAPI = false;
        }

        controls = new SimulatorControls();
        controls.Enable();

        SimulationConfig config = null;

        if (Loader.Instance != null)
        {
            config = Loader.Instance.SimConfig;
        }

        var masterSeed = seed ?? config?.Seed ?? new System.Random().Next();

        RandomGenerator = new System.Random(masterSeed);

        //Calculate map bounds and limit position compression
        if (Loader.Instance != null && Loader.Instance.Network.IsClusterSimulation)
        {
            var mapBounds = CalculateMapBounds();
            //Add margin to the bounds
            mapBounds.size += Vector3.one * 10;
            ByteCompression.SetPositionBounds(mapBounds);
        }

        ManagerHolder = new GameObject("ManagerHolder");
        ManagerHolder.transform.SetParent(transform);
        AnalysisManager     = Instantiate(analysisManagerPrefab, ManagerHolder.transform);
        AgentManager        = Instantiate(agentManagerPrefab, ManagerHolder.transform);
        CameraManager       = Instantiate(cameraManagerPrefab, ManagerHolder.transform);
        ControllableManager = Instantiate(controllableManagerPrefab, ManagerHolder.transform);
        MapManager          = Instantiate(mapManagerPrefab, ManagerHolder.transform);
        NPCManager          = Instantiate(npcManagerPrefab, ManagerHolder.transform);
        NPCManager.InitRandomGenerator(RandomGenerator.Next());
        PedestrianManager = Instantiate(pedestrianManagerPrefab, ManagerHolder.transform);
        PedestrianManager.InitRandomGenerator(RandomGenerator.Next());
        EnvironmentEffectsManager = Instantiate(environmentEffectsManagerPrefab, ManagerHolder.transform);
        EnvironmentEffectsManager.InitRandomGenerator(RandomGenerator.Next());
        UIManager = Instantiate(uiManagerPrefab, ManagerHolder.transform);

        if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Linux && Application.isEditor)
        {
            // empty
        }
        else
        {
            controls.Simulator.ToggleNPCS.performed        += ctx => NPCManager.NPCActive = !NPCManager.NPCActive;
            controls.Simulator.TogglePedestrians.performed += ctx => PedestrianManager.PedestriansActive = !PedestrianManager.PedestriansActive;
            controls.Simulator.ToggleAgent.performed       += ctx =>
            {
                if (int.TryParse(ctx.control.name, out int index))
                {
                    AgentManager.SetCurrentActiveAgent(index - 1);
                }
            };
            controls.Simulator.ToggleReset.performed      += ctx => AgentManager.ResetAgent();
            controls.Simulator.ToggleControlsUI.performed += ctx => UIManager.UIActive = !UIManager.UIActive;
        }

        if (config != null)
        {
            simulationName       = config.Name;
            clusterName          = config.ClusterName;
            mapName              = config.MapName;
            NPCManager.NPCActive = config.UseTraffic;
            PedestrianManager.PedestriansActive = config.UsePedestrians;
            if (config.Agents != null)
            {
                AgentManager.SpawnAgents(config.Agents);
            }
            apiMode     = config.ApiOnly;
            headless    = config.Headless;
            interactive = config.Interactive;
            useSeed     = config.Seed.HasValue;
            npc         = config.UseTraffic;
            pedestrian  = config.UsePedestrians;
            timeOfDay   = config.TimeOfDay.ToString("HH:mm");
            rain        = config.Rain;
            wet         = config.Wetness;
            fog         = config.Fog;
            cloud       = config.Cloudiness;

            if (headless)
            {
                controls.Disable();
            }
        }
        SIM.APIOnly = apiMode;
        SIM.LogSimulation(SIM.Simulation.SimulationStart, simulationName);
        SIM.LogSimulation(SIM.Simulation.ClusterNameStart, clusterName);
        SIM.LogSimulation(SIM.Simulation.MapStart, string.IsNullOrEmpty(mapName) ? UnityEngine.SceneManagement.SceneManager.GetActiveScene().name : mapName);
        SIM.LogSimulation(SIM.Simulation.HeadlessModeStart, state: headless);
        SIM.LogSimulation(SIM.Simulation.InteractiveModeStart, state: interactive);
        SIM.LogSimulation(SIM.Simulation.UsePredefinedSeedStart, state: useSeed);
        SIM.LogSimulation(SIM.Simulation.NPCStart, state: npc);
        SIM.LogSimulation(SIM.Simulation.RandomPedestrianStart, state: pedestrian);
        SIM.LogSimulation(SIM.Simulation.TimeOfDayStart, timeOfDay == "" ? string.Format("{0:hh}:{0:mm}", TimeSpan.FromHours(EnvironmentEffectsManager.currentTimeOfDay)) : timeOfDay);
        SIM.LogSimulation(SIM.Simulation.RainStart, rain == 0f ? EnvironmentEffectsManager.rain.ToString() : rain.ToString());
        SIM.LogSimulation(SIM.Simulation.WetnessStart, wet == 0f ? EnvironmentEffectsManager.wet.ToString() : wet.ToString());
        SIM.LogSimulation(SIM.Simulation.FogStart, fog == 0f ? EnvironmentEffectsManager.fog.ToString() : fog.ToString());
        SIM.LogSimulation(SIM.Simulation.CloudinessStart, cloud == 0f ? EnvironmentEffectsManager.cloud.ToString() : cloud.ToString());
        InitSegmenationColors();
        WireframeBoxes = gameObject.AddComponent <WireframeBoxes>();
        if (Loader.Instance != null)
        {
            TimeManager.Initialize(Loader.Instance.Network.MessagesManager);
        }
        Sensors.Initialize();
        Loader.ResetMaterials(); // TODO remove Editor hack for 2019.3.3 bug once fixed
        IsInitialized = true;
    }
Ejemplo n.º 6
0
    public void Init(int?seed = null)
    {
        controls = new SimulatorControls();
        controls.Enable();

        var config = Loader.Instance?.SimConfig;

        var masterSeed = seed ?? config?.Seed ?? new System.Random().Next();

        System.Random rand = new System.Random(masterSeed);

        AgentManager  = Instantiate(agentManagerPrefab, transform);
        CameraManager = Instantiate(cameraManagerPrefab, transform);
        MapManager    = Instantiate(mapManagerPrefab, transform);
        NPCManager    = Instantiate(npcManagerPrefab, transform);
        NPCManager.InitRandomGenerator(rand.Next());
        PedestrianManager = Instantiate(pedestrianManagerPrefab, transform);
        PedestrianManager.InitRandomGenerator(rand.Next());
        EnvironmentEffectsManager = Instantiate(environmentEffectsManagerPrefab, transform);
        EnvironmentEffectsManager.InitRandomGenerator(rand.Next());
        UIManager = Instantiate(uiManagerPrefab, transform);

        if (ApiManager.Instance != null)
        {
            IsAPI = true;
        }

        if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Linux && Application.isEditor)
        {
            // empty
        }
        else
        {
            controls.Simulator.ToggleNPCS.performed        += ctx => NPCManager.NPCActive = !NPCManager.NPCActive;
            controls.Simulator.TogglePedestrians.performed += ctx => PedestrianManager.PedestriansActive = !PedestrianManager.PedestriansActive;
            controls.Simulator.ToggleAgent.performed       += ctx =>
            {
                if (int.TryParse(ctx.control.name, out int index))
                {
                    AgentManager.SetCurrentActiveAgent(index - 1);
                }
            };
            controls.Simulator.ToggleReset.performed      += ctx => AgentManager.ResetAgent();
            controls.Simulator.ToggleControlsUI.performed += ctx => UIManager.UIActive = !UIManager.UIActive;
        }

        if (config != null)
        {
            simulationName       = config.Name;
            clusterName          = config.ClusterName;
            mapName              = config.MapName;
            NPCManager.NPCActive = config.UseTraffic;
            PedestrianManager.PedestriansActive = config.UsePedestrians;
            if (config.Agents != null)
            {
                AgentManager.SpawnAgents(config.Agents);
            }
            apiMode     = config.ApiOnly;
            headless    = config.Headless;
            interactive = config.Interactive;
            useSeed     = config.Seed.HasValue;
            npc         = config.UseTraffic;
            pedestrian  = config.UsePedestrians;
            timeOfDay   = config.TimeOfDay.ToString("HH:mm");
            rain        = config.Rain;
            wet         = config.Wetness;
            fog         = config.Fog;
            cloud       = config.Cloudiness;

            if (headless)
            {
                controls.Disable();
            }

            if (config.Interactive)
            {
                SetTimeScale(0.0f);
            }
        }
        SIM.APIOnly = apiMode;
        SIM.LogSimulation(SIM.Simulation.SimulationStart, simulationName);
        SIM.LogSimulation(SIM.Simulation.ClusterNameStart, clusterName);
        SIM.LogSimulation(SIM.Simulation.MapStart, string.IsNullOrEmpty(mapName) ? UnityEngine.SceneManagement.SceneManager.GetActiveScene().name : mapName);
        SIM.LogSimulation(SIM.Simulation.HeadlessModeStart, state: headless);
        SIM.LogSimulation(SIM.Simulation.InteractiveModeStart, state: interactive);
        SIM.LogSimulation(SIM.Simulation.UsePredefinedSeedStart, state: useSeed);
        SIM.LogSimulation(SIM.Simulation.NPCStart, state: npc);
        SIM.LogSimulation(SIM.Simulation.RandomPedestrianStart, state: pedestrian);
        SIM.LogSimulation(SIM.Simulation.TimeOfDayStart, timeOfDay == "" ? string.Format("{0:hh}:{0:mm}", TimeSpan.FromHours(EnvironmentEffectsManager.currentTimeOfDay)) : timeOfDay);
        SIM.LogSimulation(SIM.Simulation.RainStart, rain == 0f ? EnvironmentEffectsManager.rain.ToString() : rain.ToString());
        SIM.LogSimulation(SIM.Simulation.WetnessStart, wet == 0f ? EnvironmentEffectsManager.wet.ToString() : wet.ToString());
        SIM.LogSimulation(SIM.Simulation.FogStart, fog == 0f ? EnvironmentEffectsManager.fog.ToString() : fog.ToString());
        SIM.LogSimulation(SIM.Simulation.CloudinessStart, cloud == 0f ? EnvironmentEffectsManager.cloud.ToString() : cloud.ToString());
        InitSemanticTags();
        WireframeBoxes = gameObject.AddComponent <WireframeBoxes>();
    }
Ejemplo n.º 7
0
    public void Init(int?seed = null)
    {
        if (ApiManager.Instance != null)
        {
            FixedUpdateManager = ApiManager.Instance;
            IsAPI = true;
        }
        else
        {
            FixedUpdateManager = Instance;
            IsAPI = false;
        }

        controls = new SimulatorControls();
        controls.Enable();

        SimulationConfig config = null;

        if (Loader.Instance != null)
        {
            config = Loader.Instance.SimConfig;
        }

        var masterSeed = seed ?? config?.Seed ?? new System.Random().Next();

        RandomGenerator       = new System.Random(masterSeed);
        segmentationIdMapping = new SegmentationIdMapping();

        //Calculate map bounds and limit position compression
        if (Loader.Instance != null && Loader.Instance.Network.IsClusterSimulation)
        {
            var mapBounds = CalculateMapBounds();
            //Add margin to the bounds
            mapBounds.size += Vector3.one * 50;
            ByteCompression.SetPositionBounds(mapBounds);
        }

        ManagerHolder = new GameObject("ManagerHolder");
        ManagerHolder.transform.SetParent(transform);
        BridgeMessageDispatcher = new BridgeMessageDispatcher();
        AnalysisManager         = InstantiateManager(analysisManagerPrefab, ManagerHolder.transform);
        AgentManager            = InstantiateManager(agentManagerPrefab, ManagerHolder.transform);
        CameraManager           = InstantiateManager(cameraManagerPrefab, ManagerHolder.transform);
        ControllableManager     = InstantiateManager(controllableManagerPrefab, ManagerHolder.transform);
        MapManager = InstantiateManager(mapManagerPrefab, ManagerHolder.transform);
        NPCManager = InstantiateManager(npcManagerPrefab, ManagerHolder.transform);
        NPCManager.InitRandomGenerator(RandomGenerator.Next());
        PedestrianManager = InstantiateManager(pedestrianManagerPrefab, ManagerHolder.transform);
        PedestrianManager.InitRandomGenerator(RandomGenerator.Next());
        EnvironmentEffectsManager = InstantiateManager(environmentEffectsManagerPrefab, ManagerHolder.transform);
        EnvironmentEffectsManager.InitRandomGenerator(RandomGenerator.Next());
        CustomPassManager = InstantiateManager(customPassManagerPrefab, ManagerHolder.transform);
        UIManager         = InstantiateManager(uiManagerPrefab, ManagerHolder.transform);

        controls.Simulator.ToggleNPCS.performed        += ctx => NPCManager.NPCActive = !NPCManager.NPCActive;
        controls.Simulator.TogglePedestrians.performed += ctx => PedestrianManager.PedestriansActive = !PedestrianManager.PedestriansActive;
        controls.Simulator.ToggleAgent.performed       += ctx =>
        {
            if (int.TryParse(ctx.control.name, out int index))
            {
                AgentManager.SetCurrentActiveAgent(index - 1);
            }
        };
        controls.Simulator.ToggleReset.performed      += ctx => AgentManager.ResetAgent();
        controls.Simulator.ToggleControlsUI.performed += ctx => UIManager.UIActive = !UIManager.UIActive;

        if (config != null)
        {
            simulationName       = config.Name;
            clusterName          = config.ClusterName;
            mapName              = config.MapName;
            NPCManager.NPCActive = config.UseTraffic;
            PedestrianManager.PedestriansActive = config.UsePedestrians;
            if (config.Agents != null)
            {
                AgentManager.SpawnAgents(config.Agents);
            }
            apiMode     = config.ApiOnly;
            headless    = config.Headless;
            interactive = config.Interactive;
            useSeed     = config.Seed.HasValue;
            npc         = config.UseTraffic;
            pedestrian  = config.UsePedestrians;
            timeOfDay   = config.TimeOfDay.ToString("HH:mm");
            rain        = config.Rain;
            wet         = config.Wetness;
            fog         = config.Fog;
            cloud       = config.Cloudiness;
            Damage      = config.Damage;

            if (headless)
            {
                controls.Disable();
            }
        }
        InitSegmenationColors();
        WireframeBoxes = gameObject.AddComponent <WireframeBoxes>();
        if (Loader.Instance != null)
        {
            TimeManager.Initialize(Loader.Instance.Network.MessagesManager);
        }
        Sensors.Initialize();
        IsInitialized = true;
    }