using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
/// 加工系统.处理系统,加工一个数据后返回,处理一个数据后返回
public interface IProcessor
{
T GetContext(string key, T value);
void AddProcessor(string key, Func func);
void RemoveProcessor(string key, Func func);
T GetContext(T value = default);
void AddProcessor(Func func);
void RemoveProcessor(Func func);
}
public class Processor : IProcessor
{
public Dictionary> dictionary = new();
public T GetContext(T value = default) => GetContext(key, value);
public void AddProcessor(Func func) => AddProcessor(key, func);
public void RemoveProcessor(Func func) => RemoveProcessor(key, func);
string key => nameof(Processor);
public T GetContext(string key, T value)
{
key = string.Empty.GetType();
dictionary.Get(key).ForEach(x =>
{
var func = x as Func;
value = func.Invoke(value);
});
return value;
}
public void AddProcessor(string key, Func func)
{
key = string.Empty.GetType();
dictionary.Get(key).Add(func);
}
public void RemoveProcessor(string key, Func func)
{
key = string.Empty.GetType();
dictionary.Get(key).Remove(func);
}
}
}