1
This commit is contained in:
@@ -3,7 +3,9 @@ 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;
|
||||
@@ -14,6 +16,7 @@ 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.Health;
|
||||
using Net.Project.B.Interaction;
|
||||
using Net.Project.B.WorldNode;
|
||||
using Project.B.Animation;
|
||||
@@ -51,12 +54,21 @@ namespace Net.Like.Xue.Tokyo
|
||||
|
||||
//玩家角色控制器服务
|
||||
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, PlayerAnimationFactory>();
|
||||
serviceCollection.AddSingleton<IPlayerAnimationFactory>(scriptablePlayerAnimation);
|
||||
|
||||
//注册实体工厂
|
||||
serviceCollection.AddProjectBEntitiesFactory();
|
||||
serviceCollection.AddSingleton<IPlayerFactory, YangdunCreateFactory>();
|
||||
|
||||
//注册地图服务
|
||||
serviceCollection.AddSingleton<IGameMapService, GameMapService>();
|
||||
@@ -93,6 +105,7 @@ namespace Net.Like.Xue.Tokyo
|
||||
serviceCollection.AddSingleton<UXMap>();
|
||||
serviceCollection.AddSingleton<UXLoadingMap>();
|
||||
serviceCollection.AddSingleton<UXMenu>();
|
||||
serviceCollection.AddSingleton<UXConsole>();
|
||||
|
||||
//生成玩家
|
||||
serviceCollection.AddSingleton<GameSpawnPlayerService>();
|
||||
@@ -141,7 +154,9 @@ namespace Net.Like.Xue.Tokyo
|
||||
//初始化场景高亮
|
||||
serviceProvider.GetRequiredService<WorldHighlightService>();
|
||||
|
||||
Application.targetFrameRate = 60;
|
||||
serviceProvider.GetRequiredService<UXConsole>();
|
||||
|
||||
Application.targetFrameRate = 90;
|
||||
|
||||
await destroyCancellationToken.WaitUntilCanceled();
|
||||
}
|
||||
|
@@ -93,7 +93,7 @@ namespace Net.Like.Xue.Tokyo.UX
|
||||
var point = _minimapCamera.WorldToViewportPoint(_mainCamera.transform.position);
|
||||
|
||||
_miniPlayer.style.left = _minimapContainer.layout.width * point.x - _miniPlayer.layout.width / 2;
|
||||
_miniPlayer.style.top = _minimapContainer.layout.height * point.y - _miniPlayer.layout.height / 2;
|
||||
_miniPlayer.style.top = _minimapContainer.layout.height * (1-point.y) - _miniPlayer.layout.height / 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -41,7 +41,7 @@ namespace Net.Like.Xue.Tokyo.UX
|
||||
var point = _minimapCamera.WorldToViewportPoint(_mainCamera.transform.position);
|
||||
|
||||
_miniPlayer.style.left = _minimapContainer.layout.width * point.x - _miniPlayer.layout.width / 2;
|
||||
_miniPlayer.style.top = _minimapContainer.layout.height * point.y - _miniPlayer.layout.height / 2;
|
||||
_miniPlayer.style.top = _minimapContainer.layout.height * (1-point.y) - _miniPlayer.layout.height / 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "Net.Like.Xue.Tokyo.Weather.Unity",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
62
Assets/Artists/Scripts/Weather/ScriptableWeather.cs
Normal file
62
Assets/Artists/Scripts/Weather/ScriptableWeather.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITKit;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace Net.Like.Xue.Tokyo.Weather
|
||||
{
|
||||
public class ScriptableWeather : ScriptableObject
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[SerializeField] private LightingDataAsset lightingDataAsset;
|
||||
#endif
|
||||
[SerializeField] private Vector3 sunLightDirection = new Vector3(0, 1, 0);
|
||||
[SerializeField] private Color sunLightColor;
|
||||
[SerializeField] private float sunLightIntensity = 1;
|
||||
[SerializeField] private Material skyboxMaterial;
|
||||
[SerializeField] private FogMode fogMode;
|
||||
[SerializeField] private Color fogColor;
|
||||
[SerializeField] private float fogDensity;
|
||||
|
||||
[BIT]
|
||||
public void Save()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
lightingDataAsset = Lightmapping.lightingDataAsset;
|
||||
#endif
|
||||
|
||||
sunLightDirection = RenderSettings.sun.transform.eulerAngles;
|
||||
sunLightIntensity = RenderSettings.sun.intensity;
|
||||
sunLightColor = RenderSettings.sun.color;
|
||||
|
||||
skyboxMaterial = RenderSettings.skybox;
|
||||
|
||||
fogMode = RenderSettings.fogMode;
|
||||
fogColor = RenderSettings.fogColor;
|
||||
fogDensity = RenderSettings.fogDensity;
|
||||
#if UNITY_EDITOR
|
||||
EditorUtility.SetDirty(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
[BIT]
|
||||
public void Load()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
Lightmapping.lightingDataAsset = lightingDataAsset;
|
||||
#endif
|
||||
RenderSettings.sun.transform.eulerAngles = sunLightDirection;
|
||||
RenderSettings.sun.intensity = sunLightIntensity;
|
||||
RenderSettings.skybox = skyboxMaterial;
|
||||
RenderSettings.fogMode = fogMode;
|
||||
RenderSettings.fogColor = fogColor;
|
||||
RenderSettings.fogDensity = fogDensity;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
38
Assets/Artists/Scripts/WorldOptimizeService.cs
Normal file
38
Assets/Artists/Scripts/WorldOptimizeService.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MeshCombineStudio;
|
||||
using NGS.AdvancedCullingSystem.Dynamic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Net.Like.Xue.Tokyo
|
||||
{
|
||||
public class WorldOptimizeService : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform[] sources;
|
||||
[SerializeField] private Camera minimapCamera;
|
||||
private void Awake()
|
||||
{
|
||||
GetComponent<MeshCombiner>().onCombiningReady += OnReady;
|
||||
}
|
||||
private void OnReady(MeshCombiner meshcombiner)
|
||||
{
|
||||
minimapCamera.Render();
|
||||
minimapCamera.enabled = false;
|
||||
|
||||
|
||||
var controller = gameObject.AddComponent<DC_Controller>();
|
||||
controller.AddCamera(Camera.main,3000);
|
||||
foreach (var x in sources)
|
||||
{
|
||||
foreach (var renderer in x.GetComponentsInChildren<MeshRenderer>())
|
||||
{
|
||||
if (renderer.gameObject.activeInHierarchy)
|
||||
controller.AddObjectForCulling(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
174
Assets/Artists/Scripts/YangdunCreateFactory.cs
Normal file
174
Assets/Artists/Scripts/YangdunCreateFactory.cs
Normal file
@@ -0,0 +1,174 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Animancer;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using BITKit.GameSocket;
|
||||
using BITKit.WorldNode;
|
||||
using Cinemachine;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Lightbug.CharacterControllerPro.Core;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Net.Project.B.Health;
|
||||
using Net.Project.B.Interaction;
|
||||
using Net.Project.B.Inventory;
|
||||
using Net.Project.B.Weapon;
|
||||
using NodeCanvas.Framework;
|
||||
using Project.B.Animation;
|
||||
using Project.B.CharacterController;
|
||||
using Project.B.Entities;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
using Object = UnityEngine.Object;
|
||||
namespace Net.Like.Xue.Tokyo
|
||||
{
|
||||
public class YangdunCreateFactory : IPlayerFactory
|
||||
{
|
||||
private readonly ILogger<PlayerFactory> _logger;
|
||||
private readonly IServiceCollection _serviceCollection;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IWorldNodeService _worldNodeService;
|
||||
private const string PlayerPath = "Player_Base";
|
||||
private readonly List<(IEntity entity,GameObject go)> _entities = new();
|
||||
private readonly IHealthService _healthService;
|
||||
private GameObject _playerPrefab;
|
||||
private readonly InputActionGroup _inputActionGroup=new();
|
||||
|
||||
private UniTaskCompletionSource<WorldInfoPlayerStart> _waitPlayerStart=new();
|
||||
|
||||
public YangdunCreateFactory(IServiceProvider serviceProvider, IServiceCollection serviceCollection, IWorldNodeService worldNodeService, ILogger<PlayerFactory> logger, IHealthService healthService)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_serviceCollection = serviceCollection;
|
||||
_worldNodeService = worldNodeService;
|
||||
_logger = logger;
|
||||
_healthService = healthService;
|
||||
|
||||
_worldNodeService.OnNodeRegistered += OnNodeRegistered;
|
||||
|
||||
_healthService.OnHealthChanged+=OnHealthChanged;
|
||||
}
|
||||
|
||||
private void OnNodeRegistered(IWorldNode obj)
|
||||
{
|
||||
if(obj is not WorldInfoPlayerStart infoPlayerStart)return;
|
||||
_waitPlayerStart.TrySetResult(infoPlayerStart);
|
||||
}
|
||||
|
||||
public async UniTask<IEntity> CreateAsync(string addressablePath)
|
||||
{
|
||||
await UniTask.SwitchToMainThread();
|
||||
if (_playerPrefab is not null)
|
||||
{
|
||||
return await Create(addressablePath);
|
||||
}
|
||||
var asyncHandle = YooAssets.LoadAssetAsync<GameObject>(PlayerPath);
|
||||
await asyncHandle;
|
||||
_playerPrefab = asyncHandle.AssetObject as GameObject;
|
||||
|
||||
return await Create(addressablePath);
|
||||
}
|
||||
|
||||
public event Func<string, IEntity,UniTask> OnEntityCreate;
|
||||
public event Func<string, IEntity,UniTask> OnEntityCreated;
|
||||
|
||||
private async UniTask<IEntity> Create(string addressablePath = null)
|
||||
{
|
||||
var entity = new Entity();
|
||||
|
||||
var startNode = await _waitPlayerStart.Task;
|
||||
var startTransform = startNode.WorldObject.As<GameObject>().transform;
|
||||
|
||||
_waitPlayerStart = new();
|
||||
|
||||
var go = Object.Instantiate(_playerPrefab,startTransform.position,startTransform.rotation);
|
||||
|
||||
entity.ServiceCollection.Add(_serviceCollection);
|
||||
|
||||
go.GetCancellationTokenOnDestroy().Register(entity.Dispose);
|
||||
|
||||
entity.ServiceCollection.AddSingleton<IEntity>(entity);
|
||||
|
||||
entity.ServiceCollection.AddSingleton(go);
|
||||
entity.ServiceCollection.AddSingleton(go.transform);
|
||||
|
||||
entity.ServiceCollection.AddSingleton(go.GetComponent<IBlackboard>());
|
||||
|
||||
entity.ServiceCollection.AddSingleton(go.GetComponent<CharacterActor>());
|
||||
entity.ServiceCollection.AddSingleton(go.GetComponentInChildren<CinemachineVirtualCameraBase>());
|
||||
entity.ServiceCollection.AddSingleton<IAnimancerComponent>(go.GetComponent<AnimancerComponent>());
|
||||
|
||||
entity.ServiceCollection.AddSingleton<IPlayerCharacterController, PlayerCharacterController>();
|
||||
entity.ServiceCollection.AddSingleton<ICharacterController>(x=>x.GetRequiredService<IPlayerCharacterController>().CharacterController);
|
||||
|
||||
entity.ServiceCollection.AddSingleton(_inputActionGroup);
|
||||
|
||||
|
||||
entity.ServiceCollection.AddSingleton<ICharacterStateWalk, CharacterWalkState>();
|
||||
entity.ServiceCollection.AddSingleton<ICharacterStateIdle, CharacterIdleState>();
|
||||
entity.ServiceCollection.AddSingleton<ICharacterStateCrouched, CharacterCrouchedState>();
|
||||
entity.ServiceCollection.AddSingleton<ICharacterStateRun, CharacterRunState>();
|
||||
entity.ServiceCollection.AddSingleton<ICharacterSprint, CharacterSprintState>();
|
||||
entity.ServiceCollection.AddSingleton<ICharacterStateStepUp, CharacterStepUpState>();
|
||||
entity.ServiceCollection.AddSingleton<ICharacterKnocked, CharacterKnockedState>();
|
||||
|
||||
entity.ServiceCollection.AddSingleton<PlayerCameraController>();
|
||||
entity.ServiceCollection.AddSingleton<PlayerModelController>();
|
||||
|
||||
entity.ServiceCollection.AddSingleton<PlayerAnimancerController>();
|
||||
|
||||
entity.ServiceCollection.AddSingleton(_serviceProvider.GetRequiredService<IWorldInteractionService>());
|
||||
entity.ServiceCollection.AddSingleton<PlayerInteractionController>();
|
||||
|
||||
|
||||
await OnEntityCreate.UniTaskFunc(addressablePath,entity);
|
||||
|
||||
entity.ServiceProvider.GetRequiredService<ICharacterStateWalk>();
|
||||
|
||||
entity.ServiceProvider.GetRequiredService<PlayerInteractionController>();
|
||||
|
||||
var characterController = entity.ServiceProvider.GetRequiredService<ICharacterController>();
|
||||
|
||||
characterController.TransitionState<ICharacterStateWalk>();
|
||||
|
||||
entity.ServiceProvider.GetRequiredService<PlayerAnimancerController>();
|
||||
|
||||
entity.ServiceProvider.GetRequiredService<PlayerCameraController>();
|
||||
|
||||
entity.ServiceProvider.GetRequiredService<PlayerModelController>();
|
||||
|
||||
|
||||
await OnEntityCreated.UniTaskFunc(addressablePath,entity);
|
||||
|
||||
_entities.Add(new ValueTuple<IEntity, GameObject>(entity,go));
|
||||
|
||||
_logger.LogInformation($"Player Created. {entity.Id}");
|
||||
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public async void Dispose()
|
||||
{
|
||||
await UniTask.SwitchToMainThread();
|
||||
foreach (var (entity, go) in _entities)
|
||||
{
|
||||
if (entity is IDisposable disposable)
|
||||
{
|
||||
disposable.Dispose();
|
||||
}
|
||||
if (go)
|
||||
Object.Destroy(go);
|
||||
}
|
||||
_healthService.OnHealthChanged-=OnHealthChanged;
|
||||
}
|
||||
private void OnHealthChanged(int arg1, int arg2, int arg3, object arg4)
|
||||
{
|
||||
_inputActionGroup.allowInput.SetDisableElements(this,arg3<0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user