2021-04-15 04:25:22 +01:00
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
2026-10-13 18:43:15 +02:00
|
|
|
using CultMath.UnityBridge;
|
2021-04-15 04:25:22 +01:00
|
|
|
|
2026-10-13 18:43:15 +02:00
|
|
|
// 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
|
2021-04-15 04:25:22 +01:00
|
|
|
{
|
|
|
|
|
public ParticleSystem ParticleSystem;
|
2026-10-13 18:43:15 +02:00
|
|
|
|
2021-04-15 04:25:22 +01:00
|
|
|
public float Power { get; set; }
|
|
|
|
|
public Vector3 Direction { get; set; }
|
|
|
|
|
|
2026-10-13 18:43:15 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-15 04:25:22 +01:00
|
|
|
public void Update()
|
|
|
|
|
{
|
2026-10-13 18:43:15 +02:00
|
|
|
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);
|
2021-04-15 04:25:22 +01:00
|
|
|
var emission = ParticleSystem.emission;
|
2026-10-13 18:43:15 +02:00
|
|
|
emission.rateOverTimeMultiplier = _grabbing ? Power : 0;
|
2021-04-15 04:25:22 +01:00
|
|
|
}
|
2026-10-13 18:43:15 +02:00
|
|
|
}
|