readme
This commit is contained in:
80
BITKit/Scripts/Core/BITAppForGodot.cs
Normal file
80
BITKit/Scripts/Core/BITAppForGodot.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System.Threading;
|
||||
using Godot;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using HttpClient = System.Net.Http.HttpClient;
|
||||
|
||||
namespace BITKit;
|
||||
/// <summary>
|
||||
/// 为Godot提供的BITApp加载服务
|
||||
/// </summary>
|
||||
public partial class BITAppForGodot : Node
|
||||
{
|
||||
public static readonly ValidHandle AllowCursor = new();
|
||||
|
||||
/// <summary>
|
||||
/// 在构造函数中注册Logger
|
||||
/// </summary>
|
||||
public BITAppForGodot()
|
||||
{
|
||||
BIT4Log.OnLog += GD.Print;
|
||||
BIT4Log.OnWarning += GD.PushWarning;
|
||||
BIT4Log.OnNextLine += () => GD.Print();
|
||||
BIT4Log.OnException += x=>GD.PrintErr(x.ToString());
|
||||
BIT4Log.UseLogTime();
|
||||
|
||||
//启动BITApp
|
||||
BITApp.Start(ProjectSettings.GetSetting("application/config/name").AsString());
|
||||
BIT4Log.Log<BITAppForGodot>("已创建BITApp");
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
BIT4Log.Log<BITAppForGodot>("正在创建BITWebApp");
|
||||
|
||||
//添加测试用HttpClient
|
||||
BITApp.ServiceCollection.AddSingleton<HttpClient>();
|
||||
|
||||
//构造依赖服务提供接口
|
||||
BITApp.BuildService();
|
||||
|
||||
//设置光标状态
|
||||
AllowCursor.AddListener(SetCursor);
|
||||
AllowCursor.AddElement(this);
|
||||
// AllowCursor.AddElement(this);
|
||||
// Input.MouseMode = Input.MouseModeEnum.Hidden;
|
||||
// DisplayServer.MouseSetMode(DisplayServer.MouseMode.Hidden);
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
#pragma warning disable CS4014
|
||||
//停止BITApp
|
||||
BITApp.Stop();
|
||||
#pragma warning restore CS4014
|
||||
BIT4Log.Log<BITAppForGodot>("已安全退出App");
|
||||
}
|
||||
private void Exit()
|
||||
{
|
||||
GetTree().Quit();
|
||||
}
|
||||
private void WindowSetMaxSize()
|
||||
{
|
||||
var max = DisplayServer.WindowGetMaxSize();
|
||||
//DisplayServer.WindowSetMaxSize(max);
|
||||
var nextMode = DisplayServer.WindowGetMode() switch
|
||||
{
|
||||
DisplayServer.WindowMode.Fullscreen=>DisplayServer.WindowMode.Windowed,
|
||||
DisplayServer.WindowMode.Windowed=>DisplayServer.WindowMode.Fullscreen,
|
||||
_ => DisplayServer.WindowMode.Fullscreen,
|
||||
};
|
||||
DisplayServer.WindowSetMode(nextMode);
|
||||
}
|
||||
|
||||
private void WindowSetMinSize()
|
||||
{
|
||||
DisplayServer.WindowSetMode(DisplayServer.WindowMode.Minimized);
|
||||
}
|
||||
private static void SetCursor(bool allow)
|
||||
{
|
||||
Input.MouseMode = allow ? Input.MouseModeEnum.Visible : Input.MouseModeEnum.Captured;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user