FututeWand初步

This commit is contained in:
SoulliesOfficial
2026-07-01 06:32:50 -04:00
parent ddd387ef35
commit 347237443f
89 changed files with 290771 additions and 1084 deletions

View File

@@ -80,6 +80,9 @@ namespace Cielonos.MainGame
impulseSm = null;
reactionSm = null;
scheduledActions.Clear();
_toBeExecutedScheduledActions.Clear();
areaCollider = GetComponent<Collider>();
// 通过 VFXObject 组件确定 VFX 顶层节点,比遍历 parent 链更可靠。
@@ -122,11 +125,62 @@ namespace Cielonos.MainGame
hitSm?.Update();
timeSm?.Update();
moveSm?.Update();
UpdateScheduledActions();
}
}
public partial class AttackAreaBase
{
public class ScheduledAction
{
public Action action;
public float delay;
public ScheduledAction(Action action, float delay)
{
this.action = action;
this.delay = delay;
}
}
[HideInEditorMode] public List<ScheduledAction> scheduledActions = new List<ScheduledAction>();
private List<ScheduledAction> _toBeExecutedScheduledActions = new List<ScheduledAction>();
/// <summary>
/// 添加一个在指定延迟时间后执行的动作,只要 AttackArea 存在且 active 就会更新
/// </summary>
public AttackAreaBase AddScheduleAction(Action action, float delay)
{
scheduledActions.Add(new ScheduledAction(action, delay));
return this;
}
/// <summary>
/// 更新所有延迟执行的动作,不受子模块启用状态的影响
/// </summary>
private void UpdateScheduledActions()
{
if (scheduledActions.Count > 0)
{
_toBeExecutedScheduledActions.Clear();
float dt = creator != null && creator.selfTimeSm != null ? creator.selfTimeSm.DeltaTime : Time.deltaTime;
for (int i = scheduledActions.Count - 1; i >= 0; i--)
{
var scheduledAction = scheduledActions[i];
scheduledAction.delay -= dt;
if (scheduledAction.delay <= 0)
{
_toBeExecutedScheduledActions.Add(scheduledAction);
scheduledActions.RemoveAt(i);
}
}
foreach (var scheduledAction in _toBeExecutedScheduledActions)
{
scheduledAction.action?.Invoke();
}
}
}
#region TransformSubmodule
public T SetTransformSubmodule<T>(Transform target = null, float delay = 0) where T : AttackAreaBase
@@ -263,16 +317,6 @@ namespace Cielonos.MainGame
keepFlat, straightThrowInitially, straightThrowDuration, stopWhenHit);
return this as T;
}
/// <summary>
/// 设置回旋镖/旋转区域追踪移动子模块(链式/Fluent 初始化),返回子模块以供进一步配置
/// </summary>
public BoomerangMoveSubmodule SetBoomerangMoveSubmodule(CharacterBase target, float moveSpeed, float angularSpeed, Vector3 initialDirection)
{
var submodule = new BoomerangMoveSubmodule(this, target, moveSpeed, angularSpeed, initialDirection);
moveSm = submodule;
return submodule;
}
#endregion
#region RaycastSubmodule

View File

