Skip to content

Commit 94a2683

Browse files
committed
[Fix] Fixed Windows Standalone builds #if UNITY_EDITOR errors scripts bytes differences
1 parent c8a0295 commit 94a2683

File tree

5 files changed

+41
-35
lines changed

5 files changed

+41
-35
lines changed

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"recommendations": [
33
"xabikos.javascriptsnippets",
44
"wayou.vscode-todo-highlight",
5-
"visualstudiotoolsforunity.vstuc",
5+
"tamasfe.even-better-toml",
6+
"visualstudiotoolsforunity.vstuc"
67
]
78
}

Packages/com.benoitfreslon.vibration/Runtime/Scripts/Vibration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static void Vibrate()
127127

128128
Vibrate(0, typeValue: (int) VibrationType.Normal);
129129

130-
#else
130+
#elif !UNITY_STANDALONE
131131

132132
if (Application.isConsolePlatform)
133133
{

Packages/com.benoitfreslon.vibration/Runtime/Scripts/VibrationComponent.cs

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ public class VibrationComponent : MonoBehaviour
3030
[SerializeField]
3131
[Tooltip("The type of vibration effect (SHORT: Android <= 9, LIGHT...HEAVY: Android >= 10)")]
3232
protected VibrationType type = VibrationType.None;
33-
34-
#if UNITY_ANDROID
3533

3634
// -- Unity Android core instances --
3735
protected AndroidJavaClass unityPlayer;
@@ -41,8 +39,6 @@ public class VibrationComponent : MonoBehaviour
4139
protected AndroidJavaObject vibrationPlugin;
4240
protected AndroidJavaObject durationLongObj;
4341

44-
#endif
45-
4642
#endregion
4743

4844
#region Properties
@@ -89,27 +85,7 @@ protected virtual void Awake()
8985
[SuppressMessage("ReSharper", "StringLiteralTypo")]
9086
protected virtual void Start()
9187
{
92-
#if UNITY_ANDROID
93-
94-
// Avoid: "Field currentActivity or type signature not found" exception
95-
// when a device is connected over USB and using Unity Remote app
96-
try
97-
{
98-
// PS: If you wish instantiate Kotlin Companion or Java static classes straight-forward from full package name,
99-
// use the "$" special character (e.g "android.media.AudioAttributes$Builder")
100-
unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
101-
currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
102-
vibrationPlugin = new AndroidJavaObject("com.benoitfreslon.unity.vibrations.lib.Vibration", currentActivity);
103-
}
104-
catch (Exception err)
105-
{
106-
if (!err.Message.Contains("Field currentActivity"))
107-
{
108-
throw err;
109-
}
110-
}
111-
112-
#endif
88+
InitComponents();
11389
}
11490

11591
protected virtual void OnDisable()
@@ -144,13 +120,47 @@ protected virtual void OnDisable()
144120
}
145121

146122
#endregion
123+
124+
[SuppressMessage("ReSharper", "StringLiteralTypo")]
125+
protected virtual void InitComponents()
126+
{
127+
#if UNITY_ANDROID
128+
129+
// Avoid: "Field currentActivity or type signature not found" exception
130+
// when a device is connected over USB and using Unity Remote app
131+
try
132+
{
133+
// PS: If you wish instantiate Kotlin Companion or Java static classes straight-forward from full package name,
134+
// use the "$" special character (e.g "android.media.AudioAttributes$Builder")
135+
unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
136+
currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
137+
vibrationPlugin = new AndroidJavaObject("com.benoitfreslon.unity.vibrations.lib.Vibration", currentActivity);
138+
}
139+
catch (Exception err)
140+
{
141+
if (!err.Message.Contains("Field currentActivity"))
142+
{
143+
throw;
144+
}
145+
146+
if (Debug.isDebugBuild)
147+
{
148+
var warnMessage = $"[{TAG}] [Android] Error on load fields/components." +
149+
$"Exception => {err.GetType().Name} : {err.Message}";
150+
151+
Debug.LogWarning(warnMessage);
152+
}
153+
}
154+
155+
#endif
156+
}
147157

148158
protected virtual void LoadOptionsSaved()
149159
{
150160
if (options == null)
151161
{
152162
/*
153-
* Fallback to some Unity versions that ScriptableObjects
163+
* Fallback to some Unity versions that ScriptableObjects
154164
* passed by inspector disappears when plays.
155165
*
156166
* Or, if a developer forget to define a custom ScriptableObject

Packages/com.benoitfreslon.vibration/Runtime/Vibration.asmdef

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
"name": "Vibration",
33
"rootNamespace": "VibrationPlugin",
44
"references": [],
5-
"includePlatforms": [
6-
"Android",
7-
"Editor",
8-
"iOS",
9-
"WebGL"
10-
],
5+
"includePlatforms": [],
116
"excludePlatforms": [],
127
"allowUnsafeCode": false,
138
"overrideReferences": false,

Packages/com.benoitfreslon.vibration/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"displayName": "Vibration",
55
"description": "Native free plugin for Unity for Android, iOS and WebGL. Use custom vibrations/haptics on mobile.",
66
"unity": "2019.3",
7-
"version": "0.1.6",
7+
"version": "0.1.7",
88
"keywords": [],
99
"devDependencies": {
1010
"cross-var": "^1.1.0",

0 commit comments

Comments
 (0)