From 21be792b6a53069fcc585fbe63595c48b8953a92 Mon Sep 17 00:00:00 2001 From: Fredrik Lillemoen Eiding Date: Thu, 26 Dec 2024 14:02:53 +0100 Subject: [PATCH] Add colorpalette to damage popups, add damage popups to HUD --- Assets/Prefabs/Input/Player.prefab | 23 +- Assets/Prefabs/UI/DamagePopupHUD.prefab | 220 +++++++++ Assets/Prefabs/UI/DamagePopupHUD.prefab.meta | 7 + Assets/Scripts/Gamestate/PlayerManager.cs | 2 +- Assets/Scripts/Interactables/DamagePopup.cs | 58 +-- .../Interactables/DamagePopupEmitter.cs | 36 +- Assets/Scripts/UI/PlayerHUDController.cs | 32 +- Assets/Scripts/Utils/ColorPallete.cs | 24 + Assets/Scripts/Utils/ColorPallete.cs.meta | 11 + Assets/Shaders/HealthBar.shadergraph | 464 +++++++++++------- 10 files changed, 631 insertions(+), 246 deletions(-) create mode 100644 Assets/Prefabs/UI/DamagePopupHUD.prefab create mode 100644 Assets/Prefabs/UI/DamagePopupHUD.prefab.meta create mode 100644 Assets/Scripts/Utils/ColorPallete.cs create mode 100644 Assets/Scripts/Utils/ColorPallete.cs.meta diff --git a/Assets/Prefabs/Input/Player.prefab b/Assets/Prefabs/Input/Player.prefab index f0964c393..5f7a685b7 100644 --- a/Assets/Prefabs/Input/Player.prefab +++ b/Assets/Prefabs/Input/Player.prefab @@ -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 @@ -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 @@ -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 @@ -1723,6 +1741,7 @@ MonoBehaviour: spectatorTargetText: {fileID: 5857550089673397807} damageBorderFlashDuration: 0.2 popupSpammer: {fileID: 6535424167945181997} + damagePopupEmitter: {fileID: 0} speedLines: {fileID: 1712702864845135441} speedLineEase: serializedVersion: 2 @@ -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 diff --git a/Assets/Prefabs/UI/DamagePopupHUD.prefab b/Assets/Prefabs/UI/DamagePopupHUD.prefab new file mode 100644 index 000000000..bec1fb364 --- /dev/null +++ b/Assets/Prefabs/UI/DamagePopupHUD.prefab @@ -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} diff --git a/Assets/Prefabs/UI/DamagePopupHUD.prefab.meta b/Assets/Prefabs/UI/DamagePopupHUD.prefab.meta new file mode 100644 index 000000000..9c85113ec --- /dev/null +++ b/Assets/Prefabs/UI/DamagePopupHUD.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5c078cb9f2f563048a6541bfcea977b9 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Gamestate/PlayerManager.cs b/Assets/Scripts/Gamestate/PlayerManager.cs index ec567fe31..9cdf55529 100644 --- a/Assets/Scripts/Gamestate/PlayerManager.cs +++ b/Assets/Scripts/Gamestate/PlayerManager.cs @@ -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); diff --git a/Assets/Scripts/Interactables/DamagePopup.cs b/Assets/Scripts/Interactables/DamagePopup.cs index 8e8be7d12..83a14d1d3 100644 --- a/Assets/Scripts/Interactables/DamagePopup.cs +++ b/Assets/Scripts/Interactables/DamagePopup.cs @@ -7,34 +7,27 @@ 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; } } @@ -42,23 +35,30 @@ public float Damage private void Start() { - label.color = DetermineColor(); + if (IsCritical && !isHUD) + LeanTween.sequence() + .append(LeanTween.value(gameObject, (Color value) => label.color = value, ColorPallete.Health(1), ColorPallete.Health(0.2f), 0.5f).setEasePunch()) + .append(LeanTween.value(gameObject, (float value) => label.color = ColorPallete.Health(value), 1, 0, 1f).setEaseInOutExpo()); + else + LeanTween.value(gameObject, (Color value) => label.color = value, Color.white, ColorPallete.Health(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) diff --git a/Assets/Scripts/Interactables/DamagePopupEmitter.cs b/Assets/Scripts/Interactables/DamagePopupEmitter.cs index 44bde0960..0c61ef295 100644 --- a/Assets/Scripts/Interactables/DamagePopupEmitter.cs +++ b/Assets/Scripts/Interactables/DamagePopupEmitter.cs @@ -4,18 +4,22 @@ public class DamagePopupEmitter : MonoBehaviour { [SerializeField] private DamagePopup damagePopup; - + [SerializeField] private HealthController healthController; + [SerializeField] + private bool isOwnerOnly = false; private void Start() { - healthController = GetComponent(); + if (healthController == null) + healthController = GetComponent(); healthController.onDamageTaken += OnHit; } - private void Destroy() + private void OnDestroy() { - healthController.onDamageTaken -= OnHit; + if (healthController) + healthController.onDamageTaken -= OnHit; } private void OnHit(HealthController healthController, float damage, DamageInfo info) @@ -24,15 +28,25 @@ private void OnHit(HealthController healthController, float damage, DamageInfo i return; var horizontalAxis = Vector3.Cross(info.force.normalized, Vector3.up); var position = info.position + Vector3.up * Random.Range(.5f, .8f) + horizontalAxis * Random.Range(-.2f, .2f); - var popup = Instantiate(damagePopup, position, Quaternion.identity); + DamagePopup popup; + + if (isOwnerOnly && healthController.Player.inputManager) + { + popup = Instantiate(damagePopup, transform); + popup.gameObject.layer = LayerMask.NameToLayer("Gun " + healthController.Player.inputManager.playerInput.playerIndex); + } + else + { + popup = Instantiate(damagePopup, position, Quaternion.identity); - // Real players can only see their own damage numbers, all players can see AI damage numbers - // A player victim by AI damage cannot see damage done to them by AI popup (would obscure vision) - bool isPlayer = info.sourcePlayer && info.sourcePlayer.inputManager; - popup.gameObject.layer = isPlayer ? - LayerMask.NameToLayer("Gun " + info.sourcePlayer.inputManager.playerInput.playerIndex) : gameObject.layer; + // Real players can only see their own damage numbers, all players can see AI damage numbers + // A player victim by AI damage cannot see damage done to them by AI popup (would obscure vision) + bool isPlayer = info.sourcePlayer && info.sourcePlayer.inputManager; + popup.gameObject.layer = isPlayer ? + LayerMask.NameToLayer("Gun " + info.sourcePlayer.inputManager.playerInput.playerIndex) : gameObject.layer; + popup.Camera = info.sourcePlayer.GunHolder.transform; + } - popup.Camera = info.sourcePlayer.GunHolder.transform; popup.Damage = damage; popup.IsCritical = info.isCritical; } diff --git a/Assets/Scripts/UI/PlayerHUDController.cs b/Assets/Scripts/UI/PlayerHUDController.cs index 6177e9bf6..f7b0d2d24 100644 --- a/Assets/Scripts/UI/PlayerHUDController.cs +++ b/Assets/Scripts/UI/PlayerHUDController.cs @@ -157,7 +157,7 @@ void Start() chipBox.anchoredPosition = new Vector2(originalChipX, -originalChipY); healthBarScaleX = healthBar.transform.localScale.x; - healthBar.material.SetColor("_Color", HealthPalette(1f)); + healthBar.material.SetColor("_Color", ColorPallete.Health(1f)); healthTextPosition = healthText.transform.localPosition; crosshair.rectTransform.sizeDelta *= SettingsDataManager.Singleton.Data.CrosshairSize; @@ -206,7 +206,7 @@ public void AnimateHudJump() .id; } - public void OnDamageTaken(float currentHealth, float maxHealth) + public void OnDamageTaken(float currentHealth, float maxHealth, float damage) { UpdateHealthBar(currentHealth, maxHealth); LeanTween.value(gameObject, UpdateDamageBorder, 0f, 1f, damageBorderFlashDuration); @@ -270,8 +270,9 @@ private void UpdateHealthBar(float currentHealth, float maxHealth) if (width > 0) width = Mathf.Max(width, 0.001f); - LeanTween.value(healthBar.gameObject, SetHealthBar, healthBar.transform.localScale.x, width, tweenDuration); - healthBar.material.SetColor("_Color", HealthPalette(Mathf.Max(currentHealth, 0) / maxHealth)); + LeanTween.value(healthBar.gameObject, SetHealthBar, healthBar.transform.localScale.x, width, tweenDuration).setEaseInOutExpo(); + healthBar.material.SetColor("_Color", ColorPallete.Health(Mathf.Max(currentHealth, 0) / maxHealth)); + LeanTween.value(healthBar.gameObject, SetHealthBarSine, 3f, 3f, 0.5f).setEasePunch(); } private void SetHealthBar(float width) @@ -279,6 +280,11 @@ private void SetHealthBar(float width) healthBar.transform.localScale = new Vector3(width, healthBar.transform.localScale.y, healthBar.transform.localScale.z); } + private void SetHealthBarSine(float value) + { + healthBar.material.SetFloat("_SineSpeed", value); + } + public void TweenScope(float alpha, float seconds) { if (LeanTween.isTweening(scopeTween)) @@ -406,22 +412,4 @@ public void UpdateOnInitialize(GunStats stats) else crosshairMaterial.EnableKeyword("_MODE_" + mode.ToString().ToUpper()); } - - // Implementation based of https://iquilezles.org/articles/palettes/ - // Health is expected to be normalized. - public Color HealthPalette(float health) - { - health = Mathf.SmoothStep(0.25f, 0.68f, health); - Vector3 contrast = new Vector3(0.6f, 0.6f, 0f); - Vector3 brightness = new Vector3(0.6f, 0.3f, 0.5f); - Vector3 oscilations = new Vector3(0.9f, 0.9f, 0f); - Vector3 phase = new Vector3(0.69f, 0.35f, 0.6f); - Vector3 octave = Mathf.PI * 2f * (oscilations * health + phase); - Vector3 rgb = new Vector3(Mathf.Cos(octave.x), Mathf.Cos(octave.y), Mathf.Cos(octave.z)); - Vector3 palette = contrast + new Vector3( - brightness.x * rgb.x, - brightness.y * rgb.y, - brightness.z * rgb.z); - return new Color(palette.x, palette.y, palette.z); - } } diff --git a/Assets/Scripts/Utils/ColorPallete.cs b/Assets/Scripts/Utils/ColorPallete.cs new file mode 100644 index 000000000..87ef2cf20 --- /dev/null +++ b/Assets/Scripts/Utils/ColorPallete.cs @@ -0,0 +1,24 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ColorPallete +{ + // Implementation based of https://iquilezles.org/articles/palettes/ + // Health is expected to be normalized. + public static Color Health(float health) + { + health = Mathf.SmoothStep(0.25f, 0.68f, health); + Vector3 contrast = new Vector3(0.6f, 0.6f, 0f); + Vector3 brightness = new Vector3(0.6f, 0.3f, 0.5f); + Vector3 oscillations = new Vector3(0.9f, 0.9f, 0f); + Vector3 phase = new Vector3(0.69f, 0.35f, 0.6f); + Vector3 octave = Mathf.PI * 2f * (oscillations * health + phase); + Vector3 rgb = new Vector3(Mathf.Cos(octave.x), Mathf.Cos(octave.y), Mathf.Cos(octave.z)); + Vector3 palette = contrast + new Vector3( + brightness.x * rgb.x, + brightness.y * rgb.y, + brightness.z * rgb.z); + return new Color(palette.x, palette.y, palette.z); + } +} diff --git a/Assets/Scripts/Utils/ColorPallete.cs.meta b/Assets/Scripts/Utils/ColorPallete.cs.meta new file mode 100644 index 000000000..64235bb13 --- /dev/null +++ b/Assets/Scripts/Utils/ColorPallete.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dadb9bc533df2c5478b259769487dcea +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Shaders/HealthBar.shadergraph b/Assets/Shaders/HealthBar.shadergraph index fd9f73ba0..fd20fb2bb 100644 --- a/Assets/Shaders/HealthBar.shadergraph +++ b/Assets/Shaders/HealthBar.shadergraph @@ -8,6 +8,9 @@ }, { "m_Id": "1f53faf21fc44b7c9c0a3a289fca9745" + }, + { + "m_Id": "bd7dd6ceff3c405e8e4350f1a31abbb4" } ], "m_Keywords": [], @@ -82,7 +85,10 @@ "m_Id": "c46af436ff68473783aa4b557936bf45" }, { - "m_Id": "8376a1e400b0461298196a5bc920de11" + "m_Id": "e4319ca600774fa1903bba83a80e3cbe" + }, + { + "m_Id": "b767f1a5ffbb48868ea32897fd4b342a" } ], "m_GroupDatas": [], @@ -203,41 +209,41 @@ { "m_OutputSlot": { "m_Node": { - "m_Id": "8376a1e400b0461298196a5bc920de11" + "m_Id": "84cf264301be4ad39ab6fcb2410ce835" }, - "m_SlotId": 2 + "m_SlotId": 3 }, "m_InputSlot": { "m_Node": { - "m_Id": "e3479dd8f41c40938ad9d8066d23bc44" + "m_Id": "e3eef6ffaee8477b9132592da26e13cf" }, - "m_SlotId": 1 + "m_SlotId": 0 } }, { "m_OutputSlot": { "m_Node": { - "m_Id": "84cf264301be4ad39ab6fcb2410ce835" + "m_Id": "8ec7baac72a445eb8a129137413759f6" }, - "m_SlotId": 3 + "m_SlotId": 2 }, "m_InputSlot": { "m_Node": { - "m_Id": "e3eef6ffaee8477b9132592da26e13cf" + "m_Id": "bdf1253c9dda4fb8a8e15e531bf26d21" }, - "m_SlotId": 0 + "m_SlotId": 1 } }, { "m_OutputSlot": { "m_Node": { - "m_Id": "8ec7baac72a445eb8a129137413759f6" + "m_Id": "b767f1a5ffbb48868ea32897fd4b342a" }, "m_SlotId": 2 }, "m_InputSlot": { "m_Node": { - "m_Id": "bdf1253c9dda4fb8a8e15e531bf26d21" + "m_Id": "e3479dd8f41c40938ad9d8066d23bc44" }, "m_SlotId": 1 } @@ -340,6 +346,20 @@ "m_SlotId": 3 } }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "e4319ca600774fa1903bba83a80e3cbe" + }, + "m_SlotId": 0 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "b767f1a5ffbb48868ea32897fd4b342a" + }, + "m_SlotId": 0 + } + }, { "m_OutputSlot": { "m_Node": { @@ -349,7 +369,7 @@ }, "m_InputSlot": { "m_Node": { - "m_Id": "8376a1e400b0461298196a5bc920de11" + "m_Id": "b767f1a5ffbb48868ea32897fd4b342a" }, "m_SlotId": 1 } @@ -603,6 +623,54 @@ "m_SerializedDescriptor": "VertexDescription.Position" } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot", + "m_ObjectId": "11f3f1ad392f4c8da6b0c6db0d4a7824", + "m_Id": 1, + "m_DisplayName": "B", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "B", + "m_StageCapability": 3, + "m_Value": { + "e00": 3.0, + "e01": 2.0, + "e02": 2.0, + "e03": 2.0, + "e10": 2.0, + "e11": 2.0, + "e12": 2.0, + "e13": 2.0, + "e20": 2.0, + "e21": 2.0, + "e22": 2.0, + "e23": 2.0, + "e30": 2.0, + "e31": 2.0, + "e32": 2.0, + "e33": 2.0 + }, + "m_DefaultValue": { + "e00": 1.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 1.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 1.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 1.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.DynamicVectorMaterialSlot", @@ -720,30 +788,30 @@ { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot", - "m_ObjectId": "217112649ea94a6cb71b9949e1c75290", - "m_Id": 1, - "m_DisplayName": "B", - "m_SlotType": 0, + "m_ObjectId": "266c057c8ca04316b95e0686283e55dc", + "m_Id": 2, + "m_DisplayName": "Out", + "m_SlotType": 1, "m_Hidden": false, - "m_ShaderOutputName": "B", + "m_ShaderOutputName": "Out", "m_StageCapability": 3, "m_Value": { - "e00": 2.0, - "e01": 2.0, - "e02": 2.0, - "e03": 2.0, - "e10": 2.0, - "e11": 2.0, - "e12": 2.0, - "e13": 2.0, - "e20": 2.0, - "e21": 2.0, - "e22": 2.0, - "e23": 2.0, - "e30": 2.0, - "e31": 2.0, - "e32": 2.0, - "e33": 2.0 + "e00": 0.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 0.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 0.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 0.0 }, "m_DefaultValue": { "e00": 1.0, @@ -1074,6 +1142,54 @@ "m_OutputChannel": 0 } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot", + "m_ObjectId": "49ee49e57f7d483bb0d58c81df3c4d8d", + "m_Id": 0, + "m_DisplayName": "A", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "A", + "m_StageCapability": 3, + "m_Value": { + "e00": 0.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 0.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 0.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 0.0 + }, + "m_DefaultValue": { + "e00": 1.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 1.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 1.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 1.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.DynamicVectorMaterialSlot", @@ -1181,9 +1297,9 @@ "m_ShaderOutputName": "A", "m_StageCapability": 3, "m_Value": { - "e00": 0.4000000059604645, - "e01": 0.4000000059604645, - "e02": 0.4000000059604645, + "e00": 0.30000001192092898, + "e01": 0.30000001192092898, + "e02": 0.30000001192092898, "e03": 1.0, "e10": 0.0, "e11": 0.0, @@ -1557,49 +1673,6 @@ } } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.MultiplyNode", - "m_ObjectId": "8376a1e400b0461298196a5bc920de11", - "m_Group": { - "m_Id": "" - }, - "m_Name": "Multiply", - "m_DrawState": { - "m_Expanded": true, - "m_Position": { - "serializedVersion": "2", - "x": -1554.4000244140625, - "y": 665.5999755859375, - "width": 208.0, - "height": 301.60009765625 - } - }, - "m_Slots": [ - { - "m_Id": "efa287e111d748178a59d60c6bfc0f1b" - }, - { - "m_Id": "217112649ea94a6cb71b9949e1c75290" - }, - { - "m_Id": "f145e2cc2faf43bd8cb9f2b5ec0b6a9c" - } - ], - "synonyms": [ - "multiplication", - "times", - "x" - ], - "m_Precision": 0, - "m_PreviewExpanded": true, - "m_DismissedVersion": 0, - "m_PreviewMode": 0, - "m_CustomColors": { - "m_SerializableColors": [] - } -} - { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.ClampNode", @@ -1734,6 +1807,21 @@ } } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", + "m_ObjectId": "92cb2b89b42042b1b41eeb8c4b5160e2", + "m_Id": 0, + "m_DisplayName": "SineSpeed", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 3, + "m_Value": 0.0, + "m_DefaultValue": 0.0, + "m_Labels": [] +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.DynamicVectorMaterialSlot", @@ -1769,6 +1857,9 @@ }, { "m_Id": "1f53faf21fc44b7c9c0a3a289fca9745" + }, + { + "m_Id": "bd7dd6ceff3c405e8e4350f1a31abbb4" } ] } @@ -2035,6 +2126,49 @@ } } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.MultiplyNode", + "m_ObjectId": "b767f1a5ffbb48868ea32897fd4b342a", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Multiply", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -1571.199951171875, + "y": 702.4000244140625, + "width": 208.0, + "height": 301.5999755859375 + } + }, + "m_Slots": [ + { + "m_Id": "49ee49e57f7d483bb0d58c81df3c4d8d" + }, + { + "m_Id": "11f3f1ad392f4c8da6b0c6db0d4a7824" + }, + { + "m_Id": "266c057c8ca04316b95e0686283e55dc" + } + ], + "synonyms": [ + "multiplication", + "times", + "x" + ], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_DismissedVersion": 0, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.SplitNode", @@ -2082,6 +2216,34 @@ } } +{ + "m_SGVersion": 1, + "m_Type": "UnityEditor.ShaderGraph.Internal.Vector1ShaderProperty", + "m_ObjectId": "bd7dd6ceff3c405e8e4350f1a31abbb4", + "m_Guid": { + "m_GuidSerialized": "9098335d-38d0-46fe-b6d1-eb857970823d" + }, + "m_Name": "SineSpeed", + "m_DefaultRefNameVersion": 1, + "m_RefNameGeneratedByDisplayName": "SineSpeed", + "m_DefaultReferenceName": "_SineSpeed", + "m_OverrideReferenceName": "", + "m_GeneratePropertyBlock": true, + "m_UseCustomSlotLabel": false, + "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, + "m_Precision": 0, + "overrideHLSLDeclaration": false, + "hlslDeclarationOverride": 0, + "m_Hidden": false, + "m_Value": 3.0, + "m_FloatType": 0, + "m_RangeValues": { + "x": 0.0, + "y": 1.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.DistanceNode", @@ -2570,10 +2732,10 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -373.60003662109377, - "y": 152.8000030517578, - "width": 128.00003051757813, - "height": 93.60000610351563 + "x": -443.99993896484377, + "y": 247.1999969482422, + "width": 128.0, + "height": 93.60002136230469 } }, "m_Slots": [ @@ -2598,6 +2760,42 @@ } } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.PropertyNode", + "m_ObjectId": "e4319ca600774fa1903bba83a80e3cbe", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Property", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -1901.599853515625, + "y": 985.5999755859375, + "width": 132.0, + "height": 33.59991455078125 + } + }, + "m_Slots": [ + { + "m_Id": "92cb2b89b42042b1b41eeb8c4b5160e2" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_DismissedVersion": 0, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_Property": { + "m_Id": "bd7dd6ceff3c405e8e4350f1a31abbb4" + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot", @@ -2640,8 +2838,8 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -1678.4000244140625, - "y": 606.4000244140625, + "x": -1769.5999755859375, + "y": 594.4000244140625, "width": 124.0, "height": 172.79998779296876 } @@ -2697,54 +2895,6 @@ } } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot", - "m_ObjectId": "efa287e111d748178a59d60c6bfc0f1b", - "m_Id": 0, - "m_DisplayName": "A", - "m_SlotType": 0, - "m_Hidden": false, - "m_ShaderOutputName": "A", - "m_StageCapability": 3, - "m_Value": { - "e00": 2.0, - "e01": 0.0, - "e02": 0.0, - "e03": 0.0, - "e10": 0.0, - "e11": 0.0, - "e12": 0.0, - "e13": 0.0, - "e20": 0.0, - "e21": 0.0, - "e22": 0.0, - "e23": 0.0, - "e30": 0.0, - "e31": 0.0, - "e32": 0.0, - "e33": 0.0 - }, - "m_DefaultValue": { - "e00": 1.0, - "e01": 0.0, - "e02": 0.0, - "e03": 0.0, - "e10": 0.0, - "e11": 1.0, - "e12": 0.0, - "e13": 0.0, - "e20": 0.0, - "e21": 0.0, - "e22": 1.0, - "e23": 0.0, - "e30": 0.0, - "e31": 0.0, - "e32": 0.0, - "e33": 1.0 - } -} - { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", @@ -2760,54 +2910,6 @@ "m_Labels": [] } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot", - "m_ObjectId": "f145e2cc2faf43bd8cb9f2b5ec0b6a9c", - "m_Id": 2, - "m_DisplayName": "Out", - "m_SlotType": 1, - "m_Hidden": false, - "m_ShaderOutputName": "Out", - "m_StageCapability": 3, - "m_Value": { - "e00": 0.0, - "e01": 0.0, - "e02": 0.0, - "e03": 0.0, - "e10": 0.0, - "e11": 0.0, - "e12": 0.0, - "e13": 0.0, - "e20": 0.0, - "e21": 0.0, - "e22": 0.0, - "e23": 0.0, - "e30": 0.0, - "e31": 0.0, - "e32": 0.0, - "e33": 0.0 - }, - "m_DefaultValue": { - "e00": 1.0, - "e01": 0.0, - "e02": 0.0, - "e03": 0.0, - "e10": 0.0, - "e11": 1.0, - "e12": 0.0, - "e13": 0.0, - "e20": 0.0, - "e21": 0.0, - "e22": 1.0, - "e23": 0.0, - "e30": 0.0, - "e31": 0.0, - "e32": 0.0, - "e33": 1.0 - } -} - { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",