public bool GetKey(InputAlias alias) { for (var i = 0; i < NumberOfInputs; ++i) { if (GetKey(alias, i)) { return(true); } } return(false); }
public float GetAxis(InputAlias alias, int inputIndex) { if (inputIndex == 0) { return(Input.GetAxis(_keyboardAxis[alias])); } if (alias == InputAlias.Vertical) { return(-XCI.GetAxis(_xboxAxis[alias], inputIndex)); } return(XCI.GetAxis(_xboxAxis[alias], inputIndex)); }
public float GetAxis(InputAlias alias) { var max = 0.0f; for (var i = 0; i < NumberOfInputs; ++i) { if (Mathf.Abs(GetAxis(alias, i)) > Mathf.Abs(max)) { max = GetAxis(alias, i); } } return(max); }
/// <summary> /// Allows us to add to a list /// </summary> /// <param name="rList"></param> private void OnAliasListItemAdd(ReorderableList rList) { InputAlias lAlias = Activator.CreateInstance <InputAlias>(); lAlias.PrimaryID = -1; lAlias.SupportID = -1; mTarget.DefaultActionAliases.Add(lAlias); mAliasList.index = mTarget.DefaultActionAliases.Count - 1; OnAliasListItemSelect(rList); mIsDirty = true; }
/// <summary> /// Allows us to stop before removing the item /// </summary> /// <param name="rList"></param> private void OnAliasListItemRemove(ReorderableList rList) { if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to delete the item?", "Yes", "No")) { int rIndex = rList.index; rList.index--; InputAlias lAlias = mTarget.DefaultActionAliases[rIndex]; if (lAlias.Name.Length > 0 && lAlias.PrimaryID >= 0) { InputManager.RemoveAlias(lAlias.Name, lAlias.PrimaryID, (lAlias.SupportID <= 0 ? 0 : lAlias.SupportID)); } mTarget.DefaultActionAliases.RemoveAt(rIndex); OnAliasListItemSelect(rList); mIsDirty = true; } }
/// <summary> /// Called when the inspector needs to draw /// </summary> public override void OnInspectorGUI() { // Pulls variables from runtime so we have the latest values. mTargetSO.Update(); GUILayout.Space(5); EditorHelper.DrawInspectorTitle("ootii Easy Input Source"); EditorHelper.DrawInspectorDescription("Input solution that leverages ootii's advanced 'Easy Input' asset. There should only be one per scene.", MessageType.None); GUILayout.Space(5); if (!InputManagerHelper.IsDefined("WXLeftStickX")) { Color lGUIColor = GUI.color; GUI.color = new Color(1f, 0.7f, 0.7f, 1f); EditorGUILayout.HelpBox("Required Unity Input Manager entries not created. To create the entries, press the 'Reset Input Entries' button below.", MessageType.Warning); GUI.color = lGUIColor; GUILayout.Space(5); } EditorGUILayout.BeginVertical(EditorHelper.Box); EditorGUILayout.HelpBox("Reset required Unity Input Manager entries.", MessageType.None); if (GUILayout.Button("Reset Input Entries", EditorStyles.miniButton)) { ClearInputManagerEntries(); CreateInputManagerEntries(); } EditorGUILayout.EndVertical(); GUILayout.Space(5); bool lNewIsPlayerInputEnabled = EditorGUILayout.Toggle(new GUIContent("Is Input Enabled", "Determines if this component will return user input. This is NOT a global setting and does NOT effect the static 'Input Manager' from returning input."), mTarget.IsEnabled); if (lNewIsPlayerInputEnabled != mTarget.IsEnabled) { mIsDirty = true; mTarget.IsEnabled = lNewIsPlayerInputEnabled; } bool lNewIsXboxControllerEnabled = EditorGUILayout.Toggle(new GUIContent("Is Xbox Enabled", "Determines we can use the Xbox controller for input. This is a global setting that effects the static 'Input Manager'."), mTarget.IsXboxControllerEnabled); if (lNewIsXboxControllerEnabled != mTarget.IsXboxControllerEnabled) { mIsDirty = true; mTarget.IsXboxControllerEnabled = lNewIsXboxControllerEnabled; // Ensure our input manager entries exist if (mTarget.IsXboxControllerEnabled) { CreateInputManagerEntries(); } } GUILayout.Space(5); float lNewViewSensativity = EditorGUILayout.FloatField(new GUIContent("View Sensativity", "Sets how quickly the view rotates (while using the mouse)"), mTarget.ViewSensativity); if (lNewViewSensativity != mTarget.ViewSensativity) { mIsDirty = true; mTarget.ViewSensativity = lNewViewSensativity; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("View Activator", "Determines what button enables viewing."), GUILayout.Width(EditorGUIUtility.labelWidth)); int lNewViewActivator = EditorGUILayout.Popup(mTarget.ViewActivator, mActivators); if (lNewViewActivator != mTarget.ViewActivator) { mIsDirty = true; mTarget.ViewActivator = lNewViewActivator; } EditorGUILayout.EndHorizontal(); GUILayout.Space(5); EditorHelper.DrawLine(); GUILayout.Space(5f); // Show the aliases GUILayout.BeginVertical(EditorHelper.GroupBox); mAliasList.DoLayoutList(); GUILayout.EndVertical(); if (mAliasList.index >= 0) { EditorGUILayout.BeginVertical(EditorHelper.Box); InputAlias lAlias = mTarget.DefaultActionAliases[mAliasList.index]; bool lListIsDirty = DrawAliasDetailItem(ref lAlias); if (lListIsDirty) { mIsDirty = true; mTarget.DefaultActionAliases[mAliasList.index] = lAlias; } EditorGUILayout.EndVertical(); } GUILayout.Space(5); // If there is a change... update. if (mIsDirty) { // Flag the object as needing to be saved EditorUtility.SetDirty(mTarget); #if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2 EditorApplication.MarkSceneDirty(); #else if (!EditorApplication.isPlaying) { UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene()); } #endif // Pushes the values back to the runtime so it has the changes mTargetSO.ApplyModifiedProperties(); // Clear out the dirty flag mIsDirty = false; } }
/// <summary> /// Renders the currently selected step /// </summary> /// <param name="rStep"></param> private bool DrawAliasDetailItem(ref InputAlias rAlias) { bool lIsDirty = false; string lOldName = (rAlias.Name == null ? "" : rAlias.Name); int lOldPrimaryID = rAlias.PrimaryID; int lOldSupportID = rAlias.SupportID; if (rAlias.Name == null) { rAlias.Name = ""; } if (rAlias.Description == null) { rAlias.Description = ""; } EditorHelper.DrawSmallTitle(rAlias.Name); if (rAlias.Description.Length > 0) { EditorHelper.DrawInspectorDescription(rAlias.Description, MessageType.None); } else { EditorGUILayout.LabelField("", GUILayout.Width(2)); } // Friendly name string lNewName = EditorGUILayout.TextField(new GUIContent("Name", "Friendly name of the alias."), rAlias.Name); if (lNewName != rAlias.Name) { lIsDirty = true; rAlias.Name = lNewName; } // Friendly description string lNewDescription = EditorGUILayout.TextField(new GUIContent("Description", "Higher priorities will run over lower priorities."), rAlias.Description); if (lNewDescription != rAlias.Description) { lIsDirty = true; rAlias.Description = lNewDescription; } GUILayout.Space(5); // Primary ID int lPrimaryIndex = -1; for (int i = 0; i < mEnumIDs.Length; i++) { if (mEnumIDs[i] == rAlias.PrimaryID) { lPrimaryIndex = i; break; } } int lNewPrimaryIndex = EditorGUILayout.Popup("Primary Input", lPrimaryIndex, mEnumNames, GUILayout.MinWidth(50)); if (lNewPrimaryIndex != lPrimaryIndex) { if (lNewPrimaryIndex >= 0) { lIsDirty = true; rAlias.PrimaryID = mEnumIDs[lNewPrimaryIndex]; } } // Support ID int lSupportIndex = -1; for (int i = 0; i < mEnumIDs.Length; i++) { if (mEnumIDs[i] == rAlias.SupportID) { lSupportIndex = i; break; } } EditorGUILayout.BeginHorizontal(); int lNewSupportIndex = EditorGUILayout.Popup("Support Input", lSupportIndex, mEnumNames, GUILayout.MinWidth(50)); if (lNewSupportIndex != lSupportIndex) { if (lNewSupportIndex >= 0) { lIsDirty = true; rAlias.SupportID = mEnumIDs[lNewSupportIndex]; } } if (GUILayout.Button(new GUIContent("", "Clear the support"), EditorHelper.RedXButton, GUILayout.Width(16), GUILayout.Height(16))) { lIsDirty = true; rAlias.SupportID = -1; } GUILayout.Space(2); EditorGUILayout.EndHorizontal(); GUILayout.Space(5); bool lNewIsDoubleClick = EditorGUILayout.Toggle(new GUIContent("Test As Double Press", "When IsPressed is called, determine if we test as a double press."), rAlias.IsDoublePress); if (lNewIsDoubleClick != rAlias.IsDoublePress) { lIsDirty = true; rAlias.IsDoublePress = lNewIsDoubleClick; } // If the entry is dirty and we're playing, update the InputManager if (lIsDirty && Application.isPlaying) { if (lOldName.Length > 0) { InputManager.RemoveAlias(lOldName, lOldPrimaryID, (lOldSupportID <= 0 ? 0 : lOldSupportID)); } if (rAlias.Name.Length > 0 && rAlias.PrimaryID >= 0) { InputManager.AddAlias(rAlias.Name, rAlias.PrimaryID, (rAlias.SupportID <= 0 ? 0 : rAlias.SupportID)); } } return(lIsDirty); }
public bool GetKeyDown(InputAlias alias, int inputIndex) { return(inputIndex == 0 ? Input.GetKeyDown(_keyboardButtons[alias]) : XCI.GetButtonDown(_xboxButtons[alias], inputIndex)); }