mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
move DragonDocs to Unity integration
This commit is contained in:
parent
4d173dd857
commit
29e9d9edbb
@ -1,101 +0,0 @@
|
|||||||
using DCFApixels.DragonECS.PoolsCore;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS.Docs
|
|
||||||
{
|
|
||||||
[Serializable]
|
|
||||||
[DataContract]
|
|
||||||
public class DragonDocs
|
|
||||||
{
|
|
||||||
[DataMember]
|
|
||||||
private readonly DragonDocsMeta[] _metas;
|
|
||||||
[NonSerialized]
|
|
||||||
private DragonDocsMetaGroup[] _mapping = null;
|
|
||||||
|
|
||||||
public ReadOnlySpan<DragonDocsMeta> Meta
|
|
||||||
{
|
|
||||||
get { return new ReadOnlySpan<DragonDocsMeta>(_metas); }
|
|
||||||
}
|
|
||||||
public ReadOnlySpan<DragonDocsMetaGroup> Mapping
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
Init();
|
|
||||||
return new ReadOnlySpan<DragonDocsMetaGroup>(_mapping); ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private bool _isInit = false;
|
|
||||||
private void Init()
|
|
||||||
{
|
|
||||||
if (_isInit) { return; }
|
|
||||||
|
|
||||||
if (_metas.Length < 0)
|
|
||||||
{
|
|
||||||
_mapping = Array.Empty<DragonDocsMetaGroup>();
|
|
||||||
}
|
|
||||||
List<DragonDocsMetaGroup> groups = new List<DragonDocsMetaGroup>();
|
|
||||||
string name = _metas[0].Name;
|
|
||||||
int startIndex = 0;
|
|
||||||
for (int i = 1; i < _metas.Length; i++)
|
|
||||||
{
|
|
||||||
var meta = _metas[i];
|
|
||||||
if (name != meta.Name)
|
|
||||||
{
|
|
||||||
groups.Add(new DragonDocsMetaGroup(name, startIndex, i - startIndex));
|
|
||||||
name = meta.Name;
|
|
||||||
startIndex = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
groups.Add(new DragonDocsMetaGroup(name, startIndex, _metas.Length - startIndex));
|
|
||||||
_mapping = groups.ToArray();
|
|
||||||
}
|
|
||||||
private DragonDocs(DragonDocsMeta[] metas)
|
|
||||||
{
|
|
||||||
_metas = metas;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DragonDocs Generate()
|
|
||||||
{
|
|
||||||
List<DragonDocsMeta> metas = new List<DragonDocsMeta>(256);
|
|
||||||
foreach (var type in GetTypes())
|
|
||||||
{
|
|
||||||
metas.Add(new DragonDocsMeta(type.ToMeta()));
|
|
||||||
}
|
|
||||||
DragonDocsMeta[] array = metas.ToArray();
|
|
||||||
Array.Sort(array);
|
|
||||||
return new DragonDocs(array);
|
|
||||||
}
|
|
||||||
private static List<Type> GetTypes()
|
|
||||||
{
|
|
||||||
Type metaAttributeType = typeof(EcsMetaAttribute);
|
|
||||||
Type memberType = typeof(IEcsMember);
|
|
||||||
List<Type> result = new List<Type>(512);
|
|
||||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
|
||||||
{
|
|
||||||
foreach (var type in assembly.GetTypes())
|
|
||||||
{
|
|
||||||
if (memberType.IsAssignableFrom(type) || Attribute.GetCustomAttributes(type, metaAttributeType, false).Length > 1)
|
|
||||||
{
|
|
||||||
result.Add(type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public struct DragonDocsMetaGroup
|
|
||||||
{
|
|
||||||
public readonly string Name;
|
|
||||||
public readonly int StartIndex;
|
|
||||||
public readonly int Length;
|
|
||||||
public DragonDocsMetaGroup(string name, int startIndex, int length)
|
|
||||||
{
|
|
||||||
Name = name;
|
|
||||||
StartIndex = startIndex;
|
|
||||||
Length = length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS.Docs
|
|
||||||
{
|
|
||||||
[Serializable]
|
|
||||||
[DataContract]
|
|
||||||
public class DragonDocsMeta : IComparable<DragonDocsMeta>
|
|
||||||
{
|
|
||||||
[NonSerialized] private Type _sourceType;
|
|
||||||
[NonSerialized] private bool _isInitSourceType = false;
|
|
||||||
|
|
||||||
[DataMember] public readonly string AssemblyQualifiedName = string.Empty;
|
|
||||||
|
|
||||||
[DataMember] public readonly string Name = string.Empty;
|
|
||||||
[DataMember] public readonly bool IsCustomName = false;
|
|
||||||
[DataMember] public readonly MetaColor Color = MetaColor.BlackColor;
|
|
||||||
[DataMember] public readonly bool IsCustomColor = false;
|
|
||||||
[DataMember] public readonly string Autor = string.Empty;
|
|
||||||
[DataMember] public readonly string Description = string.Empty;
|
|
||||||
|
|
||||||
[DataMember] public readonly string Group = string.Empty;
|
|
||||||
[DataMember] public readonly string[] Tags = Array.Empty<string>();
|
|
||||||
|
|
||||||
public DragonDocsMeta(TypeMeta meta)
|
|
||||||
{
|
|
||||||
_sourceType = meta.Type;
|
|
||||||
AssemblyQualifiedName = meta.Type.AssemblyQualifiedName;
|
|
||||||
|
|
||||||
Name = meta.Name;
|
|
||||||
IsCustomName = meta.IsCustomName;
|
|
||||||
Color = meta.Color;
|
|
||||||
IsCustomColor = meta.IsCustomColor;
|
|
||||||
Autor = meta.Description.Author;
|
|
||||||
Description = meta.Description.Text;
|
|
||||||
|
|
||||||
Group = meta.Group.Name;
|
|
||||||
Tags = new string[meta.Tags.Count];
|
|
||||||
for (int i = 0, n = meta.Tags.Count; i < n; i++)
|
|
||||||
{
|
|
||||||
Tags[i] = meta.Tags[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryGetSourceType(out Type type)
|
|
||||||
{
|
|
||||||
type = GetSourceType();
|
|
||||||
return type != null;
|
|
||||||
}
|
|
||||||
private Type GetSourceType()
|
|
||||||
{
|
|
||||||
if (_isInitSourceType) { return _sourceType; }
|
|
||||||
_isInitSourceType = true;
|
|
||||||
_sourceType = Type.GetType(AssemblyQualifiedName);
|
|
||||||
return _sourceType;
|
|
||||||
}
|
|
||||||
|
|
||||||
int IComparable<DragonDocsMeta>.CompareTo(DragonDocsMeta other)
|
|
||||||
{
|
|
||||||
int c = string.Compare(Group, other.Group);
|
|
||||||
return c == 0 ? c : string.Compare(Name, other.Name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -34,7 +34,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
if (_path == null)
|
if (_path == null)
|
||||||
{
|
{
|
||||||
_path = Name.Split(_separatpor, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
_path = Name.Split(_separatpor, StringSplitOptions.RemoveEmptyEntries); //TODO добавить ручное StringSplitOptions.TrimEntries
|
||||||
}
|
}
|
||||||
return _path;
|
return _path;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public MetaTagsAttribute() { }
|
public MetaTagsAttribute() { }
|
||||||
public MetaTagsAttribute(string tags)
|
public MetaTagsAttribute(string tags)
|
||||||
{
|
{
|
||||||
_tags = tags.Split(_separatpor, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
_tags = tags.Split(_separatpor, StringSplitOptions.RemoveEmptyEntries); //TODO добавить ручное StringSplitOptions.TrimEntries
|
||||||
for (int i = 0; i < _tags.Length; i++)
|
for (int i = 0; i < _tags.Length; i++)
|
||||||
{
|
{
|
||||||
_tags[i] = string.Intern(_tags[i]);
|
_tags[i] = string.Intern(_tags[i]);
|
||||||
|
11
src/Debug/TypeMeta.cs.meta
Normal file
11
src/Debug/TypeMeta.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4f969a5755aec72419e45d175d1d46b9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user