Skip to content

Commit 5149442

Browse files
authored
Add files via upload
1 parent 88fcdd4 commit 5149442

16 files changed

+665
-0
lines changed

Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/InputSettingsWindow.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
public class InputSettingsWindow : EditorWindow
5+
{
6+
private InputSettings inputSettings;
7+
8+
[MenuItem("Window/Input Settings")]
9+
public static void ShowWindow()
10+
{
11+
GetWindow<InputSettingsWindow>("Input Settings");
12+
}
13+
14+
private void OnGUI()
15+
{
16+
GUILayout.Label("Input Settings", EditorStyles.boldLabel);
17+
18+
inputSettings = InputSystemProjectSettings.selectedInputSettings;
19+
inputSettings = (InputSettings)EditorGUILayout.ObjectField("Input Settings", inputSettings, typeof(InputSettings), false);
20+
21+
if (inputSettings != null)
22+
{
23+
SerializedObject serializedObject = new SerializedObject(inputSettings);
24+
SerializedProperty inputsSettingsProperty = serializedObject.FindProperty("m_Inputs");
25+
EditorGUILayout.PropertyField(inputsSettingsProperty, true);
26+
27+
serializedObject.ApplyModifiedProperties();
28+
}
29+
30+
InputSystem.main.settings = inputSettings;
31+
32+
InputSystemProjectSettings.selectedInputSettings = inputSettings;
33+
}
34+
}

Editor/InputSettingsWindow.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
using UnityEngine.InputSystem;
4+
5+
static class InputSystemProjectSettings
6+
{
7+
public static InputSettings selectedInputSettings;
8+
9+
[SettingsProvider]
10+
public static SettingsProvider CreateInputSystemSettingsProvider()
11+
{
12+
var provider = new SettingsProvider("Project/InputSystem", SettingsScope.Project)
13+
{
14+
label = "Input System",
15+
guiHandler = (searchContext) =>
16+
{
17+
selectedInputSettings = (InputSettings)EditorGUILayout.ObjectField("Input Settings", selectedInputSettings, typeof(InputSettings), false);
18+
InputSystem.selectedSettings = selectedInputSettings;
19+
20+
if (selectedInputSettings == null)
21+
{
22+
if (GUILayout.Button("Create Input Settings"))
23+
{
24+
selectedInputSettings = ScriptableObject.CreateInstance<InputSettings>();
25+
AssetDatabase.CreateAsset(selectedInputSettings, "Assets/InputSettings.asset");
26+
AssetDatabase.SaveAssets();
27+
}
28+
}
29+
else
30+
{
31+
var serializedObject = new SerializedObject(selectedInputSettings);
32+
var keysProperty = serializedObject.FindProperty("m_Inputs");
33+
34+
EditorGUILayout.PropertyField(keysProperty, true);
35+
36+
serializedObject.ApplyModifiedProperties();
37+
}
38+
39+
if (GUI.changed)
40+
{
41+
SaveSettings();
42+
}
43+
}
44+
};
45+
LoadSettings();
46+
return provider;
47+
}
48+
49+
public static void LoadSettings()
50+
{
51+
string path = EditorPrefs.GetString("InputSystemSettingsPath", "Assets/InputSettings.asset");
52+
selectedInputSettings = AssetDatabase.LoadAssetAtPath<InputSettings>(path);
53+
InputSystem.main.settings = selectedInputSettings;
54+
InputSystem.selectedSettings = selectedInputSettings;
55+
}
56+
57+
public static void SaveSettings()
58+
{
59+
if (selectedInputSettings != null)
60+
{
61+
string path = AssetDatabase.GetAssetPath(selectedInputSettings);
62+
EditorPrefs.SetString("InputSystemSettingsPath", path);
63+
InputSystem.main.settings = selectedInputSettings;
64+
InputSystem.selectedSettings = selectedInputSettings;
65+
}
66+
}
67+
}

Editor/InputSystemProjectSettings.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/KeyDrawer.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System.Collections.Generic;
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
[CustomPropertyDrawer(typeof(InputSystem.key))]
6+
public class KeyDrawer : PropertyDrawer
7+
{
8+
private static string currentBindingProperty = null;
9+
10+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
11+
{
12+
// Set label width
13+
EditorGUIUtility.labelWidth = 70;
14+
EditorGUI.BeginProperty(position, label, property);
15+
16+
// Set the position to draw fields
17+
Rect keyCodeRect = new Rect(position.x, position.y, position.width / 2 - 20, EditorGUIUtility.singleLineHeight);
18+
Rect buttonRect = new Rect(position.x + position.width / 2 - 1, position.y, (position.width / 2) - 26, EditorGUIUtility.singleLineHeight);
19+
Rect cancelButtonRect = new Rect(position.x + position.width - 28, position.y, 20, EditorGUIUtility.singleLineHeight);
20+
21+
// Get the unique property path to use as a key
22+
string propertyPath = property.propertyPath;
23+
24+
// Draw the fields
25+
EditorGUI.PropertyField(keyCodeRect, property.FindPropertyRelative("keyCode"), new GUIContent("Key"));
26+
27+
// Draw Bind Button
28+
bool isBinding = currentBindingProperty == propertyPath;
29+
if (isBinding)
30+
{
31+
if (Event.current.type == EventType.KeyDown)
32+
{
33+
property.FindPropertyRelative("keyCode").intValue = (int)Event.current.keyCode;
34+
currentBindingProperty = null;
35+
Event.current.Use();
36+
}
37+
isBinding = GUI.Toggle(buttonRect, isBinding, "Press key to bind", GUI.skin.button);
38+
}
39+
else
40+
{
41+
if (GUI.Button(buttonRect, "Bind"))
42+
{
43+
currentBindingProperty = propertyPath;
44+
}
45+
}
46+
47+
// Draw Cancel/Clear Button
48+
if (isBinding)
49+
{
50+
if (GUI.Button(cancelButtonRect, "x"))
51+
{
52+
currentBindingProperty = null;
53+
}
54+
}
55+
else
56+
{
57+
if (GUI.Button(cancelButtonRect, "x"))
58+
{
59+
if (EditorUtility.DisplayDialog("Clear Key", "Are you sure you want to clear the key?", "Yes", "No"))
60+
{
61+
property.FindPropertyRelative("keyCode").intValue = (int)KeyCode.None;
62+
}
63+
}
64+
}
65+
66+
EditorGUI.EndProperty();
67+
}
68+
69+
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
70+
{
71+
return EditorGUIUtility.singleLineHeight + 1;
72+
}
73+
}

Editor/KeyDrawer.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/InputSettings.asset

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: b7f15879f6cf706478610c1c7ca2218c, type: 3}
13+
m_Name: InputSettings
14+
m_EditorClassIdentifier:
15+
m_Inputs:
16+
Buttons:
17+
- Name: Run
18+
keys:
19+
- keyCode: 304
20+
Axis:
21+
- Name: Move
22+
type: 2
23+
Keys_Up:
24+
- keyCode: 273
25+
- keyCode: 119
26+
Keys_Down:
27+
- keyCode: 274
28+
- keyCode: 115
29+
Keys_Left:
30+
- keyCode: 276
31+
- keyCode: 97
32+
Keys_Right:
33+
- keyCode: 275
34+
- keyCode: 100

Runtime/InputSettings.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)