예제 #1
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)));
        }
    }
예제 #2
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 + ")");
        }
    }