-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnsureBulletinDefineExists.cs
More file actions
60 lines (49 loc) · 1.88 KB
/
EnsureBulletinDefineExists.cs
File metadata and controls
60 lines (49 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#if UNITY_EDITOR
using System;
using System.Linq;
using UnityEditor;
#pragma warning disable IDE0130
namespace UnityBulletin
{
/// <summary>
/// Ensures that the Bulletin scripting define symbol exists in the project.
/// This is just so that you can conditionally enable/disable code related to Bulletin in other libraries with #if BULLETIN.
/// </summary>
internal static class EnsureBulletinDefineExists
{
private static readonly string[] DEFINES = new string[] { "BULLETIN" };
[InitializeOnLoadMethod]
private static void EnsureScriptingDefineSymbol()
{
var currentTarget = EditorUserBuildSettings.selectedBuildTargetGroup;
if (currentTarget == BuildTargetGroup.Unknown)
{
return;
}
#pragma warning disable CS0618 // PlayerSettings.GetScriptingDefineSymbolsForGroup is obsolete
var definesString = PlayerSettings.GetScriptingDefineSymbolsForGroup(currentTarget).Trim();
#pragma warning restore CS0618
var defines = definesString.Split(';');
bool changed = false;
foreach (var define in DEFINES)
{
if (defines.Contains(define) == false)
{
if (definesString.EndsWith(";", StringComparison.InvariantCulture) == false)
{
definesString += ";";
}
definesString += define;
changed = true;
}
}
if (changed)
{
#pragma warning disable CS0618 // PlayerSettings.SetScriptingDefineSymbolsForGroup is obsolete
PlayerSettings.SetScriptingDefineSymbolsForGroup(currentTarget, definesString);
#pragma warning restore CS0618
}
}
}
}
#endif