184 lines
7.3 KiB
C#
184 lines
7.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using BITKit;
|
|
using BITKit.Console;
|
|
using BITKit.Mod;
|
|
using BITKit.Pool;
|
|
using BITKit.UX;
|
|
using BITKit.WorldNode;
|
|
using Cysharp.Threading.Tasks;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Hosting.Unity;
|
|
using Microsoft.Extensions.Logging;
|
|
using Net.Like.Xue.Tokyo.GameService;
|
|
using Net.Like.Xue.Tokyo.UX;
|
|
using Net.Project.B.Dialogue;
|
|
using Net.Project.B.Health;
|
|
using Net.Project.B.Interaction;
|
|
using Net.Project.B.Quest;
|
|
using Net.Project.B.UX;
|
|
using Net.Project.B.WorldNode;
|
|
using Project.B.Animation;
|
|
using Project.B.CharacterController;
|
|
using Project.B.Entities;
|
|
using Project.B.Map;
|
|
using Project.B.Player;
|
|
using Project.B.UX;
|
|
using UnityEngine;
|
|
using YooAsset;
|
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
|
|
|
namespace Net.Like.Xue.Tokyo
|
|
{
|
|
public class Program : MonoBehaviour
|
|
{
|
|
[SerializeField] private ScriptablePlayerKeyMap playerKeyMap;
|
|
[SerializeField] private ScriptablePlayerSettings playerSettings;
|
|
// Start is called before the first frame update
|
|
private async void Start()
|
|
{
|
|
DontDestroyOnLoad(gameObject);
|
|
var source = new CancellationTokenSource();
|
|
destroyCancellationToken.Register(source.Cancel);
|
|
|
|
var serviceCollection = BITApp.ServiceCollection= new ServiceCollection();
|
|
|
|
serviceCollection.AddSingleton<IServiceCollection>(serviceCollection);
|
|
|
|
serviceCollection.AddSingleton<ILoggerProvider, UnityLoggerProvider>();
|
|
serviceCollection.AddTransient<ILogger, UnityLogger>();
|
|
serviceCollection.AddLogging();
|
|
|
|
serviceCollection.AddSingleton(serviceCollection);
|
|
|
|
//玩家角色控制器服务
|
|
serviceCollection.AddSingleton<ICharacterService, CharacterService>();
|
|
|
|
//玩家生命值
|
|
serviceCollection.AddSingleton<IHealthService, HealthService>();
|
|
//对象池
|
|
serviceCollection.AddSingleton<IPoolService, UnityPoolService>();
|
|
//击倒服务
|
|
serviceCollection.AddSingleton<IKnockedService, KnockedService>();
|
|
|
|
var scriptablePlayerAnimation =await
|
|
ModService.LoadAsset<ScriptablePlayerAnimationFactory>("scriptable_player_animations");
|
|
//玩家动画
|
|
serviceCollection.AddSingleton<IPlayerAnimationFactory>(scriptablePlayerAnimation);
|
|
|
|
//注册实体工厂
|
|
serviceCollection.AddSingleton<IPlayerFactory, YangdunCreateFactory>();
|
|
|
|
//注册地图服务
|
|
serviceCollection.AddSingleton<IGameMapService, GameMapService>();
|
|
|
|
//场景互动
|
|
serviceCollection.AddSingleton<IWorldInteractionService, UnityInteractionService>();
|
|
//场景可互动高亮
|
|
serviceCollection.AddSingleton<WorldHighlightService>();
|
|
//场景互动门
|
|
serviceCollection.AddSingleton<UnityDoorService>();
|
|
//场景节点
|
|
serviceCollection.AddSingleton<IWorldNodeService, WorldNodeService>();
|
|
//场景描述节点
|
|
serviceCollection.AddSingleton<WorldInfoNodeService>();
|
|
//传送服务
|
|
serviceCollection.AddSingleton<GamePortalPlayerService>();
|
|
|
|
//玩家配置
|
|
serviceCollection.AddSingleton<IPlayerData, GamePlayerData>();
|
|
serviceCollection.AddSingleton<IPlayerService, GamePlayerService>();
|
|
serviceCollection.AddSingleton<IPlayerKeyMap>(playerKeyMap);
|
|
serviceCollection.AddSingleton<IUXKeyMap>(playerKeyMap);
|
|
serviceCollection.AddSingleton<IPlayerSettings>(playerSettings);
|
|
|
|
//循环
|
|
serviceCollection.AddSingleton<ITicker>(new GameTick());
|
|
serviceCollection.AddSingleton<IMainTicker, UnityUpdateTick>();
|
|
serviceCollection.AddSingleton<IAfterTicker, UnityLateUpdateTick>();
|
|
serviceCollection.AddSingleton<IFixedTicker, UnityFixedUpdateTick>();
|
|
|
|
//UX&Ui服务
|
|
serviceCollection.AddSingleton<IUXService, UXService>();
|
|
serviceCollection.AddSingleton<UXHud>();
|
|
serviceCollection.AddSingleton<UXMap>();
|
|
serviceCollection.AddSingleton<UXLoadingMap>();
|
|
serviceCollection.AddSingleton<UXMenu>();
|
|
serviceCollection.AddSingleton<UXConsole>();
|
|
|
|
serviceCollection.AddSingleton<UXDialogue>();
|
|
|
|
//生成玩家
|
|
serviceCollection.AddSingleton<GameSpawnPlayerService>();
|
|
|
|
//任务
|
|
serviceCollection.AddSingleton<IQuestService, QuestService>();
|
|
|
|
//对话
|
|
serviceCollection.AddSingleton<IDialogueService, DialogueService>();
|
|
serviceCollection.AddSingleton<DialogueMiddlewareNodeCanvasDialogueTree>();
|
|
|
|
//获取服务提供者
|
|
await using var serviceProvider = BITApp.ServiceProvider = serviceCollection.BuildServiceProvider();
|
|
|
|
if (serviceProvider is IDisposable disposable)
|
|
{
|
|
destroyCancellationToken.Register(disposable.Dispose);
|
|
}
|
|
|
|
var logger = serviceProvider.GetRequiredService<ILogger<Program>>();
|
|
|
|
BIT4Log.OnLog += (x) =>
|
|
{
|
|
logger.LogInformation(x);
|
|
};
|
|
BIT4Log.OnWarning += (x) =>
|
|
{
|
|
logger.LogWarning(x);
|
|
};
|
|
BIT4Log.OnException += (x) =>
|
|
{
|
|
logger.LogCritical(x,x.Message);
|
|
};
|
|
|
|
//初始化动画
|
|
await serviceProvider.GetRequiredService<IPlayerAnimationFactory>().InitializeAsync();
|
|
|
|
//初始化相机
|
|
Instantiate(await ModService.LoadAsset<GameObject>("prefab_camera"),transform);
|
|
|
|
//初始化UX
|
|
await serviceProvider.GetRequiredService<IUXService>().InitializeAsync();
|
|
serviceProvider.GetRequiredService<UXLoadingMap>();
|
|
serviceProvider.GetRequiredService<UXHud>();
|
|
serviceProvider.GetRequiredService<IUXService>().Entry<UXMenu>();
|
|
|
|
//初始化传送服务
|
|
serviceProvider.GetRequiredService<GamePortalPlayerService>();
|
|
|
|
//初始化玩家生成
|
|
serviceProvider.GetRequiredService<GameSpawnPlayerService>();
|
|
|
|
//初始化场景高亮
|
|
serviceProvider.GetRequiredService<WorldHighlightService>();
|
|
|
|
serviceProvider.GetRequiredService<UXConsole>();
|
|
|
|
serviceProvider.GetRequiredService<DialogueMiddlewareNodeCanvasDialogueTree>();
|
|
|
|
serviceProvider.GetRequiredService<UXDialogue>().Initialize(serviceProvider.GetRequiredService<UXHud>());
|
|
|
|
YooAssets.LoadAssetSync("MyShaderVariants").AssetObject.As<ShaderVariantCollection>().WarmUp();
|
|
|
|
Application.targetFrameRate = 165;
|
|
|
|
await destroyCancellationToken.WaitUntilCanceled();
|
|
}
|
|
}
|
|
|
|
}
|