コード例 #1
0
        public static VRModuleDeviceModel GetDeviceModelHint(string deviceSN)
        {
            var deviceIndex = VRModule.GetConnectedDeviceIndex(deviceSN);

            if (VRModule.IsValidDeviceIndex(deviceIndex))
            {
                return(VRModule.GetCurrentDeviceState(deviceIndex).deviceModel);
            }

            VRModuleDeviceModel deviceModel;

            if (s_modelHintTable.TryGetValue(deviceSN, out deviceModel))
            {
                return(deviceModel);
            }

            return(VRModuleDeviceModel.Unknown);
        }
コード例 #2
0
            // deviceSN must be valid
            // device must be bound
            // device can be whether connected or not
            private void InternalUnbind(string deviceSN, int boundRoleValue)
            {
                var deviceIndex = VRModule.GetConnectedDeviceIndex(deviceSN);

                if (!m_sn2role.Remove(deviceSN))
                {
                    throw new Exception("device([" + deviceIndex + "]" + deviceSN + ") already unbound");
                }

                if (VRModule.IsValidDeviceIndex(deviceIndex))
                {
                    InternalRemoveRoleBoundDevice(deviceSN, deviceIndex, boundRoleValue);
                }

                if (m_handler != null)
                {
                    m_handler.OnBindingRoleValueChanged(deviceSN, true, boundRoleValue, false, m_info.InvalidRoleValue);
                }
            }
コード例 #3
0
            // deviceSN must be valid
            // device can be whether bound or not
            // device can be whether connected or not
            private void InternalBind(string deviceSN, int roleValue)
            {
                var deviceIndex = VRModule.GetConnectedDeviceIndex(deviceSN);

                bool previousIsBound        = false;
                int  previousBoundRoleValue = m_info.InvalidRoleValue;

                if (m_sn2role.TryGetValue(deviceSN, out previousBoundRoleValue))
                {
                    if (previousBoundRoleValue == roleValue)
                    {
                        return;
                    }

                    previousIsBound = true;

                    m_sn2role.Remove(deviceSN);

                    if (VRModule.IsValidDeviceIndex(deviceIndex))
                    {
                        InternalRemoveRoleBoundDevice(deviceSN, deviceIndex, previousBoundRoleValue);
                    }
                }

                m_sn2role[deviceSN] = roleValue;

                if (VRModule.IsValidDeviceIndex(deviceIndex))
                {
                    InternalInsertRoleBoundDevice(deviceSN, deviceIndex, roleValue);
                }

                if (m_handler != null)
                {
                    m_handler.OnBindingRoleValueChanged(deviceSN, previousIsBound, previousBoundRoleValue, true, roleValue);
                }
            }
コード例 #4
0
        public static bool LoadBindingConfigFromFile(string configPath)
        {
            if (string.IsNullOrEmpty(configPath) || !File.Exists(configPath))
            {
                return(false);
            }

            using (var inputFile = new StreamReader(configPath))
            {
                s_bindingConfig = JsonUtility.FromJson <BindingConfig>(inputFile.ReadToEnd());

                foreach (var roleData in s_bindingConfig.roles)
                {
                    foreach (var binding in roleData.bindings)
                    {
                        if (VRModule.IsDeviceConnected(binding.device_sn))
                        {
                            s_modelHintTable[binding.device_sn] = VRModule.GetCurrentDeviceState(VRModule.GetConnectedDeviceIndex(binding.device_sn)).deviceModel;
                        }
                        else
                        {
                            s_modelHintTable[binding.device_sn] = binding.device_model;
                        }
                    }
                }

                return(true);
            }
        }
コード例 #5
0
        public static void LoadBindingConfigFromRoleMap(params Type[] roleTypeFilter)
        {
            var roleDataList = ListPool <RoleData> .Get();

            var filterUsed = roleTypeFilter != null && roleTypeFilter.Length > 0;

            if (filterUsed)
            {
                roleDataList.AddRange(s_bindingConfig.roles);
            }

            for (int i = 0, imax = ViveRoleEnum.ValidViveRoleTable.Count; i < imax; ++i)
            {
                var roleType = ViveRoleEnum.ValidViveRoleTable.GetValueByIndex(i);
                var roleName = ViveRoleEnum.ValidViveRoleTable.GetKeyByIndex(i);
                var roleMap  = ViveRole.GetMap(roleType);

                if (filterUsed)
                {
                    // apply filter
                    var filtered = false;
                    foreach (var t in roleTypeFilter)
                    {
                        if (roleType == t)
                        {
                            filtered = true; break;
                        }
                    }
                    if (!filtered)
                    {
                        continue;
                    }
                }

                if (roleMap.BindingCount > 0)
                {
                    var bindingTable = roleMap.BindingTable;

                    var roleData = new RoleData()
                    {
                        type     = roleName,
                        bindings = new Binding[bindingTable.Count],
                    };

                    for (int j = 0, jmax = bindingTable.Count; j < jmax; ++j)
                    {
                        var binding = new Binding();
                        binding.device_sn  = bindingTable.GetKeyByIndex(j);
                        binding.role_value = bindingTable.GetValueByIndex(j);
                        binding.role_name  = roleMap.RoleValueInfo.GetNameByRoleValue(binding.role_value);

                        // save the device_model for better recognition of the device
                        if (VRModule.IsDeviceConnected(binding.device_sn))
                        {
                            binding.device_model = VRModule.GetCurrentDeviceState(VRModule.GetConnectedDeviceIndex(binding.device_sn)).deviceModel;
                            s_modelHintTable[binding.device_sn] = binding.device_model;
                        }
                        else if (!s_modelHintTable.TryGetValue(binding.device_sn, out binding.device_model))
                        {
                            binding.device_model = VRModuleDeviceModel.Unknown;
                        }

                        roleData.bindings[j] = binding;
                    }

                    if (filterUsed)
                    {
                        // merge with existing role data
                        var roleDataIndex = roleDataList.FindIndex((item) => item.type == roleName);
                        if (roleDataIndex >= 0)
                        {
                            roleDataList[roleDataIndex] = roleData;
                        }
                        else
                        {
                            roleDataList.Add(roleData);
                        }
                    }
                    else
                    {
                        roleDataList.Add(roleData);
                    }
                }
                else
                {
                    if (roleDataList.Count > 0)
                    {
                        // don't write to config if no bindings
                        roleDataList.RemoveAll((item) => item.type == roleName);
                    }
                }
            }

            s_bindingConfig.roles = roleDataList.ToArray();

            ListPool <RoleData> .Release(roleDataList);
        }