This repository was archived by the owner on Nov 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 741
Expand file tree
/
Copy pathDefineSetter.cs
More file actions
57 lines (48 loc) · 1.69 KB
/
DefineSetter.cs
File metadata and controls
57 lines (48 loc) · 1.69 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
using System;
using System.Linq;
#if UNITY_2021_3_OR_NEWER
using UnityEditor.Build;
#endif
namespace UnityEditor.Rendering.PostProcessing
{
[InitializeOnLoad]
sealed class DefineSetter
{
const string k_Define = "UNITY_POST_PROCESSING_STACK_V2";
static DefineSetter()
{
var targets = Enum.GetValues(typeof(BuildTargetGroup))
.Cast<BuildTargetGroup>()
.Where(x => x != BuildTargetGroup.Unknown)
.Where(x => !IsObsolete(x));
foreach (var target in targets)
{
#if UNITY_2021_3_OR_NEWER
var namedTarget = NamedBuildTarget.FromBuildTargetGroup(target);
var defines = PlayerSettings.GetScriptingDefineSymbols(namedTarget).Trim();
#else
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(target).Trim();
#endif
var list = defines.Split(';', ' ')
.Where(x => !string.IsNullOrEmpty(x))
.ToList();
if (list.Contains(k_Define))
continue;
list.Add(k_Define);
defines = list.Aggregate((a, b) => a + ";" + b);
#if UNITY_2021_3_OR_NEWER
PlayerSettings.SetScriptingDefineSymbols(namedTarget, defines);
#else
PlayerSettings.SetScriptingDefineSymbolsForGroup(target, defines);
#endif
}
}
static bool IsObsolete(BuildTargetGroup group)
{
var attrs = typeof(BuildTargetGroup)
.GetField(group.ToString())
.GetCustomAttributes(typeof(ObsoleteAttribute), false);
return attrs != null && attrs.Length > 0;
}
}
}