@@ -13,6 +13,11 @@ namespace Cielonos.MainGame
public float angularSpeed;
public float angularAcceleration;
public float returnMoveSpeed = -1f;
public float returnMoveAcceleration = -1f;
public float returnAngularSpeed = -1f;
public float returnAngularAcceleration = -1f;
public bool isReturning;
public float catchRadius;
public float autoReturnTime; // Time in seconds after which it automatically returns if not triggered manually
@@ -112,15 +117,33 @@ namespace Cielonos.MainGame
return this;
}
public BoomerangMoveSubmodule WithReturnParameters(float speed, float acceleration, float angularSpeed, float angularAcceleration)
{
this.returnMoveSpeed = speed;
this.returnMoveAcceleration = acceleration;
this.returnAngularSpeed = angularSpeed;
this.returnAngularAcceleration = angularAcceleration;
return this;
}
public void TriggerReturn(float moveSpeed = -1f, float moveAcceleration = -1f, float angularSpeed = -1f, float angularAcceleration = -1f)
{
if (isReturning || !canMove) return;
isReturning = true;
target = owner.creator; // Start tracing the player/creator
if (moveSpeed >= 0f) this.moveSpeed = moveSpeed;
if (moveAcceleration >= 0f) this.moveAcceleration = moveAcceleration;
if (angularSpeed >= 0f) this.angularSpeed = angularSpeed;
if (angularAcceleration >= 0f) this.angularAcceleration = angularAcceleration;
float targetSpeed = moveSpeed >= 0f ? moveSpeed : returnMoveSpeed;
if (targetSpeed >= 0f) this.moveSpeed = targetSpeed;
float targetAcceleration = moveAcceleration >= 0f ? moveAcceleration : returnMoveAcceleration;
if (targetAcceleration >= 0f) this.moveAcceleration = targetAcceleration;
float targetAngularSpeed = angularSpeed >= 0f ? angularSpeed : returnAngularSpeed;
if (targetAngularSpeed >= 0f) this.angularSpeed = targetAngularSpeed;
float targetAngularAcceleration = angularAcceleration >= 0f ? angularAcceleration : returnAngularAcceleration;
if (targetAngularAcceleration >= 0f) this.angularAcceleration = targetAngularAcceleration;
autoConnect = false;
}

View File

@@ -15,8 +15,6 @@ namespace Cielonos.MainGame
private bool hasInvokedEnableAction;
public Action enableAction;
public Action timeOutAction;
public List<ScheduledAction> scheduledActions;
private List<ScheduledAction> toBeExecutedScheduledActions = new List<ScheduledAction>();
/// <summary>
/// enable 阶段开始前允许反应的提前量(秒),默认 0 表示无提前 grace window。
@@ -30,7 +28,6 @@ namespace Cielonos.MainGame
this.lifeTime = lifeTime;
this.remainingLifeTime = lifeTime;
this.enablingTimer = 0;
this.scheduledActions = new List<ScheduledAction>();
if (attackArea is NormalArea)
{
@@ -67,7 +64,6 @@ namespace Cielonos.MainGame
this.lifeTime = lifeTime;
this.delayTime = delayTime;
this.attackArea.isEnabling = delayTime <= 0;
this.scheduledActions = new List<ScheduledAction>();
this.timeOutAction = timeOutAction ?? (() =>
{
@@ -93,11 +89,7 @@ namespace Cielonos.MainGame
this.reactionGraceBefore = graceBefore;
}
public TimeSubmodule AddScheduleAction(Action action, float delay)
{
scheduledActions.Add(new ScheduledAction(action, delay));
return this;
}
/// <summary>
/// 判断当前时刻是否处于反应窗口内(包含 grace 区间和 enable 阶段本身)。
@@ -148,21 +140,7 @@ namespace Cielonos.MainGame
enableAction?.Invoke();
hasInvokedEnableAction = true;
}
toBeExecutedScheduledActions.Clear();
foreach (var scheduledAction in scheduledActions)
{
scheduledAction.delay -= attackArea.creator.selfTimeSm.DeltaTime;
if (scheduledAction.delay <= 0)
{
toBeExecutedScheduledActions.Add(scheduledAction);
}
}
foreach (var scheduledAction in toBeExecutedScheduledActions)
{
scheduledAction.action.Invoke();
scheduledActions.Remove(scheduledAction);
}
if (remainingLifeTime <= 0)
{
@@ -187,18 +165,5 @@ namespace Cielonos.MainGame
}
}
public partial class TimeSubmodule
{
public class ScheduledAction
{
public Action action;
public float delay;
public ScheduledAction(Action action, float delay)
{
this.action = action;
this.delay = delay;
}
}
}
}