Skip to content

Commit 6b0ef8c

Browse files
authored
Fix Compatibility Issues
1 parent 1fd8e69 commit 6b0ef8c

14 files changed

+393
-49
lines changed

Editor.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/GameInputSettingsWindow.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 GameInputSettingsWindow : EditorWindow
5+
{
6+
private GameInputSettings inputSettings;
7+
8+
[MenuItem("Window/Input Settings")]
9+
public static void ShowWindow()
10+
{
11+
GetWindow<GameInputSettingsWindow>("Input Settings");
12+
}
13+
14+
private void OnGUI()
15+
{
16+
GUILayout.Label("Input Settings", EditorStyles.boldLabel);
17+
18+
inputSettings = GameInputSystemProjectSettings.selectedInputSettings;
19+
inputSettings = (GameInputSettings)EditorGUILayout.ObjectField("Input Settings", inputSettings, typeof(GameInputSettings), 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+
GameInput.main.settings = inputSettings;
31+
32+
GameInputSystemProjectSettings.selectedInputSettings = inputSettings;
33+
}
34+
}

Editor/GameInputSettingsWindow.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 GameInputSystemProjectSettings
6+
{
7+
public static GameInputSettings 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 = (GameInputSettings)EditorGUILayout.ObjectField("Input Settings", selectedInputSettings, typeof(GameInputSettings), false);
18+
GameInput.selectedSettings = selectedInputSettings;
19+
20+
if (selectedInputSettings == null)
21+
{
22+
if (GUILayout.Button("Create Input Settings"))
23+
{
24+
selectedInputSettings = ScriptableObject.CreateInstance<GameInputSettings>();
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<GameInputSettings>(path);
53+
GameInput.main.settings = selectedInputSettings;
54+
GameInput.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+
GameInput.main.settings = selectedInputSettings;
64+
GameInput.selectedSettings = selectedInputSettings;
65+
}
66+
}
67+
}

Editor/GameInputSystemProjectSettings.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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Collections.Generic;
12
using UnityEditor;
23
using UnityEngine;
34

@@ -14,6 +15,8 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
1415

1516
// Set the position to draw fields
1617
Rect keyCodeRect = new Rect(position.x, position.y, position.width / 2 - 20, EditorGUIUtility.singleLineHeight);
18+
//Rect mouseButtonRect = new Rect(position.x + position.width / 4 - 20, position.y, position.width / 4 - 20, EditorGUIUtility.singleLineHeight);
19+
1720
Rect buttonRect = new Rect(position.x + position.width / 2 - 1, position.y, (position.width / 2) - 26, EditorGUIUtility.singleLineHeight);
1821
Rect cancelButtonRect = new Rect(position.x + position.width - 28, position.y, 20, EditorGUIUtility.singleLineHeight);
1922

@@ -22,6 +25,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
2225

2326
// Draw the fields
2427
EditorGUI.PropertyField(keyCodeRect, property.FindPropertyRelative("keyCode"), new GUIContent("Key"));
28+
//EditorGUI.PropertyField(mouseButtonRect, property.FindPropertyRelative("mouseButton"), new GUIContent("Mouse"));
2529

2630
// Draw Bind Button
2731
bool isBinding = currentBindingProperty == propertyPath;
@@ -33,6 +37,32 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
3337
currentBindingProperty = null;
3438
Event.current.Use();
3539
}
40+
else
41+
{
42+
if (Event.current.type == EventType.MouseDown)
43+
{
44+
if (Event.current.button == 0)
45+
{
46+
property.FindPropertyRelative("keyCode").intValue = (int)KeyCode.Mouse0;
47+
currentBindingProperty = null;
48+
Event.current.Use();
49+
}
50+
51+
if (Event.current.button == 1)
52+
{
53+
property.FindPropertyRelative("keyCode").intValue = (int)KeyCode.Mouse1;
54+
currentBindingProperty = null;
55+
Event.current.Use();
56+
}
57+
58+
if (Event.current.button == 2)
59+
{
60+
property.FindPropertyRelative("keyCode").intValue = (int)KeyCode.Mouse2;
61+
currentBindingProperty = null;
62+
Event.current.Use();
63+
}
64+
}
65+
}
3666
isBinding = GUI.Toggle(buttonRect, isBinding, "Press key to bind", GUI.skin.button);
3767
}
3868
else

Editor/KeyDrawer.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)