Пример #1
0
        private HOVR_Tracker GetValidTracker(HOVR_TrackerInfo info)
        {
            var validTrackers = _tracker.FindAll(x => x.DeviceClass == info.DeviceClass);

            if (validTrackers.Count == 1)
            {
                return(validTrackers[0]);
            }

            var foundPerSerial = validTrackers.Find(x => x.SerialNumber.Length > 0 && x.SerialNumber == info.SerialNumber);

            if (foundPerSerial != null)
            {
                return(foundPerSerial);
            }

            return(null);
        }
Пример #2
0
 public void Init(HOVR_TrackerInfo info)
 {
     _deviceId   = info.DeviceId;
     _hasBattery = info.HasBattery;
 }
Пример #3
0
        private void InitOpenVrDevices()
        {
            if (_vrSystem == null)
            {
                return;
            }

            List <HOVR_TrackerInfo> trackerDescriptions = new List <HOVR_TrackerInfo>();

            for (uint i = 0; i < OpenVR.k_unMaxTrackedDeviceCount; i++)
            {
                var deviceClass = _vrSystem.GetTrackedDeviceClass(i);

                if (deviceClass != ETrackedDeviceClass.Invalid)
                {
                    HOVR_TrackerInfo tmpTracker = new HOVR_TrackerInfo((int)i, deviceClass);

                    if (deviceClass == ETrackedDeviceClass.TrackingReference)
                    {
                        var modeLabel = GetDevicePropertyString(i, ETrackedDeviceProperty.Prop_ModeLabel_String, 16);
                        tmpTracker.AdditionalString = modeLabel;
                    }

                    var serialNumber = GetDevicePropertyString(i, ETrackedDeviceProperty.Prop_SerialNumber_String, 32);
                    tmpTracker.SerialNumber = serialNumber;

                    var batteryError = ETrackedPropertyError.TrackedProp_UnknownProperty;
                    _vrSystem.GetFloatTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_DeviceBatteryPercentage_Float, ref batteryError);

                    if (batteryError == ETrackedPropertyError.TrackedProp_Success)
                    {
                        tmpTracker.HasBattery = true;
                    }

                    trackerDescriptions.Add(tmpTracker);
                }
            }

            for (int i = 0; i < trackerDescriptions.Count; i++)
            {
                var curInfo = trackerDescriptions[i];
                var tracker = GetValidTracker(curInfo);

                if (tracker != null)
                {
                    if (tracker.DeviceId == HOVR_Tracker.UNINIT_DEVICE_ID)
                    {
                        tracker.Init(curInfo);

                        if (_debugLogs)
                        {
                            Debug.Log("Found OVR Device: " + curInfo.ToString(), gameObject);
                        }
                    }

                    else if (_debugLogs)
                    {
                        Debug.LogWarning("Found the same ViveTracker for multiple different detected OVR devices for info: " + curInfo.ToString(), gameObject);
                    }
                }
                else if (_debugLogs)
                {
                    Debug.LogWarning("Could not find ViveTracker for: " + curInfo.ToString(), gameObject);
                }
            }
        }