Framwork/Assets/Scripts/Base/Global.cs

57 lines
1.6 KiB
C#
Raw Normal View History

2025-06-17 09:31:12 +08:00
using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
using YooAsset;
namespace HK
{
public class Global : MonoBehaviour
{
/// <summary>
/// 资源系统运行模式
/// </summary>
public EPlayMode PlayMode = EPlayMode.EditorSimulateMode;
public string packageName = "DefaultPackage";
public string hostServerIP = "http://192.168.0.144:8080/NetworkServer/AssetsFolder/Framework";
public string sceneName = "Assets/Res/Scene/Game.unity";
private void Awake()
{
DontDestroyOnLoad(this.gameObject);
AdjustScreenResolution();
}
void Start()
{
InitAsync().Forget();
async UniTask InitAsync()
{
var initializePackage = new InitializePackage(PlayMode, packageName, hostServerIP);
await initializePackage.Start();
// 切换到主页面场景
// SceneEventDefine.ChangeToHomeScene.SendEventMessage();
// YooAssets.LoadSceneSync(SceneName);
YooAssets.LoadSceneSync(sceneName);
}
}
private void AdjustScreenResolution()
{
float w = Screen.currentResolution.width;
float h = Screen.currentResolution.height;
if (w * 16 > h * 9)
{
Screen.SetResolution((int)(h * (float)((float)9 / 16)), (int)h, true);
}
else
{
Screen.SetResolution((int)w, (int)(w * (float)((float)16 / 9)), true);
}
//#endif
}
}
}