Present landed impacts: shield ripple, hull reaction and camera kick through one ImpactPresenter
ImpactPresenter (bound on every EntityInstance by SetEntity through the one CapabilityPresentationBinder) renders feedback-1's absorbs: Feedback.Cue decides intensity and shake, DrawAhead.Carried the drawn point; a hull absorb spawns ImpactFeedback's pooled effect under the instance, and a cue with shake raises a Cinemachine impulse. ShieldManager ripples on a Shield-layer absorb. MainMenu gains a Screen Shake slider that persists on Back. Editor: WireImpactFeedback (scene wiring, scene diff in the next commit) and ImpactPresenterSmoke. Unity batchmode compile 0 error CS; ImpactPresenterSmoke exit 0. The scene is not yet wired in this commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
789fe9fcdc
commit
97d94ecfae
11 changed files with 310 additions and 1 deletions
|
|
@ -167,6 +167,13 @@ public class EntityInstance : MonoBehaviour
|
|||
|
||||
if(Shield)
|
||||
Shield.Entity = entity;
|
||||
|
||||
// Landed impacts reach the screen through the entity's one binding: the shield ripple (ShieldManager) and the
|
||||
// hull reaction and camera kick (ImpactPresenter) subscribe to the Absorb stream the simulation publishes.
|
||||
var impacts = gameObject.GetComponent<ImpactPresenter>() ?? gameObject.AddComponent<ImpactPresenter>();
|
||||
impacts.Entity = entity;
|
||||
(gameObject.GetComponent<CapabilityPresentationBinder>() ?? gameObject.AddComponent<CapabilityPresentationBinder>())
|
||||
.Bind(entity.Capabilities);
|
||||
foreach (var hullCollider in HullColliders) hullCollider.Entity = entity;
|
||||
|
||||
foreach (var item in entity.Equipment)
|
||||
|
|
|
|||
39
Assets/Scripts/Gameplay/ImpactFeedback.cs
Normal file
39
Assets/Scripts/Gameplay/ImpactFeedback.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using Cinemachine;
|
||||
using UnityEngine;
|
||||
|
||||
// Presentation tuning for landed impacts (ImpactPresenter reads it, nothing in the simulation does): the hull
|
||||
// reaction's effect prefab and size, how strongly a hit's share of the hull reads (Feedback.Cue's intensityScale),
|
||||
// and the camera impulse. A scene component, so the scene is where it is tuned; absent in menus and test scenes,
|
||||
// where ImpactPresenter does nothing.
|
||||
public class ImpactFeedback : MonoBehaviour
|
||||
{
|
||||
public static ImpactFeedback Instance { get; private set; }
|
||||
|
||||
// A scene instance of a pooled hit effect (Prototype); a hit spawns one under the struck EntityInstance.
|
||||
public Prototype HullEffect;
|
||||
|
||||
// Multiplies a hit's share of the receiver's max durability before it saturates to 0..1 (Feedback.Cue).
|
||||
public float IntensityScale = 10f;
|
||||
|
||||
// The effect's scale never drops below this, so the lightest hit still reads.
|
||||
public float MinEffectScale = .3f;
|
||||
|
||||
public CinemachineImpulseDefinition Impulse = new CinemachineImpulseDefinition();
|
||||
|
||||
// Impulses raised since the scene loaded; the batchmode smoke reads it.
|
||||
public int KicksRaised { get; private set; }
|
||||
|
||||
private void Awake() => Instance = this;
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (Instance == this) Instance = null;
|
||||
}
|
||||
|
||||
// Raises one camera impulse of the given force, travelling along `direction` from `position`.
|
||||
public void Kick(Vector3 position, Vector3 direction, float force)
|
||||
{
|
||||
KicksRaised++;
|
||||
Impulse.CreateEvent(position, direction.normalized * force);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Gameplay/ImpactFeedback.cs.meta
Normal file
2
Assets/Scripts/Gameplay/ImpactFeedback.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bfdc38a81d00b0347bb55ad6469535ff
|
||||
47
Assets/Scripts/Gameplay/ImpactPresenter.cs
Normal file
47
Assets/Scripts/Gameplay/ImpactPresenter.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using System.Collections.Generic;
|
||||
using CultMath.UnityBridge;
|
||||
using UnityEngine;
|
||||
|
||||
// How one entity's landed impacts look and feel: the hull reaction at the drawn impact point, and the player's camera
|
||||
// kick. The simulation publishes each impact once on the entity's Capabilities (FireControl); Feedback.Cue decides how
|
||||
// hard it reads and whether the camera feels it, DrawAhead.Carried decides where it is drawn; this decides nothing.
|
||||
// The shield ripple is ShieldManager's. Everything here is display-only and runs in real time.
|
||||
public class ImpactPresenter : MonoBehaviour, IAbsorbPresenter
|
||||
{
|
||||
public Entity Entity;
|
||||
|
||||
private readonly List<Prototype> _live = new List<Prototype>();
|
||||
|
||||
public void Absorb(AbsorbEvent e)
|
||||
{
|
||||
var feedback = ImpactFeedback.Instance;
|
||||
if (feedback == null || Entity == null) return;
|
||||
|
||||
var manager = ActionGameManager.Instance;
|
||||
var cue = Feedback.Cue(e, Entity.EquippedHull.Data.Durability,
|
||||
manager != null && Entity == manager.CurrentEntity,
|
||||
ActionGameManager.PlayerSettings.GraphicsSettings.ScreenShake, feedback.IntensityScale);
|
||||
var point = DrawAhead.Carried(Entity, cue.Position, ActionGameManager.Clock.Lead).ToUnity();
|
||||
|
||||
if (e.Layer == AbsorbLayer.Hull && feedback.HullEffect != null)
|
||||
{
|
||||
_live.RemoveAll(live => live == null || !live.gameObject.activeSelf);
|
||||
var effect = feedback.HullEffect.Instantiate<Prototype>();
|
||||
var size = Mathf.Max(feedback.MinEffectScale, cue.Intensity);
|
||||
effect.transform.SetParent(transform, false);
|
||||
effect.transform.position = point;
|
||||
effect.transform.localScale = Vector3.one * (size / Mathf.Max(transform.lossyScale.x, 1e-3f));
|
||||
_live.Add(effect);
|
||||
}
|
||||
|
||||
if (cue.Shake > 0f)
|
||||
feedback.Kick(point, new Vector3(cue.Direction.x, 0f, cue.Direction.z), cue.Shake);
|
||||
}
|
||||
|
||||
// A live effect is a pooled child of this instance; hand it back before the instance takes it down with it.
|
||||
private void OnDestroy()
|
||||
{
|
||||
foreach (var live in _live)
|
||||
if (live != null && live.gameObject.activeSelf) live.ReturnToPool();
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Gameplay/ImpactPresenter.cs.meta
Normal file
2
Assets/Scripts/Gameplay/ImpactPresenter.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 775c61f785344d54b9f41ad3328cecee
|
||||
|
|
@ -8,7 +8,7 @@ using static CultMath.math;
|
|||
using UniRx;
|
||||
using UnityEngine;
|
||||
|
||||
public class ShieldManager : MonoBehaviour
|
||||
public class ShieldManager : MonoBehaviour, IAbsorbPresenter
|
||||
{
|
||||
public Prototype ShieldPrototype;
|
||||
public float CollisionHitDuration = 3;
|
||||
|
|
@ -86,6 +86,14 @@ public class ShieldManager : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
// A shot the shield took ripples it where the shot landed, drawn on the hull as it is drawn. The hull layer is
|
||||
// ImpactPresenter's.
|
||||
public void Absorb(AbsorbEvent e)
|
||||
{
|
||||
if (e.Layer != AbsorbLayer.Shield || Entity == null || Entity.Shield == null || !Entity.Shield.Item.Active.Value) return;
|
||||
ShowHit(DrawAhead.Carried(Entity, e.Position, ActionGameManager.Clock.Lead).ToUnity(), CollisionHitDuration);
|
||||
}
|
||||
|
||||
public void ShowHit(Vector3 point, float duration)
|
||||
{
|
||||
var shield = ShieldPrototype.Instantiate<ShieldAnimation>();
|
||||
|
|
|
|||
Loading…
Reference in a new issue