Added RocketAssemblyStation and ReadyRocket
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
public sealed class RocketItemView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private NetworkRocketItem rocket;
|
||||
|
||||
[Header("State")]
|
||||
[SerializeField] private UnityEvent onNormalQualityApplied;
|
||||
[SerializeField] private UnityEvent onDefectiveQualityApplied;
|
||||
[SerializeField] private UnityEvent onDamagedStateApplied;
|
||||
|
||||
[Header("Critical Impact")]
|
||||
[SerializeField] private UnityEvent onCriticalImpact;
|
||||
[SerializeField] private UnityEvent<Vector3> onCriticalImpactPoint;
|
||||
[SerializeField] private UnityEvent<float> onCriticalImpactSpeed;
|
||||
|
||||
private uint observedImpactSequence;
|
||||
private RocketAssemblyQuality observedQuality;
|
||||
private bool hasAppliedQuality;
|
||||
private bool hasAppliedDamagedState;
|
||||
|
||||
private void Reset() => rocket = GetComponentInParent<NetworkRocketItem>();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (rocket == null)
|
||||
rocket = GetComponentInParent<NetworkRocketItem>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (rocket == null)
|
||||
return;
|
||||
|
||||
observedImpactSequence = rocket.CriticalImpactSequence;
|
||||
observedQuality = rocket.AssemblyQuality;
|
||||
hasAppliedQuality = false;
|
||||
hasAppliedDamagedState = false;
|
||||
rocket.Changed += ApplyState;
|
||||
rocket.CriticalImpact += HandleCriticalImpact;
|
||||
ApplyState();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (rocket == null)
|
||||
return;
|
||||
|
||||
rocket.Changed -= ApplyState;
|
||||
rocket.CriticalImpact -= HandleCriticalImpact;
|
||||
}
|
||||
|
||||
[ContextMenu("Preview/Critical Impact")]
|
||||
private void PreviewCriticalImpact()
|
||||
{
|
||||
onCriticalImpactPoint?.Invoke(transform.position);
|
||||
onCriticalImpactSpeed?.Invoke(7f);
|
||||
onCriticalImpact?.Invoke();
|
||||
onDamagedStateApplied?.Invoke();
|
||||
}
|
||||
|
||||
[ContextMenu("Preview/Normal Quality")]
|
||||
private void PreviewNormalQuality() => onNormalQualityApplied?.Invoke();
|
||||
|
||||
[ContextMenu("Preview/Defective Quality")]
|
||||
private void PreviewDefectiveQuality() => onDefectiveQualityApplied?.Invoke();
|
||||
|
||||
private void ApplyState()
|
||||
{
|
||||
if (rocket == null)
|
||||
return;
|
||||
|
||||
if (!hasAppliedQuality || observedQuality != rocket.AssemblyQuality)
|
||||
{
|
||||
observedQuality = rocket.AssemblyQuality;
|
||||
hasAppliedQuality = true;
|
||||
if (observedQuality == RocketAssemblyQuality.Defective)
|
||||
onDefectiveQualityApplied?.Invoke();
|
||||
else
|
||||
onNormalQualityApplied?.Invoke();
|
||||
}
|
||||
|
||||
if (rocket.IsCriticallyDamaged && !hasAppliedDamagedState)
|
||||
{
|
||||
hasAppliedDamagedState = true;
|
||||
onDamagedStateApplied?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleCriticalImpact()
|
||||
{
|
||||
if (rocket == null || rocket.CriticalImpactSequence == observedImpactSequence)
|
||||
return;
|
||||
|
||||
observedImpactSequence = rocket.CriticalImpactSequence;
|
||||
onCriticalImpactPoint?.Invoke(rocket.LastCriticalImpactPoint);
|
||||
onCriticalImpactSpeed?.Invoke(rocket.LastCriticalImpactSpeed);
|
||||
onCriticalImpact?.Invoke();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user