From 8b32915b9aa4302b6ee03b43fad3a4be94f30d5f Mon Sep 17 00:00:00 2001 From: Alexejhero <32238504+Alexejhero@users.noreply.github.com> Date: Tue, 12 Dec 2023 09:04:44 +0200 Subject: [PATCH] =?UTF-8?q?:classic:=20=F0=9F=A6=86=20Alex=20changing=20a?= =?UTF-8?q?=20bunch=20of=20stuff=20for=20no=20reason?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RegisterConsoleCommandsAttribute.cs | 1 - SCHIZO/Creatures/Ermfish/ErmStack.cs | 12 +- SCHIZO/Creatures/Ermshark/ErmsharkAttack.cs | 2 +- SCHIZO/Creatures/UnityCreaturePrefab.cs | 1 - SCHIZO/DataStructures/SavedRandomList.cs | 4 +- SCHIZO/Helpers/StaticHelpers.cs | 1 - SCHIZO/Items/ClonePrefab.cs | 2 +- SCHIZO/Items/Components/MiddleClickAction.cs | 2 +- SCHIZO/Items/Data/Crafting/Recipe.cs | 1 - SCHIZO/Items/Gymbag/Gymbag.cs | 2 +- SCHIZO/Items/UnityPrefab.cs | 3 +- SCHIZO/Jukebox/CustomJukeboxDisk.BelowZero.cs | 1 - .../BZErmsharkLoadingIcon.BelowZero.cs | 4 +- SCHIZO/Plugin.cs | 2 - SCHIZO/Twitch/TwitchIntegration.cs | 1 - .../Attributes/VFXComponentImagePreview.cs | 6 +- .../Scripts/SCHIZO/Items/Data/ItemData.cs | 3 +- .../Scripts/SCHIZO/Spawns/BiomeSpawnData.cs | 3 +- .../Scripts/SCHIZO/Utilities/T2DArray.cs | 44 ++++--- Unity/Assets/Scripts/SCHIZO/VFX/ARGCensor.cs | 75 +++++------ Unity/Assets/Scripts/SCHIZO/VFX/ColorTint.cs | 20 +-- .../Assets/Scripts/SCHIZO/VFX/ImageOverlay.cs | 46 +++---- Unity/Assets/Scripts/SCHIZO/VFX/MatPassID.cs | 119 +++++++++--------- .../Scripts/SCHIZO/VFX/NoiseVignette.cs | 54 ++++---- .../Assets/Scripts/SCHIZO/VFX/PreviewImage.cs | 6 +- .../Scripts/SCHIZO/VFX/SchizoVFXStack.cs | 12 +- .../Assets/Scripts/SCHIZO/VFX/TwoColorTint.cs | 26 ++-- .../Assets/Scripts/SCHIZO/VFX/VFXComponent.cs | 50 ++------ 28 files changed, 243 insertions(+), 260 deletions(-) diff --git a/SCHIZO/ConsoleCommands/RegisterConsoleCommandsAttribute.cs b/SCHIZO/ConsoleCommands/RegisterConsoleCommandsAttribute.cs index cbebf406..dd36ca6b 100644 --- a/SCHIZO/ConsoleCommands/RegisterConsoleCommandsAttribute.cs +++ b/SCHIZO/ConsoleCommands/RegisterConsoleCommandsAttribute.cs @@ -2,7 +2,6 @@ using System.Linq; using System.Reflection; using JetBrains.Annotations; -using Nautilus.Commands; using Nautilus.Handlers; namespace SCHIZO.ConsoleCommands; diff --git a/SCHIZO/Creatures/Ermfish/ErmStack.cs b/SCHIZO/Creatures/Ermfish/ErmStack.cs index 23bee26b..549dcbdb 100644 --- a/SCHIZO/Creatures/Ermfish/ErmStack.cs +++ b/SCHIZO/Creatures/Ermfish/ErmStack.cs @@ -140,19 +140,19 @@ public static void Disconnect(ErmStack node, bool plugSide = true) public bool Connect(ErmStack node, bool nodeIsPlug) => nodeIsPlug ? Connect(node, this) : Connect(this, node); public void Disconnect(bool plugSide = true) => Disconnect(this, plugSide); - public bool ShouldAttach(Carryable _, CarryCreature socket) + public bool ShouldAttach(Carryable _, CarryCreature attachSocket) { - ErmStack socketStack = socket.GetComponent(); + ErmStack socketStack = attachSocket.GetComponent(); if (!socketStack) return true; return socketStack.head != head && socketStack.tail != tail && !socketStack.nextPlug; } - public void OnConnected(Carryable plug, CarryCreature socket) + public void OnConnected(Carryable connectedPlug, CarryCreature connectedSocket) { // only called on the plug side - so we update the socket from the plug - ErmStack socketStack = socket.GetComponent(); + ErmStack socketStack = connectedSocket.GetComponent(); if (!socketStack) return; socketStack.nextPlug = this; @@ -162,10 +162,10 @@ public void OnConnected(Carryable plug, CarryCreature socket) socketStack.WalkToHead().ForEach(s => s.tail = tail); } - public void OnDisconnected(Carryable plug, CarryCreature socket) + public void OnDisconnected(Carryable disconnectedPlug, CarryCreature disconnectedSocket) { // only called on the plug side - so we update the socket from the plug - ErmStack socketStack = socket.GetComponent(); + ErmStack socketStack = disconnectedSocket.GetComponent(); if (!socketStack) return; socketStack.nextPlug = null; diff --git a/SCHIZO/Creatures/Ermshark/ErmsharkAttack.cs b/SCHIZO/Creatures/Ermshark/ErmsharkAttack.cs index 24f94a4a..51e0b43e 100644 --- a/SCHIZO/Creatures/Ermshark/ErmsharkAttack.cs +++ b/SCHIZO/Creatures/Ermshark/ErmsharkAttack.cs @@ -14,7 +14,7 @@ public override void OnTouch(Collider collider) GameObject target = GetTarget(collider); - if (global::CreatureData.GetCreatureType(gameObject) == global::CreatureData.GetCreatureType(target)) return; + if (CreatureData.GetCreatureType(gameObject) == CreatureData.GetCreatureType(target)) return; if (GetComponentsInParent().Any(handler => handler.HandleMeleeAttack(target))) return; Player player = target.GetComponent(); diff --git a/SCHIZO/Creatures/UnityCreaturePrefab.cs b/SCHIZO/Creatures/UnityCreaturePrefab.cs index 9377857b..cf0b12ff 100644 --- a/SCHIZO/Creatures/UnityCreaturePrefab.cs +++ b/SCHIZO/Creatures/UnityCreaturePrefab.cs @@ -2,7 +2,6 @@ using System.Diagnostics.CodeAnalysis; using ECCLibrary; using Nautilus.Handlers; -using SCHIZO.Helpers; using SCHIZO.Items; using UnityEngine; using UWE; diff --git a/SCHIZO/DataStructures/SavedRandomList.cs b/SCHIZO/DataStructures/SavedRandomList.cs index d8ff742f..69ceb673 100644 --- a/SCHIZO/DataStructures/SavedRandomList.cs +++ b/SCHIZO/DataStructures/SavedRandomList.cs @@ -11,7 +11,7 @@ public sealed class SavedRandomList : IEnumerable { private record struct IdentifiableItem(string Identifier, T Value); - private class PlayerPrefsManager(string key) : RandomList.IInitialStateModifier + private class PlayerPrefsManager(string playerPrefsPrefix) : RandomList.IInitialStateModifier { private record struct RegistryKey(string Value); @@ -46,7 +46,7 @@ public void Reset() } } - private RegistryKey KeyOf(string identifier) => new($"SCHIZO_RandomList_{key}_{identifier}"); + private RegistryKey KeyOf(string identifier) => new($"SCHIZO_RandomList_{playerPrefsPrefix}_{identifier}"); private static bool Contains(RegistryKey key) => PlayerPrefs.HasKey(key.Value); diff --git a/SCHIZO/Helpers/StaticHelpers.cs b/SCHIZO/Helpers/StaticHelpers.cs index 4e77acf4..12c3122e 100644 --- a/SCHIZO/Helpers/StaticHelpers.cs +++ b/SCHIZO/Helpers/StaticHelpers.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using HarmonyLib; using TriInspector; namespace SCHIZO.Helpers; diff --git a/SCHIZO/Items/ClonePrefab.cs b/SCHIZO/Items/ClonePrefab.cs index 3e04e03b..71bbda81 100644 --- a/SCHIZO/Items/ClonePrefab.cs +++ b/SCHIZO/Items/ClonePrefab.cs @@ -9,8 +9,8 @@ public abstract class ClonePrefab : UnityPrefab protected readonly TechType clonedTechType; [SetsRequiredMembers] - protected ClonePrefab(ModItem item, TechType cloned) : base(item) // ReSharper disable once ConvertToPrimaryConstructor + protected ClonePrefab(ModItem item, TechType cloned) : base(item) { clonedTechType = cloned; } diff --git a/SCHIZO/Items/Components/MiddleClickAction.cs b/SCHIZO/Items/Components/MiddleClickAction.cs index a1287a04..de319a61 100644 --- a/SCHIZO/Items/Components/MiddleClickAction.cs +++ b/SCHIZO/Items/Components/MiddleClickAction.cs @@ -32,7 +32,7 @@ void IPrefabInit.PrefabInit(GameObject prefab) private string Validate(TechType techType) { - if (target?.GetType() is not { } type) + if (target!?.GetType() is not { } type) return $"{nameof(target)} is required and was not provided"; MethodInfo methodInfo = type.GetMethod(method); diff --git a/SCHIZO/Items/Data/Crafting/Recipe.cs b/SCHIZO/Items/Data/Crafting/Recipe.cs index ade2178d..4feb3cd6 100644 --- a/SCHIZO/Items/Data/Crafting/Recipe.cs +++ b/SCHIZO/Items/Data/Crafting/Recipe.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.Linq; using Nautilus.Crafting; diff --git a/SCHIZO/Items/Gymbag/Gymbag.cs b/SCHIZO/Items/Gymbag/Gymbag.cs index 6330f5d7..e6e6d7bd 100644 --- a/SCHIZO/Items/Gymbag/Gymbag.cs +++ b/SCHIZO/Items/Gymbag/Gymbag.cs @@ -1,6 +1,5 @@ using System.Diagnostics.CodeAnalysis; using Nautilus.Handlers; -using SCHIZO.Helpers; using UnityEngine; namespace SCHIZO.Items.Gymbag; @@ -15,6 +14,7 @@ public sealed class Gymbag : ClonePrefab #endif [SetsRequiredMembers] + // ReSharper disable once ConvertToPrimaryConstructor public Gymbag(ModItem modItem) : base(modItem, CLONE_TARGET) { } diff --git a/SCHIZO/Items/UnityPrefab.cs b/SCHIZO/Items/UnityPrefab.cs index 1881bbb6..20aaa007 100644 --- a/SCHIZO/Items/UnityPrefab.cs +++ b/SCHIZO/Items/UnityPrefab.cs @@ -7,7 +7,6 @@ using SCHIZO.Helpers; using SCHIZO.Items.Data; using SCHIZO.Registering; -using SCHIZO.Sounds; using SCHIZO.Spawns; using UnityEngine; using Object = UnityEngine.Object; @@ -34,8 +33,8 @@ static UnityPrefab() protected PrefabInfo PrefabInfo => ModItem.PrefabInfo; [SetsRequiredMembers] - public UnityPrefab(ModItem item) : base(item) // ReSharper disable once ConvertToPrimaryConstructor + public UnityPrefab(ModItem item) : base(item) { ModItem = item; } diff --git a/SCHIZO/Jukebox/CustomJukeboxDisk.BelowZero.cs b/SCHIZO/Jukebox/CustomJukeboxDisk.BelowZero.cs index 192ba007..2d99b691 100644 --- a/SCHIZO/Jukebox/CustomJukeboxDisk.BelowZero.cs +++ b/SCHIZO/Jukebox/CustomJukeboxDisk.BelowZero.cs @@ -1,5 +1,4 @@ using System.Text; -using FMODUnity; using Nautilus.Handlers; using Nautilus.Utility; using SCHIZO.Sounds; diff --git a/SCHIZO/Loading/BZErmsharkLoadingIcon.BelowZero.cs b/SCHIZO/Loading/BZErmsharkLoadingIcon.BelowZero.cs index a3a13f12..aae81a4d 100644 --- a/SCHIZO/Loading/BZErmsharkLoadingIcon.BelowZero.cs +++ b/SCHIZO/Loading/BZErmsharkLoadingIcon.BelowZero.cs @@ -31,7 +31,6 @@ public static implicit operator BZAnimation(FrameAnimation anim) private int originalCols; private RectTransform rectTransform; - private RectTransform rectParent; private Vector2 originalSpriteDimensions => new(originalTexture.width / originalCols, originalTexture.height / originalRows); private Vector2 ourSpriteDimensions => new(texture.width / columns, texture.height / rows); @@ -47,10 +46,9 @@ private void Awake() Destroy(this); return; } - /// indices correspond to + // indices correspond to ourAnimations = [idle, moving, stopping]; rectTransform = loadingScreen.pengling.rectTransform; - rectParent = (RectTransform) rectTransform.parent; originalAnimations = loadingScreen.animations; originalTexture = loadingScreen.pengling.mainTexture; diff --git a/SCHIZO/Plugin.cs b/SCHIZO/Plugin.cs index 50faba36..608b4e15 100644 --- a/SCHIZO/Plugin.cs +++ b/SCHIZO/Plugin.cs @@ -4,8 +4,6 @@ using BepInEx; using BepInEx.Logging; using ECCLibrary; -using FMOD; -using FMODUnity; using HarmonyLib; using SCHIZO.ConsoleCommands; using SCHIZO.Helpers; diff --git a/SCHIZO/Twitch/TwitchIntegration.cs b/SCHIZO/Twitch/TwitchIntegration.cs index 486d9b60..7a9c7467 100644 --- a/SCHIZO/Twitch/TwitchIntegration.cs +++ b/SCHIZO/Twitch/TwitchIntegration.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Linq; using JetBrains.Annotations; using Nautilus.Commands; using SCHIZO.ConsoleCommands; diff --git a/Unity/Assets/Editor/Scripts/PropertyDrawers/NonTriInspector/Attributes/VFXComponentImagePreview.cs b/Unity/Assets/Editor/Scripts/PropertyDrawers/NonTriInspector/Attributes/VFXComponentImagePreview.cs index c699d5a0..08436c94 100644 --- a/Unity/Assets/Editor/Scripts/PropertyDrawers/NonTriInspector/Attributes/VFXComponentImagePreview.cs +++ b/Unity/Assets/Editor/Scripts/PropertyDrawers/NonTriInspector/Attributes/VFXComponentImagePreview.cs @@ -5,15 +5,15 @@ namespace Editor.Scripts.PropertyDrawers.NonTriInspector.Attributes { [CustomPropertyDrawer(typeof(PreviewImageAttribute), true)] - public class VFXComponentImagePreview() : PropertyDrawer + public class VFXComponentImagePreview : PropertyDrawer { private Texture image; public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { - // TODO: this is not ideal + // TODO: this is not ideal image = (Texture) property.objectReferenceValue; - GUIStyle style = new GUIStyle(EditorStyles.label); + GUIStyle style = new(EditorStyles.label); style.alignment = TextAnchor.UpperCenter; GUILayout.Box(image, style); } diff --git a/Unity/Assets/Scripts/SCHIZO/Items/Data/ItemData.cs b/Unity/Assets/Scripts/SCHIZO/Items/Data/ItemData.cs index eadbe919..a8a47706 100644 --- a/Unity/Assets/Scripts/SCHIZO/Items/Data/ItemData.cs +++ b/Unity/Assets/Scripts/SCHIZO/Items/Data/ItemData.cs @@ -1,5 +1,4 @@ -using System; -using System.Linq; +using System.Linq; using JetBrains.Annotations; using SCHIZO.Attributes; using SCHIZO.Interop.Subnautica.Enums; diff --git a/Unity/Assets/Scripts/SCHIZO/Spawns/BiomeSpawnData.cs b/Unity/Assets/Scripts/SCHIZO/Spawns/BiomeSpawnData.cs index 646c4785..f5f328b5 100644 --- a/Unity/Assets/Scripts/SCHIZO/Spawns/BiomeSpawnData.cs +++ b/Unity/Assets/Scripts/SCHIZO/Spawns/BiomeSpawnData.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using TriInspector; using UnityEngine; diff --git a/Unity/Assets/Scripts/SCHIZO/Utilities/T2DArray.cs b/Unity/Assets/Scripts/SCHIZO/Utilities/T2DArray.cs index dc09b706..feb1aa42 100644 --- a/Unity/Assets/Scripts/SCHIZO/Utilities/T2DArray.cs +++ b/Unity/Assets/Scripts/SCHIZO/Utilities/T2DArray.cs @@ -1,25 +1,26 @@ using System.Collections.Generic; -using TriInspector; -using UnityEngine; using UnityEditor; +using UnityEngine; + +#if UNITY_EDITOR +using TriInspector; +#endif namespace SCHIZO.Utilities { - [CreateAssetMenu(menuName ="SCHIZO/Utilities/Texture2D Array")] + [CreateAssetMenu(menuName = "SCHIZO/Utilities/Texture2D Array")] public class T2DArray : ScriptableObject { - [HideInInspector] - public Texture2DArray array; + [HideInInspector] public Texture2DArray array; #if UNITY_EDITOR [Required, ValidateInput(nameof(ValidateTextures))] public List textures; + public TextureWrapMode wrapMode = TextureWrapMode.Clamp; public FilterMode filterMode = FilterMode.Point; - [Space] - [ShowIf(nameof(array), null)] - public TextureCompressionQuality compressionQuality; + [Space] [ShowIf(nameof(array), null)] public TextureCompressionQuality compressionQuality; [ShowInInspector, ShowIf(nameof(array), null), ReadOnly] public TextureFormat compressionFormat; @@ -33,7 +34,8 @@ private void OnValidate() } } - private bool validtationPass = false; + private bool validationPass = false; + private TriValidationResult ValidateTextures() { if (textures.Count > 1) textures.RemoveAll(o => o == null); @@ -46,27 +48,30 @@ private TriValidationResult ValidateTextures() foreach (Texture texture in textures) { - if (texture.width != w || texture.height != h ) + if (texture.width != w || texture.height != h) { - validtationPass = false; + validationPass = false; return TriValidationResult.Error("All Textures must have same dimensions!"); } - if(((Texture2D) texture).format != format) + + if (((Texture2D) texture).format != format) { - validtationPass = false; + validationPass = false; return TriValidationResult.Error("All Textures must have same format!"); } } - validtationPass = true; + + validationPass = true; compressionFormat = format; return TriValidationResult.Valid; } - validtationPass = true; + + validationPass = true; return TriValidationResult.Warning("Please assign at least 2 textures, or use Texture2D if single texture is intended"); } // for some reason Texture2DArray sub asset does not update when overwriting it, so uuh it's a one time thing i guess - [Button, ShowIf(nameof(array), null), ShowIf(nameof(validtationPass),true)] + [Button, ShowIf(nameof(array), null), ShowIf(nameof(validationPass), true)] private void GenerateArray() { if (textures.Count == 0 || textures[0] == null) return; @@ -84,12 +89,13 @@ private Texture2DArray PopulateTexture2DArray() { List tt = textures; - Texture2DArray t2da = new Texture2DArray(tt[0].width, tt[0].height, tt.Count, compressionFormat, false, true); - + Texture2DArray t2da = new(tt[0].width, tt[0].height, tt.Count, compressionFormat, false, true); + for (int i = 0; i < tt.Count; i++) { - Graphics.CopyTexture(tt[i], 0,0, t2da, i,0); + Graphics.CopyTexture(tt[i], 0, 0, t2da, i, 0); } + t2da.wrapMode = wrapMode; t2da.filterMode = filterMode; diff --git a/Unity/Assets/Scripts/SCHIZO/VFX/ARGCensor.cs b/Unity/Assets/Scripts/SCHIZO/VFX/ARGCensor.cs index 4c7dbf21..e49fad2c 100644 --- a/Unity/Assets/Scripts/SCHIZO/VFX/ARGCensor.cs +++ b/Unity/Assets/Scripts/SCHIZO/VFX/ARGCensor.cs @@ -1,57 +1,60 @@ -using SCHIZO.VFX; using TriInspector; using UnityEngine; -public class ARGCensor : MonoBehaviour +namespace SCHIZO.VFX { - [InlineEditor] - public Material effectMaterial; + public class ARGCensor : MonoBehaviour + { + private static readonly int _texID = Shader.PropertyToID("_Images"); - public float fadeOutStartDistance = 35f; - public float scale = 1.3f; - public float frameChangeInterval = 0.08f; + [InlineEditor] + public Material effectMaterial; - private MatPassID matPassID; + public float fadeOutStartDistance = 35f; + public float scale = 1.3f; + public float frameChangeInterval = 0.08f; - private float lastUpdate; - private float lastRnd = 0f; - private int texID = Shader.PropertyToID("_Images"); - private float arrayDepth; + private MatPassID matPassID; - public void Awake() - { - _ = SchizoVFXStack.VFXStack; + private float lastUpdate; + private float lastRnd; + private float arrayDepth; - matPassID = new MatPassID(effectMaterial); + public void Awake() + { + _ = SchizoVFXStack.Instance; - lastUpdate = Time.time; - arrayDepth = ((Texture2DArray) effectMaterial.GetTexture(texID)).depth; - } + matPassID = new MatPassID(effectMaterial); - public void LateUpdate() - { - Vector3 dirToCam = (Camera.main.transform.position - transform.position).normalized; - Vector3 pos = Camera.main.WorldToScreenPoint(transform.position + dirToCam); + lastUpdate = Time.time; + arrayDepth = ((Texture2DArray) effectMaterial.GetTexture(_texID)).depth; + } - float dot = Vector3.Dot(transform.forward, dirToCam); + public void LateUpdate() + { + Vector3 dirToCam = (Camera.main!.transform.position - transform.position).normalized; + Vector3 pos = Camera.main.WorldToScreenPoint(transform.position + dirToCam); - bool isBelowWaterLevel = Camera.main.transform.position.y < 0f; + float dot = Vector3.Dot(transform.forward, dirToCam); - if (isBelowWaterLevel && pos.z > 0 && dot > -0.3f) - { - if (Time.time - lastUpdate > frameChangeInterval) + bool isBelowWaterLevel = Camera.main.transform.position.y < 0f; + + if (isBelowWaterLevel && pos.z > 0 && dot > -0.3f) { - lastRnd = Random.Range(0, arrayDepth) * Time.timeScale; - lastUpdate = Time.time; - } + if (Time.time - lastUpdate > frameChangeInterval) + { + lastRnd = Random.Range(0, arrayDepth) * Time.timeScale; + lastUpdate = Time.time; + } - float opacity = Mathf.Clamp01((1f / pos.z) * fadeOutStartDistance); + float opacity = Mathf.Clamp01((1f / pos.z) * fadeOutStartDistance); - matPassID.SetVector("_ScreenPosition", new Vector4(pos.x, pos.y, pos.z, lastRnd)); - matPassID.SetFloat("_Strength", opacity); - matPassID.SetFloat("_Scale", scale); + matPassID.SetVector("_ScreenPosition", new Vector4(pos.x, pos.y, pos.z, lastRnd)); + matPassID.SetFloat("_Strength", opacity); + matPassID.SetFloat("_Scale", scale); - SchizoVFXStack.RenderEffect(matPassID); + SchizoVFXStack.Instance.RenderEffect(matPassID); + } } } } diff --git a/Unity/Assets/Scripts/SCHIZO/VFX/ColorTint.cs b/Unity/Assets/Scripts/SCHIZO/VFX/ColorTint.cs index 0bbd10c4..6294ea68 100644 --- a/Unity/Assets/Scripts/SCHIZO/VFX/ColorTint.cs +++ b/Unity/Assets/Scripts/SCHIZO/VFX/ColorTint.cs @@ -1,15 +1,17 @@ -using SCHIZO.VFX; using UnityEngine; -public class ColorTint : VFXComponent +namespace SCHIZO.VFX { - public Color color; - public BlendMode blendMode; - - public override void SetProperties() + public class ColorTint : VFXComponent { - base.SetProperties(); - matPassID.SetColor("_Color", color); - matPassID.passID = (int) blendMode; + public Color color; + public BlendMode blendMode; + + public override void SetProperties() + { + base.SetProperties(); + matPassID.SetColor("_Color", color); + matPassID.PassID = (int) blendMode; + } } } diff --git a/Unity/Assets/Scripts/SCHIZO/VFX/ImageOverlay.cs b/Unity/Assets/Scripts/SCHIZO/VFX/ImageOverlay.cs index 952a2676..e7a3b530 100644 --- a/Unity/Assets/Scripts/SCHIZO/VFX/ImageOverlay.cs +++ b/Unity/Assets/Scripts/SCHIZO/VFX/ImageOverlay.cs @@ -1,29 +1,31 @@ -using SCHIZO.VFX; using TriInspector; using UnityEngine; -public class ImageOverlay : VFXComponent +namespace SCHIZO.VFX { - [InfoBox("Despite appearing stretched on non 1:1 aspect ratio previews, it should display correct in game.")] - [InfoBox("To avoid artifacts, image must have a border of transparent pixels on the edges.")] - public Texture2D image; - public TextureWrapMode wrapMode = TextureWrapMode.Clamp; - public BlendMode blendMode = BlendMode.Normal; - - [Range(0f, 10f)] - public float scale = 1; - [Range(0f, 1f)] - public float strength = 0.1f; - - public Vector2 position; - public override void SetProperties() + public class ImageOverlay : VFXComponent { - base.SetProperties(); - matPassID.passID = (int) blendMode; - image.wrapMode = wrapMode; - matPassID.SetTexture("_Image", image); - matPassID.SetVector("_Position", new Vector4(position.x, position.y, 0f, 0f)); - matPassID.SetFloat("_Strength", strength); - matPassID.SetFloat("_Scale", scale); + [InfoBox("Despite appearing stretched on non 1:1 aspect ratio previews, it should display correct in game.")] + [InfoBox("To avoid artifacts, image must have a border of transparent pixels on the edges.")] + public Texture2D image; + public TextureWrapMode wrapMode = TextureWrapMode.Clamp; + public BlendMode blendMode = BlendMode.Normal; + + [Range(0f, 10f)] + public float scale = 1; + [Range(0f, 1f)] + public float strength = 0.1f; + + public Vector2 position; + public override void SetProperties() + { + base.SetProperties(); + matPassID.PassID = (int) blendMode; + image.wrapMode = wrapMode; + matPassID.SetTexture("_Image", image); + matPassID.SetVector("_Position", new Vector4(position.x, position.y, 0f, 0f)); + matPassID.SetFloat("_Strength", strength); + matPassID.SetFloat("_Scale", scale); + } } } diff --git a/Unity/Assets/Scripts/SCHIZO/VFX/MatPassID.cs b/Unity/Assets/Scripts/SCHIZO/VFX/MatPassID.cs index c24a4d9a..b55cedf5 100644 --- a/Unity/Assets/Scripts/SCHIZO/VFX/MatPassID.cs +++ b/Unity/Assets/Scripts/SCHIZO/VFX/MatPassID.cs @@ -1,89 +1,90 @@ using System.Collections.Generic; using UnityEngine; -namespace SCHIZO.VFX; - -/// -/// Material Properties can be set via SetVector(), SetFloat(), SetColor(), SetTexture() methods. -/// -public sealed class MatPassID(Material material) +namespace SCHIZO.VFX { - public MatPassID(Material material, int passID) : this(material) { _passID = passID; } + /// + /// Material Properties can be set via , , , methods. + /// + public sealed class MatPassID(Material material) + { + public int PassID { get; set; } - public int passID { set => _passID = value; private get => _passID; } - private int _passID; + private Dictionary _vectors; + private Dictionary _floats; + private Dictionary _colors; + private Dictionary _textures; - private Dictionary vectors; - public void SetVector(string name, Vector4 value) - { - int id = Shader.PropertyToID(name); + public void SetVector(string name, Vector4 value) + { + int id = Shader.PropertyToID(name); - vectors ??= []; - vectors[id] = value; - } + _vectors ??= []; + _vectors[id] = value; + } - private Dictionary floats; - public void SetFloat(string name, float value) - { - int id = Shader.PropertyToID(name); - floats ??= []; - floats[id] = value; - } + public void SetFloat(string name, float value) + { + int id = Shader.PropertyToID(name); - private Dictionary colors; - public void SetColor(string name, Color value) - { - int id = Shader.PropertyToID(name); + _floats ??= []; + _floats[id] = value; + } - colors ??= []; - colors[id] = value; - } + public void SetColor(string name, Color value) + { + int id = Shader.PropertyToID(name); - private Dictionary textures; - public void SetTexture(string name, Texture value) - { - int id = Shader.PropertyToID(name); + _colors ??= []; + _colors[id] = value; + } - textures ??= []; - textures[id] = value; - } + public void SetTexture(string name, Texture value) + { + int id = Shader.PropertyToID(name); - public Material ApplyProperties(out int passID) - { - passID = Mathf.Clamp(_passID, 0, material.passCount - 1); + _textures ??= []; + _textures[id] = value; + } - if(vectors != null && vectors.Count != 0) + public Material ApplyProperties(out int passID) { - foreach (KeyValuePair v in vectors) + passID = Mathf.Clamp(PassID, 0, material.passCount - 1); + + if (_vectors != null && _vectors.Count != 0) { - material.SetVector(v.Key, v.Value); + foreach (KeyValuePair v in _vectors) + { + material.SetVector(v.Key, v.Value); + } } - } - if(floats != null && floats.Count != 0) - { - foreach (KeyValuePair f in floats) + if (_floats != null && _floats.Count != 0) { - material.SetFloat(f.Key, f.Value); + foreach (KeyValuePair f in _floats) + { + material.SetFloat(f.Key, f.Value); + } } - } - if(colors != null && colors.Count != 0) - { - foreach (KeyValuePair c in colors) + if (_colors != null && _colors.Count != 0) { - material.SetColor(c.Key, c.Value); + foreach (KeyValuePair c in _colors) + { + material.SetColor(c.Key, c.Value); + } } - } - if(textures != null && textures.Count != 0) - { - foreach (KeyValuePair t in textures) + if (_textures != null && _textures.Count != 0) { - material.SetTexture(t.Key, t.Value); + foreach (KeyValuePair t in _textures) + { + material.SetTexture(t.Key, t.Value); + } } + + return material; } - return material; } } diff --git a/Unity/Assets/Scripts/SCHIZO/VFX/NoiseVignette.cs b/Unity/Assets/Scripts/SCHIZO/VFX/NoiseVignette.cs index 8a13e6ae..371cc01f 100644 --- a/Unity/Assets/Scripts/SCHIZO/VFX/NoiseVignette.cs +++ b/Unity/Assets/Scripts/SCHIZO/VFX/NoiseVignette.cs @@ -1,33 +1,41 @@ -using SCHIZO.VFX; using TriInspector; -using UnityEditor; using UnityEngine; -public class NoiseVignette : VFXComponent +#if UNITY_EDITOR +using UnityEditor; +#endif + +namespace SCHIZO.VFX { - public Texture2D noiseTexture; + public class NoiseVignette : VFXComponent + { + public Texture2D noiseTexture; + + [ValidateInput(nameof(ValidateNormalMap))] + public Texture2D displacementNormal; - [ValidateInput(nameof(ValidateNormalMap))] - public Texture2D displacementNormal; + [Range(0f, 1f)] public float displacementStrength = 0.5f; + [Range(0f, 1f)] public float strength = 1f; - [Range(0f, 1f)] - public float displacementStrength = 0.5f; - [Range(0f, 1f)] - public float strength = 1f; - private TriValidationResult ValidateNormalMap() - { + private TriValidationResult ValidateNormalMap() + { #if UNITY_EDITOR - TextureImporter importer = (TextureImporter) AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(displacementNormal)); - if(importer.textureType != TextureImporterType.NormalMap) { return TriValidationResult.Error("Normal map is required"); } + TextureImporter importer = (TextureImporter) AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(displacementNormal)); + if (importer.textureType != TextureImporterType.NormalMap) + { + return TriValidationResult.Error("Normal map is required"); + } #endif - return TriValidationResult.Valid; - } - public override void SetProperties() - { - base.SetProperties(); - matPassID.SetTexture("_Image", noiseTexture); - matPassID.SetTexture("_Displacement", displacementNormal); - matPassID.SetFloat("_DispStrength", displacementStrength); - matPassID.SetFloat("_Strength", strength); + return TriValidationResult.Valid; + } + + public override void SetProperties() + { + base.SetProperties(); + matPassID.SetTexture("_Image", noiseTexture); + matPassID.SetTexture("_Displacement", displacementNormal); + matPassID.SetFloat("_DispStrength", displacementStrength); + matPassID.SetFloat("_Strength", strength); + } } } diff --git a/Unity/Assets/Scripts/SCHIZO/VFX/PreviewImage.cs b/Unity/Assets/Scripts/SCHIZO/VFX/PreviewImage.cs index 438d0e4e..0c8a21af 100644 --- a/Unity/Assets/Scripts/SCHIZO/VFX/PreviewImage.cs +++ b/Unity/Assets/Scripts/SCHIZO/VFX/PreviewImage.cs @@ -3,8 +3,6 @@ namespace SCHIZO.VFX { - [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] - public sealed class PreviewImageAttribute() : PropertyAttribute - { - } + [AttributeUsage(AttributeTargets.Field)] + public sealed class PreviewImageAttribute : PropertyAttribute; } diff --git a/Unity/Assets/Scripts/SCHIZO/VFX/SchizoVFXStack.cs b/Unity/Assets/Scripts/SCHIZO/VFX/SchizoVFXStack.cs index 6bf4c9cb..6de650bd 100644 --- a/Unity/Assets/Scripts/SCHIZO/VFX/SchizoVFXStack.cs +++ b/Unity/Assets/Scripts/SCHIZO/VFX/SchizoVFXStack.cs @@ -7,20 +7,18 @@ public class SchizoVFXStack : MonoBehaviour { private static SchizoVFXStack _instance; - public static SchizoVFXStack VFXStack + public static SchizoVFXStack Instance { get { - if (_instance != null) return _instance; - _instance = Camera.main.GetComponent(); - if (_instance == null) _instance = Camera.main.gameObject.AddComponent(); - return _instance; + if (_instance) return _instance; + return _instance = Camera.main!.gameObject.AddComponent(); } } - private static List effectMaterials = []; + private static readonly List effectMaterials = []; - public static void RenderEffect(MatPassID m) + public void RenderEffect(MatPassID m) { if (effectMaterials.Contains(m)) return; effectMaterials.Add(m); diff --git a/Unity/Assets/Scripts/SCHIZO/VFX/TwoColorTint.cs b/Unity/Assets/Scripts/SCHIZO/VFX/TwoColorTint.cs index 90b3b9b8..2baa0de7 100644 --- a/Unity/Assets/Scripts/SCHIZO/VFX/TwoColorTint.cs +++ b/Unity/Assets/Scripts/SCHIZO/VFX/TwoColorTint.cs @@ -1,18 +1,20 @@ -using SCHIZO.VFX; using UnityEngine; -public class TwoColorTint : VFXComponent +namespace SCHIZO.VFX { - public Color innerColor = Color.red; - public Color outerColor = Color.green; - [Range(0f, 1f)] - public float strength = 0.3f; - - public override void SetProperties() + public class TwoColorTint : VFXComponent { - base.SetProperties(); - matPassID.SetColor("_Color", innerColor); - matPassID.SetColor("_Color0", outerColor); - matPassID.SetFloat("_Strength", strength); + public Color innerColor = Color.red; + public Color outerColor = Color.green; + [Range(0f, 1f)] + public float strength = 0.3f; + + public override void SetProperties() + { + base.SetProperties(); + matPassID.SetColor("_Color", innerColor); + matPassID.SetColor("_Color0", outerColor); + matPassID.SetFloat("_Strength", strength); + } } } diff --git a/Unity/Assets/Scripts/SCHIZO/VFX/VFXComponent.cs b/Unity/Assets/Scripts/SCHIZO/VFX/VFXComponent.cs index a87ad3f5..e26a73eb 100644 --- a/Unity/Assets/Scripts/SCHIZO/VFX/VFXComponent.cs +++ b/Unity/Assets/Scripts/SCHIZO/VFX/VFXComponent.cs @@ -1,32 +1,28 @@ -using TriInspector; using UnityEngine; -namespace SCHIZO.VFX { +#if UNITY_EDITOR +using TriInspector; +#endif +namespace SCHIZO.VFX +{ public class VFXComponent : MonoBehaviour { - [ReadOnly] - public Material material; - - [HideInInspector] - public MatPassID matPassID; + [ReadOnly] public Material material; - [SerializeField] - private bool isActive = true; + [HideInInspector] public MatPassID matPassID; #if UNITY_EDITOR - [OnValueChanged(nameof(SetNewResultTexture))] public Texture2D previewImage; - [PreviewImage] - public Texture2D previewResult; + [PreviewImage] public Texture2D previewResult; private void OnValidate() { if (previewImage) { - if (previewResult == null) { SetNewResultTexture(); } + if (previewResult == null) SetNewResultTexture(); if ((previewImage.height != previewResult.height) || (previewImage.width != previewResult.width)) { } SetProperties(); RenderTexture tempResult = RenderTexture.GetTemporary(previewImage.width, previewImage.height, 0, RenderTextureFormat.ARGBHalf); @@ -35,42 +31,22 @@ private void OnValidate() tempResult.Release(); } } + private void SetNewResultTexture() { previewResult = new Texture2D(previewImage.width, previewImage.height, TextureFormat.RGBAHalf, false); } #endif - public void SetActive() - { - isActive = true; - } - - public void SetDisable() - { - isActive = false; - } - public virtual void SetProperties() { - if (matPassID == null) - { - matPassID = new(material); - } - } - - public virtual void Awake() - { - _ = SchizoVFXStack.VFXStack; + matPassID ??= new MatPassID(material); } public virtual void Update() { - if (isActive) - { - SetProperties(); - SchizoVFXStack.RenderEffect(matPassID); - } + SetProperties(); + SchizoVFXStack.Instance.RenderEffect(matPassID); } } }