2.5d test

This commit is contained in:
2026-09-27 21:08:05 +09:00
parent 84dd12414a
commit abd2da2057
201 changed files with 24297 additions and 295 deletions
@@ -1,3 +1,4 @@
using System;
using UnityEngine;
using BumpCombat.Constants;
@@ -17,9 +18,17 @@ namespace BumpCombat.Defense
private float delayRemaining;
private bool animationFinished;
private Vector2 travelStart;
private System.Func<Vector2> travelStartProvider;
private Vector2 travelEnd;
private float travelDuration;
private float travelElapsed;
private Action travelArrival;
private System.Func<Vector2> travelEndProvider;
private System.Func<bool> travelCanAdvance;
private bool travelArrivalInvoked;
private bool hideRendererAtArrival;
private System.Action completionCallback;
private bool finished;
private bool fitsLightningBeam;
private Vector2 beamStart;
private Vector2 beamEnd;
@@ -27,11 +36,16 @@ namespace BumpCombat.Defense
private bool centersImpactWave;
private Vector2 impactWaveCenter;
private float impactWaveScale;
private bool fitsLightningStormGround;
private Vector2 lightningStormGroundCenter;
private float lightningStormGroundRadius;
public void Play(SpriteRenderer renderer, string sequenceKey, Sprite[] sequenceFrames,
bool destroyOnFinish, string followingKey = null,
Sprite[] followingFrames = null, float startDelay = 0f)
{
completionCallback = null;
finished = false;
target = renderer;
key = sequenceKey;
frames = sequenceFrames;
@@ -41,8 +55,7 @@ namespace BumpCombat.Defense
delayRemaining = Mathf.Max(0f, startDelay);
if (target == null || frames == null || frames.Length == 0)
{
enabled = false;
if (destroyWhenFinished) Destroy(gameObject);
FinishSequence();
return;
}
frame = 0;
@@ -69,13 +82,55 @@ namespace BumpCombat.Defense
UpdateVisualAlignment();
}
public void Travel(Vector2 start, Vector2 end, float duration)
public void FitLightningStormGround(Vector2 center, float radius)
{
fitsLightningStormGround = true;
lightningStormGroundCenter = center;
lightningStormGroundRadius = Mathf.Max(0f, radius);
UpdateVisualAlignment();
}
public bool IsFinished => finished;
public void SetCompletionCallback(System.Action callback)
{
if (callback == null) return;
if (finished) callback();
else completionCallback += callback;
}
public void SetCanAdvance(System.Func<bool> canAdvance)
{
travelCanAdvance = canAdvance;
}
public void Travel(Vector2 start, Vector2 end, float duration,
Action onArrival = null, System.Func<Vector2> endProvider = null,
System.Func<bool> canAdvance = null, bool hideAtArrival = false,
System.Func<Vector2> startProvider = null)
{
travelStart = start;
travelStartProvider = startProvider;
travelEnd = end;
travelDuration = Mathf.Max(0.001f, duration);
travelElapsed = 0f;
transform.position = start;
travelArrival = onArrival;
travelEndProvider = endProvider;
travelCanAdvance = canAdvance ?? travelCanAdvance;
travelArrivalInvoked = false;
hideRendererAtArrival = hideAtArrival;
if (delayRemaining <= 0f) ResolveTravelStart();
else transform.position = start;
}
private void ResolveTravelStart()
{
if (travelStartProvider != null)
{
travelStart = travelStartProvider();
travelStartProvider = null;
}
transform.position = travelStart;
}
private void Update()
@@ -85,17 +140,28 @@ namespace BumpCombat.Defense
FinishSequence();
return;
}
if (travelCanAdvance != null && !travelCanAdvance()) return;
if (delayRemaining > 0f)
{
delayRemaining -= Time.deltaTime;
if (delayRemaining > 0f) return;
if (travelDuration > 0f || travelStartProvider != null)
ResolveTravelStart();
target.enabled = true;
}
if (travelDuration > 0f && travelElapsed < travelDuration)
{
travelElapsed += Time.deltaTime;
Vector2 currentEnd = travelEndProvider != null
? travelEndProvider() : travelEnd;
transform.position = Vector2.Lerp(
travelStart, travelEnd, Mathf.Clamp01(travelElapsed / travelDuration));
travelStart, currentEnd, Mathf.Clamp01(travelElapsed / travelDuration));
if (travelElapsed >= travelDuration && !travelArrivalInvoked)
{
travelArrivalInvoked = true;
if (hideRendererAtArrival && target != null) target.enabled = false;
travelArrival?.Invoke();
}
}
if (animationFinished)
{
@@ -147,6 +213,16 @@ namespace BumpCombat.Defense
transform.position = beamStart - (Vector2)(transform.right * localStart);
transform.localScale = new Vector3(scaleX, beamThickness, 1f);
}
if (fitsLightningStormGround)
{
float scale = lightningStormGroundRadius * target.sprite.pixelsPerUnit
/ DefenseTowerArtBounds.LightningStormGroundRadiusPixels;
transform.localScale = Vector3.one * scale;
Vector2 localCenter = (DefenseTowerArtBounds.LightningStormGroundCenterPixels
- target.sprite.pivot) / target.sprite.pixelsPerUnit;
transform.position = lightningStormGroundCenter
- (Vector2)transform.TransformVector(localCenter);
}
if (centersImpactWave)
{
transform.localScale = Vector3.one * impactWaveScale;
@@ -158,6 +234,8 @@ namespace BumpCombat.Defense
private void FinishSequence()
{
if (finished) return;
finished = true;
if (destroyWhenFinished)
{
Destroy(gameObject);
@@ -167,6 +245,10 @@ namespace BumpCombat.Defense
if (target != null) target.enabled = false;
enabled = false;
}
System.Action callback = completionCallback;
completionCallback = null;
callback?.Invoke();
}
}
}