From f049177e20a276049c61edbad631c1b2bbdd5706 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 15 Oct 2020 19:05:22 +0800 Subject: -advanced inspector +odin --- .../Scripts/Editor/EnsureOdinInspectorDefine.cs | 121 +++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 Assets/Plugins/Sirenix/Odin Inspector/Scripts/Editor/EnsureOdinInspectorDefine.cs (limited to 'Assets/Plugins/Sirenix/Odin Inspector/Scripts/Editor/EnsureOdinInspectorDefine.cs') diff --git a/Assets/Plugins/Sirenix/Odin Inspector/Scripts/Editor/EnsureOdinInspectorDefine.cs b/Assets/Plugins/Sirenix/Odin Inspector/Scripts/Editor/EnsureOdinInspectorDefine.cs new file mode 100644 index 00000000..be82f389 --- /dev/null +++ b/Assets/Plugins/Sirenix/Odin Inspector/Scripts/Editor/EnsureOdinInspectorDefine.cs @@ -0,0 +1,121 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) Sirenix IVS. All rights reserved. +// +//----------------------------------------------------------------------- + +#if UNITY_EDITOR + +namespace Sirenix.Utilities +{ + using System; + using System.Linq; + using UnityEditor; + + /// + /// Defines the ODIN_INSPECTOR symbol. + /// + internal static class EnsureOdinInspectorDefine + { + private static readonly string[] DEFINES = new string[] { "ODIN_INSPECTOR", "ODIN_INSPECTOR_3" }; + + [InitializeOnLoadMethod] + private static void EnsureScriptingDefineSymbol() + { + var currentTarget = EditorUserBuildSettings.selectedBuildTargetGroup; + + if (currentTarget == BuildTargetGroup.Unknown) + { + return; + } + + var definesString = PlayerSettings.GetScriptingDefineSymbolsForGroup(currentTarget).Trim(); + 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) + { + PlayerSettings.SetScriptingDefineSymbolsForGroup(currentTarget, definesString); + } + } + } + + // + // If you have a project where only some users have Odin, and you want to utilize the ODIN_INSPECTOR + // define symbol. Then, in order to only define the symbol for those with Odin, you can delete this script, + // which prevent ODIN_INSPECTOR from being added to the Unity's player settings. + // + // And instead automatically add the ODIN_INSPECTOR define to an mcs.rsp file if Odin exists using the script below. + // You can then ignore the mcs.rsp file in source control. + // + // Remember to manually remove the ODIN_INSPECTOR define symbol in player settings after removing this script. + // + // static class AddOdinInspectorDefineIfOdinExist + // { + // private const string ODIN_MCS_DEFINE = "-define:ODIN_INSPECTOR"; + // + // [InitializeOnLoadMethod] + // private static void AddOrRemoveOdinDefine() + // { + // var addDefine = AppDomain.CurrentDomain.GetAssemblies().Any(x => x.FullName.StartsWith("Sirenix.OdinInspector.Editor")); + // + // #if ODIN_INSPECTOR + // var hasDefine = true; + // #else + // var hasDefine = false; + // #endif + // + // if (addDefine == hasDefine) + // { + // return; + // } + // + // var mcsPath = Path.Combine(Application.dataPath, "mcs.rsp"); + // var hasMcsFile = File.Exists(mcsPath); + // + // if (addDefine) + // { + // var lines = hasMcsFile ? File.ReadAllLines(mcsPath).ToList() : new List(); + // if (!lines.Any(x => x.Trim() == ODIN_MCS_DEFINE)) + // { + // lines.Add(ODIN_MCS_DEFINE); + // File.WriteAllLines(mcsPath, lines.ToArray()); + // AssetDatabase.Refresh(); + // } + // } + // else if (hasMcsFile) + // { + // var linesWithoutOdinDefine = File.ReadAllLines(mcsPath).Where(x => x.Trim() != ODIN_MCS_DEFINE).ToArray(); + // + // if (linesWithoutOdinDefine.Length == 0) + // { + // // Optional - Remove the mcs file instead if it doesn't contain any lines. + // File.Delete(mcsPath); + // } + // else + // { + // File.WriteAllLines(mcsPath, linesWithoutOdinDefine); + // } + // + // AssetDatabase.Refresh(); + // } + // } + // } +} + +#endif // UNITY_EDITOR \ No newline at end of file -- cgit v1.1-26-g67d0