Loot 3 group A: the grab is presented, not simulated
IGrabPresenter.Grab(GrabEvent) only; the binder's Transform and velocity resolvers go. TractorBeam presents a running grab (aims at Started's TargetPosition, emits at Power, dark otherwise). FieldDriver draws its tendril from GrabEvents alone with a real-time phase clock over each event's PhaseDuration and writes no transform and destroys nothing; its grab times move to FieldTester, now the scene's stand-in sim that owns its pickup's timeline and pose. ItemPickup keeps its label lit while held. ImpactPresenterSmoke becomes CapabilityPresentationSmoke with a grab section; its two untracked-ship expectations follow DrawsAt since contact-hud. Builds (Unity 6000.3.24f1 batchmode: smoke ok, scene opens, no missing script). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
24ab95af8d
commit
48b42992ee
9 changed files with 232 additions and 166 deletions
|
|
@ -8,27 +8,18 @@ using UnityEngine;
|
|||
// playground-cut.md fork L: "presentation is chosen per item, independently of capability... one
|
||||
// presentation... can visualize any subset of an item's capabilities"). This binder has no knowledge
|
||||
// of FieldDriver or any other concrete presentation, and no knowledge of what publishes events --
|
||||
// today the FieldShieldTest scene calls Bind() directly; a real capability owner will do the same
|
||||
// later without this binder changing.
|
||||
// EntityInstance binds every entity's events, and the FieldShieldTest scene binds its stand-in sim's the same way.
|
||||
public class CapabilityPresentationBinder : MonoBehaviour
|
||||
{
|
||||
private readonly List<IDisposable> _subscriptions = new List<IDisposable>();
|
||||
private Func<FloatingBodyId, Transform> _grabTargetResolver;
|
||||
private Func<FloatingBodyId, Vector3> _grabInitialVelocityResolver;
|
||||
|
||||
// Subscribes every presenter interface implemented by components on this object or its children to
|
||||
// the matching stream of `events`. `grabTargetResolver`/`grabInitialVelocityResolver` resolve a
|
||||
// GrabEvent's target id to the live Transform/velocity a grab presenter needs; the owner
|
||||
// of `events` supplies them (the test scene today; the real pickup capability's caller later).
|
||||
public void Bind(CapabilityEvents events, Func<FloatingBodyId, Transform> grabTargetResolver = null,
|
||||
Func<FloatingBodyId, Vector3> grabInitialVelocityResolver = null)
|
||||
// the matching stream of `events`.
|
||||
public void Bind(CapabilityEvents events)
|
||||
{
|
||||
Unbind();
|
||||
if (events == null) return;
|
||||
|
||||
_grabTargetResolver = grabTargetResolver;
|
||||
_grabInitialVelocityResolver = grabInitialVelocityResolver;
|
||||
|
||||
foreach (var presenter in GetComponentsInChildren<IAbsorbPresenter>(true))
|
||||
{
|
||||
var p = presenter;
|
||||
|
|
@ -38,12 +29,7 @@ public class CapabilityPresentationBinder : MonoBehaviour
|
|||
foreach (var presenter in GetComponentsInChildren<IGrabPresenter>(true))
|
||||
{
|
||||
var p = presenter;
|
||||
_subscriptions.Add(events.Grab.Subscribe(e =>
|
||||
{
|
||||
var target = _grabTargetResolver?.Invoke(e.Target);
|
||||
var velocity = _grabInitialVelocityResolver?.Invoke(e.Target) ?? Vector3.zero;
|
||||
p.Grab(e, target, velocity);
|
||||
}));
|
||||
_subscriptions.Add(events.Grab.Subscribe(e => p.Grab(e)));
|
||||
}
|
||||
|
||||
foreach (var presenter in GetComponentsInChildren<IMeleePresenter>(true))
|
||||
|
|
@ -63,8 +49,6 @@ public class CapabilityPresentationBinder : MonoBehaviour
|
|||
{
|
||||
foreach (var s in _subscriptions) s.Dispose();
|
||||
_subscriptions.Clear();
|
||||
_grabTargetResolver = null;
|
||||
_grabInitialVelocityResolver = null;
|
||||
}
|
||||
|
||||
private void OnDisable() => Unbind();
|
||||
|
|
|
|||
|
|
@ -10,13 +10,10 @@ public interface IAbsorbPresenter
|
|||
void Absorb(AbsorbEvent e);
|
||||
}
|
||||
|
||||
// Grab needs a live Transform to animate, which the engine-free GrabEvent cannot carry (its
|
||||
// Target is a plain identity, not a Unity reference). The binder resolves the id through a
|
||||
// delegate supplied by the event source's owner and hands the presenter the result, along with the
|
||||
// initial velocity the target was already moving with (also owner-supplied, for the same reason).
|
||||
// Presenters read the event and the simulated pose, never a Transform the sim does not own.
|
||||
public interface IGrabPresenter
|
||||
{
|
||||
void Grab(GrabEvent e, Transform target, Vector3 initialVelocity);
|
||||
void Grab(GrabEvent e);
|
||||
}
|
||||
|
||||
public interface IMeleePresenter
|
||||
|
|
|
|||
|
|
@ -63,11 +63,7 @@ public class FieldDriver : MonoBehaviour, IAbsorbPresenter, IGrabPresenter, IMel
|
|||
// public float GrabScaleAnimationExponent = .5f;
|
||||
|
||||
[Inspectable]
|
||||
public float GrabExtendTime;
|
||||
[Inspectable]
|
||||
public float GrabEnvelopTime;
|
||||
[Inspectable]
|
||||
public float GrabPullTime;
|
||||
public float TendrilTipScale = 1;
|
||||
|
||||
[Inspectable]
|
||||
public RectTransform.Axis RefractionAxis = RectTransform.Axis.Horizontal;
|
||||
|
|
@ -81,29 +77,17 @@ public class FieldDriver : MonoBehaviour, IAbsorbPresenter, IGrabPresenter, IMel
|
|||
private float _meleeTime;
|
||||
private bool _meleeActive;
|
||||
private MeshCollider _collider;
|
||||
private Transform _grabObject;
|
||||
private Vector3 _grabObjectStartPos;
|
||||
private Vector3 _grabObjectStartTendrilBasePos;
|
||||
private Vector3 _grabObjectEndPos;
|
||||
private Vector3 _grabObjectVelocity;
|
||||
private float _grabObjectScale;
|
||||
private bool _grabbing;
|
||||
private GrabPhase _grabPhase;
|
||||
private float _grabTime;
|
||||
private TendrilPhase _grabPhase;
|
||||
private float _phaseDuration;
|
||||
private Vector3 _grabStart;
|
||||
private Vector3 _grabStartTendrilBase;
|
||||
private Vector3 _tendrilBasePos;
|
||||
private Vector3 _tendrilBendTarget;
|
||||
private Vector3 _tendrilTargetPos;
|
||||
private float _fadePoint;
|
||||
|
||||
// Named distinctly from the global GrabPhase (CapabilityEvents.cs): this is FieldDriver's own
|
||||
// internal tendril-animation timing, still owned here until a real pickup capability exists to
|
||||
// publish per-phase GrabEvent transitions (see Grab(GrabEvent, Transform, Vector3) below).
|
||||
private enum TendrilPhase
|
||||
{
|
||||
Extend,
|
||||
Envelop,
|
||||
Pull
|
||||
}
|
||||
|
||||
private struct FieldHit
|
||||
{
|
||||
public float3 Position;
|
||||
|
|
@ -181,32 +165,41 @@ public class FieldDriver : MonoBehaviour, IAbsorbPresenter, IGrabPresenter, IMel
|
|||
_meleeTime = 0;
|
||||
}
|
||||
|
||||
public bool CanGrab => _grabObject == null;
|
||||
|
||||
public void GrabObject(Transform t, Vector3 v)
|
||||
{
|
||||
_grabPhase = TendrilPhase.Extend;
|
||||
_grabObject = t;
|
||||
_grabObjectStartPos = t.position;
|
||||
_grabObjectVelocity = v;
|
||||
_grabObjectScale = t.localScale.x;
|
||||
_tendrilBasePos = _grabObjectStartTendrilBasePos = _collider.ClosestPoint(_grabObjectStartPos);
|
||||
_fadePoint = .999f;
|
||||
}
|
||||
|
||||
// IAbsorbPresenter: delegates straight to the existing hit-buffer mechanism. e.DamageType is not
|
||||
// read -- the field shield has no per-damage-type visual today; it rides along in the event for
|
||||
// presentations that do vary by type (the mask itself is absorb-capability data, out of scope here).
|
||||
public void Absorb(AbsorbEvent e) => AddHit(e.Position, e.Direction, e.Magnitude);
|
||||
|
||||
// IGrabPresenter: only the Started phase does anything today. FieldDriver still times the
|
||||
// extend/envelop/pull animation itself (TendrilPhase above, driven by GrabExtendTime/
|
||||
// GrabEnvelopTime/GrabPullTime) because no capability yet publishes those phase transitions;
|
||||
// once one does, this is where FieldDriver would react to Envelop/Pull/Completed/Cancelled too.
|
||||
public void Grab(GrabEvent e, Transform target, Vector3 initialVelocity)
|
||||
// IGrabPresenter: the simulation owns the grab; this draws the tendril from the events alone. Started records
|
||||
// where the item is held and where the tendril leaves the field; Extend, Envelop and Pull set the phase and
|
||||
// restart the real-time phase clock over the event's duration (it clamps at 1 until the next event, so a
|
||||
// slowed simulation stretches the wait, not the animation); Completed and Cancelled end it.
|
||||
public void Grab(GrabEvent e)
|
||||
{
|
||||
if (e.Phase == GrabPhase.Started && target != null)
|
||||
GrabObject(target, initialVelocity);
|
||||
switch (e.Phase)
|
||||
{
|
||||
case GrabPhase.Started:
|
||||
_grabbing = true;
|
||||
_grabPhase = GrabPhase.Started;
|
||||
_grabStart = e.TargetPosition.ToUnity();
|
||||
_tendrilBasePos = _grabStartTendrilBase = _collider.ClosestPoint(_grabStart);
|
||||
_tendrilTargetPos = _grabStart;
|
||||
_fadePoint = .999f;
|
||||
break;
|
||||
case GrabPhase.Extend:
|
||||
case GrabPhase.Envelop:
|
||||
case GrabPhase.Pull:
|
||||
if (!_grabbing) break;
|
||||
_grabPhase = e.Phase;
|
||||
_grabTime = 0;
|
||||
_phaseDuration = e.PhaseDuration;
|
||||
break;
|
||||
case GrabPhase.Completed:
|
||||
case GrabPhase.Cancelled:
|
||||
_grabbing = false;
|
||||
_field.SetFloat("_TendrilInfluence", 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// IMeleePresenter: the field shield's swing shape comes from its own authored curves
|
||||
|
|
@ -277,74 +270,47 @@ public class FieldDriver : MonoBehaviour, IAbsorbPresenter, IGrabPresenter, IMel
|
|||
}
|
||||
|
||||
|
||||
if(_grabObject != null)
|
||||
if (_grabbing && _grabPhase != GrabPhase.Started)
|
||||
{
|
||||
_grabTime += Time.deltaTime / _grabPhase switch
|
||||
_grabTime = min(1, _grabTime + Time.deltaTime / max(_phaseDuration, 1e-4f));
|
||||
_tendrilBasePos = damp(_tendrilBasePos.ToCultMath(), _tendrilTargetPos.ToCultMath(), TendrilBaseDamping, Time.deltaTime).ToUnity();
|
||||
switch (_grabPhase)
|
||||
{
|
||||
TendrilPhase.Extend => GrabExtendTime,
|
||||
TendrilPhase.Envelop => GrabEnvelopTime,
|
||||
TendrilPhase.Pull => GrabPullTime,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
if (_grabTime > 1)
|
||||
{
|
||||
_grabTime = 0;
|
||||
if (_grabPhase == TendrilPhase.Envelop)
|
||||
{
|
||||
_grabObjectEndPos = _grabObject.position;
|
||||
}
|
||||
if (_grabPhase == TendrilPhase.Pull)
|
||||
{
|
||||
Destroy(_grabObject.gameObject);
|
||||
_grabObject = null;
|
||||
_field.SetFloat("_TendrilInfluence", 0);
|
||||
}
|
||||
else _grabPhase++;
|
||||
}
|
||||
|
||||
if (_grabObject != null)
|
||||
{
|
||||
_tendrilBasePos = damp(_tendrilBasePos.ToCultMath(), _grabObject.position.ToCultMath(), TendrilBaseDamping, Time.deltaTime).ToUnity();
|
||||
switch (_grabPhase)
|
||||
{
|
||||
case TendrilPhase.Extend:
|
||||
_tendrilBendTarget = _grabObjectStartPos;
|
||||
_grabObject.position += _grabObjectVelocity * Time.deltaTime;
|
||||
_tendrilTargetPos = lerp(
|
||||
lerp(_grabObjectStartTendrilBasePos.ToCultMath(), _grabObjectStartPos.ToCultMath(), _grabTime),
|
||||
lerp(_grabObjectStartPos.ToCultMath(), _grabObject.position.ToCultMath(), _grabTime),
|
||||
pow(_grabTime, TendrilExtensionExponent)).ToUnity();
|
||||
_field.SetFloat("_TendrilInfluence", pow(_grabTime, TendrilExtendBaseAnimationExponent));
|
||||
_field.SetFloat("_TendrilSize", lerp(TendrilBaseRadius/2,TendrilBaseRadius,pow(_grabTime, TendrilExtendBaseAnimationExponent)));
|
||||
_field.SetFloat("_TendrilRadius", _grabObjectScale * pow(_grabTime, TendrilTipRadiusAnimationExponent) * TendrilTipRadius);
|
||||
break;
|
||||
case TendrilPhase.Envelop:
|
||||
_tendrilBendTarget = _grabObjectStartPos;
|
||||
_tendrilTargetPos = _grabObject.position += _grabObjectVelocity * Time.deltaTime * (1-_grabTime);
|
||||
_field.SetFloat("_TendrilInfluence", 1);
|
||||
_field.SetFloat("_TendrilSize", TendrilBaseRadius);
|
||||
_field.SetFloat("_TendrilRadius", _grabObjectScale * TendrilTipRadius);
|
||||
break;
|
||||
case TendrilPhase.Pull:
|
||||
_tendrilTargetPos = _grabObject.position = lerp(_grabObjectEndPos.ToCultMath(), transform.position.ToCultMath(), _grabTime*_grabTime).ToUnity();
|
||||
_tendrilBendTarget = lerp(_grabObjectStartPos.ToCultMath(), _grabObjectEndPos.ToCultMath(), _grabTime*_grabTime).ToUnity();
|
||||
if (_fadePoint > .99 && transform.InverseTransformPoint(_grabObject.position).sqrMagnitude < 1)
|
||||
_fadePoint = _grabTime;
|
||||
_field.SetFloat("_TendrilInfluence", pow(smoothstep(1, _fadePoint, _grabTime), TendrilFadeExponent));
|
||||
_field.SetFloat("_TendrilSize", TendrilBaseRadius);
|
||||
_field.SetFloat("_TendrilRadius", _grabObjectScale * TendrilTipRadius);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
var tendrilRadii = EnvelopeRadiiOrFallback();
|
||||
_field.SetVector("_TendrilBase", Vector3.Scale(transform.InverseTransformPoint(_tendrilBasePos).normalized, tendrilRadii));
|
||||
_field.SetVector("_TendrilBend", Vector3.Scale(transform.InverseTransformPoint(_tendrilBendTarget), tendrilRadii));
|
||||
_field.SetVector("_TendrilTarget", Vector3.Scale(transform.InverseTransformPoint(_tendrilTargetPos), tendrilRadii));
|
||||
case GrabPhase.Extend:
|
||||
_tendrilBendTarget = _grabStart;
|
||||
_tendrilTargetPos = lerp(
|
||||
lerp(_grabStartTendrilBase.ToCultMath(), _grabStart.ToCultMath(), _grabTime),
|
||||
_grabStart.ToCultMath(),
|
||||
pow(_grabTime, TendrilExtensionExponent)).ToUnity();
|
||||
_field.SetFloat("_TendrilInfluence", pow(_grabTime, TendrilExtendBaseAnimationExponent));
|
||||
_field.SetFloat("_TendrilSize", lerp(TendrilBaseRadius/2,TendrilBaseRadius,pow(_grabTime, TendrilExtendBaseAnimationExponent)));
|
||||
_field.SetFloat("_TendrilRadius", TendrilTipScale * pow(_grabTime, TendrilTipRadiusAnimationExponent) * TendrilTipRadius);
|
||||
break;
|
||||
case GrabPhase.Envelop:
|
||||
_tendrilBendTarget = _grabStart;
|
||||
_tendrilTargetPos = _grabStart;
|
||||
_field.SetFloat("_TendrilInfluence", 1);
|
||||
_field.SetFloat("_TendrilSize", TendrilBaseRadius);
|
||||
_field.SetFloat("_TendrilRadius", TendrilTipScale * TendrilTipRadius);
|
||||
break;
|
||||
case GrabPhase.Pull:
|
||||
// The same curve as Zone's held pose (Zone.cs): the tip rides the item the simulation pulls in.
|
||||
_tendrilTargetPos = lerp(_grabStart.ToCultMath(), transform.position.ToCultMath(), smoothstep(0, 1, _grabTime)).ToUnity();
|
||||
_tendrilBendTarget = _grabStart;
|
||||
if (_fadePoint > .99 && transform.InverseTransformPoint(_tendrilTargetPos).sqrMagnitude < 1)
|
||||
_fadePoint = _grabTime;
|
||||
_field.SetFloat("_TendrilInfluence", pow(smoothstep(1, _fadePoint, _grabTime), TendrilFadeExponent));
|
||||
_field.SetFloat("_TendrilSize", TendrilBaseRadius);
|
||||
_field.SetFloat("_TendrilRadius", TendrilTipScale * TendrilTipRadius);
|
||||
break;
|
||||
}
|
||||
var tendrilRadii = EnvelopeRadiiOrFallback();
|
||||
_field.SetVector("_TendrilBase", Vector3.Scale(transform.InverseTransformPoint(_tendrilBasePos).normalized, tendrilRadii));
|
||||
_field.SetVector("_TendrilBend", Vector3.Scale(transform.InverseTransformPoint(_tendrilBendTarget), tendrilRadii));
|
||||
_field.SetVector("_TendrilTarget", Vector3.Scale(transform.InverseTransformPoint(_tendrilTargetPos), tendrilRadii));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private float almostIdentity( float x )
|
||||
{
|
||||
return x*x*(2.0f-x);
|
||||
|
|
@ -358,7 +324,7 @@ public class FieldDriver : MonoBehaviour, IAbsorbPresenter, IGrabPresenter, IMel
|
|||
private const int GIZMO_STEPS = 16;
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
if (_grabObject != null)
|
||||
if (_grabbing)
|
||||
{
|
||||
Vector3 previous = _tendrilBasePos;
|
||||
for (int i = 1; i <= GIZMO_STEPS; i++)
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ public class ItemPickup : MonoBehaviour
|
|||
var viewAngle = acos(dot(toThis, ViewDirection)) * Mathf.Rad2Deg;
|
||||
if (length(diff) < LabelDisplayMaxDistance && viewAngle < LabelDisplayAngle)
|
||||
_displayTime = Time.time;
|
||||
if (_floating?.Holder != null) _displayTime = Time.time;
|
||||
var targetAlpha = Time.time - _displayTime < LabelPersistDuration ? 1 : 0;
|
||||
var c = ScanLabel.color;
|
||||
c.a = c.a + sign(targetAlpha - c.a) * (Time.deltaTime / LabelFadeDuration);
|
||||
|
|
|
|||
|
|
@ -1,22 +1,51 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using CultMath.UnityBridge;
|
||||
|
||||
public class TractorBeam : MonoBehaviour
|
||||
// Presents the ship's grab: while the simulation holds an item, the beam looks along the ground-plane vector to the
|
||||
// point the item was held from and emits at Power. Zone pulls the held item along the segment from the ship to that
|
||||
// point (docs/aetheria-release-map.md L11), which is why GrabEvent.TargetPosition on Started is the exact aim and no
|
||||
// pose lookup is needed. Idle, the beam turns with Direction and emits nothing. The simulation decides every grab fact.
|
||||
public class TractorBeam : MonoBehaviour, IGrabPresenter
|
||||
{
|
||||
public ParticleSystem ParticleSystem;
|
||||
public float Radius;
|
||||
public float Traction;
|
||||
public float Distance;
|
||||
|
||||
|
||||
public float Power { get; set; }
|
||||
public Vector3 Direction { get; set; }
|
||||
|
||||
private bool _grabbing;
|
||||
private Vector3 _heldPoint;
|
||||
private Vector3 _heldDirection;
|
||||
|
||||
// Cancelled can carry no position (a vanished item), so only Started is read for one.
|
||||
public void Grab(GrabEvent e)
|
||||
{
|
||||
switch (e.Phase)
|
||||
{
|
||||
case GrabPhase.Started:
|
||||
_grabbing = true;
|
||||
_heldPoint = e.TargetPosition.ToUnity();
|
||||
_heldDirection = Direction;
|
||||
break;
|
||||
case GrabPhase.Completed:
|
||||
case GrabPhase.Cancelled:
|
||||
_grabbing = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
transform.rotation = Quaternion.LookRotation(Direction);
|
||||
// The beam draws nothing until it presents a sim grab (loot-3): no particles, and no pull; the simulation
|
||||
// decides every floating item's motion.
|
||||
var look = Direction;
|
||||
if (_grabbing)
|
||||
{
|
||||
var toHeld = _heldPoint - transform.position;
|
||||
toHeld.y = 0;
|
||||
if (toHeld.sqrMagnitude > 1e-6f) _heldDirection = toHeld;
|
||||
look = _heldDirection;
|
||||
}
|
||||
transform.rotation = Quaternion.LookRotation(look);
|
||||
var emission = ParticleSystem.emission;
|
||||
emission.rateOverTimeMultiplier = 0;
|
||||
emission.rateOverTimeMultiplier = _grabbing ? Power : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue