4 protected const float UNCONSCIOUS_EFFECT_DURATION = 0.5;
5 protected const float UNCONSCIOUS_FADEOUT_DURATION = 0.8;
6 protected const float UNCONSCIOUS_OSCILIATION_OVERSHOOT = 0.2;
7 protected const float UNCONSCIOUS_ALPHAMASK_MIN = 0.4;
8 protected const float UNCONSCIOUS_ALPHAMASK_MAX = 0.7;
9 protected const float UNCONSCIOUS_OPACITY_DIFF = 0.05;
12 protected bool m_bOverUnder;
13 protected WidgetAnimationBase m_UnconMaskAnim;
14 protected ImageWidget m_wDeath;
18 protected ChimeraCharacter m_pCharacterEntity;
20 [
Attribute(
"0", UIWidgets.ComboBox,
"Which curve shape should be used for lerping the effect in",
"", ParamEnumArray.FromEnum(EAnimationCurve)) ]
21 EAnimationCurve m_eUnconsciousEffectAnimIn;
23 [
Attribute(
"0", UIWidgets.ComboBox,
"Which curve shape should be used for lerping the effect out",
"", ParamEnumArray.FromEnum(EAnimationCurve)) ]
24 EAnimationCurve m_eUnconsciousEffectAnimOut;
27 override void DisplayStartDraw(IEntity owner)
29 m_pCharacterEntity = ChimeraCharacter.Cast(owner);
30 m_wDeath = ImageWidget.Cast(
m_wRoot.FindAnyWidget(
"DeathOverlay"));
34 override void DisplayControlledEntityChanged(IEntity from, IEntity to)
38 m_pCharacterEntity = ChimeraCharacter.Cast(to);
39 if (!m_pCharacterEntity)
45 CharacterControllerComponent controller = m_pCharacterEntity.GetCharacterController();
47 DisplayConsciousnessChanged(
false);
51 protected override void DisplayConsciousnessChanged(
bool conscious,
bool init =
false)
53 UnconsciousnessEffect(conscious);
57 protected void UnconsciousnessEffect(
bool conscious)
60 PlayUnconAnim(UNCONSCIOUS_EFFECT_DURATION);
66 protected void PlayUnconAnim(
float speed)
74 m_wDeath.SetVisible(
true);
75 m_bOverUnder = !m_bOverUnder;
77 float unconProgress = 1 - GetUnconProgress();
79 EAnimationCurve curve;
83 curve = m_eUnconsciousEffectAnimIn;
84 targetProgress = unconProgress + (unconProgress * UNCONSCIOUS_OSCILIATION_OVERSHOOT);
85 AnimateWidget.Opacity(m_wDeath, 1, speed);
89 curve = m_eUnconsciousEffectAnimOut;
90 targetProgress = unconProgress - (unconProgress * UNCONSCIOUS_OSCILIATION_OVERSHOOT);
91 AnimateWidget.Opacity(m_wDeath, 1 - UNCONSCIOUS_OPACITY_DIFF, speed);
94 m_UnconMaskAnim = AnimateWidget.AlphaMask(m_wDeath, Math.Lerp(UNCONSCIOUS_ALPHAMASK_MIN, UNCONSCIOUS_ALPHAMASK_MAX, targetProgress), speed);
95 m_UnconMaskAnim.SetCurve(curve);
98 m_UnconMaskAnim.GetOnCompleted().Insert(OnAnimCycleComplete);
102 protected void OnAnimCycleComplete(WidgetAnimationBase anim)
107 anim.GetOnCycleCompleted().Remove(OnAnimCycleComplete);
110 GetGame().GetCallqueue().CallLater(PlayUnconAnim, param1: UNCONSCIOUS_EFFECT_DURATION);
114 protected float GetUnconProgress()
116 if (!m_pDamageManager)
119 SCR_CharacterResilienceHitZone resilience = SCR_CharacterResilienceHitZone.Cast(m_pDamageManager.GetResilienceHitZone());
124 if (blood && blood.GetHealthScaled() < blood.GetDamageStateThreshold(
ECharacterBloodState.UNCONSCIOUS))
127 return Math.Lerp(0, resilience.GetDamageStateThreshold(
ECharacterResilienceState.WEAKENED), resilience.GetHealthScaled());
131 protected void StopUnconAnim()
134 m_UnconMaskAnim.GetOnCycleCompleted().Remove(OnAnimCycleComplete);
139 AnimateWidget.AlphaMask(m_wDeath, 0, UNCONSCIOUS_FADEOUT_DURATION);
140 AnimateWidget.Opacity(m_wDeath, 0, UNCONSCIOUS_FADEOUT_DURATION);
144 protected override void ClearEffects()
147 m_UnconMaskAnim.GetOnCycleCompleted().Remove(OnAnimCycleComplete);
151 AnimateWidget.StopAllAnimations(m_wDeath);
152 m_wDeath.SetOpacity(0);
153 m_wDeath.SetMaskProgress(0);