Skip to content

Commit

Permalink
Add colorpalette to damage popups, add damage popups to HUD
Browse files Browse the repository at this point in the history
  • Loading branch information
Fueredoriku committed Dec 24, 2024
1 parent 69240de commit be8bd35
Show file tree
Hide file tree
Showing 10 changed files with 633 additions and 246 deletions.
23 changes: 21 additions & 2 deletions Assets/Prefabs/Input/Player.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
damagePopup: {fileID: 3456343568974069144, guid: 216963e07a2087cc99a5e9c4e6b0454e, type: 3}
healthController: {fileID: 0}
isOwnerOnly: 0
--- !u!114 &8692423856261334150
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1552,6 +1554,7 @@ GameObject:
- component: {fileID: 8513528357214213258}
- component: {fileID: 1876285937171696916}
- component: {fileID: 2367956686065937511}
- component: {fileID: 8639708736638023490}
m_Layer: 5
m_Name: HealthHud
m_TagString: Untagged
Expand Down Expand Up @@ -1641,6 +1644,21 @@ SpriteRenderer:
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!114 &8639708736638023490
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3099507315220960622}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8df77ee5e94e96a21a1c251683e0d3a7, type: 3}
m_Name:
m_EditorClassIdentifier:
damagePopup: {fileID: 3456343568974069144, guid: 5c078cb9f2f563048a6541bfcea977b9, type: 3}
healthController: {fileID: 6717855691676836013}
isOwnerOnly: 1
--- !u!1 &3124495339848130259
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1723,6 +1741,7 @@ MonoBehaviour:
spectatorTargetText: {fileID: 5857550089673397807}
damageBorderFlashDuration: 0.2
popupSpammer: {fileID: 6535424167945181997}
damagePopupEmitter: {fileID: 0}
speedLines: {fileID: 1712702864845135441}
speedLineEase:
serializedVersion: 2
Expand Down Expand Up @@ -3431,10 +3450,10 @@ SpriteRenderer:
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RenderingLayerMask: 4
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 2100000, guid: 0ae925ac9e062854c9254d87fa608379, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
Expand Down
220 changes: 220 additions & 0 deletions Assets/Prefabs/UI/DamagePopupHUD.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2974520026730963027
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3748194351601288369}
- component: {fileID: 2158285029245345615}
- component: {fileID: 3456343568974069144}
m_Layer: 5
m_Name: DamagePopupHUD
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &3748194351601288369
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2974520026730963027}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.065, y: 0.065, z: 0.065}
m_ConstrainProportionsScale: 1
m_Children:
- {fileID: 1314711177337031033}
m_Father: {fileID: 0}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0.5}
m_SizeDelta: {x: 100, y: 10}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!223 &2158285029245345615
Canvas:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2974520026730963027}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 2
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_VertexColorAlwaysGammaSpace: 0
m_AdditionalShaderChannelsFlag: 25
m_UpdateRectTransformForStandalone: 0
m_SortingLayerID: 1056283955
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!114 &3456343568974069144
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2974520026730963027}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 668d5ec3f37469ffba85b5699368e1e3, type: 3}
m_Name:
m_EditorClassIdentifier:
label: {fileID: 3771122092874266332}
scaleMultiplier: 2
lowDamage: 10
highDamage: 70
normalLowColor: {r: 1, g: 1, b: 1, a: 1}
normalHighColor: {r: 0.94509804, g: 0.9032764, b: 0.45098042, a: 1}
criticalLowColor: {r: 0.6344173, g: 0.9716981, b: 0.55460125, a: 1}
criticalHighColor: {r: 0.22903016, g: 0.8301887, b: 0.08223567, a: 1}
isHUD: 1
--- !u!1 &7123424410564671507
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1314711177337031033}
- component: {fileID: 6385217241309795779}
- component: {fileID: 3771122092874266332}
m_Layer: 5
m_Name: Damage
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1314711177337031033
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7123424410564671507}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 1
m_Children: []
m_Father: {fileID: 3748194351601288369}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 5}
m_SizeDelta: {x: 100, y: 10}
m_Pivot: {x: 0.5, y: 1}
--- !u!222 &6385217241309795779
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7123424410564671507}
m_CullTransparentMesh: 1
--- !u!114 &3771122092874266332
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7123424410564671507}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: 20
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 72b62df8bbd2d494eb26e2df684260be, type: 2}
m_sharedMaterial: {fileID: -1782873873408761557, guid: 72b62df8bbd2d494eb26e2df684260be, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 12
m_fontSizeBase: 12
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 1
m_HorizontalAlignment: 2
m_VerticalAlignment: 4096
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
7 changes: 7 additions & 0 deletions Assets/Prefabs/UI/DamagePopupHUD.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/Scripts/Gamestate/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private void UpdateAimAngleRpc(float yAngle)
private void OnDamageTaken(HealthController healthController, float damage, DamageInfo info)
{
if (hudController)
hudController.OnDamageTaken(healthController.CurrentHealth, healthController.MaxHealth);
hudController.OnDamageTaken(healthController.CurrentHealth, healthController.MaxHealth, damage);

if (info.damageType == DamageType.Explosion)
ScreenShake(info.damage * 0.005f);
Expand Down
58 changes: 29 additions & 29 deletions Assets/Scripts/Interactables/DamagePopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,58 @@ public class DamagePopup : MonoBehaviour
private TMP_Text label;

[SerializeField]
private float lowDamage = 20;
private float scaleMultiplier = 2f;

[SerializeField]
private float highDamage = 80;

[SerializeField]
private Color normalLowColor;

[SerializeField]
private Color normalHighColor;

[SerializeField]
private Color criticalLowColor;

[SerializeField]
private Color criticalHighColor;
private bool isHUD = false;

public Transform Camera { get; set; }

private float lastDamage;

public float Damage
{
set
{
label.text = Mathf.RoundToInt(value).ToString();
label.text = isHUD
? $"-{Mathf.RoundToInt(value)}%"
: Mathf.RoundToInt(value).ToString();
lastDamage = value;
}
get
{
return int.Parse(label.text);
return lastDamage;
}
}

public bool IsCritical { get; set; }

private void Start()
{
label.color = DetermineColor();
if (IsCritical && !isHUD)
LeanTween.sequence()
.append(LeanTween.value(gameObject, (Color value) => label.color = value, ColorPallete.HealthPalette(1), ColorPallete.HealthPalette(0.2f), 0.5f).setEasePunch())
.append(LeanTween.value(gameObject, (float value) => label.color = ColorPallete.HealthPalette(value), 1, 0, 1f).setEaseInOutExpo());
else
LeanTween.value(gameObject, (Color value) => label.color = value, Color.white, ColorPallete.HealthPalette(0.2f), 1f).setEasePunch();

var scale = transform.lossyScale;
LeanTween.sequence()
.append(LeanTween.moveY(gameObject, transform.position.y + 1f, .2f).setEaseInOutExpo())
.append(LeanTween.scale(gameObject, scale * 2f, .4f).setEasePunch())
.insert(LeanTween.moveY(gameObject, transform.position.y + 2f, 1).setEaseInOutExpo())
.append(LeanTween.scale(gameObject, Vector3.zero, .2f).setEaseOutQuad()
.setOnComplete(() => Destroy(gameObject)));
if (isHUD)
LeanTween.sequence()
.append(LeanTween.moveLocalY(gameObject, transform.localPosition.y + 1, .2f).setEaseInOutExpo())
.append(LeanTween.scale(gameObject, scale * scaleMultiplier, .4f).setEasePunch())
.insert(LeanTween.moveLocalY(gameObject, transform.localPosition.y + 2, 1).setEaseInOutExpo())
.append(LeanTween.scale(gameObject, Vector3.zero, .2f).setEaseOutQuad()
.setOnComplete(() => Destroy(gameObject)));
else
LeanTween.sequence()
.append(LeanTween.moveY(gameObject, transform.position.y + 1f, .2f).setEaseInOutExpo())
.append(LeanTween.scale(gameObject, scale * scaleMultiplier, .4f).setEasePunch())
.insert(LeanTween.moveY(gameObject, transform.position.y + 2f, 1).setEaseInOutExpo())
.append(LeanTween.scale(gameObject, Vector3.zero, .2f).setEaseOutQuad()
.setOnComplete(() => Destroy(gameObject)));
}

private Color DetermineColor() =>
IsCritical
? Color.Lerp(criticalLowColor, criticalHighColor, (Damage - lowDamage) / highDamage)
: Color.Lerp(normalLowColor, normalHighColor, (Damage - lowDamage) / highDamage);


private void Update()
{
if (Camera)
Expand Down
Loading

0 comments on commit be8bd35

Please sign in to comment.