1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using System;
- using System.Collections.Generic;
- namespace COM3D2.MeidoPhotoStudio.Plugin
- {
- public class EffectManager : IManager, ISerializable
- {
- public const string header = "EFFECT";
- public const string footer = "END_EFFECT";
- private readonly Dictionary<Type, IEffectManager> EffectManagers = new Dictionary<Type, IEffectManager>();
- public T Get<T>() where T : IEffectManager
- => EffectManagers.ContainsKey(typeof(T)) ? (T)EffectManagers[typeof(T)] : default;
- public T AddManager<T>() where T : IEffectManager, new()
- {
- T manager = new T();
- EffectManagers[typeof(T)] = manager;
- manager.Activate();
- return manager;
- }
- public void Serialize(System.IO.BinaryWriter binaryWriter)
- {
- binaryWriter.Write(header);
- foreach (IEffectManager effectManager in EffectManagers.Values) effectManager.Serialize(binaryWriter);
- binaryWriter.Write(footer);
- }
- public void Deserialize(System.IO.BinaryReader binaryReader)
- {
- string header;
- while ((header = binaryReader.ReadString()) != footer)
- {
- switch (header)
- {
- case BloomEffectManager.header:
- Get<BloomEffectManager>().Deserialize(binaryReader);
- break;
- case DepthOfFieldEffectManager.header:
- Get<DepthOfFieldEffectManager>().Deserialize(binaryReader);
- break;
- case VignetteEffectManager.header:
- Get<VignetteEffectManager>().Deserialize(binaryReader);
- break;
- case FogEffectManager.header:
- Get<FogEffectManager>().Deserialize(binaryReader);
- break;
- case SepiaToneEffectManger.header:
- Get<SepiaToneEffectManger>().Deserialize(binaryReader);
- break;
- case BlurEffectManager.header:
- Get<BlurEffectManager>().Deserialize(binaryReader);
- break;
- }
- }
- }
- public void Activate()
- {
- foreach (IEffectManager effectManager in EffectManagers.Values) effectManager.Activate();
- }
- public void Deactivate()
- {
- foreach (IEffectManager effectManager in EffectManagers.Values) effectManager.Deactivate();
- }
- public void Update() { }
- }
- }
|