92 lines
3.1 KiB
C#
92 lines
3.1 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 宏定义开关窗口
|
|
/// </summary>
|
|
public class MacroEditorWindow : EditorWindow
|
|
{
|
|
/// <summary>
|
|
/// 强制流程宏
|
|
/// </summary>
|
|
private const string MACRO_FIRST_TIME_FLOW = "FIRST_TIME_FLOW";
|
|
/// <summary>
|
|
/// 新手引导宏
|
|
/// </summary>
|
|
private const string MACRO_GUIDE = "GUIDE";
|
|
/// <summary>
|
|
/// 功能锁宏
|
|
/// </summary>
|
|
private const string MACRO_FUNCTION_LOCK = "FUNCTION_LOCK";
|
|
|
|
/// <summary>
|
|
/// 是否启用强制流程
|
|
/// </summary>
|
|
private bool isEnableFirstTimeFlow;
|
|
/// <summary>
|
|
/// 是否启用新手引导
|
|
/// </summary>
|
|
private bool isEnableGuide;
|
|
/// <summary>
|
|
/// 是否启用功能锁
|
|
/// </summary>
|
|
private bool isEnableFunctionLock;
|
|
|
|
[MenuItem("Tools/*(宏定义)功能开关")]
|
|
private static void ShowWindow()
|
|
{
|
|
MacroEditorWindow window = (MacroEditorWindow)GetWindow(typeof(MacroEditorWindow), true, "(宏定义)功能开关");
|
|
window.Show();
|
|
window.Focus();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
BuildTargetGroup currentTargetGroup = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget);
|
|
string currentDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(currentTargetGroup);
|
|
isEnableFirstTimeFlow = currentDefines.Contains(MACRO_FIRST_TIME_FLOW);
|
|
isEnableGuide = currentDefines.Contains(MACRO_GUIDE);
|
|
isEnableFunctionLock = currentDefines.Contains(MACRO_FUNCTION_LOCK);
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
|
|
isEnableFirstTimeFlow = EditorGUILayout.Toggle("强制流程", isEnableFirstTimeFlow);
|
|
|
|
isEnableGuide = EditorGUILayout.Toggle("新手引导(开引导默认开强制流程)", isEnableGuide);
|
|
if (isEnableGuide)
|
|
isEnableFirstTimeFlow = true;
|
|
|
|
isEnableFunctionLock = EditorGUILayout.Toggle("功能锁", isEnableFunctionLock);
|
|
|
|
if (GUILayout.Button("确定"))
|
|
{
|
|
BuildTargetGroup currentTargetGroup = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget);
|
|
SetDefineSymbols(currentTargetGroup, MACRO_FIRST_TIME_FLOW, isEnableFirstTimeFlow);
|
|
SetDefineSymbols(currentTargetGroup, MACRO_GUIDE, isEnableGuide);
|
|
SetDefineSymbols(currentTargetGroup, MACRO_FUNCTION_LOCK, isEnableFunctionLock);
|
|
Close();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置宏定义列表
|
|
/// </summary>
|
|
/// <param name="buildTargetGroup"></param>
|
|
/// <param name="define"></param>
|
|
/// <param name="enable"></param>
|
|
private static void SetDefineSymbols(BuildTargetGroup buildTargetGroup, string define, bool enable)
|
|
{
|
|
string currentDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup);//获取目标平台下的宏命令
|
|
if (enable)
|
|
{
|
|
if (!currentDefines.Contains(define))
|
|
currentDefines += $";{define}";
|
|
}
|
|
else
|
|
currentDefines = currentDefines.Replace(define, string.Empty);
|
|
|
|
PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, currentDefines);
|
|
}
|
|
} |