DCS/ruiyiweiUX/Assets/Scripts/Configuration/CrossPlatformInitializer.cs

241 lines
7.8 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// using UnityEngine;
// /// <summary>
// /// 跨平台系统初始化器
// /// 在应用启动时初始化各平台特定功能
// /// </summary>
// public class CrossPlatformInitializer : MonoBehaviour
// {
// [Header("初始化设置")]
// [Tooltip("是否在启动时自动初始化")]
// public bool InitializeOnStart = true;
// [Tooltip("是否显示详细日志")]
// public bool VerboseLogging = true;
// void Start()
// {
// if (InitializeOnStart)
// {
// InitializePlatform();
// }
// }
// /// <summary>
// /// 初始化当前平台的功能
// /// </summary>
// public void InitializePlatform()
// {
// if (VerboseLogging)
// {
// Debug.Log("=== 跨平台系统初始化 ===");
// Debug.Log($"当前平台: {Application.platform}");
// Debug.Log($"Unity版本: {Application.unityVersion}");
// Debug.Log($"设备型号: {SystemInfo.deviceModel}");
// }
// // 初始化平台特定功能
// #if UNITY_ANDROID && !UNITY_EDITOR
// InitializeAndroid();
// #elif UNITY_STANDALONE_WIN && !UNITY_EDITOR
// InitializeWindows();
// #else
// InitializeEditor();
// #endif
// // 初始化网络功能
// InitializeNetworking();
// if (VerboseLogging)
// {
// Debug.Log("=== 跨平台系统初始化完成 ===");
// }
// }
// #if UNITY_ANDROID && !UNITY_EDITOR
// /// <summary>
// /// 初始化Android平台功能
// /// </summary>
// private void InitializeAndroid()
// {
// Debug.Log("初始化Android平台功能...");
// // 初始化Android权限管理
// AndroidPermissionManager.InitializePermissions();
// // 检查并请求必要权限
// CheckAndRequestPermissions();
// // 初始化Android特定的系统控制
// Debug.Log("Android系统控制器已就绪");
// // 显示设备信息
// Debug.Log($"Android版本: {SystemInfo.operatingSystem}");
// Debug.Log($"处理器: {SystemInfo.processorType}");
// Debug.Log($"内存: {SystemInfo.systemMemorySize}MB");
// }
// private void CheckAndRequestPermissions()
// {
// // 检查网络权限
// if (!AndroidPermissionManager.HasNetworkStatePermission())
// {
// Debug.LogWarning("缺少网络状态权限");
// }
// if (!AndroidPermissionManager.HasWifiStatePermission())
// {
// Debug.LogWarning("缺少WiFi状态权限");
// }
// // 检查系统设置权限
// if (!AndroidPermissionManager.HasWriteSettingsPermission())
// {
// Debug.LogWarning("缺少写入设置权限,亮度控制可能无法工作");
// // 可以选择在这里请求权限
// // AndroidPermissionManager.RequestWriteSettingsPermission();
// }
// }
// #elif UNITY_STANDALONE_WIN && !UNITY_EDITOR
// /// <summary>
// /// 初始化Windows平台功能
// /// </summary>
// private void InitializeWindows()
// {
// Debug.Log("初始化Windows平台功能...");
// // Windows平台通常不需要特殊的初始化
// Debug.Log("Windows系统控制器已就绪");
// // 显示系统信息
// Debug.Log($"Windows版本: {SystemInfo.operatingSystem}");
// Debug.Log($"处理器: {SystemInfo.processorType}");
// Debug.Log($"内存: {SystemInfo.systemMemorySize}MB");
// Debug.Log($"显卡: {SystemInfo.graphicsDeviceName}");
// }
// #else
// /// <summary>
// /// 初始化编辑器或其他平台
// /// </summary>
// private void InitializeEditor()
// {
// Debug.Log("初始化编辑器/其他平台功能...");
// Debug.Log("使用模拟功能进行开发调试");
// }
// #endif
// /// <summary>
// /// 初始化网络功能
// /// </summary>
// private void InitializeNetworking()
// {
// try
// {
// #if UNITY_ANDROID && !UNITY_EDITOR
// // Android平台跳过网络状态检查避免Unity底层网络错误
// Debug.Log("网络状态检查已跳过 (Android平台避免网络错误)");
// string networkStatus = "配置模式 (跳过网络检查)";
// string localIP = "配置中";
// #else
// // 其他平台:保留网络状态检查
// var reachability = Application.internetReachability;
// string networkStatus = reachability switch
// {
// NetworkReachability.NotReachable => "无网络连接",
// NetworkReachability.ReachableViaCarrierDataNetwork => "移动数据网络",
// NetworkReachability.ReachableViaLocalAreaNetwork => "WiFi/以太网",
// _ => "未知网络"
// };
// Debug.Log($"网络状态: {networkStatus}");
// // 获取本地IP
// string localIP = "未知";
// #endif
// #if !UNITY_EDITOR
// try
// {
// localIP = CrossPlatformNetworkManager.GetLocalIPAddress();
// }
// catch (System.Exception ex)
// {
// Debug.LogWarning($"获取本地IP失败: {ex.Message}");
// }
// #endif
// Debug.Log($"本地IP: {localIP}");
// }
// catch (System.Exception ex)
// {
// Debug.LogError($"网络初始化失败: {ex.Message}");
// }
// }
// /// <summary>
// /// 测试系统功能
// /// </summary>
// [ContextMenu("测试系统功能")]
// public void TestSystemFunctions()
// {
// Debug.Log("=== 系统功能测试 ===");
// // 测试音量控制
// Debug.Log("测试音量控制...");
// #if !UNITY_EDITOR
// try
// {
// WindowsSystemController.SystemVolumeUp();
// System.Threading.Thread.Sleep(500);
// WindowsSystemController.SystemVolumeDown();
// }
// catch (System.Exception ex)
// {
// Debug.LogError($"音量控制测试失败: {ex.Message}");
// }
// #endif
// // 测试亮度控制
// Debug.Log("测试亮度控制...");
// #if !UNITY_EDITOR
// try
// {
// WindowsSystemController.SetMonitorBrightness(80);
// }
// catch (System.Exception ex)
// {
// Debug.LogError($"亮度控制测试失败: {ex.Message}");
// }
// #endif
// // 测试网络功能
// Debug.Log("测试网络功能...");
// #if !UNITY_EDITOR
// try
// {
// string ip = CrossPlatformNetworkManager.GetLocalIPAddress();
// string networkType = CrossPlatformNetworkManager.GetNetworkTypeDescription();
// Debug.Log($"IP: {ip}, 网络类型: {networkType}");
// }
// catch (System.Exception ex)
// {
// Debug.LogError($"网络功能测试失败: {ex.Message}");
// }
// #endif
// Debug.Log("=== 系统功能测试完成 ===");
// }
// }
// /// <summary>
// /// 启动时自动初始化的属性
// /// 在场景加载时自动创建CrossPlatformInitializer
// /// </summary>
// [System.AttributeUsage(System.AttributeTargets.Class)]
// public class AutoInitializeAttribute : System.Attribute
// {
// public bool CreateOnStart { get; set; } = true;
// }