diff --git a/CustomShaderDesc.cs b/CustomShaderDesc.cs index dc1a490..98784a8 100644 --- a/CustomShaderDesc.cs +++ b/CustomShaderDesc.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using UnityEngine; +using UnityEngine; namespace SphereOpt; @@ -10,46 +8,13 @@ public class CustomShaderDesc public readonly Shader shader; public readonly string shaderName; public readonly string replacementForShader; - public readonly Dictionary addedProperties; - public CustomShaderDesc (string shortName, string shaderToReplace, string replacementShader, Dictionary addedProps) + public CustomShaderDesc (string shortName, string shaderToReplace, string replacementShader) { shader = CustomShaderManager.GetShader(replacementShader); if (shader == null) SphereOpt.logger.LogError($"Could not find shader for name: {replacementShader}"); shaderName = replacementShader; replacementForShader = shaderToReplace; - if (addedProps == null) addedProps = new Dictionary(); - addedProperties = addedProps; this.shortName = shortName; } - - public Type TypeOfAddedProperty(string propName) - { - if (!addedProperties.TryGetValue(propName, out var ePropType)) - { - SphereOpt.logger.LogWarning($"{shaderName} has no added property named {propName}."); - return null; - } - - return ePropType switch - { - EShaderPropType.Buffer => typeof(ComputeBuffer), - EShaderPropType.Color => typeof(Color), - EShaderPropType.Float => typeof(float), - EShaderPropType.Int => typeof(int), - EShaderPropType.Matrix => typeof(Matrix4x4), - EShaderPropType.Vector => typeof(Vector4), - _ => throw new ArgumentOutOfRangeException() - }; - } -} - -public enum EShaderPropType -{ - Buffer, - Color, - Float, - Int, - Matrix, - Vector } \ No newline at end of file diff --git a/CustomShaderManager.cs b/CustomShaderManager.cs index e349206..443b087 100644 --- a/CustomShaderManager.cs +++ b/CustomShaderManager.cs @@ -1,5 +1,4 @@ -using SphereOpt; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Reflection; using UnityEngine; @@ -43,7 +42,6 @@ public static void InitWithBundle(AssetBundle assetBundle) if (!LoadShadersFromBundle()) { SphereOpt.logger.LogError("Failed to load custom shaders from bundle."); - return; } } @@ -68,10 +66,9 @@ private static bool LoadShadersFromBundle() return true; } - public static void AddCustomShaderDesc(string shortName, string shaderToReplace, string replacementShader, - Dictionary addedProps = null) + public static void AddCustomShaderDesc(string shortName, string shaderToReplace, string replacementShader) { - CustomShaderDesc shaderDesc = new(shortName, shaderToReplace, replacementShader, addedProps); + CustomShaderDesc shaderDesc = new(shortName, shaderToReplace, replacementShader); customShaderDescs.Add(shaderDesc); replacementForShaderMap.Add(shaderDesc.replacementForShader, shaderDesc); shortNameMap.Add(shaderDesc.shortName, shaderDesc); @@ -80,12 +77,12 @@ public static void AddCustomShaderDesc(string shortName, string shaderToReplace, public static CustomShaderDesc LookupReplacementShaderFor(string originalShaderName) { - return replacementForShaderMap.TryGetValue(originalShaderName, out CustomShaderDesc customShader) ? customShader : null; + return replacementForShaderMap.TryGetValue(originalShaderName, out var customShader) ? customShader : null; } public static bool ReplaceShaderIfAvailable(Material mat) { - if (replacementForShaderMap.TryGetValue(mat.shader.name, out CustomShaderDesc customShaderDesc)) + if (replacementForShaderMap.TryGetValue(mat.shader.name, out var customShaderDesc)) { SphereOpt.logger.LogInfo($"replacing shader on: {mat.name}"); ApplyCustomShaderToMaterial(mat, customShaderDesc); @@ -105,17 +102,6 @@ public static Shader GetShader (string customShaderName) return null; } - public static CustomShaderDesc GetCustomShaderDescByShortName(string shortName) - { - if (!shortNameMap.TryGetValue(shortName, out CustomShaderDesc csd)) - { - SphereOpt.logger.LogError($"CustomShaderDesc with ShortName: {shortName} not found"); - return null; - } - - return csd; - } - public static void ApplyCustomShaderToMaterial(Material mat, CustomShaderDesc replacementShader) { mat.shader = replacementShader.shader; @@ -128,32 +114,4 @@ public static void ApplyCustomShaderToMaterial(Material mat, CustomShaderDesc re matList.Add(mat); } - - public static void SetPropByShortName(string propName, float propVal, string shortName) - { - CustomShaderDesc csd = GetCustomShaderDescByShortName(shortName); - if (csd == null) - { - SphereOpt.logger.LogError($"No CustomShaderDesc found with shortName: {shortName}"); - return; - } - - var propType = csd.TypeOfAddedProperty(propName); - if (propType == null) - { - SphereOpt.logger.LogError($"CustomShaderDesc has no AddedProperty named: {propName}"); - return; - - } - - if (propType != typeof(float)) - { - SphereOpt.logger.LogError($"Property {propName} is of type {csd.TypeOfAddedProperty(propName)} but value provided is float"); - } - - foreach (var mat in shaderReplacedOnMaterialsMap[csd]) - { - mat.SetFloat(propName, propVal); - } - } } \ No newline at end of file diff --git a/Patch_VFPreload.cs b/Patch_VFPreload.cs index daeb3a1..a7db041 100644 --- a/Patch_VFPreload.cs +++ b/Patch_VFPreload.cs @@ -1,5 +1,4 @@ -using System.ComponentModel; -using HarmonyLib; +using HarmonyLib; using UnityEngine; namespace SphereOpt; diff --git a/SphereOpt.cs b/SphereOpt.cs index 786c952..995d045 100644 --- a/SphereOpt.cs +++ b/SphereOpt.cs @@ -14,7 +14,7 @@ public class SphereOpt : BaseUnityPlugin private static AssetBundle bundle; private static readonly string AssemblyPath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(SphereOpt)).Location); - public static AssetBundle Bundle + private static AssetBundle Bundle { get {