Skip to content

Commit b2a56f0

Browse files
committed
fix(Examples): display error if script define symbols have not been set
There is an issue where the new example scenes don't set the required VRTK script define symbols because this is done via the SDK Manager script and that is no longer present in the example scenes as it is dynamically loaded in via the constructor scene. This fix simply throws an error if the example scene cannot find the required scripting define symbols and attempts to provide useful information for the user to rectify the issue.
1 parent b417b5b commit b2a56f0

File tree

5 files changed

+42
-10
lines changed

5 files changed

+42
-10
lines changed

Assets/VRTK/Examples/ExampleResources/SharedResources/Scripts/VRTKExample_AdditiveSceneLoader.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
{
33
#if UNITY_EDITOR
44
using UnityEditor;
5+
using System.Collections.Generic;
6+
using System.Linq;
57
#endif
68
using UnityEngine;
79
using UnityEngine.SceneManagement;
@@ -26,6 +28,7 @@ public class VRTKExample_AdditiveSceneLoader : MonoBehaviour
2628

2729
protected virtual void Awake()
2830
{
31+
CheckScriptingDefineSymbols();
2932
if (!Application.isPlaying && Application.isEditor)
3033
{
3134
ManageBuildSettings();
@@ -45,6 +48,20 @@ protected virtual void Awake()
4548
}
4649
}
4750
}
51+
protected virtual void CheckScriptingDefineSymbols()
52+
{
53+
#if UNITY_EDITOR
54+
bool isMissingSDKSymbols = PlayerSettings
55+
.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup)
56+
.Split(';')
57+
.All(symbol => !symbol.StartsWith(SDK_ScriptingDefineSymbolPredicateAttribute.RemovableSymbolPrefix, System.StringComparison.Ordinal));
58+
59+
if (isMissingSDKSymbols)
60+
{
61+
VRTK_Logger.Error("No VRTK scripting define symbols have been found. " + VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.SCRIPTING_DEFINE_SYMBOLS_NOT_FOUND), true);
62+
}
63+
#endif
64+
}
4865

4966
protected virtual void ManageBuildSettings()
5067
{

Assets/VRTK/Examples/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Examples
22

3+
**Important Note**
4+
5+
> The example scenes no longer contain the `VRTK_SDKManager` as this is loaded in at runtime via the `VRTK_SDKManager_Constructor` scene. As the `VRTK_SDKManager` script is responsible for setting up the required Unity Scripting Define Symbols for installed SDKs it is required that the `VRTK_SDKManager_Constructor` scene is opened in the Unity Editor when first using the project or when installing a new supported SDK so it can set up the scripting define symbols. The example scenes will not work until the scripting define symbols have been set up correctly so please ensure that the `VRTK_SDKManager_Constructor` scene is loaded into the Unity Editor first.
6+
37
This directory contains Unity3d scenes that demonstrate the scripts and prefabs being used in the game world to create desired functionality.
48

59
> *VRTK offers a VR Simulator that works without any third party SDK, but VR device support requires a supported VR SDK to be imported into the Unity project.*

Assets/VRTK/Source/Scripts/Internal/VRTK_Logger.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public enum CommonMessageKeys
3434
SDK_NOT_FOUND,
3535
SDK_MANAGER_ERRORS,
3636
SCRIPTING_DEFINE_SYMBOLS_ADDED,
37-
SCRIPTING_DEFINE_SYMBOLS_REMOVED
37+
SCRIPTING_DEFINE_SYMBOLS_REMOVED,
38+
SCRIPTING_DEFINE_SYMBOLS_NOT_FOUND
3839
}
3940

