private void AddTPDToCamera(Camera camera)
 {
     TrackedPoseDriver tpd = camera.gameObject.AddComponent<TrackedPoseDriver>();
     tpd.SetPoseSource(TrackedPoseDriver.DeviceType.GenericXRDevice, TrackedPoseDriver.TrackedPose.Center);
     tpd.UseRelativeTransform = false;
     Debug.Log("Added Tracked Pose Driver to the camera named " + camera.name, camera);
 }
Exemple #2
0
        public override void OnInspectorGUI()
        {
            TrackedPoseDriver tpd = target as TrackedPoseDriver;

            serializedObject.Update();

            if (m_PoseProviderProp.objectReferenceValue == null)
            {
                EditorGUILayout.PropertyField(m_DeviceProp, Styles.deviceLabel);

                int selectedIndex = -1;
                for (int i = 0; i < TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].Poses.Count; ++i)
                {
                    if ((int)TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].Poses[i] == m_PoseLabelProp.enumValueIndex)
                    {
                        selectedIndex = i;
                        break;
                    }
                }
                Rect rect = EditorGUILayout.GetControlRect();
                EditorGUI.LabelField(rect, Styles.poseLabel);
                rect.xMin += EditorGUIUtility.labelWidth;

                if (selectedIndex != -1)
                {
                    int index = EditorGUI.Popup(rect, selectedIndex, TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].PoseNames.ToArray());
                    m_PoseLabelProp.enumValueIndex = (int)TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].Poses[index];
                    if (tpd &&
                        (m_DeviceProp.enumValueIndex == 0 &&
                         (m_PoseLabelProp.enumValueIndex != (int)(TrackedPoseDriver.TrackedPose.Center)) &&
                         (m_PoseLabelProp.enumValueIndex != (int)TrackedPoseDriver.TrackedPose.ColorCamera)))
                    {
                        Camera camera = tpd.GetComponent <Camera>();
                        if (camera != null)
                        {
                            EditorGUILayout.HelpBox(Styles.cameraWarning, MessageType.Warning, true);
                        }
                    }
                }
                else
                {
                    int index = EditorGUI.Popup(rect, 0, TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].PoseNames.ToArray());
                    m_PoseLabelProp.enumValueIndex = (int)TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].Poses[index];
                    EditorGUILayout.HelpBox(Styles.devicePropWarning, MessageType.Warning, true);
                }
            }
            else
            {
                EditorGUILayout.HelpBox(Styles.poseProviderWarning, MessageType.Info, true);
            }

            EditorGUILayout.PropertyField(m_TrackingTypeProp, Styles.trackingLabel);
            EditorGUILayout.PropertyField(m_UpdateTypeProp, Styles.updateLabel);
            EditorGUILayout.PropertyField(m_UseRelativeTransformProp, Styles.relativeLabel);

            EditorGUILayout.PropertyField(m_PoseProviderProp, Styles.poseProviderLabel);

            serializedObject.ApplyModifiedProperties();
        }
    public override void Load(string fileName)
    {
        m_ClipList = new List <BaseRecordData>();
        string filePath = Application.streamingAssetsPath + "/Behaviors/" + fileName + "_" + recordName + ".txt";

        if (new FileInfo(filePath).Exists == false)
        {
            return;
        }

        using (FileStream fs = File.OpenRead(filePath))
        {
            using (StreamReader sr = new StreamReader(fs))
            {
                String line;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] elements  = line.Trim().Split('#');
                    int      index     = int.Parse(elements[0]);
                    float    timeStamp = Convert.ToSingle(elements[1]);

                    string[] s = elements[2].Trim().Split('/');

                    Matrix4x4 m = Matrix4x4.zero;
                    for (int i = 0; i < 4; i++)
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            m[i, j] = Convert.ToSingle(s[i * 4 + j]);
                        }
                    }

                    m_ClipList.Add(new TransformRecordData(index, timeStamp, m));
                }
            }
        }

        // disable steam vr input
        Valve.VR.SteamVR_Behaviour_Pose pos = GetComponent <Valve.VR.SteamVR_Behaviour_Pose>();
        if (pos != null)
        {
            pos.poseAction = Valve.VR.SteamVR_Input.GetAction <Valve.VR.SteamVR_Action_Pose>("");
        }

        UnityEngine.SpatialTracking.TrackedPoseDriver driver = GetComponent <UnityEngine.SpatialTracking.TrackedPoseDriver>();
        if (driver != null)
        {
            driver.trackingType = (UnityEngine.SpatialTracking.TrackedPoseDriver.TrackingType) 3;
        }
    }