This commit is contained in:
Mikhail 2023-12-24 18:17:43 +08:00
parent 208f401480
commit 2f07b3f016
6 changed files with 32 additions and 109 deletions

View File

@ -73,7 +73,7 @@ namespace DCFApixels.DragonECS
} }
}//TODO КОНЕЦ убрать дублирование кода - вынести в отедльный метод }//TODO КОНЕЦ убрать дублирование кода - вынести в отедльный метод
if (!fieldInfo.TryGetAttribute(out InjectAttribute injectAttribute)) if (!fieldInfo.TryGetCustomAttribute(out InjectAttribute injectAttribute))
continue; continue;
if (injectAttribute is IncAttribute) if (injectAttribute is IncAttribute)

View File

@ -1,4 +1,4 @@
using DCFApixels.DragonECS.AutoInjectionsInternal; using DCFApixels.DragonECS.AutoInjections.Internal;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -150,7 +150,8 @@ namespace DCFApixels.DragonECS
} }
} }
[DebugHide, DebugColor(DebugColor.Gray)] [MetaTags(MetaTags.HIDDEN)]
[MetaColor(MetaColor.Gray)]
public class AutoInjectSystem : IEcsPreInject, IEcsInject<EcsPipeline>, IEcsPreInitInjectProcess public class AutoInjectSystem : IEcsPreInject, IEcsInject<EcsPipeline>, IEcsPreInitInjectProcess
{ {
private EcsPipeline _pipeline; private EcsPipeline _pipeline;

View File

@ -72,141 +72,87 @@ namespace DCFApixels.DragonECS
} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
internal class IEcsProcessWrapperBase internal class EcsProcessWrapperBase
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool CheckParameters(MethodInfo method, out bool isHasParam) public static bool CheckParameters(MethodInfo method)
{ {
var parametres = method.GetParameters(); return method.GetParameters().Length <= 0;
isHasParam = false;
if (parametres.Length != 0 && (parametres[0].ParameterType != typeof(EcsPipeline)))
return false;
isHasParam = parametres.Length > 0;
return true;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Action CreateEmptyAction(object target, MethodInfo method) public static Action CreateAction(object target, MethodInfo method)
{ {
return EcsAutoProcessUtility.CreateDelegate<Action>(target, method); return EcsAutoProcessUtility.CreateDelegate<Action>(target, method);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Action<EcsPipeline> CreateAction(object target, MethodInfo method)
{
return EcsAutoProcessUtility.CreateDelegate<Action<EcsPipeline>>(target, method);
}
} }
internal class IEcsProcessEmptyWrapper : IEcsProcessWrapperBase, IEcsDebugMetaProvider internal class IEcsProcessWrapper : EcsProcessWrapperBase, IEcsMetaProvider
{ {
public object system; public object system;
public Action a; public Action a;
public object DebugMetaSource => system; public object MetaSource => system;
}
internal class IEcsProcessWrapper : IEcsProcessWrapperBase, IEcsDebugMetaProvider
{
public object system;
public Action<EcsPipeline> a;
public object DebugMetaSource => system;
} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
[EcsProcessWrapperBuilder(nameof(PreInit), nameof(Builder))] [EcsProcessWrapperBuilder(nameof(PreInit), nameof(Builder))]
internal class EcsPreInitProcessEmptyWrapper : IEcsProcessEmptyWrapper, IEcsPreInitProcess internal class EcsPreInitProcessWrapper : IEcsProcessWrapper, IEcsPreInitProcess
{ {
public EcsPreInitProcessEmptyWrapper(object target, Action a) { system = target; this.a = a; } public EcsPreInitProcessWrapper(object target, Action a) { system = target; this.a = a; }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PreInit(EcsPipeline pipeline) => a(); public void PreInit() => a();
public static IEcsProcess Builder(object target, MethodInfo method) public static IEcsProcess Builder(object target, MethodInfo method)
{ {
if (target is IEcsPreInitProcess) return null; if (target is IEcsPreInitProcess) return null;
if (CheckParameters(method, out bool isHasParam)) if (CheckParameters(method))
if (isHasParam) return new EcsPreInitProcessWrapper(target, CreateAction(target, method));
return new EcsPreInitProcessWrapper(target, CreateAction(target, method));
else
return new EcsPreInitProcessEmptyWrapper(target, CreateEmptyAction(target, method));
return null; return null;
} }
} }
internal class EcsPreInitProcessWrapper : IEcsProcessWrapper, IEcsPreInitProcess
{
public EcsPreInitProcessWrapper(object target, Action<EcsPipeline> a) { system = target; this.a = a; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PreInit(EcsPipeline pipeline) => a(pipeline);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
[EcsProcessWrapperBuilder(nameof(Init), nameof(Builder))] [EcsProcessWrapperBuilder(nameof(Init), nameof(Builder))]
internal class EcsInitProcessEmptyWrapper : IEcsProcessEmptyWrapper, IEcsInitProcess internal class EcsInitProcessWrapper : IEcsProcessWrapper, IEcsInitProcess
{ {
public EcsInitProcessEmptyWrapper(object target, Action a) { system = target; this.a = a; } public EcsInitProcessWrapper(object target, Action a) { system = target; this.a = a; }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Init(EcsPipeline pipeline) => a(); public void Init() => a();
public static IEcsProcess Builder(object target, MethodInfo method) public static IEcsProcess Builder(object target, MethodInfo method)
{ {
if (target is IEcsInitProcess) return null; if (target is IEcsInitProcess) return null;
if (CheckParameters(method, out bool isHasParam)) if (CheckParameters(method))
if (isHasParam) return new EcsInitProcessWrapper(target, CreateAction(target, method));
return new EcsInitProcessWrapper(target, CreateAction(target, method));
else
return new EcsInitProcessEmptyWrapper(target, CreateEmptyAction(target, method));
return null; return null;
} }
} }
internal class EcsInitProcessWrapper : IEcsProcessWrapper, IEcsInitProcess
{
public EcsInitProcessWrapper(object target, Action<EcsPipeline> a) { system = target; this.a = a; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Init(EcsPipeline pipeline) => a(pipeline);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
[EcsProcessWrapperBuilder(nameof(Run), nameof(Builder))] [EcsProcessWrapperBuilder(nameof(Run), nameof(Builder))]
internal class EcsRunProcessEmptyWrapper : IEcsProcessEmptyWrapper, IEcsRunProcess internal class EcsRunProcessEmptyWrapper : IEcsProcessWrapper, IEcsRunProcess
{ {
public EcsRunProcessEmptyWrapper(object target, Action a) { system = target; this.a = a; } public EcsRunProcessEmptyWrapper(object target, Action a) { system = target; this.a = a; }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Run(EcsPipeline pipeline) => a(); public void Run() => a();
public static IEcsProcess Builder(object target, MethodInfo method) public static IEcsProcess Builder(object target, MethodInfo method)
{ {
if (target is IEcsRunProcess) return null; if (target is IEcsRunProcess) return null;
if (CheckParameters(method, out bool isHasParam)) if (CheckParameters(method))
if (isHasParam) return new EcsRunProcessEmptyWrapper(target, CreateAction(target, method));
return new EcsRunProcessWrapper(target, CreateAction(target, method));
else
return new EcsRunProcessEmptyWrapper(target, CreateEmptyAction(target, method));
return null; return null;
} }
} }
internal class EcsRunProcessWrapper : IEcsProcessWrapper, IEcsRunProcess
{
public EcsRunProcessWrapper(object target, Action<EcsPipeline> a) { system = target; this.a = a; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Run(EcsPipeline pipeline) => a(pipeline);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
[EcsProcessWrapperBuilder(nameof(Destroy), nameof(Builder))] [EcsProcessWrapperBuilder(nameof(Destroy), nameof(Builder))]
internal class EcsDestroyProcessEmptyWrapper : IEcsProcessEmptyWrapper, IEcsDestroyProcess internal class EcsDestroyProcessEmptyWrapper : IEcsProcessWrapper, IEcsDestroyProcess
{ {
public EcsDestroyProcessEmptyWrapper(object target, Action a) { system = target; this.a = a; } public EcsDestroyProcessEmptyWrapper(object target, Action a) { system = target; this.a = a; }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Destroy(EcsPipeline pipeline) => a(); public void Destroy() => a();
public static IEcsProcess Builder(object target, MethodInfo method) public static IEcsProcess Builder(object target, MethodInfo method)
{ {
if (target is IEcsDestroyProcess) return null; if (target is IEcsRunProcess) return null;
if (CheckParameters(method, out bool isHasParam)) if (CheckParameters(method))
if (isHasParam) return new EcsDestroyProcessEmptyWrapper(target, CreateAction(target, method));
return new EcsDestroyProcessWrapper(target, CreateAction(target, method));
else
return new EcsDestroyProcessEmptyWrapper(target, CreateEmptyAction(target, method));
return null; return null;
} }
} }
internal class EcsDestroyProcessWrapper : IEcsProcessWrapper, IEcsDestroyProcess
{
public EcsDestroyProcessWrapper(object target, Action<EcsPipeline> a) { system = target; this.a = a; }
[MethodImpl(MethodImplOptions.AggressiveInlining)] public void Destroy(EcsPipeline pipeline) => a(pipeline);
}
/*
public interface ISomeCustomeProcess : IEcsProcess public interface ISomeCustomeProcess : IEcsProcess
{ {
void DoSomething(); void DoSomething();
@ -228,4 +174,5 @@ namespace DCFApixels.DragonECS
return new SomeCustomeProcessWrapper(system, EcsAutoProcessUtility.CreateDelegate<Action>(system, method)); return new SomeCustomeProcessWrapper(system, EcsAutoProcessUtility.CreateDelegate<Action>(system, method));
} }
} }
*/
} }

View File

@ -5,7 +5,7 @@ using System.Runtime.Serialization;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
namespace AutoInjectionsInternal namespace AutoInjections.Internal
{ {
internal static class Throw internal static class Throw
{ {

View File

@ -1,14 +0,0 @@
using System;
using System.Reflection;
namespace DCFApixels.DragonECS
{
internal static class ReflectionExtensions
{
public static bool TryGetAttribute<T>(this MemberInfo self, out T attribute) where T : Attribute
{
attribute = self.GetCustomAttribute<T>();
return attribute != null;
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 1f6eaf9c4ba7e4b4996a1600ff39f19f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: