mirror of
https://github.com/DCFApixels/Unity-DebugX.git
synced 2025-09-18 01:54:37 +08:00
update define symbols
This commit is contained in:
parent
e23e157285
commit
d0ac5a165e
@ -1,6 +1,5 @@
|
|||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEditor.Build;
|
|
||||||
using UnityEditor.Compilation;
|
using UnityEditor.Compilation;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -13,22 +12,24 @@ namespace DCFApixels.DebugXCore.Internal
|
|||||||
{
|
{
|
||||||
DebugXSettings window = (DebugXSettings)EditorWindow.GetWindow(typeof(DebugXSettings));
|
DebugXSettings window = (DebugXSettings)EditorWindow.GetWindow(typeof(DebugXSettings));
|
||||||
window.Show();
|
window.Show();
|
||||||
window._isHasDisableDebugXInBuildSymbols = null;
|
//window._isHasDisableDebugXInBuildSymbols = null;
|
||||||
CompilationPipeline.compilationFinished -= CompilationPipeline_compilationFinished;
|
CompilationPipeline.compilationFinished -= CompilationPipeline_compilationFinished;
|
||||||
CompilationPipeline.compilationFinished += CompilationPipeline_compilationFinished;
|
CompilationPipeline.compilationFinished += CompilationPipeline_compilationFinished;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CompilationPipeline_compilationFinished(object obj)
|
private static void CompilationPipeline_compilationFinished(object obj)
|
||||||
{
|
{
|
||||||
_isCompilation = false;
|
//_isCompilation = false;
|
||||||
|
_defines = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool _isCompilation;
|
//private static bool _isCompilation;
|
||||||
private bool? _isHasDisableDebugXInBuildSymbols = false;
|
//private bool? _isHasDisableDebugXInBuildSymbols = false;
|
||||||
private const string DEFINE_NAME = nameof(DebugXDefines.DEBUGX_DISABLE_INBUILD);
|
//private const string DEFINE_NAME = nameof(DebugXDefines.DEBUGX_DISABLE_INBUILD);
|
||||||
|
private static (string name, bool flag)[] _defines = null;
|
||||||
private void OnGUI()
|
private void OnGUI()
|
||||||
{
|
{
|
||||||
|
|
||||||
float tmpValue;
|
float tmpValue;
|
||||||
|
|
||||||
DebugX.GlobalTimeScale = EditorGUILayout.FloatField("TimeScale", DebugX.GlobalTimeScale);
|
DebugX.GlobalTimeScale = EditorGUILayout.FloatField("TimeScale", DebugX.GlobalTimeScale);
|
||||||
@ -53,55 +54,76 @@ namespace DCFApixels.DebugXCore.Internal
|
|||||||
DebugX.GlobalColor = color;
|
DebugX.GlobalColor = color;
|
||||||
|
|
||||||
|
|
||||||
if (_isCompilation == false)
|
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||||
|
GUILayout.Label("Scripting Define Symbols", EditorStyles.helpBox);
|
||||||
|
if (_defines == null)
|
||||||
{
|
{
|
||||||
if (_isHasDisableDebugXInBuildSymbols == null)
|
_defines = DefinesUtility.LoadDefines(typeof(DebugXDefines));
|
||||||
{
|
|
||||||
BuildTargetGroup group = EditorUserBuildSettings.selectedBuildTargetGroup;
|
|
||||||
#if UNITY_6000_0_OR_NEWER
|
|
||||||
string symbolsString = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(group));
|
|
||||||
#else
|
|
||||||
string symbolsString = PlayerSettings.GetScriptingDefineSymbolsForGroup(group);
|
|
||||||
#endif
|
|
||||||
_isHasDisableDebugXInBuildSymbols = symbolsString.Contains(DEFINE_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorGUI.BeginChangeCheck();
|
|
||||||
_isHasDisableDebugXInBuildSymbols = !EditorGUILayout.ToggleLeft("Show Gizmos in Build", !_isHasDisableDebugXInBuildSymbols.Value);
|
|
||||||
|
|
||||||
if (EditorGUI.EndChangeCheck())
|
|
||||||
{
|
|
||||||
BuildTargetGroup group = EditorUserBuildSettings.selectedBuildTargetGroup;
|
|
||||||
#if UNITY_6000_0_OR_NEWER
|
|
||||||
string symbolsString = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(group));
|
|
||||||
#else
|
|
||||||
string symbolsString = PlayerSettings.GetScriptingDefineSymbolsForGroup(group);
|
|
||||||
#endif
|
|
||||||
if (symbolsString.Contains(DEFINE_NAME) == false)
|
|
||||||
{
|
|
||||||
symbolsString = symbolsString + ", " + DEFINE_NAME;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
symbolsString = symbolsString.Replace(DEFINE_NAME, "");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#if UNITY_6000_0_OR_NEWER
|
|
||||||
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(group), symbolsString);
|
|
||||||
#else
|
|
||||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(group, symbolsString);
|
|
||||||
#endif
|
|
||||||
_isCompilation = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
for (int i = 0; i < _defines.Length; i++)
|
||||||
{
|
{
|
||||||
_isHasDisableDebugXInBuildSymbols = null;
|
ref var define = ref _defines[i];
|
||||||
GUI.enabled = false;
|
define.flag = EditorGUILayout.ToggleLeft(define.name, define.flag);
|
||||||
EditorGUILayout.ToggleLeft("Show Gizmos in Build (Locked for compilation)", false);
|
|
||||||
GUI.enabled = true;
|
|
||||||
}
|
}
|
||||||
|
if (GUILayout.Button("Apply Defines"))
|
||||||
|
{
|
||||||
|
DefinesUtility.ApplyDefines(_defines);
|
||||||
|
}
|
||||||
|
GUILayout.EndVertical();
|
||||||
|
|
||||||
|
// if (_isCompilation == false)
|
||||||
|
// {
|
||||||
|
// if (_isHasDisableDebugXInBuildSymbols == null)
|
||||||
|
// {
|
||||||
|
// BuildTargetGroup group = EditorUserBuildSettings.selectedBuildTargetGroup;
|
||||||
|
//#if UNITY_6000_0_OR_NEWER
|
||||||
|
// string symbolsString = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(group));
|
||||||
|
//#else
|
||||||
|
// string symbolsString = PlayerSettings.GetScriptingDefineSymbolsForGroup(group);
|
||||||
|
//#endif
|
||||||
|
// _isHasDisableDebugXInBuildSymbols = symbolsString.Contains(DEFINE_NAME);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// EditorGUI.BeginChangeCheck();
|
||||||
|
// _isHasDisableDebugXInBuildSymbols = !EditorGUILayout.ToggleLeft("Show Gizmos in Build", !_isHasDisableDebugXInBuildSymbols.Value);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// if (EditorGUI.EndChangeCheck())
|
||||||
|
// {
|
||||||
|
// BuildTargetGroup group = EditorUserBuildSettings.selectedBuildTargetGroup;
|
||||||
|
//#if UNITY_6000_0_OR_NEWER
|
||||||
|
// string symbolsString = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(group));
|
||||||
|
//#else
|
||||||
|
// string symbolsString = PlayerSettings.GetScriptingDefineSymbolsForGroup(group);
|
||||||
|
//#endif
|
||||||
|
// if (symbolsString.Contains(DEFINE_NAME) == false)
|
||||||
|
// {
|
||||||
|
// symbolsString = symbolsString + ", " + DEFINE_NAME;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// symbolsString = symbolsString.Replace(DEFINE_NAME, "");
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//#if UNITY_6000_0_OR_NEWER
|
||||||
|
// PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(group), symbolsString);
|
||||||
|
//#else
|
||||||
|
// PlayerSettings.SetScriptingDefineSymbolsForGroup(group, symbolsString);
|
||||||
|
//#endif
|
||||||
|
// _isCompilation = true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// _isHasDisableDebugXInBuildSymbols = null;
|
||||||
|
// GUI.enabled = false;
|
||||||
|
// EditorGUILayout.ToggleLeft("Show Gizmos in Build (Locked for compilation)", false);
|
||||||
|
// GUI.enabled = true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
40
Editor/Settings/DefinesUtility.cs
Normal file
40
Editor/Settings/DefinesUtility.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEditor.Build;
|
||||||
|
|
||||||
|
namespace DCFApixels.DebugXCore.Internal
|
||||||
|
{
|
||||||
|
internal static class DefinesUtility
|
||||||
|
{
|
||||||
|
public static (string name, bool flag)[] LoadDefines(Type defineConstsType)
|
||||||
|
{
|
||||||
|
const BindingFlags REFL_FLAGS = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
|
||||||
|
var fields = defineConstsType.GetFields(REFL_FLAGS);
|
||||||
|
return fields.Where(o => o.FieldType == typeof(bool)).Select(o => (o.Name, (bool)o.GetValue(null))).ToArray();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ApplyDefines((string name, bool flag)[] defines)
|
||||||
|
{
|
||||||
|
BuildTargetGroup group = EditorUserBuildSettings.selectedBuildTargetGroup;
|
||||||
|
#if UNITY_6000_0_OR_NEWER
|
||||||
|
string symbolsString = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(group));
|
||||||
|
#else
|
||||||
|
string symbolsString = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (int i = 0; i < defines.Length; i++)
|
||||||
|
{
|
||||||
|
symbolsString = symbolsString.Replace(defines[i].name, "");
|
||||||
|
}
|
||||||
|
symbolsString += ";" + string.Join(';', defines.Where(o => o.flag).Select(o => o.name));
|
||||||
|
#if UNITY_6000_0_OR_NEWER
|
||||||
|
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(group), symbolsString);
|
||||||
|
#else
|
||||||
|
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, symbolsString);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2
Editor/Settings/DefinesUtility.cs.meta
Normal file
2
Editor/Settings/DefinesUtility.cs.meta
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 77addf06144f4214a925257238d65cb0
|
@ -48,19 +48,19 @@ namespace DCFApixels.DebugXCore
|
|||||||
public static class DebugXDefines
|
public static class DebugXDefines
|
||||||
{
|
{
|
||||||
public const bool DEBUGX_DISABLE_INBUILD =
|
public const bool DEBUGX_DISABLE_INBUILD =
|
||||||
#if DISABLE_DEBUGX_INBUILD
|
#if DEBUGX_DISABLE_INBUILD
|
||||||
true;
|
true;
|
||||||
#else
|
#else
|
||||||
false;
|
false;
|
||||||
#endif
|
#endif
|
||||||
public const bool DEBUGX_ENABLE_PHYSICS2D =
|
public const bool DEBUGX_ENABLE_PHYSICS2D =
|
||||||
#if DISABLE_DEBUGX_INBUILD
|
#if DEBUGX_ENABLE_PHYSICS2D
|
||||||
true;
|
true;
|
||||||
#else
|
#else
|
||||||
false;
|
false;
|
||||||
#endif
|
#endif
|
||||||
public const bool DEBUGX_ENABLE_PHYSICS3D =
|
public const bool DEBUGX_ENABLE_PHYSICS3D =
|
||||||
#if DISABLE_DEBUGX_INBUILD
|
#if DEBUGX_ENABLE_PHYSICS3D
|
||||||
true;
|
true;
|
||||||
#else
|
#else
|
||||||
false;
|
false;
|
||||||
|
Loading…
Reference in New Issue
Block a user