NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Weapon/WeaponLine.cs

61 lines
1.3 KiB
C#
Raw Normal View History

2023-10-19 15:00:19 +08:00
using Gameplay.Pool;
2023-08-22 19:08:45 +08:00
namespace Gameplay.Weapon
{
2023-10-19 15:00:19 +08:00
using Effect;
2023-08-22 19:08:45 +08:00
using UnityEngine;
2023-10-19 15:00:19 +08:00
public class WeaponLine: IPoolData
2023-08-22 19:08:45 +08:00
{
public EffectPlayingData effect;
2023-10-19 15:00:19 +08:00
public bool needRemove;
2023-08-22 19:08:45 +08:00
public Vector3 endPos;
public float flySpeed;
2023-11-02 19:53:39 +08:00
public void StartFly(Vector3 end, float inFlySpeed)
2023-08-22 19:08:45 +08:00
{
endPos = end;
2023-11-02 19:53:39 +08:00
flySpeed = inFlySpeed;
2023-08-22 19:08:45 +08:00
}
public void ViewUpdate(float dt)
{
if (effect == null) return;
if (needRemove) return;
var moveDistance = flySpeed * dt;
var toEnd = endPos - effect.transform.position;
toEnd.y = 0;
var distance = toEnd.magnitude;
if (distance <= moveDistance)
{
effect.transform.position = endPos;
needRemove = true;
return;
}
var dir = toEnd.normalized;
effect.transform.position += dir * moveDistance;
}
2023-10-19 15:00:19 +08:00
public void DestroyEffect()
2023-08-22 19:08:45 +08:00
{
if (effect == null)
{
return;
}
effect.Destroy();
effect = null;
}
2023-10-19 15:00:19 +08:00
public void OnGet()
{
needRemove = false;
}
public void OnReturn()
{
}
2023-08-22 19:08:45 +08:00
}
}