From 2f088b5590a645c0ff3fd43d24a2e33a25aec227 Mon Sep 17 00:00:00 2001 From: Reinier Vens Date: Sat, 6 Mar 2021 02:42:19 +0000 Subject: [PATCH] Heatstroke VFX Filling the heatstroke meter now results in a postprocessing filter which increasingly distorts the player's view as they get closer to death. --- Assets/Scenes/ARPG.unity | 110 +++++++++++++++++- .../Postprocessing Profile Heatstroke.asset | 3 + ...stprocessing Profile Heatstroke.asset.meta | 8 ++ ...processing Profile Severe Heatstroke.asset | 3 + ...ssing Profile Severe Heatstroke.asset.meta | 8 ++ Assets/Scripts/Gameplay/ActionGameManager.cs | 31 ++++- Assets/Scripts/Gameplay/GameSettings.cs | 2 + .../Scripts/ServerShared/Behaviors/Cockpit.cs | 15 +-- Assets/Scripts/ServerShared/Entity.cs | 26 +++++ Assets/Scripts/ServerShared/Settings.cs | 1 + Assets/Scripts/UI/SchematicDisplay.cs | 2 +- 11 files changed, 183 insertions(+), 26 deletions(-) create mode 100644 Assets/Scenes/ARPG_Profiles/Postprocessing Profile Heatstroke.asset create mode 100644 Assets/Scenes/ARPG_Profiles/Postprocessing Profile Heatstroke.asset.meta create mode 100644 Assets/Scenes/ARPG_Profiles/Postprocessing Profile Severe Heatstroke.asset create mode 100644 Assets/Scenes/ARPG_Profiles/Postprocessing Profile Severe Heatstroke.asset.meta diff --git a/Assets/Scenes/ARPG.unity b/Assets/Scenes/ARPG.unity index 68afe8c2c..facf859c3 100644 --- a/Assets/Scenes/ARPG.unity +++ b/Assets/Scenes/ARPG.unity @@ -2329,7 +2329,7 @@ Transform: - {fileID: 488792361} - {fileID: 970624070} m_Father: {fileID: 1665127616} - m_RootOrder: 5 + m_RootOrder: 7 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &204301709 GameObject: @@ -11021,7 +11021,7 @@ Transform: - {fileID: 1075335641} - {fileID: 166261017} m_Father: {fileID: 1665127616} - m_RootOrder: 6 + m_RootOrder: 8 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &831892783 GameObject: @@ -11060,6 +11060,54 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: -2, y: 24} m_Pivot: {x: 0.5, y: 1} +--- !u!1 &837424433 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 837424434} + - component: {fileID: 837424435} + m_Layer: 8 + m_Name: Severe Heatstroke Postprocessing + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &837424434 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 837424433} + 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_Children: [] + m_Father: {fileID: 1665127616} + m_RootOrder: 5 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &837424435 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 837424433} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8b9a305e18de0c04dbd257a21cd47087, type: 3} + m_Name: + m_EditorClassIdentifier: + sharedProfile: {fileID: 11400000, guid: dd57a2fd868ca1042b1ce02b253716e7, type: 2} + isGlobal: 1 + blendDistance: 0 + weight: 0 + priority: 2 --- !u!1 &840997851 GameObject: m_ObjectHideFlags: 0 @@ -13106,6 +13154,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 39f95af24dd29a645895a57a75460b0c, type: 3} m_Name: m_EditorClassIdentifier: + HeatstrokePP: {fileID: 1404901906} + SevereHeatstrokePP: {fileID: 837424435} ViewDot: {fileID: 146394778} TargetIndicator: {fileID: 1556666357} LockIndicator: {fileID: 1876420642} @@ -16581,6 +16631,54 @@ CanvasGroup: m_Interactable: 1 m_BlocksRaycasts: 1 m_IgnoreParentGroups: 0 +--- !u!1 &1404901904 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1404901905} + - component: {fileID: 1404901906} + m_Layer: 8 + m_Name: Heatstroke Postprocessing + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1404901905 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1404901904} + 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_Children: [] + m_Father: {fileID: 1665127616} + m_RootOrder: 4 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1404901906 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1404901904} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8b9a305e18de0c04dbd257a21cd47087, type: 3} + m_Name: + m_EditorClassIdentifier: + sharedProfile: {fileID: 11400000, guid: a66f8baac31efff459abb11a52203aa6, type: 2} + isGlobal: 1 + blendDistance: 0 + weight: 0 + priority: 1 --- !u!1 &1416434298 GameObject: m_ObjectHideFlags: 0 @@ -18080,7 +18178,7 @@ Transform: - {fileID: 1537342002} - {fileID: 39508928} m_Father: {fileID: 1665127616} - m_RootOrder: 4 + m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1547889400 MonoBehaviour: @@ -18146,7 +18244,7 @@ PrefabInstance: - target: {fileID: 878382121558056004, guid: 2758dfa2744d7ad4d8877545189d116e, type: 3} propertyPath: m_AnchoredPosition.x - value: 55.675 + value: 0 objectReference: {fileID: 0} - target: {fileID: 878382121558056004, guid: 2758dfa2744d7ad4d8877545189d116e, type: 3} @@ -19077,7 +19175,7 @@ PrefabInstance: - target: {fileID: 878382121558056004, guid: 2758dfa2744d7ad4d8877545189d116e, type: 3} propertyPath: m_AnchoredPosition.x - value: 60.98 + value: 0 objectReference: {fileID: 0} - target: {fileID: 878382121558056004, guid: 2758dfa2744d7ad4d8877545189d116e, type: 3} @@ -19710,6 +19808,8 @@ Transform: - {fileID: 393266592} - {fileID: 2115559090} - {fileID: 937280108} + - {fileID: 1404901905} + - {fileID: 837424434} - {fileID: 1547889399} - {fileID: 199435031} - {fileID: 826773974} diff --git a/Assets/Scenes/ARPG_Profiles/Postprocessing Profile Heatstroke.asset b/Assets/Scenes/ARPG_Profiles/Postprocessing Profile Heatstroke.asset new file mode 100644 index 000000000..dd942ff07 --- /dev/null +++ b/Assets/Scenes/ARPG_Profiles/Postprocessing Profile Heatstroke.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59eae226239b838c23ad3ab9517acc279af0601e97ddc04805c79824114c8c6d +size 25079 diff --git a/Assets/Scenes/ARPG_Profiles/Postprocessing Profile Heatstroke.asset.meta b/Assets/Scenes/ARPG_Profiles/Postprocessing Profile Heatstroke.asset.meta new file mode 100644 index 000000000..e3a6425de --- /dev/null +++ b/Assets/Scenes/ARPG_Profiles/Postprocessing Profile Heatstroke.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a66f8baac31efff459abb11a52203aa6 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/ARPG_Profiles/Postprocessing Profile Severe Heatstroke.asset b/Assets/Scenes/ARPG_Profiles/Postprocessing Profile Severe Heatstroke.asset new file mode 100644 index 000000000..522cc9b9e --- /dev/null +++ b/Assets/Scenes/ARPG_Profiles/Postprocessing Profile Severe Heatstroke.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:52a2533eeb2847de31677711ed51feac8cf27919be1b2e749e14941bcfcac565 +size 25736 diff --git a/Assets/Scenes/ARPG_Profiles/Postprocessing Profile Severe Heatstroke.asset.meta b/Assets/Scenes/ARPG_Profiles/Postprocessing Profile Severe Heatstroke.asset.meta new file mode 100644 index 000000000..d47d53b3b --- /dev/null +++ b/Assets/Scenes/ARPG_Profiles/Postprocessing Profile Severe Heatstroke.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: dd57a2fd868ca1042b1ce02b253716e7 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Gameplay/ActionGameManager.cs b/Assets/Scripts/Gameplay/ActionGameManager.cs index c24e44be1..a2f53df67 100644 --- a/Assets/Scripts/Gameplay/ActionGameManager.cs +++ b/Assets/Scripts/Gameplay/ActionGameManager.cs @@ -14,6 +14,7 @@ using UniRx; using UnityEngine; using Unity.Mathematics; using UnityEngine.InputSystem; +using UnityEngine.Rendering.PostProcessing; using UnityEngine.UI; using static Unity.Mathematics.math; using float2 = Unity.Mathematics.float2; @@ -22,6 +23,8 @@ using Random = UnityEngine.Random; public class ActionGameManager : MonoBehaviour { + public PostProcessVolume HeatstrokePP; + public PostProcessVolume SevereHeatstrokePP; public PlaceUIElementWorldspace ViewDot; public PlaceUIElementWorldspace TargetIndicator; public Prototype LockIndicator; @@ -55,20 +58,27 @@ public class ActionGameManager : MonoBehaviour private float _time; private AetheriaInput _input; private int _zoomLevelIndex; + private Ship _currentShip; // private ShipInput _shipInput; private List _shipAgents = new List(); - private IDisposable _shipTargetSubscription; private float2 _shipYawPitch; private float3 _viewDirection; private (HardpointData[] hardpoints, Transform[] barrels, PlaceUIElementWorldspace crosshair)[] _articulationGroups; private (LockWeapon targetLock, PlaceUIElementWorldspace indicator, Rotate spin)[] _lockingIndicators; + private List _shipSubscriptions = new List(); + private float _severeHeatstrokePhase; public List PlayerEntities { get; } = new List(); public EquippedDockingBay DockingBay { get; private set; } public Entity DockedEntity { get; private set; } - - public Ship CurrentShip { get; set; } + + public Ship CurrentShip + { + get => _currentShip; + set => _currentShip = value; + } + public DatabaseCache ItemData { get; private set; } public ItemManager ItemManager { get; private set; } public Zone Zone { get; private set; } @@ -81,6 +91,7 @@ public class ActionGameManager : MonoBehaviour (float2(0, -1), "Rear") }; + public void SaveLoadout(EntityPack pack) { File.WriteAllBytes(Path.Combine(_loadoutPath.FullName, $"{pack.Name}.preset"), MessagePackSerializer.Serialize(pack)); @@ -479,6 +490,8 @@ public class ActionGameManager : MonoBehaviour var bay = entity.TryDock(CurrentShip); if (bay != null) { + foreach(var subscription in _shipSubscriptions) subscription.Dispose(); + _shipSubscriptions.Clear(); DockedEntity = entity; SectorRenderer.PerspectiveEntity = DockedEntity; DockingBay = bay; @@ -550,8 +563,7 @@ public class ActionGameManager : MonoBehaviour if (float.IsNaN(CurrentShip.Hull.Durability)) Debug.Log("WTF!"); }); - _shipTargetSubscription?.Dispose(); - _shipTargetSubscription = CurrentShip.Target.Subscribe(target => + _shipSubscriptions.Add(CurrentShip.Target.Subscribe(target => { TargetIndicator.gameObject.SetActive(CurrentShip.Target.Value != null); TargetShipPanel.gameObject.SetActive(target != null); @@ -560,7 +572,9 @@ public class ActionGameManager : MonoBehaviour TargetShipPanel.Display(target, true); TargetSchematicDisplay.ShowShip(target, CurrentShip); } - }); + })); + + //_shipSubscriptions.Add(CurrentShip.HeatstrokeRisk.Subscribe(_ => _severeHeatstrokePhase = 0)); Cursor.lockState = CursorLockMode.Locked; GameplayUI.SetActive(true); @@ -647,6 +661,11 @@ public class ActionGameManager : MonoBehaviour _viewDirection = mul(float3(0, 0, 1), Unity.Mathematics.float3x3.Euler(float3(_shipYawPitch.yx, 0), RotationOrder.YXZ)); CurrentShip.LookDirection = _viewDirection; CurrentShip.MovementDirection = _input.Player.Move.ReadValue(); + HeatstrokePP.weight = saturate(unlerp(0, Settings.GameplaySettings.SevereHeatstrokeRiskThreshold, CurrentShip.Heatstroke)); + var severeHeatstrokeLerp = saturate(unlerp(Settings.GameplaySettings.SevereHeatstrokeRiskThreshold, 1, CurrentShip.Heatstroke)); + SevereHeatstrokePP.weight = + severeHeatstrokeLerp + severeHeatstrokeLerp * (1 - severeHeatstrokeLerp) * + max(Settings.HeatstrokePhasingFloor, sin(Time.time * Settings.HeatstrokePhasingFrequency)); } } foreach(var agent in _shipAgents) diff --git a/Assets/Scripts/Gameplay/GameSettings.cs b/Assets/Scripts/Gameplay/GameSettings.cs index df6dfc311..f5b72e170 100644 --- a/Assets/Scripts/Gameplay/GameSettings.cs +++ b/Assets/Scripts/Gameplay/GameSettings.cs @@ -10,6 +10,8 @@ using UnityEngine; [CreateAssetMenu(fileName = "Sector Display Properties", menuName = "Aetheria/Sector Display Properties")] public class GameSettings : ScriptableObject { + public float HeatstrokePhasingFloor = 0; + public float HeatstrokePhasingFrequency = 5; public float WormholeDistanceRatio; public float DefaultZoneRadius; public float DefaultZoneMass; diff --git a/Assets/Scripts/ServerShared/Behaviors/Cockpit.cs b/Assets/Scripts/ServerShared/Behaviors/Cockpit.cs index 047c0f120..5d7efb5c6 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Cockpit.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Cockpit.cs @@ -27,7 +27,6 @@ public class Cockpit : IBehavior public BehaviorData Data => _data; - public float Heatstroke { get; private set; } public Cockpit(ItemManager context, CockpitData data, Entity entity, EquippedItem item) { @@ -35,22 +34,10 @@ public class Cockpit : IBehavior _data = data; Entity = entity; Item = item; - Heatstroke = 0; } public bool Execute(float delta) { - if (Item.Temperature > Context.GameplaySettings.HeatstrokeTemperature) - { - Heatstroke = saturate( - Heatstroke + - pow(Item.Temperature - Context.GameplaySettings.HeatstrokeTemperature, Context.GameplaySettings.HeatstrokeExponent) * - Context.GameplaySettings.HeatstrokeMultiplier * delta); - } - else - { - Heatstroke = saturate(Heatstroke - Context.GameplaySettings.HeatstrokeRecoverySpeed * delta); - } - return Heatstroke < Context.GameplaySettings.HeatstrokeControlLimit; + return true; } } \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Entity.cs b/Assets/Scripts/ServerShared/Entity.cs index e6bcba3ef..02a4259a5 100644 --- a/Assets/Scripts/ServerShared/Entity.cs +++ b/Assets/Scripts/ServerShared/Entity.cs @@ -97,6 +97,8 @@ public abstract class Entity } public Shield Shield { get; private set; } + public Cockpit Cockpit { get; private set; } + public float Heatstroke { get; private set; } public float TargetRange { get; private set; } public float MaxTemp { get; private set; } @@ -112,6 +114,7 @@ public abstract class Entity public Subject ItemOnline = new Subject(); public Subject HullDamage = new Subject(); public Subject Docked = new Subject(); + public Subject HeatstrokeRisk = new Subject(); public UniRx.IObservable ItemDestroyed; public UniRx.IObservable HullArmorDepleted; @@ -123,6 +126,7 @@ public abstract class Entity public virtual void Activate() { _active = true; + Heatstroke = 0; foreach (var item in Equipment) foreach (var behavior in item.Behaviors) { @@ -355,6 +359,8 @@ public abstract class Entity _heatsinks.Remove(heatsink); if (b is Shield) Shield = null; + if (b is Cockpit) + Cockpit = null; } return item.EquippableItem; @@ -533,6 +539,8 @@ public abstract class Entity _heatsinks.Add(heatsink); if (b is Shield shield) Shield = shield; + if (b is Cockpit cockpit) + Cockpit = cockpit; } equippedItem.OnOnline += () => ItemOnline.OnNext(equippedItem); @@ -731,6 +739,24 @@ public abstract class Entity UpdateTemperature(delta); + if(Cockpit != null) + { + if (Cockpit.Item.Temperature > ItemManager.GameplaySettings.HeatstrokeTemperature) + { + var previous = Heatstroke; + Heatstroke = saturate( + Heatstroke + + pow(Cockpit.Item.Temperature - ItemManager.GameplaySettings.HeatstrokeTemperature, ItemManager.GameplaySettings.HeatstrokeExponent) * + ItemManager.GameplaySettings.HeatstrokeMultiplier * delta); + if(previous < ItemManager.GameplaySettings.SevereHeatstrokeRiskThreshold && Heatstroke > ItemManager.GameplaySettings.SevereHeatstrokeRiskThreshold) + HeatstrokeRisk.OnNext(Unit.Default); + } + else + { + Heatstroke = saturate(Heatstroke - ItemManager.GameplaySettings.HeatstrokeRecoverySpeed * delta); + } + } + if (_active) { foreach (var equippedItem in _orderedEquipment) diff --git a/Assets/Scripts/ServerShared/Settings.cs b/Assets/Scripts/ServerShared/Settings.cs index 9af5d9b5b..95af78cb2 100644 --- a/Assets/Scripts/ServerShared/Settings.cs +++ b/Assets/Scripts/ServerShared/Settings.cs @@ -88,6 +88,7 @@ public class ZoneGenerationSettings [Serializable, MessagePackObject(keyAsPropertyName: true), JsonObject] public class GameplaySettings { + public float SevereHeatstrokeRiskThreshold = .25f; public float WormholeDepth = 1000; public float WormholeExitVelocity = 20; public float WormholeExitRadius = 50; diff --git a/Assets/Scripts/UI/SchematicDisplay.cs b/Assets/Scripts/UI/SchematicDisplay.cs index 221eeef09..8a1f9fc6e 100644 --- a/Assets/Scripts/UI/SchematicDisplay.cs +++ b/Assets/Scripts/UI/SchematicDisplay.cs @@ -241,7 +241,7 @@ public class SchematicDisplay : MonoBehaviour CockpitTemperatureLabel.text = $"{((int)(_cockpit.Item.Temperature - 273.15f)).ToString()}°C"; - HeatstrokeMeterFill.anchorMax = new Vector2(_cockpit.Heatstroke, 1); + HeatstrokeMeterFill.anchorMax = new Vector2(_entity.Heatstroke, 1); HeatstrokeLimitFill.anchorMax = new Vector2(_cockpit.Item.Temperature / Settings.GameplaySettings.HeatstrokeTemperature, 1); if (_capacitors.Length == 0)