mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-17 17:34:34 +08:00
stash
This commit is contained in:
parent
6d0037485b
commit
f4c5dce0ff
@ -1,8 +1,6 @@
|
|||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
using DCFApixels.DragonECS;
|
using DCFApixels.DragonECS;
|
||||||
using DCFApixels.DragonECS.PoolsCore;
|
using DCFApixels.DragonECS.PoolsCore;
|
||||||
using DCFApixels.DragonECS.Unity;
|
|
||||||
using DCFApixels.DragonECS.Unity.Editors;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -143,20 +141,37 @@ public static class GeneratorUtility
|
|||||||
public delegate void ApplyHandler<TComponent>(ref TComponent data);
|
public delegate void ApplyHandler<TComponent>(ref TComponent data);
|
||||||
public delegate void ApplyHandler<TComponent, TPool>(ref TComponent data, TPool pool);
|
public delegate void ApplyHandler<TComponent, TPool>(ref TComponent data, TPool pool);
|
||||||
|
|
||||||
public static bool SkanTypeStructure(Type type)
|
public static TypeScan SkanTypeStructure(Type type)
|
||||||
{
|
{
|
||||||
|
return TypeScan.Scan(type);
|
||||||
}
|
}
|
||||||
private static bool IsSerializableField(FieldInfo fieldInfo)
|
private static bool IsSerializableField(FieldInfo fieldInfo)
|
||||||
{
|
{
|
||||||
return fieldInfo.IsPublic || fieldInfo.GetCustomAttribute<SerializeField>() != null || fieldInfo.GetCustomAttribute<SerializeReference>() != null;
|
return fieldInfo.IsPublic || fieldInfo.GetCustomAttribute<SerializeField>() != null || fieldInfo.GetCustomAttribute<SerializeReference>() != null;
|
||||||
}
|
}
|
||||||
private static bool IsCanUnsafeOverride(FieldInfo fieldInfo)
|
private static bool IsCanUnsafeOverwrite(FieldInfo fieldInfo, bool isLeaf)
|
||||||
{
|
{
|
||||||
|
if (isLeaf)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (fieldInfo.FieldType.IsValueType)
|
if (fieldInfo.FieldType.IsValueType)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static bool IsLeafField(FieldInfo fieldInfo)
|
||||||
|
{
|
||||||
|
if (fieldInfo.FieldType.IsEnum)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (fieldInfo.FieldType.IsPrimitive)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (fieldInfo.FieldType == typeof(string))
|
if (fieldInfo.FieldType == typeof(string))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@ -169,35 +184,126 @@ public static class GeneratorUtility
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//public interface IUnityCompilatorInfo // defines hack
|
public class TypeScan
|
||||||
//{
|
{
|
||||||
// /// <summary> VMT size </summary>
|
public static readonly TypeScan NoSerializableScan = new TypeScan();
|
||||||
// public int ObjectVirtualDataSize { get; }
|
|
||||||
// /// <summary> can rewrite VMT </summary>
|
public readonly bool IsSerializable;
|
||||||
// public bool IsSupportRewriteObjectVirtualData { get; }
|
public readonly bool IsCanUnsafeOverwrite;
|
||||||
//}
|
|
||||||
//private class UnityCompilatorInfo : IUnityCompilatorInfo
|
public readonly bool IsClass;
|
||||||
//{
|
public readonly bool IsStruct;
|
||||||
// public int ObjectVirtualDataSize
|
|
||||||
// {
|
public readonly FieldScan[] Fields = Array.Empty<FieldScan>();
|
||||||
// get
|
public readonly Type SerializableType;
|
||||||
// {
|
|
||||||
// return 8;
|
//public readonly string[] EnumFlagNames;
|
||||||
// }
|
|
||||||
// }
|
private TypeScan() { }
|
||||||
// public bool IsSupportRewriteObjectVirtualData
|
private TypeScan(Type type)
|
||||||
// {
|
{
|
||||||
// get
|
IsSerializable = true;
|
||||||
// {
|
SerializableType = type;
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
IsCanUnsafeOverwrite = true;
|
||||||
|
ReadOnlySpan<FieldScan> fields = FieldScan.GetFieldScans(type);
|
||||||
|
for (int i = 0; i < fields.Length; i++)
|
||||||
|
{
|
||||||
|
var field = fields[i];
|
||||||
|
if (field.IsCanUnsafeOverwrite == false)
|
||||||
|
{
|
||||||
|
IsCanUnsafeOverwrite = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Fields = fields.ToArray();
|
||||||
|
}
|
||||||
|
public static TypeScan Scan(Type type)
|
||||||
|
{
|
||||||
|
if (type.GetCustomAttribute<System.SerializableAttribute>() == null)
|
||||||
|
{
|
||||||
|
return NoSerializableScan;
|
||||||
|
}
|
||||||
|
return new TypeScan(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FieldScan
|
||||||
|
{
|
||||||
|
public static readonly FieldScan NoSerializableScan = new FieldScan();
|
||||||
|
|
||||||
|
public readonly bool IsSerializable;
|
||||||
|
|
||||||
|
public readonly bool IsSerializeField;
|
||||||
|
public readonly bool IsSerializeReference;
|
||||||
|
public readonly bool IsUnityObject;
|
||||||
|
|
||||||
|
public readonly bool IsLeaf;
|
||||||
|
public readonly bool IsCanUnsafeOverwrite;
|
||||||
|
public readonly TypeScan ValueTypeScan;
|
||||||
|
public readonly FieldInfo SerializableFieldInfo;
|
||||||
|
|
||||||
|
//public readonly
|
||||||
|
|
||||||
|
private FieldScan() { }
|
||||||
|
private FieldScan(FieldInfo field)
|
||||||
|
{
|
||||||
|
IsSerializable = true;
|
||||||
|
SerializableFieldInfo = field;
|
||||||
|
IsLeaf = IsLeafField(field);
|
||||||
|
IsCanUnsafeOverwrite = IsCanUnsafeOverwrite(field, IsLeaf);
|
||||||
|
|
||||||
|
if (field.FieldType.IsValueType)
|
||||||
|
{
|
||||||
|
ValueTypeScan = TypeScan.Scan(field.FieldType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static FieldScan[] FieldsBuffer = new FieldScan[64];
|
||||||
|
private static int FieldsBufferCount = 0;
|
||||||
|
public static ReadOnlySpan<FieldScan> GetFieldScans(Type type)
|
||||||
|
{
|
||||||
|
var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
||||||
|
if (FieldsBuffer == null || FieldsBuffer.Length < fields.Length)
|
||||||
|
{
|
||||||
|
var newsize = DCFApixels.DragonECS.Unity.Internal.ArrayUtility.NormalizeSizeToPowerOfTwo(fields.Length);
|
||||||
|
FieldsBuffer = new FieldScan[newsize];
|
||||||
|
}
|
||||||
|
for (int i = 0; i < fields.Length; i++)
|
||||||
|
{
|
||||||
|
FieldsBuffer[i] = Scan(fields[i]);
|
||||||
|
FieldsBufferCount++;
|
||||||
|
}
|
||||||
|
return new ReadOnlySpan<FieldScan>(FieldsBuffer, 0, FieldsBufferCount);
|
||||||
|
}
|
||||||
|
public static void CleanGetFieldScansBuffer()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < FieldsBufferCount; i++)
|
||||||
|
{
|
||||||
|
FieldsBuffer[i] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static FieldScan Scan(FieldInfo field)
|
||||||
|
{
|
||||||
|
if (IsSerializableField(field) == false)
|
||||||
|
{
|
||||||
|
return NoSerializableScan;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new FieldScan(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//public class AttributeScan { } // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class ConverterWrapperBase<TStencil>
|
public abstract class ConverterWrapperBase<TStencil>
|
||||||
{
|
{
|
||||||
public abstract void Apply(ref TStencil component, short worldID, int entityID);
|
public abstract void Apply(ref TStencil component, short worldID, int entityID);
|
||||||
|
Loading…
Reference in New Issue
Block a user