From 92697989e1c780bd01004e4e6a49ac38644dcd12 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 22 Feb 2024 17:06:30 +0800 Subject: [PATCH] fixes --- src/AutoInjectSystem.cs | 24 +++- src/AutoProcesses/AutoProcesses.cs | 179 ------------------------ src/AutoProcesses/AutoProcesses.cs.meta | 11 -- src/Processes.cs | 7 + src/Utils/Exceptions.cs | 2 - 5 files changed, 25 insertions(+), 198 deletions(-) delete mode 100644 src/AutoProcesses/AutoProcesses.cs delete mode 100644 src/AutoProcesses/AutoProcesses.cs.meta create mode 100644 src/Processes.cs diff --git a/src/AutoInjectSystem.cs b/src/AutoInjectSystem.cs index ea6c137..f198e68 100644 --- a/src/AutoInjectSystem.cs +++ b/src/AutoInjectSystem.cs @@ -37,7 +37,9 @@ namespace DCFApixels.DragonECS } } foreach (var item in _systemProoperties.Keys) + { _notInjected.Add(item); + } } private static void Do(Type type, List result) @@ -139,10 +141,10 @@ namespace DCFApixels.DragonECS private readonly struct InjectedPropertyRecord { - public readonly IEcsProcess target; + public readonly IEcsSystem target; public readonly IInjectedProperty property; public EcsInjectAttribute Attribute => property.GetAutoInjectAttribute(); - public InjectedPropertyRecord(IEcsProcess target, IInjectedProperty property) + public InjectedPropertyRecord(IEcsSystem target, IInjectedProperty property) { this.target = target; this.property = property; @@ -152,28 +154,38 @@ namespace DCFApixels.DragonECS [MetaTags(MetaTags.HIDDEN)] [MetaColor(MetaColor.Gray)] - public class AutoInjectSystem : IEcsPreInject, IEcsInject, IEcsPreInitInjectProcess + public class AutoInjectSystem : IEcsInject, IEcsPipelineMember, IEcsPreInitInjectProcess { private EcsPipeline _pipeline; + EcsPipeline IEcsPipelineMember.Pipeline { get => _pipeline; set => _pipeline = value; } private List _delayedInjects = new List(); private AutoInjectionMap _autoInjectionMap; private bool _preInitInjectCompleted = false; - public void Inject(EcsPipeline obj) => _pipeline = obj; - public void PreInject(object obj) + + public void Inject(object obj) { if (!_preInitInjectCompleted) + { _delayedInjects.Add(obj); + } else + { _autoInjectionMap.Inject(obj.GetType(), obj); + } + } + public void OnPreInitInjectionBefore(EcsPipeline pipeline) + { + _pipeline = pipeline; } - public void OnPreInitInjectionBefore() { } public void OnPreInitInjectionAfter() { _autoInjectionMap = new AutoInjectionMap(_pipeline); _preInitInjectCompleted = true; foreach (var obj in _delayedInjects) + { _autoInjectionMap.Inject(obj.GetType(), obj); + } _autoInjectionMap.InjectDummy(); _autoInjectionMap.OnPreInitInjectionComplete(); diff --git a/src/AutoProcesses/AutoProcesses.cs b/src/AutoProcesses/AutoProcesses.cs deleted file mode 100644 index 7818169..0000000 --- a/src/AutoProcesses/AutoProcesses.cs +++ /dev/null @@ -1,179 +0,0 @@ -//using System; -//using System.Collections.Generic; -//using System.Reflection; -//using System.Runtime.CompilerServices; -// -//namespace DCFApixels.DragonECS -//{ -// public static class AutoProcesses -// { -// private static Dictionary _builders; -// [MethodImpl(MethodImplOptions.AggressiveInlining)] -// private static bool TryGetCustomAttribute(Type self, out T attribute) where T : Attribute -// { -// attribute = self.GetCustomAttribute(); -// return attribute != null; -// } -// static AutoProcesses() -// { -// _builders = new Dictionary(); -// foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) -// { -// var types = assembly.GetTypes(); -// foreach (var type in types) -// { -// if (type.IsGenericType) -// continue; -// if (TryGetCustomAttribute(type, out EcsProcessWrapperBuilderAttribute attr)) -// { -// MethodInfo method = type.GetMethod(attr.wrapperBuilderMethodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); -// BuilderHandler action = (BuilderHandler)Delegate.CreateDelegate(typeof(BuilderHandler), null, method); -// _builders.Add(attr.processMethodName, action); -// } -// } -// } -// } -// public static EcsPipeline.Builder AddAuto(this EcsPipeline.Builder self, object system, string layerName = null) -// { -// var methods = system.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); -// foreach (var method in methods) -// { -// if (_builders.TryGetValue(method.Name, out var builder)) -// { -// var process = builder(system, method); -// if (process != null) -// self.Add(process, layerName); -// } -// } -// if (system is IEcsProcess systemInterface) -// self.Add(systemInterface, layerName); -// return self; -// } -// private delegate IEcsProcess BuilderHandler(object targete, MethodInfo method); -// } -// -// [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)] -// sealed class EcsProcessWrapperBuilderAttribute : Attribute -// { -// public readonly string processMethodName; -// public readonly string wrapperBuilderMethodName; -// public EcsProcessWrapperBuilderAttribute(string processMethodName, string wrapperBuilderMethodName = "Builder") -// { -// this.processMethodName = processMethodName; -// this.wrapperBuilderMethodName = wrapperBuilderMethodName; -// } -// } -// public static class EcsAutoProcessUtility -// { -// public static TDelegate CreateDelegate(object system, MethodInfo method) where TDelegate : Delegate -// { -// return (TDelegate)Delegate.CreateDelegate(typeof(TDelegate), system, method); -// } -// } -// -// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// internal class EcsProcessWrapperBase -// { -// [MethodImpl(MethodImplOptions.AggressiveInlining)] -// public static bool CheckParameters(MethodInfo method) -// { -// return method.GetParameters().Length <= 0; -// } -// [MethodImpl(MethodImplOptions.AggressiveInlining)] -// public static Action CreateAction(object target, MethodInfo method) -// { -// return EcsAutoProcessUtility.CreateDelegate(target, method); -// } -// } -// internal class IEcsProcessWrapper : EcsProcessWrapperBase, IEcsMetaProvider -// { -// public object system; -// public Action a; -// public object MetaSource => system; -// } -// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// [EcsProcessWrapperBuilder(nameof(PreInit), nameof(Builder))] -// internal class EcsPreInitProcessWrapper : IEcsProcessWrapper, IEcsPreInitProcess -// { -// public EcsPreInitProcessWrapper(object target, Action a) { system = target; this.a = a; } -// [MethodImpl(MethodImplOptions.AggressiveInlining)] -// public void PreInit() => a(); -// public static IEcsProcess Builder(object target, MethodInfo method) -// { -// if (target is IEcsPreInitProcess) return null; -// if (CheckParameters(method)) -// return new EcsPreInitProcessWrapper(target, CreateAction(target, method)); -// return null; -// } -// } -// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// [EcsProcessWrapperBuilder(nameof(Init), nameof(Builder))] -// internal class EcsInitProcessWrapper : IEcsProcessWrapper, IEcsInitProcess -// { -// public EcsInitProcessWrapper(object target, Action a) { system = target; this.a = a; } -// [MethodImpl(MethodImplOptions.AggressiveInlining)] -// public void Init() => a(); -// public static IEcsProcess Builder(object target, MethodInfo method) -// { -// if (target is IEcsInitProcess) return null; -// if (CheckParameters(method)) -// return new EcsInitProcessWrapper(target, CreateAction(target, method)); -// return null; -// } -// } -// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// [EcsProcessWrapperBuilder(nameof(Run), nameof(Builder))] -// internal class EcsRunProcessEmptyWrapper : IEcsProcessWrapper, IEcsRunProcess -// { -// public EcsRunProcessEmptyWrapper(object target, Action a) { system = target; this.a = a; } -// [MethodImpl(MethodImplOptions.AggressiveInlining)] -// public void Run() => a(); -// public static IEcsProcess Builder(object target, MethodInfo method) -// { -// if (target is IEcsRunProcess) return null; -// if (CheckParameters(method)) -// return new EcsRunProcessEmptyWrapper(target, CreateAction(target, method)); -// return null; -// } -// } -// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// [EcsProcessWrapperBuilder(nameof(Destroy), nameof(Builder))] -// internal class EcsDestroyProcessEmptyWrapper : IEcsProcessWrapper, IEcsDestroyProcess -// { -// public EcsDestroyProcessEmptyWrapper(object target, Action a) { system = target; this.a = a; } -// [MethodImpl(MethodImplOptions.AggressiveInlining)] -// public void Destroy() => a(); -// public static IEcsProcess Builder(object target, MethodInfo method) -// { -// if (target is IEcsRunProcess) return null; -// if (CheckParameters(method)) -// return new EcsDestroyProcessEmptyWrapper(target, CreateAction(target, method)); -// return null; -// } -// } -// -// /* -// public interface ISomeCustomeProcess : IEcsProcess -// { -// void DoSomething(); -// } -// //Только при наличии этого атрибута будет вызван метод Builder который создаст обертку для DoSomething -// [EcsProcessWrapperBuilder(nameof(DoSomething), nameof(Builder))] -// internal class SomeCustomeProcessWrapper : ISomeCustomeProcess, IEcsDebugMetaProvider -// { -// public object system; -// public Action action; -// //IEcsDebugMetaProvider.DebugMetaSource используется чтобы для обертки отображалось данные из debug-атрибутов вроде DebugName -// public object DebugMetaSource => system; -// public SomeCustomeProcessWrapper(object system, Action action) { this.system = system; this.action = action; } -// public void DoSomething() => action(); -// public static IEcsProcess Builder(object system, MethodInfo method) -// { -// //Исключает те системы которые уже имеют интерфейс, иначе в рантайме вызов метода-процесса будет дублироваться -// if (system is ISomeCustomeProcess) return null; //возвращение null -// return new SomeCustomeProcessWrapper(system, EcsAutoProcessUtility.CreateDelegate(system, method)); -// } -// } -// */ -//} -// \ No newline at end of file diff --git a/src/AutoProcesses/AutoProcesses.cs.meta b/src/AutoProcesses/AutoProcesses.cs.meta deleted file mode 100644 index 666cd6b..0000000 --- a/src/AutoProcesses/AutoProcesses.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b12c6a19f3706144c80a1d33f86ec659 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/Processes.cs b/src/Processes.cs new file mode 100644 index 0000000..b7a8427 --- /dev/null +++ b/src/Processes.cs @@ -0,0 +1,7 @@ +namespace DCFApixels.DragonECS +{ + public interface IInjectRaw : IEcsSystem + { + void Inject(object obj); + } +} diff --git a/src/Utils/Exceptions.cs b/src/Utils/Exceptions.cs index edff6fc..8886430 100644 --- a/src/Utils/Exceptions.cs +++ b/src/Utils/Exceptions.cs @@ -1,7 +1,6 @@ using System; using System.Reflection; using System.Runtime.CompilerServices; -using System.Runtime.Serialization; namespace DCFApixels.DragonECS { @@ -34,6 +33,5 @@ namespace DCFApixels.DragonECS public EcsAutoInjectionException() { } public EcsAutoInjectionException(string message) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message) { } public EcsAutoInjectionException(string message, Exception inner) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message, inner) { } - protected EcsAutoInjectionException(SerializationInfo info, StreamingContext context) : base(info, context) { } } }