完成滤镜系统初步抽象
This commit is contained in:
parent
adde033fa1
commit
73a5b9d258
@ -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
|
||||
|
@ -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<TickLoop>();
|
||||
|
75
AxibugEmuOnline.Client/Assets/Script/Filter/FilterEffect.cs
Normal file
75
AxibugEmuOnline.Client/Assets/Script/Filter/FilterEffect.cs
Normal file
@ -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<EditableParamerter> m_editableParamList;
|
||||
|
||||
public IReadOnlyCollection<EditableParamerter> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4df899ccb7155d44be59fbc5289cedd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -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<EnumMaskStyle> MaskStyle = new ParameterOverride<EnumMaskStyle> { value = EnumMaskStyle.ApertureGrille };
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Filter> 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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 滤镜列表
|
||||
/// </summary>
|
||||
public IReadOnlyList<Filter> Filters => m_filters;
|
||||
|
||||
/// <summary>
|
||||
/// 打开滤镜
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭滤镜效果
|
||||
/// </summary>
|
||||
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<EditableParamerter> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5354e2e13dbff91438a04b9de2351645
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user