Files
JJBB/Assets/Project/Script/Plugin/WuChangGhostAuraController.cs
2024-08-23 15:49:34 +08:00

79 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using GCGame.Table;
using Module.Log;
using UnityEngine;
public class WuChangGhostAuraController : MonoBehaviour, IParticleCleaner
{
private WuChangGhostController[] _bombers;
private float _intervalDegree;
private float _radius;
private float _speedDegree;
public Vector3 ownerPos { get; set; }
public float DelayRecoveryTime
{
get { return 0; }
}
public void StartDelayRecovery()
{
}
public void Init(int bomberCount, Tab_Effect data)
{
var radius = data.GetParamValuebyIndex(0) * 0.01f;
var rotateRate = data.GetParamValuebyIndex(1);
var returnSpeed = data.GetParamValuebyIndex(2) * 0.01f;
_bombers = new WuChangGhostController[bomberCount];
if (bomberCount > 0)
{
var bomberExample = transform.Find("Bomber");
for (var i = 1; i < bomberCount; i++)
{
var bomberTrans = Instantiate(bomberExample);
bomberTrans.SetParent(bomberExample.parent);
bomberTrans.localPosition = bomberExample.localPosition;
bomberTrans.localRotation = bomberExample.localRotation;
bomberTrans.localScale = bomberExample.localScale;
_bombers[i] = bomberTrans.gameObject.AddComponent<WuChangGhostController>();
}
_bombers[0] = bomberExample.gameObject.AddComponent<WuChangGhostController>();
for (var i = 0; i < bomberCount; i++)
_bombers[i].Init(this, i, returnSpeed);
_intervalDegree = 360f / bomberCount;
_speedDegree = rotateRate;
_radius = radius;
}
else
{
LogModule.ErrorLog("无常幽灵数量配置为0");
}
}
public void AttackTarget(Transform target, Vector3 offset, float impactTime)
{
var targetPos = target.position + offset;
WuChangGhostController bomber = null;
var lastDistSqr = float.PositiveInfinity;
for (var i = 0; i < _bombers.Length; i++)
if (_bombers[i].state == WuChangGhostController.GhostState.Docked)
{
var distSqr = (_bombers[i].transform.position - targetPos).sqrMagnitude;
if (distSqr < lastDistSqr)
{
lastDistSqr = distSqr;
bomber = _bombers[i];
}
}
if (bomber != null)
bomber.AttackTarget(target, offset, impactTime);
}
public Vector3 GetHangerPosition(int index)
{
var degree = Time.unscaledTime * _speedDegree + index * _intervalDegree;
return ownerPos + Quaternion.Euler(0f, degree, 0f) * Vector3.forward * _radius;
}
}