diff --git a/AxibugEmuOnline.Client/Assets/AxiProjectTools/Editors/AxiProjectTools.cs b/AxibugEmuOnline.Client/Assets/AxiProjectTools/Editors/AxiProjectTools.cs index f531ce2..31e3825 100644 --- a/AxibugEmuOnline.Client/Assets/AxiProjectTools/Editors/AxiProjectTools.cs +++ b/AxibugEmuOnline.Client/Assets/AxiProjectTools/Editors/AxiProjectTools.cs @@ -1,4 +1,4 @@ -#if UNITY_EDITOR +#if UNITY_EDITOR using System; using System.Collections.Generic; using System.IO; @@ -6,6 +6,7 @@ using System.Linq; using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; +using UnityEngine.SceneManagement; public class AxiProjectTools : EditorWindow { @@ -28,7 +29,7 @@ public class AxiProjectTools : EditorWindow } } - [MenuItem("Axibugֲ/[1]ɼԤͳµUGUI")] + [MenuItem("Axibug移植工具/[1]采集所有预制体和场景下的UGUI组件")] public static void Part1() { GoTAxiProjectToolsSence(); @@ -42,17 +43,17 @@ public class AxiProjectTools : EditorWindow EditorSceneManager.OpenScene(path); - // һб洢ڵ + // 创建一个列表来存储根节点 List rootNodes = new List(); - // еж + // 遍历场景中的所有对象 GameObject[] allObjects = FindObjectsOfType(); foreach (GameObject obj in allObjects) { - // Ƿи + // 检查对象是否有父对象 if (obj.transform.parent == null) { - // ûиһڵ + // 如果没有父对象,则它是一个根节点 rootNodes.Add(obj); } } @@ -76,7 +77,7 @@ public class AxiProjectTools : EditorWindow AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); GoTAxiProjectToolsSence(); - Debug.Log(" [1]ɼԤͳµUGUI"); + Debug.Log("处理完毕 [1]采集所有预制体和场景下的UGUI组件"); } static void GetPrefab(string path) @@ -102,11 +103,11 @@ public class AxiProjectTools : EditorWindow Type monoType = monoCom.GetType(); if (!monoType.Assembly.FullName.Contains("UnityEngine.UI")) continue; - // ȡMonoScriptԴ + // 获取MonoScript资源 MonoScript monoScript = MonoScript.FromMonoBehaviour(monoCom); if (monoScript != null) { - // ȡMonoScriptԴGUID + // 获取MonoScript资源的GUID string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(monoScript)); Debug.Log($"{nodename} | [{monoType.Name}] {guid}({monoType.FullName})"); ComType2GUID[monoType.FullName] = @@ -119,19 +120,19 @@ public class AxiProjectTools : EditorWindow } else { - Debug.LogError("!!!! û"); + Debug.LogError("!!!! 没得"); } } - // + //遍历 foreach (Transform child in trans.transform) LoopPrefabNode(nodename, child.gameObject, depth + 1); #else - Debug.Log("Ͱ汾Ҫִб"); + Debug.Log("低版本不要执行本函数"); #endif } - [MenuItem("Axibugֲ/[2]мű")] + [MenuItem("Axibug移植工具/[2]生成中间脚本代码")] public static void Part2() { if (UnityEngine.Windows.Directory.Exists(outCsDir)) @@ -151,16 +152,16 @@ public class AxiProjectTools : EditorWindow } catch (Exception ex) { - Debug.LogError("дʧ" + ex.ToString()); + Debug.LogError("写入失败" + ex.ToString()); } } - Debug.Log("д"); + Debug.Log("写入完毕"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); - Debug.Log(" [2]мű"); + Debug.Log("处理完毕 [2]生成中间脚本代码"); } - [MenuItem("Axibugֲ/[3]ռɵĽű")] + [MenuItem("Axibug移植工具/[3]收集生成的脚本")] public static void Part3() { AxiPrefabCache cache = AssetDatabase.LoadAssetAtPath(cachecfgPath); @@ -170,17 +171,17 @@ public class AxiProjectTools : EditorWindow MonoScript monoScript = allMonoScripts.FirstOrDefault(w => w.name == data.ToName); if (monoScript == null) { - Debug.LogError("ûҵ" + data.ToName); + Debug.LogError("没找到" + data.ToName); continue; } string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(monoScript)); data.ToGUID = guid; data.monoScript = monoScript; } - Debug.Log("д"); + Debug.Log("写入完毕"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); - Debug.Log(" [3]ռɵĽű"); + Debug.Log("处理完毕 [3]收集生成的脚本"); } static List FindAllAssetsOfType() where T : UnityEngine.Object @@ -191,7 +192,7 @@ public class AxiProjectTools : EditorWindow foreach (string guid in allGuids) { string path = AssetDatabase.GUIDToAssetPath(guid); - if (path.EndsWith(".cs") || path.EndsWith(".js") || path.EndsWith(".boo")) // Unityֶֽ֧űԣִUnityҪʹC# + if (path.EndsWith(".cs") || path.EndsWith(".js") || path.EndsWith(".boo")) // Unity支持多种脚本语言,但现代Unity主要使用C# { T asset = AssetDatabase.LoadAssetAtPath(path); if (asset != null) @@ -204,7 +205,7 @@ public class AxiProjectTools : EditorWindow } - [MenuItem("Axibugֲ/[4]滻Ԥͳе")] + [MenuItem("Axibug移植工具/[4]替换所有预制体和场景中的组件")] public static void Part4() { AxiPrefabCache cache = AssetDatabase.LoadAssetAtPath(cachecfgPath); @@ -218,7 +219,7 @@ public class AxiProjectTools : EditorWindow ProcessAllPrefabs("*.anim", tempReplaceDict); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); - Debug.Log(" [4]滻Ԥͳе"); + Debug.Log("处理完毕 [4]替换所有预制体和场景中的组件"); } static void ProcessAllPrefabs(string form, Dictionary tempReplaceDict, bool reverse = false) @@ -235,15 +236,15 @@ public class AxiProjectTools : EditorWindow string newValue = reverse ? VARIABLE.Key : VARIABLE.Value; ReplaceValue(absolutePaths[i], oldValue, newValue); } - EditorUtility.DisplayProgressBar("Ԥ塭", "ԤС", (float)i / absolutePaths.Length); + EditorUtility.DisplayProgressBar("处理预制体……", "处理预制体中……", (float)i / absolutePaths.Length); } EditorUtility.ClearProgressBar(); } /// - /// 滻ֵ + /// 替换值 /// - /// ļ· + /// 文件路径 static void ReplaceValue(string strFilePath, string oldLine, string newLine) { if (File.Exists(strFilePath)) @@ -258,7 +259,7 @@ public class AxiProjectTools : EditorWindow } - [MenuItem("Axibugֲ/[5]UnPackǶԤͳеԤ")] + [MenuItem("Axibug移植工具/[5]UnPack所有嵌套预制体和场景中的预制体")] public static void UnpackPrefabs() { @@ -276,7 +277,7 @@ public class AxiProjectTools : EditorWindow prefabCount++; } } - Debug.Log($"{prefabCount}ԤUnpack"); + Debug.Log($"{prefabCount}个预制体Unpack"); string[] sceneGuids = AssetDatabase.FindAssets("t:scene"); foreach (string guid in sceneGuids) @@ -290,21 +291,21 @@ public class AxiProjectTools : EditorWindow GameObject[] rootObjects = currentScene.GetRootGameObjects(); foreach (GameObject rootObj in rootObjects) { - // еж + // 遍历场景中的所有对象 TraverseHierarchy(rootObj); } - // Save the scene // ȡǰ򿪵ij + // Save the scene // 获取当前打开的场景 currentScene = EditorSceneManager.GetActiveScene(); - // 泡ļĬ·ƣ + // 保存场景到文件(默认路径和名称) bool success = EditorSceneManager.SaveScene(currentScene, currentScene.path); - Debug.Log($"{currentScene.name} Unpack"); + Debug.Log($"{currentScene.name}场景中 所有物体Unpack"); } GoTAxiProjectToolsSence(); - Debug.Log(" [5]UnPackԤ"); + Debug.Log("处理完毕 [5]UnPack所有预制体"); #else - Debug.Log("Ͱ汾Ҫִб"); + Debug.Log("低版本不要执行本函数"); #endif } @@ -323,33 +324,33 @@ public class AxiProjectTools : EditorWindow PrefabUtility.SaveAsPrefabAsset(obj, prefabPath); GameObject.DestroyImmediate(obj); #else - Debug.Log("Ͱ汾Ҫִб"); + Debug.Log("低版本不要执行本函数"); #endif } static void TraverseHierarchy(GameObject obj) { #if UNITY_2018_4_OR_NEWER - // öǷԤʵ + // 检查该对象是否是预制体的实例 if (PrefabUtility.IsPartOfPrefabInstance(obj)) { - // ԤʵתΪͨϷ + // 将预制体实例转换为普通游戏对象 PrefabUtility.UnpackPrefabInstance(obj, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction); Debug.Log("Prefab instance converted to game object: " + obj.name); } - // ݹӶ + // 递归遍历子对象 for (int i = 0; i < obj.transform.childCount; i++) { TraverseHierarchy(obj.transform.GetChild(i).gameObject); } #else - Debug.Log("Ͱ汾Ҫִб"); + Debug.Log("低版本不要执行本函数"); #endif } - [MenuItem("Axibugֲ/[6]޸Sprite")] + [MenuItem("Axibug移植工具/[6]修复Sprite")] public static void FixMultipleMaterialSprites() { string[] guids = AssetDatabase.FindAssets("t:sprite"); @@ -360,7 +361,7 @@ public class AxiProjectTools : EditorWindow string path = AssetDatabase.GUIDToAssetPath(guid); Sprite sprite = AssetDatabase.LoadAssetAtPath(path); - // Ƿж + // 检查是否有多个材质 if (IsUsingMultipleMaterials(sprite)) { spritesToFix.Add(sprite); @@ -368,7 +369,7 @@ public class AxiProjectTools : EditorWindow } } - // ޸ÿҵSprite + // 修复每个找到的Sprite foreach (var sprite in spritesToFix) { FixSprite(sprite); @@ -376,14 +377,14 @@ public class AxiProjectTools : EditorWindow AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); - Debug.Log(" [6]޸Sprite"); + Debug.Log("处理完毕 [6]修复Sprite"); } private static bool IsUsingMultipleMaterials(Sprite sprite) { if (sprite == null) return false; - // ȡIJ + // 获取精灵的材质 var textureImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(sprite)) as TextureImporter; return textureImporter != null && textureImporter.spriteImportMode == SpriteImportMode.Multiple; @@ -391,24 +392,24 @@ public class AxiProjectTools : EditorWindow private static void FixSprite(Sprite sprite) { - // ȡSprite· + // 获取Sprite的路径 string path = AssetDatabase.GetAssetPath(sprite); var textureImporter = AssetImporter.GetAtPath(path) as TextureImporter; if (textureImporter != null) { - // 浱ǰиϢ + // 保存当前切割信息 SpriteMetaData[] originalMetaData = textureImporter.spritesheet; - // ʱSprite + // 临时禁用Sprite导入 textureImporter.spriteImportMode = SpriteImportMode.None; textureImporter.SaveAndReimport(); - // Sprite벢ԭи + // 重新启用Sprite导入并保持原样切割参数 textureImporter.spriteImportMode = SpriteImportMode.Multiple; - textureImporter.spritesheet = originalMetaData; // ָԭиϢ + textureImporter.spritesheet = originalMetaData; // 恢复原来的切割信息 - // µӦø + // 重新导入以应用更改 textureImporter.SaveAndReimport(); } } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/FilterManager.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/FilterManager.cs index bc28153..5721c60 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/FilterManager.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/FilterManager.cs @@ -7,19 +7,19 @@ using static AxibugEmuOnline.Client.FilterEffect; namespace AxibugEmuOnline.Client { - public class FilterManager - { - private List m_filters; - private Dictionary m_filterPlatforms = new Dictionary(); - private AlphaWraper m_previewFilterWraper; - FilterRomSetting m_filterRomSetting; - /// - /// 滤镜列表 - /// - public IReadOnlyList Filters => m_filters; + public class FilterManager + { + private List m_filters; + private Dictionary m_filterPlatforms = new Dictionary(); + private AlphaWraper m_previewFilterWraper; + FilterRomSetting m_filterRomSetting; + /// + /// 滤镜列表 + /// + public IReadOnlyList Filters => m_filters; - public FilterManager(CanvasGroup filterPreview, CanvasGroup mainBg) - { + public FilterManager(CanvasGroup filterPreview, CanvasGroup mainBg) + { #if UNITY_PSP2 m_filters = new List(); m_filterRomSetting = new FilterRomSetting(); @@ -27,376 +27,374 @@ namespace AxibugEmuOnline.Client return; #endif - m_filters = new List - { - new Filter(new FixingPixelArtGrille()), - new Filter(new LCDPostEffect()), - new Filter(new MattiasCRT()), - }; - var json = PlayerPrefs.GetString(nameof(FilterRomSetting)); - m_filterRomSetting = JsonUtility.FromJson(json) ?? new FilterRomSetting(); + m_filters = new List + { + new Filter(new FixingPixelArtGrille()), + new Filter(new LCDPostEffect()), + new Filter(new MattiasCRT()), + }; + var json = PlayerPrefs.GetString(nameof(FilterRomSetting)); + m_filterRomSetting = JsonUtility.FromJson(json) ?? new FilterRomSetting(); - m_previewFilterWraper = new AlphaWraper(mainBg, filterPreview, false); - ShutDownFilterPreview(); - ShutDownFilter(); - } + m_previewFilterWraper = new AlphaWraper(mainBg, filterPreview, false); + ShutDownFilterPreview(); + ShutDownFilter(); + } - private RenderTexture result = null; - public Texture ExecuteFilterRender(Texture src) - { - if (result == null) - { - //result = RenderTexture.GetTemporary(Screen.width, Screen.height); - result = Initer.instance.renderTest; - } - else if (result.width != Screen.width || result.height != Screen.height) - { - //RenderTexture.ReleaseTemporary(result); - //result = RenderTexture.GetTemporary(Screen.width, Screen.height); - result = Initer.instance.renderTest; - } + private RenderTexture result = null; + public Texture ExecuteFilterRender(Texture src) + { + if (result == null) + { + result = RenderTexture.GetTemporary(Screen.width, Screen.height); + } + else if (result.width != Screen.width || result.height != Screen.height) + { + RenderTexture.ReleaseTemporary(result); + result = RenderTexture.GetTemporary(Screen.width, Screen.height); + } - bool anyFilterEnable = false; - foreach (var filter in Filters) - { - if (!filter.m_setting.Enable.GetValue()) continue; - filter.m_setting.Render(src, result); - anyFilterEnable = true; - } + bool anyFilterEnable = false; + foreach (var filter in Filters) + { + if (!filter.m_setting.Enable.GetValue()) continue; + filter.m_setting.Render(src, result); + anyFilterEnable = true; + } - if (anyFilterEnable) - return result; - else - return src; - } + if (anyFilterEnable) + return result; + else + return src; + } - /// 关闭滤镜预览 - public void ShutDownFilterPreview() - { - m_previewFilterWraper.On = false; - } + /// 关闭滤镜预览 + public void ShutDownFilterPreview() + { + m_previewFilterWraper.On = false; + } - /// 开启滤镜预览 - public void EnableFilterPreview() - { - m_previewFilterWraper.On = true; - } + /// 开启滤镜预览 + public void EnableFilterPreview() + { + m_previewFilterWraper.On = true; + } - /// - /// 打开滤镜 - /// - /// - public void EnableFilter(Filter filter) - { - foreach (var selfFiler in Filters) - { - if (selfFiler != filter) selfFiler.m_setting.Enable.Override(false); - else selfFiler.m_setting.Enable.Override(true); - } - } + /// + /// 打开滤镜 + /// + /// + public void EnableFilter(Filter filter) + { + foreach (var selfFiler in Filters) + { + if (selfFiler != filter) selfFiler.m_setting.Enable.Override(false); + else selfFiler.m_setting.Enable.Override(true); + } + } - /// - /// 关闭滤镜效果 - /// - public void ShutDownFilter() - { - //关闭所有后处理效果 - foreach (var filter in Filters) - filter.m_setting.Enable.Override(false); - } + /// + /// 关闭滤镜效果 + /// + public void ShutDownFilter() + { + //关闭所有后处理效果 + foreach (var filter in Filters) + filter.m_setting.Enable.Override(false); + } - /// - /// 为指定rom设置滤镜以及滤镜的预设 - /// - /// rom对象 - /// 滤镜 - /// 滤镜预设 - public void SetupFilter(RomFile rom, Filter filter, FilterPreset preset) - { - m_filterRomSetting.Setup(rom, filter, preset); + /// + /// 为指定rom设置滤镜以及滤镜的预设 + /// + /// rom对象 + /// 滤镜 + /// 滤镜预设 + public void SetupFilter(RomFile rom, Filter filter, FilterPreset preset) + { + m_filterRomSetting.Setup(rom, filter, preset); - string json = m_filterRomSetting.ToJson(); - PlayerPrefs.SetString(nameof(FilterRomSetting), json); - } + string json = m_filterRomSetting.ToJson(); + PlayerPrefs.SetString(nameof(FilterRomSetting), json); + } - /// - /// 获得指定rom配置的滤镜设置 - /// - /// rom对象 - /// 此元组任意内任意成员都有可能为空 - public GetFilterSetting_result GetFilterSetting(RomFile rom) - { - var value = m_filterRomSetting.Get(rom); - Filter filter = null; - FilterPreset preset = null; + /// + /// 获得指定rom配置的滤镜设置 + /// + /// rom对象 + /// 此元组任意内任意成员都有可能为空 + public GetFilterSetting_result GetFilterSetting(RomFile rom) + { + var value = m_filterRomSetting.Get(rom); + Filter filter = null; + FilterPreset preset = null; - //filter = Filters.FirstOrDefault(f => f.Name == value.filterName); - //if (filter != null) - //{ - // string presetName = value.presetName; - // preset = filter.Presets.FirstOrDefault(p => p.Name == presetName); - //} + //filter = Filters.FirstOrDefault(f => f.Name == value.filterName); + //if (filter != null) + //{ + // string presetName = value.presetName; + // preset = filter.Presets.FirstOrDefault(p => p.Name == presetName); + //} - filter = Filters.FirstOrDefault(f => f.Name == value.Item1); - if (filter != null) - { - string presetName = value.Item2; - preset = filter.Presets.FirstOrDefault(p => p.Name == presetName); - } + filter = Filters.FirstOrDefault(f => f.Name == value.Item1); + if (filter != null) + { + string presetName = value.Item2; + preset = filter.Presets.FirstOrDefault(p => p.Name == presetName); + } - return new GetFilterSetting_result() - { - filter = filter, - preset = preset - }; - } + return new GetFilterSetting_result() + { + filter = filter, + preset = preset + }; + } - public struct GetFilterSetting_result - { - public Filter filter; - public FilterPreset preset; - } + public struct GetFilterSetting_result + { + public Filter filter; + public FilterPreset preset; + } - public class Filter - { - public string Name => m_setting.Name; - public IReadOnlyCollection Paramerters => m_setting.EditableParam; - /// 滤镜预设 - public List Presets = new List(); - /// 滤镜默认预设 - public FilterPreset DefaultPreset = new FilterPreset("DEFAULT"); + public class Filter + { + public string Name => m_setting.Name; + public IReadOnlyCollection Paramerters => m_setting.EditableParam; + /// 滤镜预设 + public List Presets = new List(); + /// 滤镜默认预设 + public FilterPreset DefaultPreset = new FilterPreset("DEFAULT"); - internal FilterEffect m_setting; + internal FilterEffect m_setting; - public Filter(FilterEffect setting) - { - m_setting = setting; + public Filter(FilterEffect setting) + { + m_setting = setting; - loadPresets(); - } + loadPresets(); + } - private void loadPresets() - { - var json = PlayerPrefs.GetString($"Filter_{Name}_PresetList", string.Empty); - var loadedPresets = JsonUtility.FromJson(json); - if (loadedPresets == null) return; - else Presets = loadedPresets.presets; - } + private void loadPresets() + { + var json = PlayerPrefs.GetString($"Filter_{Name}_PresetList", string.Empty); + var loadedPresets = JsonUtility.FromJson(json); + if (loadedPresets == null) return; + else Presets = loadedPresets.presets; + } - public void SavePresets() - { - var json = JsonUtility.ToJson(new FilterPresetList(Presets)); - PlayerPrefs.SetString($"Filter_{Name}_PresetList", json); - } + public void SavePresets() + { + var json = JsonUtility.ToJson(new FilterPresetList(Presets)); + PlayerPrefs.SetString($"Filter_{Name}_PresetList", json); + } - public MsgBool CreatePreset(string presetName, out FilterPreset newPreset) - { - newPreset = null; - if (string.IsNullOrWhiteSpace(presetName)) return "名称不能为空"; - if (Presets.Count(p => p.Name == presetName) != 0) return "名称重复"; + public MsgBool CreatePreset(string presetName, out FilterPreset newPreset) + { + newPreset = null; + if (string.IsNullOrWhiteSpace(presetName)) return "名称不能为空"; + if (Presets.Count(p => p.Name == presetName) != 0) return "名称重复"; - newPreset = new FilterPreset(presetName); - Presets.Add(newPreset); + newPreset = new FilterPreset(presetName); + Presets.Add(newPreset); - SavePresets(); + SavePresets(); - return true; - } + return true; + } - public void RemovePreset(FilterPreset preset) - { - if (!Presets.Remove(preset)) return; - SavePresets(); + public void RemovePreset(FilterPreset preset) + { + if (!Presets.Remove(preset)) return; + SavePresets(); - EventInvoker.RaiseFilterPresetRemoved(this, preset); - } + EventInvoker.RaiseFilterPresetRemoved(this, preset); + } - public void ResetPreset() - { - foreach (var param in Paramerters) - { - param.ResetToDefault(); - } - } + public void ResetPreset() + { + foreach (var param in Paramerters) + { + param.ResetToDefault(); + } + } - public void ApplyPreset(FilterPreset preset) - { - foreach (var param in Paramerters) - { - var value = preset.GetParamValue(param.Name, param.ValueType); - if (value == null) - param.ResetToDefault(); - else - param.Apply(value); - } + public void ApplyPreset(FilterPreset preset) + { + foreach (var param in Paramerters) + { + var value = preset.GetParamValue(param.Name, param.ValueType); + if (value == null) + param.ResetToDefault(); + else + param.Apply(value); + } - } + } - } + } - [Serializable] - private class FilterPresetList - { - public List presets; + [Serializable] + private class FilterPresetList + { + public List presets; - public FilterPresetList(List presets) - { - this.presets = presets; - foreach (var preset in presets) - { - preset.ReadyForJson(); - } - } - } + public FilterPresetList(List presets) + { + this.presets = presets; + foreach (var preset in presets) + { + preset.ReadyForJson(); + } + } + } - [Serializable] - public class FilterPreset - { - [SerializeField] - public string Name; - [SerializeField] - private List m_paramName = new List(); - [SerializeField] - private List m_valueJson = new List(); + [Serializable] + public class FilterPreset + { + [SerializeField] + public string Name; + [SerializeField] + private List m_paramName = new List(); + [SerializeField] + private List m_valueJson = new List(); - private bool m_cacheReady = false; - private Dictionary m_paramName2ValueJson; - public FilterPreset(string presetName) - { - Name = presetName; - } + private bool m_cacheReady = false; + private Dictionary m_paramName2ValueJson; + public FilterPreset(string presetName) + { + Name = presetName; + } - public void ReadyForJson() - { - prepareCache(); + public void ReadyForJson() + { + prepareCache(); - m_paramName = m_paramName2ValueJson.Keys.ToList(); - m_valueJson = m_paramName2ValueJson.Values.ToList(); - } + m_paramName = m_paramName2ValueJson.Keys.ToList(); + m_valueJson = m_paramName2ValueJson.Values.ToList(); + } - public string GetParamValueJson(string paramName) - { - prepareCache(); - string value; - m_paramName2ValueJson.TryGetValue(paramName, out value); - return value; - } + public string GetParamValueJson(string paramName) + { + prepareCache(); + string value; + m_paramName2ValueJson.TryGetValue(paramName, out value); + return value; + } - public object GetParamValue(string paramName, Type valueType) - { - var rawStr = GetParamValueJson(paramName); - if (rawStr == null) return null; + public object GetParamValue(string paramName, Type valueType) + { + var rawStr = GetParamValueJson(paramName); + if (rawStr == null) return null; - if (valueType == typeof(float)) - { - float floatVal; - float.TryParse(rawStr, out floatVal); - return floatVal; - } - else if (valueType.IsEnum) - { - var names = Enum.GetNames(valueType); - var values = Enum.GetValues(valueType); + if (valueType == typeof(float)) + { + float floatVal; + float.TryParse(rawStr, out floatVal); + return floatVal; + } + else if (valueType.IsEnum) + { + var names = Enum.GetNames(valueType); + var values = Enum.GetValues(valueType); - for (int i = 0; i < names.Length; i++) - { - if (names[i].Equals(rawStr)) - { - return values.GetValue(i); - } - } - return null; - } - else - { - App.log.Error($"尚未支持的滤镜参数类型{valueType}"); - return null; - } - } + for (int i = 0; i < names.Length; i++) + { + if (names[i].Equals(rawStr)) + { + return values.GetValue(i); + } + } + return null; + } + else + { + App.log.Error($"尚未支持的滤镜参数类型{valueType}"); + return null; + } + } - public void SetParamValue(string paramName, Type valueType, object value) - { - prepareCache(); - m_paramName2ValueJson[paramName] = value.ToString(); - } + public void SetParamValue(string paramName, Type valueType, object value) + { + prepareCache(); + m_paramName2ValueJson[paramName] = value.ToString(); + } - private void prepareCache() - { - if (m_cacheReady) return; + private void prepareCache() + { + if (m_cacheReady) return; - m_paramName2ValueJson = new Dictionary(); - for (int i = 0; i < m_paramName.Count; i++) - { - m_paramName2ValueJson[m_paramName[i]] = m_valueJson[i]; - } + m_paramName2ValueJson = new Dictionary(); + for (int i = 0; i < m_paramName.Count; i++) + { + m_paramName2ValueJson[m_paramName[i]] = m_valueJson[i]; + } - m_cacheReady = true; - } - } + m_cacheReady = true; + } + } - [Serializable] - public class FilterRomSetting - { - [SerializeField] - private List m_romID; - [SerializeField] - private List m_items; + [Serializable] + public class FilterRomSetting + { + [SerializeField] + private List m_romID; + [SerializeField] + private List m_items; - bool m_cacheReady = false; - Dictionary m_cache; + bool m_cacheReady = false; + Dictionary m_cache; - public void Setup(RomFile rom, Filter filter, FilterPreset preset) - { - prepareCache(); + public void Setup(RomFile rom, Filter filter, FilterPreset preset) + { + prepareCache(); - if (filter == null) - m_cache.Remove(rom.ID); - else - m_cache[rom.ID] = new Item { FilterName = filter.Name, PresetName = preset != null ? preset.Name : null }; - } + if (filter == null) + m_cache.Remove(rom.ID); + else + m_cache[rom.ID] = new Item { FilterName = filter.Name, PresetName = preset != null ? preset.Name : null }; + } - public string ToJson() - { - prepareCache(); - m_romID = m_cache.Keys.ToList(); - m_items = m_cache.Values.ToList(); + public string ToJson() + { + prepareCache(); + m_romID = m_cache.Keys.ToList(); + m_items = m_cache.Values.ToList(); - return JsonUtility.ToJson(this); - } + return JsonUtility.ToJson(this); + } - public ValueTuple Get(RomFile rom) - { - prepareCache(); + public ValueTuple Get(RomFile rom) + { + prepareCache(); - Item item; - m_cache.TryGetValue(rom.ID, out item); - return new ValueTuple(item.FilterName, item.PresetName); - } + Item item; + m_cache.TryGetValue(rom.ID, out item); + return new ValueTuple(item.FilterName, item.PresetName); + } - private void prepareCache() - { - if (m_cacheReady) return; + private void prepareCache() + { + if (m_cacheReady) return; - if (m_items == null) m_items = new List(); - if (m_romID == null) m_romID = new List(); - m_cache = new Dictionary(); - for (int i = 0; i < m_romID.Count && i < m_items.Count; i++) - { - m_cache[m_romID[i]] = m_items[i]; - } + if (m_items == null) m_items = new List(); + if (m_romID == null) m_romID = new List(); + m_cache = new Dictionary(); + for (int i = 0; i < m_romID.Count && i < m_items.Count; i++) + { + m_cache[m_romID[i]] = m_items[i]; + } - m_cacheReady = true; - } + m_cacheReady = true; + } - [Serializable] - struct Item - { - public string FilterName; - public string PresetName; - } - } - } + [Serializable] + struct Item + { + public string FilterName; + public string PresetName; + } + } + } }