public static InputAction CreateButton(string controlSchemeName, string buttonName, KeyCode primaryKey, KeyCode secondaryKey) { ControlScheme scheme = GetControlScheme(controlSchemeName); if (scheme == null) { Debug.LogError(string.Format("A control scheme named \'{0}\' does not exist", controlSchemeName)); return(null); } if (m_instance.m_actionLookup[controlSchemeName].ContainsKey(buttonName)) { Debug.LogError(string.Format("The control scheme named {0} already contains an action named {1}", controlSchemeName, buttonName)); return(null); } InputAction action = scheme.CreateNewAction(buttonName); InputBinding primary = action.CreateNewBinding(); primary.Type = InputType.Button; primary.Positive = primaryKey; InputBinding secondary = action.CreateNewBinding(primary); secondary.Positive = secondaryKey; action.Initialize(); m_instance.m_actionLookup[controlSchemeName][buttonName] = action; return(action); }
/// <summary> /// Deletes the specified control scheme. If the speficied control scheme is /// active for any player then the active control scheme for the respective player will be set to null. /// </summary> public static bool DeleteControlScheme(string name) { ControlScheme scheme = GetControlScheme(name); if (scheme == null) { return(false); } m_instance.m_actionLookup.Remove(name); m_instance.m_schemeLookup.Remove(name); m_instance.m_controlSchemes.Remove(scheme); if (m_instance.m_playerOneScheme.Name == scheme.Name) { m_instance.m_playerOneScheme = null; } if (m_instance.m_playerTwoScheme.Name == scheme.Name) { m_instance.m_playerTwoScheme = null; } if (m_instance.m_playerThreeScheme.Name == scheme.Name) { m_instance.m_playerThreeScheme = null; } if (m_instance.m_playerFourScheme.Name == scheme.Name) { m_instance.m_playerFourScheme = null; } return(true); }
/// <summary> /// Changes the active control scheme. /// </summary> public static void SetControlScheme(string name, PlayerID playerID) { PlayerID?playerWhoUsesControlScheme = m_instance.IsControlSchemeInUse(name); if (playerWhoUsesControlScheme.HasValue && playerWhoUsesControlScheme.Value != playerID) { Debug.LogErrorFormat("The control scheme named \'{0}\' is already being used by player {1}", name, playerWhoUsesControlScheme.Value.ToString()); return; } if (playerWhoUsesControlScheme.HasValue && playerWhoUsesControlScheme.Value == playerID) { return; } ControlScheme controlScheme = null; if (m_instance.m_schemeLookup.TryGetValue(name, out controlScheme)) { controlScheme.Reset(); m_instance.SetControlSchemeByPlayerID(playerID, controlScheme); m_instance.RaisePlayerControlsChangedEvent(playerID); } else { Debug.LogError(string.Format("A control scheme named \'{0}\' does not exist", name)); } }
public static ControlScheme GetControlScheme(string name) { ControlScheme scheme = null; if(m_instance.m_schemeLookup.TryGetValue(name, out scheme)) return scheme; return null; }
public static bool IsKeyUsedInControlScheme(string controlSchemeName, KeyCode key, out KeyUsageResult usage) { ControlScheme scheme = GetControlScheme(controlSchemeName); usage = KeyUsageResult.None; return(scheme != null?scheme.IsKeyUsedInAnyAction(key, out usage) : false); }
private void CreateAndSetDefaultScheme() { if (m_controlSchemes.Count > 0) { var deafult = ControlScheme.Duplicate("default", m_controlSchemes[0]); m_controlSchemes.Insert(0, deafult); m_playerOneDefault = deafult.UniqueID; } }
private static bool AnyInput(ControlScheme scheme) { if (scheme != null) { return(scheme.AnyInput); } return(false); }
private void SetControlSchemeByPlayerID(PlayerID playerID, ControlScheme scheme) { if(playerID == PlayerID.One) m_playerOneScheme = scheme; else if(playerID == PlayerID.Two) m_playerTwoScheme = scheme; else if(playerID == PlayerID.Three) m_playerThreeScheme = scheme; else if(playerID == PlayerID.Four) m_playerFourScheme = scheme; }
private void UpdateControlScheme(ControlScheme scheme, PlayerID playerID) { if(scheme != null) { float deltaTime = m_ignoreTimescale ? Time.unscaledDeltaTime : Time.deltaTime; scheme.Update(deltaTime); if(m_remoteUpdateHandler != null) m_remoteUpdateHandler(playerID); } }
private void Initialize() { m_schemeLookup.Clear(); m_actionLookup.Clear(); m_playerOneScheme = null; m_playerTwoScheme = null; m_playerThreeScheme = null; m_playerFourScheme = null; if (m_controlSchemes.Count == 0) { return; } CreateAndSetDefaultScheme(); PopulateLookupTables(); if (!string.IsNullOrEmpty(m_playerOneDefault) && m_schemeLookupByID.ContainsKey(m_playerOneDefault)) { m_playerOneScheme = m_schemeLookupByID[m_playerOneDefault]; } else { if (m_controlSchemes.Count > 0) { m_playerOneScheme = m_controlSchemes[0]; } } if (!string.IsNullOrEmpty(m_playerTwoDefault) && m_schemeLookupByID.ContainsKey(m_playerTwoDefault)) { m_playerTwoScheme = m_schemeLookupByID[m_playerTwoDefault]; } if (!string.IsNullOrEmpty(m_playerThreeDefault) && m_schemeLookupByID.ContainsKey(m_playerThreeDefault)) { m_playerThreeScheme = m_schemeLookupByID[m_playerThreeDefault]; } if (!string.IsNullOrEmpty(m_playerFourDefault) && m_schemeLookupByID.ContainsKey(m_playerFourDefault)) { m_playerFourScheme = m_schemeLookupByID[m_playerFourDefault]; } foreach (ControlScheme scheme in m_controlSchemes) { scheme.Initialize(); } Input.ResetInputAxes(); }
public static bool DeleteAction(string controlSchemeName, string actionName) { ControlScheme scheme = GetControlScheme(controlSchemeName); InputAction action = GetAction(controlSchemeName, actionName); if(scheme != null && action != null) { m_instance.m_actionLookup[scheme.Name].Remove(action.Name); scheme.DeleteAction(action); return true; } return false; }
private void WriteControlScheme(ControlScheme scheme, XmlWriter writer) { writer.WriteStartElement("ControlScheme"); writer.WriteAttributeString("name", scheme.Name); writer.WriteAttributeString("id", scheme.UniqueID); writer.WriteElementString("Description", scheme.Description); foreach (var action in scheme.Actions) { WriteInputAction(action, writer); } writer.WriteEndElement(); }
private ControlScheme ReadControlScheme_V1(XmlNode node) { string name = ReadAttribute(node, "name", "Unnamed Configuration"); ControlScheme scheme = new ControlScheme(name); var actionNodes = SelectNodes(node, "AxisConfiguration"); foreach (XmlNode child in actionNodes) { ReadInputAction_V1(scheme, child); } return(scheme); }
private void ReadInputAction_V2(ControlScheme scheme, XmlNode node) { string name = ReadAttribute(node, "name", "Unnamed Action"); InputAction action = scheme.CreateNewAction(name); action.Description = ReadNode(SelectSingleNode(node, "Description")); var bindingNodes = SelectNodes(node, "Binding"); foreach (XmlNode child in bindingNodes) { ReadInputBinding_V2(action, child); } }
public static ControlScheme CreateControlScheme(string name) { if(m_instance.m_schemeLookup.ContainsKey(name)) { Debug.LogError(string.Format("A control scheme named \'{0}\' already exists", name)); return null; } ControlScheme scheme = new ControlScheme(name); m_instance.m_controlSchemes.Add(scheme); m_instance.m_schemeLookup[name] = scheme; m_instance.m_actionLookup[name] = new Dictionary<string, InputAction>(); return scheme; }
public static ControlScheme Duplicate(string name, ControlScheme source) { ControlScheme duplicate = new ControlScheme(); duplicate.m_name = name; duplicate.m_description = source.m_description; duplicate.m_uniqueID = GenerateUniqueID(); duplicate.m_actions = new List <InputAction>(); foreach (var action in source.m_actions) { duplicate.m_actions.Add(InputAction.Duplicate(action)); } return(duplicate); }
/// <summary> /// Creates an uninitialized input action. It's your responsability to configure it properly. /// </summary> public static InputAction CreateEmptyAction(string controlSchemeName, string actionName) { ControlScheme scheme = GetControlScheme(controlSchemeName); if(scheme == null) { Debug.LogError(string.Format("A control scheme named \'{0}\' does not exist", controlSchemeName)); return null; } if(m_instance.m_actionLookup[controlSchemeName].ContainsKey(actionName)) { Debug.LogError(string.Format("The control scheme named {0} already contains an action named {1}", controlSchemeName, actionName)); return null; } InputAction action = scheme.CreateNewAction(actionName); m_instance.m_actionLookup[controlSchemeName][actionName] = action; return action; }
private ControlScheme Load_V1(XmlDocument doc, string schemeName) { if (string.IsNullOrEmpty(schemeName)) { return(null); } ControlScheme scheme = null; var schemeNodes = SelectNodes(doc.DocumentElement, "InputConfiguration"); foreach (XmlNode node in schemeNodes) { if (ReadAttribute(node, "name") == schemeName) { scheme = ReadControlScheme_V1(node); break; } } return(scheme); }
public static InputAction CreateAnalogAxis(string controlScheme, string axisName, int joystick, int axis, float sensitivity, float deadZone) { ControlScheme scheme = GetControlScheme(controlScheme); if (scheme == null) { Debug.LogError(string.Format("A control scheme named \'{0}\' does not exist", controlScheme)); return(null); } if (m_instance.m_actionLookup[controlScheme].ContainsKey(axisName)) { Debug.LogError(string.Format("The control scheme named {0} already contains an action named {1}", controlScheme, axisName)); return(null); } if (axis < 0 || axis >= InputBinding.MAX_JOYSTICK_AXES) { Debug.LogError("Joystick axis is out of range. Cannot create new analog axis."); return(null); } if (joystick < 0 || joystick >= InputBinding.MAX_JOYSTICKS) { Debug.LogError("Joystick is out of range. Cannot create new analog axis."); return(null); } InputAction action = scheme.CreateNewAction(axisName); InputBinding binding = action.CreateNewBinding(); binding.Type = InputType.AnalogAxis; binding.Axis = axis; binding.Joystick = joystick; binding.DeadZone = deadZone; binding.Sensitivity = sensitivity; action.Initialize(); m_instance.m_actionLookup[controlScheme][axisName] = action; return(action); }
public static InputAction CreateRemoteAxis(string controlSchemeName, string axisName) { ControlScheme scheme = GetControlScheme(controlSchemeName); if(scheme == null) { Debug.LogError(string.Format("A control scheme named \'{0}\' does not exist", controlSchemeName)); return null; } if(m_instance.m_actionLookup[controlSchemeName].ContainsKey(axisName)) { Debug.LogError(string.Format("The control scheme named {0} already contains an action named {1}", controlSchemeName, axisName)); return null; } InputAction action = scheme.CreateNewAction(axisName); InputBinding binding = action.CreateNewBinding(); binding.Type = InputType.RemoteAxis; action.Initialize(); m_instance.m_actionLookup[controlSchemeName][axisName] = action; return action; }
public static InputAction CreateAnalogButton(string controlSchemeName, string buttonName, int joystick, int axis) { ControlScheme scheme = GetControlScheme(controlSchemeName); if (scheme == null) { Debug.LogError(string.Format("A control scheme named \'{0}\' does not exist", controlSchemeName)); return(null); } if (m_instance.m_actionLookup[controlSchemeName].ContainsKey(buttonName)) { Debug.LogError(string.Format("The input configuration named {0} already contains an action named {1}", controlSchemeName, buttonName)); return(null); } if (axis < 0 || axis >= InputBinding.MAX_JOYSTICK_AXES) { Debug.LogError("Joystick axis is out of range. Cannot create new analog button."); return(null); } if (joystick < 0 || joystick >= InputBinding.MAX_JOYSTICKS) { Debug.LogError("Joystick is out of range. Cannot create new analog button."); return(null); } InputAction action = scheme.CreateNewAction(buttonName); InputBinding binding = action.CreateNewBinding(); binding.Type = InputType.AnalogButton; binding.Joystick = joystick; binding.Axis = axis; action.Initialize(); m_instance.m_actionLookup[controlSchemeName][buttonName] = action; return(action); }
private ControlScheme ReadControlScheme_V2(XmlNode node) { string name = ReadAttribute(node, "name", "Unnamed Control Scheme"); string id = ReadAttribute(node, "id", null); ControlScheme scheme = new ControlScheme(name); scheme.UniqueID = id ?? ControlScheme.GenerateUniqueID(); var descriptionNode = SelectSingleNode(node, "Description"); if (descriptionNode != null) { scheme.Description = descriptionNode.InnerText; } var actionNodes = SelectNodes(node, "Action"); foreach (XmlNode child in actionNodes) { ReadInputAction_V2(scheme, child); } return(scheme); }
private void ReadInputAction_V1(ControlScheme scheme, XmlNode node) { string name = ReadAttribute(node, "name", "Unnamed Axis"); InputAction action = scheme.CreateNewAction(name); InputBinding binding = action.CreateNewBinding(); foreach (XmlNode child in node.ChildNodes) { switch (child.LocalName) { case "description": action.Description = child.InnerText; break; case "positive": binding.Positive = InputBinding.StringToKey(child.InnerText); break; case "negative": binding.Negative = InputBinding.StringToKey(child.InnerText); break; case "deadZone": binding.DeadZone = ReadAsFloat(child); break; case "gravity": binding.Gravity = ReadAsFloat(child, 1.0f); break; case "sensitivity": binding.Sensitivity = ReadAsFloat(child, 1.0f); break; case "snap": binding.Snap = ReadAsBool(child); break; case "invert": binding.Invert = ReadAsBool(child); break; case "type": binding.Type = InputBinding.StringToInputType(child.InnerText); break; case "axis": binding.Axis = ReadAsInt(child); break; case "joystick": binding.Joystick = ReadAsInt(child); break; } } if (binding.Type == InputType.Button || binding.Type == InputType.DigitalAxis) { XmlNode altPositiveNode = SelectSingleNode(node, "altPositive"); XmlNode altNegativeNode = SelectSingleNode(node, "altNegative"); InputBinding secondary = action.CreateNewBinding(binding); secondary.Positive = InputBinding.StringToKey(altPositiveNode.InnerText); secondary.Negative = InputBinding.StringToKey(altNegativeNode.InnerText); } }
public static ControlScheme Duplicate(ControlScheme source) { return(Duplicate(source.Name, source)); }
public static bool IsKeyUsedInControlScheme(string controlSchemeName, KeyCode key) { ControlScheme scheme = GetControlScheme(controlSchemeName); return(scheme.IsKeyUsedInAnyAction(key)); }