#if UNITY_EDITOR using System.Collections.Generic; using System.Linq; using UnityEditor; namespace NobleConnect { /// /// Adds the given define symbols to PlayerSettings define symbols. /// Just add your own define symbols to the Symbols property at the below. /// [InitializeOnLoad] public class AddNobleConnectScriptingDefine : Editor { /// /// Symbols that will be added to the editor /// public static readonly string[] Symbols = new string[] { "NOBLE_CONNECT", // Noble Connect exists "NOBLE_CONNECT_1", // Major version "NOBLE_CONNECT_1_37" // Major and minor version }; /// /// Add define symbols as soon as Unity gets done compiling. /// static AddNobleConnectScriptingDefine() { // Get the current scripting defines string definesString = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup); // Convert the string to a list List allDefines = definesString.Split(';').ToList(); // Remove any old version defines from previous installs for (int i = allDefines.Count-1; i >= 0; i--) { if (allDefines[i].StartsWith("NOBLE_CONNECT") && !Symbols.Contains(allDefines[i])) { allDefines.RemoveAt(i); } } // Add any symbols that weren't already in the list allDefines.AddRange(Symbols.Except(allDefines)); PlayerSettings.SetScriptingDefineSymbolsForGroup( EditorUserBuildSettings.selectedBuildTargetGroup, string.Join(";", allDefines.ToArray()) ); } } } #endif