4041
public static VRTK_Logger instance = null;
@@ -51,7 +52,8 @@ public enum CommonMessageKeys
5152
{ CommonMessageKeys.SDK_NOT_FOUND, "The SDK '{0}' doesn't exist anymore. The fallback SDK '{1}' will be used instead." },
5253
{ CommonMessageKeys.SDK_MANAGER_ERRORS, "The current SDK Manager setup is causing the following errors:\n\n{0}" },
5354
{ CommonMessageKeys.SCRIPTING_DEFINE_SYMBOLS_ADDED, "Scripting Define Symbols added to [Project Settings->Player] for {0}: {1}" },
54-
{ CommonMessageKeys.SCRIPTING_DEFINE_SYMBOLS_REMOVED, "Scripting Define Symbols removed from [Project Settings->Player] for {0}: {1}" }
55+
{ CommonMessageKeys.SCRIPTING_DEFINE_SYMBOLS_REMOVED, "Scripting Define Symbols removed from [Project Settings->Player] for {0}: {1}" },
56+
{ CommonMessageKeys.SCRIPTING_DEFINE_SYMBOLS_NOT_FOUND, "If you are attempting to run an example scene and have not opened the `VRTK/Examples/VRTK_SDKManager_Constructor` scene in the Unity Editor then this is most likely why you are receiving this error message, try opening the `VRTK/Examples/VRTK_SDKManager_Constructor` scene and letting it configure the relevant scripting define symbols and then re-open the desired example scene and try again." }
5557
};
5658

5759
public static Dictionary<CommonMessageKeys, int> commonMessageParts = new Dictionary<CommonMessageKeys, int>();
@@ -124,22 +126,22 @@ public static void Warn(string message)
124126
Log(LogLevels.Warn, message);
125127
}
126128

127-
public static void Error(string message)
129+
public static void Error(string message, bool forcePause = false)
128130
{
129-
Log(LogLevels.Error, message);
131+
Log(LogLevels.Error, message, forcePause);
130132
}
131133

132-
public static void Fatal(string message)
134+
public static void Fatal(string message, bool forcePause = false)
133135
{
134-
Log(LogLevels.Fatal, message);
136+
Log(LogLevels.Fatal, message, forcePause);
135137
}
136138

137-
public static void Fatal(Exception exception)
139+
public static void Fatal(Exception exception, bool forcePause = false)
138140
{
139-
Log(LogLevels.Fatal, exception.Message);
141+
Log(LogLevels.Fatal, exception.Message, forcePause);
140142
}
141143

142-
public static void Log(LogLevels level, string message)
144+
public static void Log(LogLevels level, string message, bool forcePause = false)
143145
{
144146
#if VRTK_NO_LOGGING
145147
return;
@@ -163,6 +165,11 @@ public static void Log(LogLevels level, string message)
163165
break;
164166
case LogLevels.Error:
165167
case LogLevels.Fatal:
168+
if (forcePause)
169+
{
170+
UnityEngine.Debug.Break();
171+
}
172+
166173
if (instance.throwExceptions)
167174
{
168175
throw new Exception(message);

Assets/VRTK/Source/Scripts/Utilities/SDK/VRTK_SDKSetup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ private static string GetSDKErrorDescription<BaseType>(string prettyName, VRTK_S
493493

494494
if (installedInfos.Select(installedInfo => installedInfo.type).Contains(selectedType))
495495
{
496-
return description + " Its needed scripting define symbols are not added. You can click the GameObject with the `VRTK_SDKManager` script attached to it in Edit Mode and choose to automatically let the manager handle the scripting define symbols.";
496+
return description + " Its needed scripting define symbols are not added. You can click the GameObject with the `VRTK_SDKManager` script attached to it in Edit Mode and choose to automatically let the manager handle the scripting define symbols." + VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.SCRIPTING_DEFINE_SYMBOLS_NOT_FOUND);
497497
}
498498

499499
return description + " The needed vendor SDK isn't installed.";

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ see if your query has already been answered.
4545
* Open the folder in Unity to load the project.
4646
* Have a look at the included example scenes.
4747

48+
**Important Note**
49+
50+
> The example scenes no longer contain the `VRTK_SDKManager` as this is loaded in at runtime via the `VRTK_SDKManager_Constructor` scene. As the `VRTK_SDKManager` script is responsible for setting up the required Unity Scripting Define Symbols for installed SDKs it is required that the `VRTK_SDKManager_Constructor` scene is opened in the Unity Editor when first using the project or when installing a new supported SDK so it can set up the scripting define symbols. The example scenes will not work until the scripting define symbols have been set up correctly so please ensure that the `VRTK_SDKManager_Constructor` scene is loaded into the Unity Editor first.
51+
4852
The example scenes support all the VRTK supported VR SDKs. To make use
4953
of VR devices (besides the included VR Simulator) import the needed
5054
third party VR SDK into the project.

0 commit comments

Comments
 (0)