예제 #1
0
    private void InitScenario()
    {
        // First release any previously loaded objects
        foreach (GameObject car in cars)
        {
            Destroy(car);
        }
        cars.Clear();

        if (envModel != null)
        {
            Destroy(envModel);
        }


        if (ESMiniLib.SE_Init(Application.streamingAssetsPath + OSC_filename,
                              disable_controllers ? 1 : 0,
                              OSG_visualization ? 1 : 0,
                              threads ? 1 : 0,
                              0) != 0) // don't create .dat-recording for replayer
        {
            print("failed to load scenario");
            return;
        }

        // Load environment 3D model
        string sceneGraphFilename = Marshal.PtrToStringAnsi(ESMiniLib.SE_GetSceneGraphFilename());

        Debug.Log("Loading " + Path.GetFileNameWithoutExtension(sceneGraphFilename));
        envModel = (GameObject)Instantiate(Resources.Load(Path.GetFileNameWithoutExtension(sceneGraphFilename)));
    }
예제 #2
0
 public void Reload()
 {
     Debug.Log("Reload");
     cam.transform.SetParent(null);
     ESMiniLib.SE_Close();
     InitScenario();
 }
예제 #3
0
    static void ParamDeclarationCallback(IntPtr user_data_ptr)
    {
        UserData user_data = (UserData)Marshal.PtrToStructure(user_data_ptr, typeof(UserData));

        Debug.Log(user_data.message_ + ": Set TargetSpeedFactor = " + user_data.speedFactor_);
        ESMiniLib.SE_SetParameterDouble("TargetSpeedFactor", user_data.speedFactor_);
    }
예제 #4
0
    private void Start()
    {
        state = new ScenarioObjectState();
        cam   = GameObject.FindWithTag("MainCamera");

        // Prepare and register callback for initializing scneario parameters
        // The user_data is typically not needed, but included here just to show
        // how to pass any kind of structure to the callback.
        UserData user_data = new UserData("This is a message", 1.6);

        user_data_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(user_data));
        Marshal.StructureToPtr(user_data, user_data_ptr, false);

        // This call must be made BEFORE SE_Init(), and is only needed once.
        ESMiniLib.SE_RegisterParameterDeclarationCallback(ParamDeclarationCallback, user_data_ptr);

        InitScenario();
    }
예제 #5
0
    private void Update()
    {
        ESMiniLib.SE_StepDT(Time.deltaTime);

        if (ESMiniLib.SE_GetQuitFlag())
        {
     #if UNITY_EDITOR
            // Application.Quit() does not work in the editor so
            // UnityEditor.EditorApplication.isPlaying need to be set to false to end the game
            ESMiniLib.SE_Close();
            UnityEditor.EditorApplication.isPlaying = false;
     #else
            Application.Quit();
     #endif
        }

        // Check nr of objects
        for (int i = 0; i < ESMiniLib.SE_GetNumberOfObjects(); i++)
        {
            ESMiniLib.SE_GetObjectState(i, ref state);

            // Instantiate objects
            if (cars.Count <= i)
            {
                // Add scenario controlled objects
                int model_id = Mathf.Min(state.model_id, objectNames.Count - 1);
                cars.Add((GameObject)Instantiate(Resources.Load(objectNames[model_id])));
                Debug.Log("Adding " + objectNames[model_id]);

                // Attach camera to first object
                if (i == 0)
                {
                    cam.transform.SetParent(cars[0].transform);
                    cam.transform.position = new Vector3(0.0f, 4f, -12.0f);
                    cam.transform.rotation = Quaternion.Euler(10, 0, 0);
                }
            }

            // Adapt to Unity coordinate system
            cars[i].transform.position = RH2Unity(new Vector3(state.x, state.y, state.z));
            cars[i].transform.rotation = Quaternion.Euler(RHHPR2UnityXYZ(new Vector3(state.h, state.p, state.r)));
        }
    }
예제 #6
0
    private void InitScenario()
    {
        // First release any previously loaded objects
        foreach (GameObject car in cars)
        {
            Destroy(car);
        }
        cars.Clear();

        if (envModel != null)
        {
            Destroy(envModel);
        }


        if (ESMiniLib.SE_Init(Application.streamingAssetsPath + OSC_filename,
                              disable_controllers ? 1 : 0,
                              OSG_visualization ? 1 : 0,
                              threads ? 1 : 0,
                              0) != 0) // don't create .dat-recording for replayer
        {
            print("failed to load scenario");
            return;
        }

        // Load environment 3D model
        string sceneGraphFilename = Marshal.PtrToStringAnsi(ESMiniLib.SE_GetSceneGraphFilename());

        Debug.Log("Loading " + Path.GetFileNameWithoutExtension(sceneGraphFilename));
        envModel = (GameObject)Instantiate(Resources.Load(Path.GetFileNameWithoutExtension(sceneGraphFilename)));

        // Fetch names of entities within the scenario
        int nObjects = ESMiniLib.SE_GetNumberOfObjects();

        for (int i = 0; i < nObjects; i++)
        {
            string typeName      = Marshal.PtrToStringAnsi(ESMiniLib.SE_GetObjectTypeName(i));
            string objectName    = Marshal.PtrToStringAnsi(ESMiniLib.SE_GetObjectName(i));
            string modelFileName = Marshal.PtrToStringAnsi(ESMiniLib.SE_GetObjectModelFileName(i));
            Debug.Log("Object[" + i + "]: " + objectName + " (type: " + typeName + ", model: " + modelFileName + ")");
        }
    }
예제 #7
0
 void OnApplicationQuit()
 {
     Debug.Log("Quit");
     ESMiniLib.SE_Close();
 }
예제 #8
0
 void OnApplicationQuit()
 {
     Debug.Log("Quit");
     ESMiniLib.SE_Close();
     Marshal.FreeHGlobal(user_data_ptr);
 }