120 lines
4.1 KiB
C#
120 lines
4.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using Microsoft.Extensions.Logging;
|
|
using Net.Project.B.Emoji;
|
|
using Net.Project.B.Health;
|
|
using Project.B.CharacterController;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
using Object = UnityEngine.Object;
|
|
|
|
namespace Net.Like.Xue.Tokyo
|
|
{
|
|
public class GodMode:IDisposable
|
|
{
|
|
private readonly IEntitiesService _entitiesService;
|
|
private readonly IHealthService _healthService;
|
|
private readonly IMainTicker _ticker;
|
|
private readonly ValidHandle _allow = new();
|
|
private readonly ILogger<GodMode> _logger;
|
|
|
|
private readonly ScriptableYangdunData _data;
|
|
private bool _allowGodMode;
|
|
|
|
public GodMode(IMainTicker ticker, IHealthService healthService, ILogger<GodMode> logger, IEntitiesService entitiesService)
|
|
{
|
|
_ticker = ticker;
|
|
_healthService = healthService;
|
|
_logger = logger;
|
|
_entitiesService = entitiesService;
|
|
|
|
_ticker.Add(OnTick);
|
|
|
|
_healthService.OnHealthPlus += OnHealthPlus;
|
|
|
|
_allow.AddListener(OnAllow);
|
|
|
|
_data = _entitiesService.QueryComponents<ScriptableYangdunData>()[0];
|
|
}
|
|
|
|
private void OnAllow(bool allow)
|
|
{
|
|
_logger.LogInformation(allow ? "开启无敌" : "关闭无敌");
|
|
|
|
if (allow)
|
|
{
|
|
foreach (var (_, emojiService,gameObject,characterController) in _entitiesService
|
|
.QueryComponents<LocalPlayerComponent, IEmojiService<AnimationClip>,GameObject,ICharacterController>())
|
|
{
|
|
emojiService.Play(new EmojiData<AnimationClip>()
|
|
{
|
|
Clip = _data.BoostAnimation
|
|
});
|
|
|
|
{
|
|
var groundVfx = Object.Instantiate(_data.GroundVfx.gameObject, characterController.Position,characterController.Rotation);
|
|
|
|
{
|
|
if (groundVfx.TryGetComponent<ParticleSystem>(out var vfx))
|
|
{
|
|
vfx.Play(true);
|
|
}
|
|
}
|
|
}
|
|
{
|
|
gameObject.TryGetComponent<Animator>(out var animator);
|
|
|
|
foreach (var (humanBone,particleSystems) in _data.BoneVfx)
|
|
{
|
|
var bone = animator.GetBoneTransform(humanBone);
|
|
|
|
if (!bone)
|
|
{
|
|
_logger.LogWarning($"在{animator.gameObject.name}上没有找到骨骼:{humanBone}");
|
|
continue;
|
|
}
|
|
foreach (var particleSystem in particleSystems)
|
|
{
|
|
var bodyVfx = Object.Instantiate(particleSystem.gameObject, bone.position, bone.rotation);
|
|
|
|
if (!bodyVfx.TryGetComponent<ParticleSystem>(out var vfx)) continue;
|
|
vfx.Play(true);
|
|
|
|
//vfx.Stop(withChildren: true, stopBehavior: ParticleSystemStopBehavior.StopEmitting);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private int OnHealthPlus(int arg1, int arg2, int arg3, object arg4)
|
|
{
|
|
if (_allow.Allow)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
return arg3;
|
|
}
|
|
|
|
private void OnTick(float obj)
|
|
{
|
|
if (Keyboard.current is { homeKey: { wasPressedThisFrame: true } })
|
|
{
|
|
_allow.SetElements(this,_allowGodMode=!_allowGodMode);
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_ticker.Remove(OnTick);
|
|
}
|
|
}
|
|
|
|
}
|
|
|