public SwitchListData(SwitchMapping switchMapping) { Id = switchMapping.Id; NormallyClosed = switchMapping.IsNormallyClosed; Description = switchMapping.Description; Source = switchMapping.Source; InputActionMap = switchMapping.InputActionMap; InputAction = switchMapping.InputAction; Constant = switchMapping.Constant; Device = switchMapping.Device; if (string.IsNullOrEmpty(switchMapping.DeviceItem) && Device != null && Device.AvailableSwitches.Count() == 1) { DeviceItem = Device.AvailableSwitches.First().Id; } else { DeviceItem = switchMapping.DeviceItem; } PulseDelay = switchMapping.PulseDelay; SwitchMapping = switchMapping; }
private static GamelogicEngineSwitch GuessSwitchDeviceItem(GamelogicEngineSwitch engineSwitch, ISwitchDeviceComponent device) { // if there's only one switch, it's the one. if (device.AvailableSwitches.Count() == 1 && string.IsNullOrEmpty(engineSwitch.DeviceItemHint)) { return(device.AvailableSwitches.First()); } // otherwise, if not hint, we can't know. if (string.IsNullOrEmpty(engineSwitch.DeviceItemHint)) { return(null); } // match by regex foreach (var deviceSwitch in device.AvailableSwitches) { var regex = new Regex(engineSwitch.DeviceItemHint, RegexOptions.IgnoreCase); if (regex.Match(deviceSwitch.Id).Success) { return(deviceSwitch); } } return(null); }
public bool SwitchDeviceExists(ISwitchDeviceComponent component) => _switchDevices.ContainsKey(component);
internal void RegisterSwitchDevice(ISwitchDeviceComponent component, IApiSwitchDevice switchDeviceApi) => _switchDevices[component] = switchDeviceApi;
internal IApiSwitch Switch(ISwitchDeviceComponent component, string deviceSwitchId) => _switchDevices.ContainsKey(component) ? _switchDevices[component].Switch(deviceSwitchId) : null;
internal IApiSwitch Switch(ISwitchDeviceComponent component, string switchItem) => _player.Switch(component, switchItem);
/// <summary> /// Links a switch device to an existing switch mapping if it matches a given name. /// </summary> /// <param name="tableComponent">Table component for retrieving mappings.</param> /// <param name="elementName">The name that the switch device's GameObject has to match in order to be linked.</param> /// <param name="switchId">The ID of the switch mapping that the switch device will be linked to</param> /// <param name="switchDevice">The switch device to be linked</param> protected static void LinkSwitch(TableComponent tableComponent, string elementName, string switchId, ISwitchDeviceComponent switchDevice) { if (!string.Equals(switchDevice.gameObject.name, elementName, StringComparison.OrdinalIgnoreCase)) { return; } LinkSwitch(tableComponent, switchId, switchDevice); }
/// <summary> /// Links a switch device to an existing switch mapping. /// </summary> /// <param name="tableComponent">Table component for retrieving mappings.</param> /// <param name="switchId">The ID of the switch mapping that the switch device will be linked to</param> /// <param name="switchDevice">The switch device to be linked</param> /// <param name="switchDeviceItem">Switch ID inside of the device item. If null, the first switch will be used.</param> protected static void LinkSwitch(TableComponent tableComponent, string switchId, ISwitchDeviceComponent switchDevice, string switchDeviceItem = null) { var switchMapping = tableComponent.MappingConfig.Switches.FirstOrDefault(sw => sw.Id == switchId); if (switchMapping == null) { return; } switchMapping.Device = switchDevice; switchMapping.DeviceItem = switchDeviceItem ?? switchDevice.AvailableSwitches.First().Id; }
public void ClearDevice() { Device = null; DeviceItem = null; Update(); }