247 lines
11 KiB
C#
247 lines
11 KiB
C#
|
|
// using UnityEngine;
|
|||
|
|
// using UnityEditor;
|
|||
|
|
// using System.IO;
|
|||
|
|
|
|||
|
|
// /// <summary>
|
|||
|
|
// /// 跨平台功能管理编辑器工具
|
|||
|
|
// /// 用于启用/禁用跨平台系统控制功能
|
|||
|
|
// /// </summary>
|
|||
|
|
// public class CrossPlatformManagerEditor : EditorWindow
|
|||
|
|
// {
|
|||
|
|
// private static readonly string[] TEMPORARY_MARKERS = {
|
|||
|
|
// "// TODO: 等待Unity编译新类后启用",
|
|||
|
|
// "// 临时修复"
|
|||
|
|
// };
|
|||
|
|
|
|||
|
|
// private static readonly string[] FILES_TO_CHECK = {
|
|||
|
|
// "Assets/Scripts/Services/SystemSettingsService.cs",
|
|||
|
|
// "Assets/Scripts/Views/NetworkSettingPanel.cs"
|
|||
|
|
// };
|
|||
|
|
|
|||
|
|
// private bool showDebugInfo = false;
|
|||
|
|
// private Vector2 scrollPosition;
|
|||
|
|
|
|||
|
|
// [MenuItem("DCS/跨平台功能管理")]
|
|||
|
|
// public static void ShowWindow()
|
|||
|
|
// {
|
|||
|
|
// GetWindow<CrossPlatformManagerEditor>("跨平台功能管理");
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// void OnGUI()
|
|||
|
|
// {
|
|||
|
|
// GUILayout.Label("跨平台系统控制功能管理", EditorStyles.boldLabel);
|
|||
|
|
// EditorGUILayout.Space();
|
|||
|
|
|
|||
|
|
// EditorGUILayout.HelpBox(
|
|||
|
|
// "这个工具帮助你启用或禁用跨平台系统控制功能。" +
|
|||
|
|
// "如果Unity已经成功编译了新的跨平台类,可以点击'启用真实系统控制'来激活功能。",
|
|||
|
|
// MessageType.Info);
|
|||
|
|
|
|||
|
|
// EditorGUILayout.Space();
|
|||
|
|
|
|||
|
|
// // 检查新类是否可用
|
|||
|
|
// bool hasWindowsController = HasClass("WindowsSystemController");
|
|||
|
|
// bool hasNetworkManager = HasClass("CrossPlatformNetworkManager");
|
|||
|
|
// bool hasPermissionManager = HasClass("AndroidPermissionManager");
|
|||
|
|
// bool hasTimeManager = HasClass("TimeSettingsPermissionManager");
|
|||
|
|
|
|||
|
|
// EditorGUILayout.BeginHorizontal();
|
|||
|
|
// EditorGUILayout.LabelField("WindowsSystemController:", hasWindowsController ? "✓ 可用" : "✗ 不可用");
|
|||
|
|
// EditorGUILayout.EndHorizontal();
|
|||
|
|
|
|||
|
|
// EditorGUILayout.BeginHorizontal();
|
|||
|
|
// EditorGUILayout.LabelField("CrossPlatformNetworkManager:", hasNetworkManager ? "✓ 可用" : "✗ 不可用");
|
|||
|
|
// EditorGUILayout.EndHorizontal();
|
|||
|
|
|
|||
|
|
// EditorGUILayout.BeginHorizontal();
|
|||
|
|
// EditorGUILayout.LabelField("AndroidPermissionManager:", hasPermissionManager ? "✓ 可用" : "✗ 不可用");
|
|||
|
|
// EditorGUILayout.EndHorizontal();
|
|||
|
|
|
|||
|
|
// EditorGUILayout.BeginHorizontal();
|
|||
|
|
// EditorGUILayout.LabelField("TimeSettingsPermissionManager:", hasTimeManager ? "✓ 可用" : "✗ 不可用");
|
|||
|
|
// EditorGUILayout.EndHorizontal();
|
|||
|
|
|
|||
|
|
// EditorGUILayout.Space();
|
|||
|
|
|
|||
|
|
// bool allClassesAvailable = hasWindowsController && hasNetworkManager && hasPermissionManager && hasTimeManager;
|
|||
|
|
|
|||
|
|
// GUI.enabled = allClassesAvailable;
|
|||
|
|
// if (GUILayout.Button("启用真实系统控制", GUILayout.Height(30)))
|
|||
|
|
// {
|
|||
|
|
// EnableRealSystemControl();
|
|||
|
|
// }
|
|||
|
|
// GUI.enabled = true;
|
|||
|
|
|
|||
|
|
// if (!allClassesAvailable)
|
|||
|
|
// {
|
|||
|
|
// EditorGUILayout.HelpBox("部分跨平台类不可用。请确保Unity已完成编译。", MessageType.Warning);
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// EditorGUILayout.Space();
|
|||
|
|
|
|||
|
|
// if (GUILayout.Button("恢复临时修复(禁用系统控制)", GUILayout.Height(25)))
|
|||
|
|
// {
|
|||
|
|
// DisableRealSystemControl();
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// EditorGUILayout.Space();
|
|||
|
|
|
|||
|
|
// showDebugInfo = EditorGUILayout.Foldout(showDebugInfo, "调试信息");
|
|||
|
|
// if (showDebugInfo)
|
|||
|
|
// {
|
|||
|
|
// scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUILayout.Height(200));
|
|||
|
|
// ShowDebugInfo();
|
|||
|
|
// EditorGUILayout.EndScrollView();
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// EditorGUILayout.Space();
|
|||
|
|
|
|||
|
|
// if (GUILayout.Button("刷新Unity资产"))
|
|||
|
|
// {
|
|||
|
|
// AssetDatabase.Refresh();
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// private bool HasClass(string className)
|
|||
|
|
// {
|
|||
|
|
// var type = System.Type.GetType(className);
|
|||
|
|
// return type != null;
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// private void EnableRealSystemControl()
|
|||
|
|
// {
|
|||
|
|
// int filesModified = 0;
|
|||
|
|
|
|||
|
|
// foreach (string filePath in FILES_TO_CHECK)
|
|||
|
|
// {
|
|||
|
|
// if (File.Exists(filePath))
|
|||
|
|
// {
|
|||
|
|
// string content = File.ReadAllText(filePath);
|
|||
|
|
// string originalContent = content;
|
|||
|
|
|
|||
|
|
// // 启用WindowsSystemController调用
|
|||
|
|
// content = content.Replace(
|
|||
|
|
// "// bool success = WindowsSystemController.SetMonitorBrightness(brightnessInt);",
|
|||
|
|
// "bool success = WindowsSystemController.SetMonitorBrightness(brightnessInt);"
|
|||
|
|
// );
|
|||
|
|
// content = content.Replace(
|
|||
|
|
// "// bool success = WindowsSystemController.SetSystemVolume(volume);",
|
|||
|
|
// "bool success = WindowsSystemController.SetSystemVolume(volume);"
|
|||
|
|
// );
|
|||
|
|
|
|||
|
|
// // 启用CrossPlatformNetworkManager调用
|
|||
|
|
// content = content.Replace(
|
|||
|
|
// "// NetworkReachability reachability = CrossPlatformNetworkManager.GetNetworkReachability();",
|
|||
|
|
// "NetworkReachability reachability = CrossPlatformNetworkManager.GetNetworkReachability();"
|
|||
|
|
// );
|
|||
|
|
// content = content.Replace(
|
|||
|
|
// "// string networkType = CrossPlatformNetworkManager.GetNetworkTypeDescription();",
|
|||
|
|
// "string networkType = CrossPlatformNetworkManager.GetNetworkTypeDescription();"
|
|||
|
|
// );
|
|||
|
|
// content = content.Replace(
|
|||
|
|
// "// string currentIP = CrossPlatformNetworkManager.GetLocalIPAddress();",
|
|||
|
|
// "string currentIP = CrossPlatformNetworkManager.GetLocalIPAddress();"
|
|||
|
|
// );
|
|||
|
|
// content = content.Replace(
|
|||
|
|
// "// bool hasInternet = CrossPlatformNetworkManager.HasInternetConnection();",
|
|||
|
|
// "bool hasInternet = CrossPlatformNetworkManager.HasInternetConnection();"
|
|||
|
|
// );
|
|||
|
|
|
|||
|
|
// // 启用TimeSettingsPermissionManager调用
|
|||
|
|
// content = content.Replace(
|
|||
|
|
// "// if (!TimeSettingsPermissionManager.HasTimeSettingsPermission())",
|
|||
|
|
// "if (!TimeSettingsPermissionManager.HasTimeSettingsPermission())"
|
|||
|
|
// );
|
|||
|
|
// content = content.Replace(
|
|||
|
|
// "// \t\tDebug.LogWarning($\"缺少时间设置权限: {TimeSettingsPermissionManager.GetTimeSettingsLimitations()}\");",
|
|||
|
|
// "\t\tDebug.LogWarning($\"缺少时间设置权限: {TimeSettingsPermissionManager.GetTimeSettingsLimitations()}\");"
|
|||
|
|
// );
|
|||
|
|
// content = content.Replace(
|
|||
|
|
// "// \t\tbool permissionResult = TimeSettingsPermissionManager.RequestTimeSettingsPermission();",
|
|||
|
|
// "\t\tbool permissionResult = TimeSettingsPermissionManager.RequestTimeSettingsPermission();"
|
|||
|
|
// );
|
|||
|
|
// content = content.Replace(
|
|||
|
|
// "// if (TimeSettingsPermissionManager.VerifyTimeSet(dateTime))",
|
|||
|
|
// "if (TimeSettingsPermissionManager.VerifyTimeSet(dateTime))"
|
|||
|
|
// );
|
|||
|
|
|
|||
|
|
// // 删除临时修复代码
|
|||
|
|
// content = System.Text.RegularExpressions.Regex.Replace(content,
|
|||
|
|
// @"bool success = true; // 临时修复",
|
|||
|
|
// "");
|
|||
|
|
// content = System.Text.RegularExpressions.Regex.Replace(content,
|
|||
|
|
// @"string currentIP = ""127\.0\.0\.1""; // 临时修复",
|
|||
|
|
// "");
|
|||
|
|
// content = System.Text.RegularExpressions.Regex.Replace(content,
|
|||
|
|
// @"string networkType = ""Unknown""; // 临时修复",
|
|||
|
|
// "");
|
|||
|
|
// content = System.Text.RegularExpressions.Regex.Replace(content,
|
|||
|
|
// @"bool hasInternet = true; // 临时修复",
|
|||
|
|
// "");
|
|||
|
|
// content = System.Text.RegularExpressions.Regex.Replace(content,
|
|||
|
|
// @"NetworkReachability reachability = Application\.internetReachability; // 临时修复",
|
|||
|
|
// "");
|
|||
|
|
// content = System.Text.RegularExpressions.Regex.Replace(content,
|
|||
|
|
// @"string networkType = reachability\.ToString\(\); // 临时修复",
|
|||
|
|
// "");
|
|||
|
|
// content = System.Text.RegularExpressions.Regex.Replace(content,
|
|||
|
|
// @"string currentIP = ""127\.0\.0\.1""; // 临时修复",
|
|||
|
|
// "");
|
|||
|
|
|
|||
|
|
// if (content != originalContent)
|
|||
|
|
// {
|
|||
|
|
// File.WriteAllText(filePath, content);
|
|||
|
|
// filesModified++;
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// AssetDatabase.Refresh();
|
|||
|
|
|
|||
|
|
// EditorUtility.DisplayDialog("启用完成",
|
|||
|
|
// $"已启用真实系统控制功能。\n修改了 {filesModified} 个文件。",
|
|||
|
|
// "确定");
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// private void DisableRealSystemControl()
|
|||
|
|
// {
|
|||
|
|
// EditorUtility.DisplayDialog("功能说明",
|
|||
|
|
// "恢复临时修复需要手动操作。\n" +
|
|||
|
|
// "如果需要禁用系统控制,请在代码中注释掉相应的调用。",
|
|||
|
|
// "知道了");
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// private void ShowDebugInfo()
|
|||
|
|
// {
|
|||
|
|
// EditorGUILayout.LabelField("系统信息:", EditorStyles.boldLabel);
|
|||
|
|
// EditorGUILayout.LabelField($"Unity版本: {Application.unityVersion}");
|
|||
|
|
// EditorGUILayout.LabelField($"平台: {Application.platform}");
|
|||
|
|
// EditorGUILayout.LabelField($"编辑器平台: {EditorUserBuildSettings.activeBuildTarget}");
|
|||
|
|
|
|||
|
|
// EditorGUILayout.Space();
|
|||
|
|
// EditorGUILayout.LabelField("文件检查:", EditorStyles.boldLabel);
|
|||
|
|
|
|||
|
|
// foreach (string filePath in FILES_TO_CHECK)
|
|||
|
|
// {
|
|||
|
|
// bool exists = File.Exists(filePath);
|
|||
|
|
// EditorGUILayout.LabelField($"{filePath}: {(exists ? "存在" : "不存在")}");
|
|||
|
|
|
|||
|
|
// if (exists)
|
|||
|
|
// {
|
|||
|
|
// string content = File.ReadAllText(filePath);
|
|||
|
|
// int todoCount = 0;
|
|||
|
|
// foreach (string marker in TEMPORARY_MARKERS)
|
|||
|
|
// {
|
|||
|
|
// todoCount += System.Text.RegularExpressions.Regex.Matches(content, marker).Count;
|
|||
|
|
// }
|
|||
|
|
// EditorGUILayout.LabelField($" 待修复标记: {todoCount}");
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// EditorGUILayout.Space();
|
|||
|
|
// EditorGUILayout.LabelField("类型检查:", EditorStyles.boldLabel);
|
|||
|
|
// EditorGUILayout.LabelField("所有跨平台类:", HasClass("WindowsSystemController") &&
|
|||
|
|
// HasClass("CrossPlatformNetworkManager") &&
|
|||
|
|
// HasClass("AndroidPermissionManager") ? "全部可用" : "部分不可用");
|
|||
|
|
// }
|
|||
|
|
// }
|