Skip to content

Commit a7a0ba1

Browse files
committed
Errors fixed and symbols checking improved
1 parent 68294f9 commit a7a0ba1

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
{
2-
"name": "Unity.DebugModeDefineSymbol.Editor"
3-
}
2+
"name": "Unity.DebugModeDefineSymbol.Editor",
3+
"rootNamespace": "",
4+
"references": [],
5+
"includePlatforms": [
6+
"Editor"
7+
],
8+
"excludePlatforms": [],
9+
"allowUnsafeCode": false,
10+
"overrideReferences": false,
11+
"precompiledReferences": [],
12+
"autoReferenced": true,
13+
"defineConstraints": [],
14+
"versionDefines": [],
15+
"noEngineReferences": false
16+
}

Editor/UnityDebugModeDefineSymbol.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ namespace UnityDebugModeDefineSymbol.Editor
66
{
77
internal static class DebugModeDefineSymbol
88
{
9-
private static bool _debugIsOn;
109
private const string debugModeSymbol = "DEBUG_MODE_IN_USE";
1110

1211

1312
[MenuItem("Tools/Debug Mode Definition/On")]
1413
internal static void TurnOnDebugModeDefinition()
1514
{
16-
_debugIsOn = GetState();
17-
if (_debugIsOn)
15+
if (DefineDebugModeActivity())
1816
{
1917
EditorUtility.DisplayDialog("Debug mode definition is turned On",
2018
"DEBUG_MODE_IN_USE is already included in the scripting define symbols", "OK");
@@ -24,17 +22,15 @@ internal static void TurnOnDebugModeDefinition()
2422
if (EditorUtility.DisplayDialog("Turn on the debug mode definition?",
2523
"If the debug mode enabled, all the code in the definition 'DEBUG_MODE_IN_USE' will be executed", "Yes", "No"))
2624
{
27-
_debugIsOn = true;
2825
PlayerPrefs.SetInt("debugModeInUseKey", 1);
29-
DefineSymbols();
26+
DefineSymbols(true);
3027
}
3128
}
3229
}
3330
[MenuItem("Tools/Debug Mode Definition/Off")]
3431
internal static void TurnOffDebugModeDefinition()
3532
{
36-
_debugIsOn = GetState();
37-
if (!_debugIsOn)
33+
if (!DefineDebugModeActivity())
3834
{
3935
EditorUtility.DisplayDialog("Debug mode definition is already turned off",
4036
"The code in the 'DEBUG_MODE_IN_USE' definition is not executed", "OK");
@@ -44,23 +40,30 @@ internal static void TurnOffDebugModeDefinition()
4440
if (EditorUtility.DisplayDialog("Turn off the debug mode definition?",
4541
"The code in the 'DEBUG_MODE_IN_USE' definition will not be execute", "Yes", "No"))
4642
{
47-
_debugIsOn = false;
4843
PlayerPrefs.SetInt("debugModeInUseKey", 0);
49-
DefineSymbols();
44+
DefineSymbols(false);
5045
}
5146
}
5247
}
5348

54-
private static bool GetState() => PlayerPrefs.GetInt("debugModeInUseKey", 0) == 1;
49+
private static bool DefineDebugModeActivity()
50+
{
51+
BuildTargetGroup currentTarget = EditorUserBuildSettings.selectedBuildTargetGroup;
52+
53+
List<string> scriptingSymbols =
54+
new List<string>(PlayerSettings.GetScriptingDefineSymbolsForGroup(currentTarget).Split(';'));
55+
56+
return scriptingSymbols.Contains(debugModeSymbol);
57+
}
5558

56-
private static void DefineSymbols()
59+
private static void DefineSymbols(bool state)
5760
{
5861
BuildTargetGroup currentTarget = EditorUserBuildSettings.selectedBuildTargetGroup;
5962

6063
List<string> scriptingSymbols =
6164
new List<string>(PlayerSettings.GetScriptingDefineSymbolsForGroup(currentTarget).Split(';'));
6265

63-
if (_debugIsOn)
66+
if (state)
6467
{
6568
if (!scriptingSymbols.Contains(debugModeSymbol)) scriptingSymbols.Add(debugModeSymbol);
6669
else return;

0 commit comments

Comments
 (0)