Skip to content

Commit 7cc9efb

Browse files
committed
Micro optimization and removed casting
1 parent a7e71ff commit 7cc9efb

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

Assets/SInput/Scripts/CommonGamepadBindings.cs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Collections;
21
using System.Collections.Generic;
32
using UnityEngine;
43

@@ -14,48 +13,51 @@ public static void ReloadCommonMaps() {
1413

1514
//Debug.Log("Loading common mapping");
1615

17-
OSFamily thisOS = OSFamily.Other;
18-
if (Application.platform == RuntimePlatform.OSXEditor) thisOS = OSFamily.MacOSX;
19-
if (Application.platform == RuntimePlatform.OSXPlayer) thisOS = OSFamily.MacOSX;
20-
if (Application.platform == RuntimePlatform.WindowsEditor) thisOS = OSFamily.Windows;
21-
if (Application.platform == RuntimePlatform.WindowsPlayer) thisOS = OSFamily.Windows;
22-
if (Application.platform == RuntimePlatform.LinuxEditor) thisOS = OSFamily.Linux;
23-
if (Application.platform == RuntimePlatform.LinuxPlayer) thisOS = OSFamily.Linux;
24-
if (Application.platform == RuntimePlatform.Android) thisOS = OSFamily.Android;
25-
if (Application.platform == RuntimePlatform.IPhonePlayer) thisOS = OSFamily.IOS;
26-
if (Application.platform == RuntimePlatform.PS4) thisOS = OSFamily.PS4;
27-
if (Application.platform == RuntimePlatform.PSP2) thisOS = OSFamily.PSVita;
28-
if (Application.platform == RuntimePlatform.XboxOne) thisOS = OSFamily.XboxOne;
29-
if (Application.platform == RuntimePlatform.Switch) thisOS = OSFamily.Switch;
30-
31-
System.Object[] commonMappingAssets = Resources.LoadAll("", typeof(CommonMapping));
16+
OSFamily thisOS;
17+
switch (Application.platform) {
18+
case RuntimePlatform.OSXEditor: thisOS = OSFamily.MacOSX; break;
19+
case RuntimePlatform.OSXPlayer: thisOS = OSFamily.MacOSX; break;
20+
case RuntimePlatform.WindowsEditor: thisOS = OSFamily.Windows; break;
21+
case RuntimePlatform.WindowsPlayer: thisOS = OSFamily.Windows; break;
22+
case RuntimePlatform.LinuxEditor: thisOS = OSFamily.Linux; break;
23+
case RuntimePlatform.LinuxPlayer: thisOS = OSFamily.Linux; break;
24+
case RuntimePlatform.Android: thisOS = OSFamily.Android; break;
25+
case RuntimePlatform.IPhonePlayer: thisOS = OSFamily.IOS; break;
26+
case RuntimePlatform.PS4: thisOS = OSFamily.PS4; break;
27+
case RuntimePlatform.PSP2: thisOS = OSFamily.PSVita; break;
28+
case RuntimePlatform.XboxOne: thisOS = OSFamily.XboxOne; break;
29+
case RuntimePlatform.Switch: thisOS = OSFamily.Switch; break;
30+
default: thisOS = OSFamily.Other; break;
31+
}
32+
33+
CommonMapping[] commonMappingAssets = Resources.LoadAll<CommonMapping>("");
3234
commonMappings = new List<CommonMapping>();
3335
string[] gamepads = Sinput.gamepads;
3436
int defaultMappingIndex = -1;
3537
for (int i = 0; i < commonMappingAssets.Length; i++) {
3638
//Debug.Log("HELLOOOOO");
37-
//if (((CommonMapping)commonMappingAssets[i]).isXRdevice) Debug.Log("XR deviiiiiice");
39+
//if ((commonMappingAssets[i]).isXRdevice) Debug.Log("XR deviiiiiice");
3840

39-
if (((CommonMapping)commonMappingAssets[i]).os == thisOS) {
41+
if ((commonMappingAssets[i]).os == thisOS) {
4042
bool gamepadConnected = false;
4143
bool partialMatch = false;
42-
for (int k = 0; k < ((CommonMapping)commonMappingAssets[i]).names.Count; k++) {
44+
for (int k = 0; k < (commonMappingAssets[i]).names.Count; k++) {
4345
for (int g = 0; g < gamepads.Length; g++) {
44-
if (((CommonMapping)commonMappingAssets[i]).names[k].ToUpper() == gamepads[g]) gamepadConnected = true;
46+
if ((commonMappingAssets[i]).names[k].ToUpper() == gamepads[g]) gamepadConnected = true;
4547
}
4648
}
4749

48-
for (int k = 0; k < ((CommonMapping)commonMappingAssets[i]).partialNames.Count; k++) {
50+
for (int k = 0; k < (commonMappingAssets[i]).partialNames.Count; k++) {
4951
for (int g = 0; g < gamepads.Length; g++) {
50-
if (gamepads[g].Contains(((CommonMapping)commonMappingAssets[i]).partialNames[k].ToUpper())) partialMatch = true;
52+
if (gamepads[g].Contains((commonMappingAssets[i]).partialNames[k].ToUpper())) partialMatch = true;
5153
}
5254
}
5355

54-
if (gamepadConnected) commonMappings.Add((CommonMapping)commonMappingAssets[i]);
55-
if (partialMatch && !gamepadConnected) commonMappings.Add((CommonMapping)commonMappingAssets[i]);
56-
if (!partialMatch && !gamepadConnected && ((CommonMapping)commonMappingAssets[i]).isDefault) commonMappings.Add((CommonMapping)commonMappingAssets[i]);
56+
if (gamepadConnected) commonMappings.Add(commonMappingAssets[i]);
57+
if (partialMatch && !gamepadConnected) commonMappings.Add(commonMappingAssets[i]);
58+
if (!partialMatch && !gamepadConnected && (commonMappingAssets[i]).isDefault) commonMappings.Add((CommonMapping)commonMappingAssets[i]);
5759

58-
if (((CommonMapping)commonMappingAssets[i]).isDefault) defaultMappingIndex = commonMappings.Count - 1;
60+
if ((commonMappingAssets[i]).isDefault) defaultMappingIndex = commonMappings.Count - 1;
5961
}
6062
}
6163

0 commit comments

Comments
 (0)