static bool CompareKeys(HardKey key1, HardKey key2) { return((key1.Name == key2.Name) && key1.Primary.Equals(key2.Primary) && key1.Sensitivity == key2.Sensitivity); }
public void OnGUI() { if (keys == null) { LoadKeys(); } GUIStyle backstyle = new GUIStyle(); EditorGUILayout.BeginVertical(backstyle); GUILayout.Label("Inputs", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); PlayerPrefs.SetInt("HARDINPUT-FORCEDEFAULT", EditorGUILayout.ToggleLeft(new GUIContent("Force Defaults", "Toggle 'TRUE' and it will always load the default bindings in the editor."), PlayerPrefs.GetInt("HARDINPUT-FORCEDEFAULT", 0) == 1) ? 1 : 0); wantsAnalysis = EditorGUILayout.ToggleLeft(new GUIContent("Realtime Inputs", "Toggle 'TRUE' and the inspector window will show keypresses in runtime."), wantsAnalysis); autoSave = EditorGUILayout.ToggleLeft(new GUIContent("Autosave", "Toggle 'TRUE' and all changes will automatically be saved."), autoSave); EditorGUILayout.EndHorizontal(); GUILayout.Space(5); scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.ExpandWidth(true), GUILayout.Height(500)); bool shouldSave = false; List <HardKey> test = new List <HardKey>(); for (int i = 0; i < keys.Length; i++) { HardKey newKey = keys[i]; HardKey oldKey = hardUtility.CopyKey(newKey); test.Add(newKey); // Colours and foldout GUIStyle style = new GUIStyle(); style.normal.background = MakeTex(colours[i % 2]); EditorGUILayout.BeginVertical(style); GUIStyle titleStyle = new GUIStyle(); titleStyle.fontStyle = FontStyle.Bold; titleStyle.margin = new RectOffset(10, 10, 10, 10); EditorStyles.boldLabel.normal.textColor = new Color32(0, 0, 0, 255); if (Application.isPlaying && wantsAnalysis) { if (hardManager.Current().GetKey(newKey.Name)) { titleStyle.normal.textColor = new Color32(0, 0, 0, 255); } else { titleStyle.normal.textColor = new Color32(0, 0, 0, 150); } } if (opened == null) { LoadKeys(); } opened[i] = EditorGUILayout.Foldout(opened[i], (opened[i] ? "▼ " : "► ") + newKey.Name, true, titleStyle); // End of foldout and colouring EditorGUI.indentLevel++; if (opened != null && opened[i]) { newKey.Name = EditorGUILayout.TextField(new GUIContent("Name", "The name used to be referenced in code. E.g. GetKeyDown('Forward')"), newKey.Name); newKey.Sensitivity = EditorGUILayout.Slider(new GUIContent("Sensitivity", "This effects how quickly a key or axis scales when using 'GetAxis()' it will not effect other input methods like 'GeyKey()' or 'GetKeyDown()'"), newKey.Sensitivity, 0, 100); EditorGUILayout.LabelField("Primary", EditorStyles.boldLabel); EditorGUI.indentLevel++; keyType[i, 0] = (KeyType)EditorGUILayout.EnumPopup(new GUIContent("Input Type", "Select whether you want to check a mouse axis, or a keyboard input."), keyType[i, 0]); if (keyType[i, 0] == KeyType.Keypress) { newKey.Primary = (KeyCode)EditorGUILayout.EnumPopup(new GUIContent("Primary", "The main option used for a users input."), newKey.PrimaryKey); } else if (keyType[i, 0] == KeyType.Axis) { newKey.Primary = (KeyAxis)EditorGUILayout.EnumPopup(new GUIContent("Primary", "The main option used for a users input."), newKey.PrimaryAxis); } else if (keyType[i, 0] == KeyType.Controller) { newKey.Primary = (KeyController)EditorGUILayout.EnumPopup(new GUIContent("Primary", "The main option used for a users input."), newKey.PrimaryCont); } EditorGUI.indentLevel--; EditorGUILayout.LabelField("Secondary", EditorStyles.boldLabel); EditorGUI.indentLevel++; keyType[i, 1] = (KeyType)EditorGUILayout.EnumPopup(new GUIContent("Input Type", "Select whether you want to check a mouse axis, or a keyboard input."), keyType[i, 1]); if (keyType[i, 1] == KeyType.Keypress) { newKey.Secondary = (KeyCode)EditorGUILayout.EnumPopup(new GUIContent("Secondary", "The secondary option used for a users input."), newKey.SecondaryKey); } else if (keyType[i, 1] == KeyType.Axis) { newKey.Secondary = (KeyAxis)EditorGUILayout.EnumPopup(new GUIContent("Secondary", "The secondary option used for a users input."), newKey.SecondaryAxis); } else if (keyType[i, 1] == KeyType.Controller) { newKey.Secondary = (KeyController)EditorGUILayout.EnumPopup(new GUIContent("Secondary", "The secondary option used for a users input."), newKey.SecondaryCont); } EditorGUI.indentLevel--; if (oldKey.Name != newKey.Name || oldKey.Sensitivity != newKey.Sensitivity || oldKey.Primary.ToString() != newKey.Primary.ToString() || oldKey.Secondary.ToString() != newKey.Secondary.ToString()) { shouldSave = true; } GUILayout.Space(20); if (GUILayout.Button("Remove Key", EditorStyles.toolbarButton)) { RemoveInput(i); } } EditorGUI.indentLevel--; EditorGUILayout.EndVertical(); } ; if (shouldSave && autoSave) { Save(); } if (GUILayout.Button("Add Input", EditorStyles.toolbarButton)) { AddInput(); } if (!CheckInputAsset() && EditorPrefs.GetBool("HARDSHELL_IgnoreAssetError", false) == false) { backstyle.normal.background = MakeTex(new Color32(255, 50, 50, 255)); EditorGUILayout.BeginVertical(backstyle); EditorGUILayout.LabelField("Your default Unity file 'InputManager.asset' is incorrectly configured.", EditorStyles.boldLabel); EditorGUILayout.LabelField("Please click the button below to fix this."); EditorGUILayout.LabelField("If you are still having errors then contact below for support."); EditorGUILayout.LabelField("(This will overwrite your default Unity inputs, but is required for controller support)"); EditorGUILayout.LabelField("(If you modifiy the default unity inputs for whatever reason then this error will persist,"); EditorGUILayout.LabelField("if everything run's fine then just press the ignore button below)"); if (GUILayout.Button("Fix InputManager.asset", EditorStyles.toolbarButton)) { FixInputAsset(); } if (GUILayout.Button("Ignore error.", EditorStyles.toolbarButton)) { EditorPrefs.SetBool("HARDSHELL_IgnoreAssetError", true); } EditorGUILayout.EndVertical(); } EditorGUILayout.EndScrollView(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Refresh", EditorStyles.toolbarButton)) { LoadKeys(); } if (GUILayout.Button(new GUIContent("Save", "Save the current bindings."), EditorStyles.toolbarButton)) { Save(); Debug.Log("Hard Shell Input: Saved bindings!"); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Reimport InputManager.asset", EditorStyles.toolbarButton)) { FixInputAsset(); } GUILayout.Space(20); GUILayout.Label("Created by Haydn Comley (Version: " + version + ")", EditorStyles.boldLabel); GUILayout.Label("Find more of me at:", EditorStyles.boldLabel); GUILayout.Label("www.hardshellstudios.com + www.haydncomley.com"); GUILayout.Label("Email for help at:", EditorStyles.boldLabel); GUILayout.Label("[email protected] or [email protected]"); GUILayout.Label("Tutorials can be found on YouTube:", EditorStyles.boldLabel); if (GUILayout.Button("Click Here or Link https://www.youtube.com/channel/UCgqEGyFYByfBFCoIWQrhGEg", EditorStyles.toolbarButton)) { System.Diagnostics.Process.Start("https://www.youtube.com/channel/UCgqEGyFYByfBFCoIWQrhGEg"); } EditorGUILayout.EndHorizontal(); }
/// <summary> /// Returns a prettier, formatted string for display in game to show what button a key is bound to. /// </summary> public static string MakeKeycodePretty(string KeyName, bool GetPrimary = true) { HardKey key = hardManager.Current().Find(KeyName); string name = key.Primary.ToString(); KeyCode keycode = key.PrimaryKey; KeyController keycontroller = key.PrimaryCont; KeyAxis keyaxis = key.PrimaryAxis; if (GetPrimary) { name = key.Primary.ToString(); } else { name = key.Secondary.ToString(); keycode = key.SecondaryKey; keycontroller = key.SecondaryCont; keyaxis = key.SecondaryAxis; } if (key.CheckPrimary(typeof(KeyCode)) && GetPrimary || key.CheckSecondary(typeof(KeyCode)) && !GetPrimary) { if (name.Contains("Alpha")) { return(name.Replace("Alpha", "")); } else if (name.Contains("Keypad")) { return(name.Replace("Keypad", "Keypad ")); } else if (name.Contains("Left")) { return(name.Replace("Left", "Left ")); } else if (name.Contains("Right")) { return(name.Replace("Right", "Right ")); } else if (name.Contains("Up")) { return(name.Replace("Up", "Up ")); } else if (name.Contains("Down")) { return(name.Replace("Down", "Down ")); } else if (name.Contains("Mouse0")) { return("Left Mouse"); } else if (name.Contains("Mouse1")) { return("Right Mouse"); } else if (name.Contains("Mouse2")) { return("Middle Mouse"); } else if (name.Contains("Mouse")) { return("Mouse " + name.Replace("Mouse", "")); } } else if (key.CheckPrimary(typeof(KeyAxis)) && GetPrimary || key.CheckSecondary(typeof(KeyAxis)) && !GetPrimary) { if (keyaxis == KeyAxis.MouseX) { return("Mouse X"); } else if (keyaxis == KeyAxis.MouseY) { return("Mouse Y"); } else if (keyaxis == KeyAxis.ScrollWheel) { return("Scroll Wheel"); } else if (keyaxis == KeyAxis.ScrollWheelDown) { return("Scroll Wheel Down"); } else if (keyaxis == KeyAxis.ScrollWheelUp) { return("Scroll Wheel Up"); } } else if (key.CheckPrimary(typeof(KeyController)) && GetPrimary || key.CheckSecondary(typeof(KeyController)) && !GetPrimary) { switch (keycontroller) { case KeyController.LeftStickX: return("Left Stick X"); case KeyController.LeftStickY: return("Left Stick Y"); case KeyController.RightStickX: return("Right Stick X"); case KeyController.RightStickY: return("Right Stick Y"); case KeyController.DPadX: return("D-PAD X"); case KeyController.DPadY: return("D-PAD Y"); case KeyController.LeftTrigger: return("Left Trigger"); case KeyController.RightTrigger: return("Right Trigger"); case KeyController.LeftStickUp: return("Left Stick Up"); case KeyController.LeftStickDown: return("Left Stick Down"); case KeyController.LeftStickLeft: return("Left Stick Left"); case KeyController.LeftStickRight: return("Left Stick Right"); case KeyController.RightStickUp: return("Right Stick Up"); case KeyController.RightStickDown: return("Right Stick Down"); case KeyController.RightStickLeft: return("Right Stick Left"); case KeyController.RightStickRight: return("Right Stick Right"); case KeyController.DPadUp: return("D-PAD Up"); case KeyController.DPadDown: return("D-PAD Down"); case KeyController.DPadLeft: return("D-PAD Left"); case KeyController.DPadRight: return("D-PAD Right"); } } return(name); }