diff --git a/AxibugEmuOnline.Client/Assets/Scene/AxibugEmuOnline.Client.unity b/AxibugEmuOnline.Client/Assets/Scene/AxibugEmuOnline.Client.unity index e6a5bc7f..5348750e 100644 --- a/AxibugEmuOnline.Client/Assets/Scene/AxibugEmuOnline.Client.unity +++ b/AxibugEmuOnline.Client/Assets/Scene/AxibugEmuOnline.Client.unity @@ -13389,6 +13389,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 980f937ad27ad8540afeb8b7f100997e, type: 3} m_Name: m_EditorClassIdentifier: + m_filterVolume: {fileID: 1475480930} --- !u!1 &1427887268 GameObject: m_ObjectHideFlags: 0 diff --git a/AxibugEmuOnline.Client/Assets/Script/App.cs b/AxibugEmuOnline.Client/Assets/Script/App.cs index fe55e095..b21c61cc 100644 --- a/AxibugEmuOnline.Client/Assets/Script/App.cs +++ b/AxibugEmuOnline.Client/Assets/Script/App.cs @@ -5,6 +5,7 @@ using System.IO; using System.Threading.Tasks; using UnityEngine; using UnityEngine.Networking; +using UnityEngine.Rendering.PostProcessing; using static AxibugEmuOnline.Client.HttpAPI; using static AxibugEmuOnline.Client.Manager.LogManager; @@ -27,6 +28,7 @@ namespace AxibugEmuOnline.Client.ClientCore public static CacheManager CacheMgr; public static AppRoom roomMgr; public static AppSettings settings; + public static FilterManager filter; #region Mono public static TickLoop tickLoop; private static CoroutineRunner coRunner; @@ -37,7 +39,7 @@ namespace AxibugEmuOnline.Client.ClientCore #else public static string PersistentDataPath => Application.persistentDataPath; #endif - public static void Init() + public static void Init(PostProcessVolume filterVolume) { settings = new AppSettings(); @@ -53,6 +55,7 @@ namespace AxibugEmuOnline.Client.ClientCore nesRomLib = new RomLib(EnumPlatform.NES); CacheMgr = new CacheManager(); roomMgr = new AppRoom(); + filter = new FilterManager(filterVolume); var go = new GameObject("[AppAxibugEmuOnline]"); GameObject.DontDestroyOnLoad(go); tickLoop = go.AddComponent(); diff --git a/AxibugEmuOnline.Client/Assets/Script/Filter/FilterEffect.cs b/AxibugEmuOnline.Client/Assets/Script/Filter/FilterEffect.cs new file mode 100644 index 00000000..4346e01b --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/Filter/FilterEffect.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using UnityEngine; +using UnityEngine.Rendering.PostProcessing; + +namespace AxibugEmuOnline.Client +{ + public abstract class FilterEffect : PostProcessEffectSettings + { + private List m_editableParamList; + + public IReadOnlyCollection EditableParam => m_editableParamList.AsReadOnly(); + + public FilterEffect() + { + GetEditableFilterParamters(); + } + protected void GetEditableFilterParamters() + { + var parameters = (from t in GetType().GetFields(BindingFlags.Instance | BindingFlags.Public) + where t.FieldType.IsSubclassOf(typeof(ParameterOverride)) + where t.DeclaringType.IsSubclassOf(typeof(FilterEffect)) + orderby t.MetadataToken + select t); + m_editableParamList = parameters.Select(p => new EditableParamerter(p.Name, (ParameterOverride)p.GetValue(this))).ToList(); + } + + public class EditableParamerter + { + private ParameterOverride m_paramObject; + private FieldInfo valueFieldInfo; + + public Type ValueType { get; private set; } + public string Name { get; private set; } + public object Value + { + get => valueFieldInfo.GetValue(m_paramObject); + set + { + valueFieldInfo.SetValue(m_paramObject, value); + } + } + public EditableParamerter(string name, ParameterOverride paramObject) + { + m_paramObject = paramObject; + Name = name; + + var paramType = paramObject.GetType(); + + valueFieldInfo = paramType.GetField("value", BindingFlags.Public | BindingFlags.Instance); + if (valueFieldInfo != null) + { + ValueType = valueFieldInfo.FieldType; + } + else + { + ValueType = typeof(object); + } + } + + public string Serilized() + { + return JsonUtility.ToJson(Value); + } + + public void Apply(string json) + { + var overrideValue = JsonUtility.FromJson(json, ValueType); + Value = overrideValue; + } + } + } +} diff --git a/AxibugEmuOnline.Client/Assets/Script/Filter/FilterEffect.cs.meta b/AxibugEmuOnline.Client/Assets/Script/Filter/FilterEffect.cs.meta new file mode 100644 index 00000000..d4fee7cb --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/Filter/FilterEffect.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c4df899ccb7155d44be59fbc5289cedd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Script/Filter/FixingPixelArtGrille.cs b/AxibugEmuOnline.Client/Assets/Script/Filter/FixingPixelArtGrille.cs index f8bfb136..6ecb2a16 100644 --- a/AxibugEmuOnline.Client/Assets/Script/Filter/FixingPixelArtGrille.cs +++ b/AxibugEmuOnline.Client/Assets/Script/Filter/FixingPixelArtGrille.cs @@ -1,11 +1,12 @@ using AxibugEmuOnline.Client; using AxibugEmuOnline.Client.ClientCore; +using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering.PostProcessing; [System.Serializable] [PostProcess(typeof(FixingPixelArtGrilleRenderer), PostProcessEvent.BeforeStack, "Filter/FixingPixelArtGrille")] -public sealed class FixingPixelArtGrille : PostProcessEffectSettings +public sealed class FixingPixelArtGrille : FilterEffect { public ParameterOverride MaskStyle = new ParameterOverride { value = EnumMaskStyle.ApertureGrille }; diff --git a/AxibugEmuOnline.Client/Assets/Script/Filter/GameCamera Profile.asset b/AxibugEmuOnline.Client/Assets/Script/Filter/GameCamera Profile.asset index f62c9669..e9c21819 100644 --- a/AxibugEmuOnline.Client/Assets/Script/Filter/GameCamera Profile.asset +++ b/AxibugEmuOnline.Client/Assets/Script/Filter/GameCamera Profile.asset @@ -13,8 +13,8 @@ MonoBehaviour: m_Name: GameCamera Profile m_EditorClassIdentifier: settings: - - {fileID: 8004032914748422304} ---- !u!114 &8004032914748422304 + - {fileID: 117625959343581733} +--- !u!114 &117625959343581733 MonoBehaviour: m_ObjectHideFlags: 3 m_CorrespondingSourceObject: {fileID: 0} @@ -32,7 +32,7 @@ MonoBehaviour: value: 1 MaskStyle: overrideState: 0 - value: 3 + value: 1 DrawResolution: overrideState: 0 value: {x: 272, y: 240} @@ -44,19 +44,19 @@ MonoBehaviour: value: -2 HardBloomScan: overrideState: 0 - value: -4.06 + value: -4 HardBloomPix: overrideState: 0 - value: -1.15 + value: -1.5 BloomAmount: overrideState: 0 - value: 0.483 + value: 0.0625 Warp: overrideState: 0 - value: {x: 0.12, y: 0.04} + value: {x: 0.015625, y: 0.041666668} MaskLight: overrideState: 0 - value: 3 + value: 1.5 MaskDrak: overrideState: 0 - value: 0.1 + value: 0.5 diff --git a/AxibugEmuOnline.Client/Assets/Script/Initer.cs b/AxibugEmuOnline.Client/Assets/Script/Initer.cs index 0189d9de..1445779a 100644 --- a/AxibugEmuOnline.Client/Assets/Script/Initer.cs +++ b/AxibugEmuOnline.Client/Assets/Script/Initer.cs @@ -1,13 +1,17 @@ using AxibugEmuOnline.Client.ClientCore; using UnityEngine; +using UnityEngine.Rendering.PostProcessing; namespace AxibugEmuOnline.Client { public class Initer : MonoBehaviour { + [SerializeField] + PostProcessVolume m_filterVolume; + private void Awake() { - App.Init(); + App.Init(m_filterVolume); } } } diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/FilterManager.cs b/AxibugEmuOnline.Client/Assets/Script/Manager/FilterManager.cs new file mode 100644 index 00000000..af0795c4 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/FilterManager.cs @@ -0,0 +1,87 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using UnityEngine.Rendering.PostProcessing; +using static AxibugEmuOnline.Client.FilterEffect; + +namespace AxibugEmuOnline.Client +{ + public class FilterManager + { + private PostProcessProfile m_filterPorfile; + private List m_filters; + + public FilterManager(PostProcessVolume filterVolume) + { + m_filterPorfile = filterVolume.profile; + m_filters = m_filterPorfile.settings.Where(setting=>setting is FilterEffect).Select(setting => new Filter(setting as FilterEffect)).ToList(); + + ShutDownFilter(); + } + + /// + /// 滤镜列表 + /// + public IReadOnlyList Filters => m_filters; + + /// + /// 打开滤镜 + /// + /// + public void EnableFilter(Filter filter) + { + foreach(var selfFiler in Filters) + { + if (selfFiler != filter) selfFiler.m_setting.enabled.Override(false); + else selfFiler.m_setting.enabled.Override(true); + } + } + + /// + /// 关闭滤镜效果 + /// + public void ShutDownFilter() + { + //关闭所有后处理效果 + foreach (var setting in m_filterPorfile.settings) + setting.enabled.Override(false); + } + + public struct Filter + { + public readonly string Name => m_setting.name; + + internal FilterEffect m_setting; + + public Filter(FilterEffect setting) + { + m_setting = setting; + } + + internal IReadOnlyCollection Paramerters => m_setting.EditableParam; + + public override readonly int GetHashCode() + { + return m_setting.GetHashCode(); + } + + public override readonly bool Equals(object obj) + { + if(obj == null) return false; + if (!(obj is Filter)) return false; + + return ((Filter)obj).GetHashCode() == GetHashCode(); + } + + public static bool operator ==(Filter left, Filter right) + { + return left.GetHashCode() == right.GetHashCode(); + } + + public static bool operator !=(Filter left, Filter right) + { + return !(left == right); + } + } + } +} diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/FilterManager.cs.meta b/AxibugEmuOnline.Client/Assets/Script/Manager/FilterManager.cs.meta new file mode 100644 index 00000000..d7ab243c --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/FilterManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5354e2e13dbff91438a04b9de2351645 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: