mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
update MetaGroup
This commit is contained in:
parent
d4415c3127
commit
394820549f
@ -193,32 +193,32 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetGroup
|
#region GetGroup
|
||||||
public static MetaGroup GetGroup(object obj)
|
public static ReadonlyMetaGroup GetGroup(object obj)
|
||||||
{
|
{
|
||||||
return GetTypeMeta(obj).Group;
|
return GetTypeMeta(obj).Group;
|
||||||
}
|
}
|
||||||
public static MetaGroup GetGroup<T>()
|
public static ReadonlyMetaGroup GetGroup<T>()
|
||||||
{
|
{
|
||||||
return GetTypeMeta<T>().Group;
|
return GetTypeMeta<T>().Group;
|
||||||
}
|
}
|
||||||
public static MetaGroup GetGroup(Type type)
|
public static ReadonlyMetaGroup GetGroup(Type type)
|
||||||
{
|
{
|
||||||
return GetTypeMeta(type).Group;
|
return GetTypeMeta(type).Group;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool TryGetGroup(object obj, out MetaGroup group)
|
public static bool TryGetGroup(object obj, out ReadonlyMetaGroup group)
|
||||||
{
|
{
|
||||||
TypeMeta meta = GetTypeMeta(obj);
|
TypeMeta meta = GetTypeMeta(obj);
|
||||||
group = meta.Group;
|
group = meta.Group;
|
||||||
return group.IsNull;
|
return group.IsNull;
|
||||||
}
|
}
|
||||||
public static bool TryGetGroup<T>(out MetaGroup group)
|
public static bool TryGetGroup<T>(out ReadonlyMetaGroup group)
|
||||||
{
|
{
|
||||||
TypeMeta meta = GetTypeMeta<T>();
|
TypeMeta meta = GetTypeMeta<T>();
|
||||||
group = meta.Group;
|
group = meta.Group;
|
||||||
return group.IsNull;
|
return group.IsNull;
|
||||||
}
|
}
|
||||||
public static bool TryGetGroup(Type type, out MetaGroup group)
|
public static bool TryGetGroup(Type type, out ReadonlyMetaGroup group)
|
||||||
{
|
{
|
||||||
TypeMeta meta = GetTypeMeta(type);
|
TypeMeta meta = GetTypeMeta(type);
|
||||||
group = meta.Group;
|
group = meta.Group;
|
||||||
@ -308,7 +308,15 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class TypeMeta
|
public interface ITypeMeta
|
||||||
|
{
|
||||||
|
public string Name { get; }
|
||||||
|
public MetaColor Color { get; }
|
||||||
|
public string Description { get; }
|
||||||
|
public ReadonlyMetaGroup Group { get; }
|
||||||
|
public IReadOnlyCollection<string> Tags { get; }
|
||||||
|
}
|
||||||
|
public sealed class TypeMeta : ITypeMeta
|
||||||
{
|
{
|
||||||
internal readonly Type _type;
|
internal readonly Type _type;
|
||||||
|
|
||||||
@ -319,7 +327,7 @@ namespace DCFApixels.DragonECS
|
|||||||
private string _name;
|
private string _name;
|
||||||
private MetaColor _color;
|
private MetaColor _color;
|
||||||
private string _description;
|
private string _description;
|
||||||
private MetaGroup _group;
|
private ReadonlyMetaGroup _group;
|
||||||
private IReadOnlyCollection<string> _tags;
|
private IReadOnlyCollection<string> _tags;
|
||||||
private int _typeCode;
|
private int _typeCode;
|
||||||
|
|
||||||
@ -409,7 +417,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Group
|
#region Group
|
||||||
public MetaGroup Group
|
public ReadonlyMetaGroup Group
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@ -539,9 +547,9 @@ namespace DCFApixels.DragonECS.Internal
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetGroup
|
#region GetGroup
|
||||||
public static MetaGroup GetGroup(Type type)
|
public static ReadonlyMetaGroup GetGroup(Type type)
|
||||||
{
|
{
|
||||||
return type.TryGetCustomAttribute(out MetaGroupAttribute atr) ? atr.GetData() : MetaGroup.Empty;
|
return type.TryGetCustomAttribute(out MetaGroupAttribute atr) ? atr.Data : ReadonlyMetaGroup.Empty;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -1,14 +1,22 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
|
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
|
||||||
public sealed class MetaGroupAttribute : EcsMetaAttribute
|
public sealed class MetaGroupAttribute : EcsMetaAttribute
|
||||||
{
|
{
|
||||||
public static readonly MetaGroupAttribute Empty = new MetaGroupAttribute("");
|
public readonly MetaGroup Data;
|
||||||
public readonly string name;
|
public MetaGroupAttribute(string name)
|
||||||
|
{
|
||||||
|
Data = new MetaGroup(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class MetaGroup
|
||||||
|
{
|
||||||
|
public static readonly MetaGroup Empty = new MetaGroup("");
|
||||||
|
|
||||||
|
public readonly string Name;
|
||||||
private string[] path = null;
|
private string[] path = null;
|
||||||
public IReadOnlyCollection<string> Splited
|
public IReadOnlyCollection<string> Splited
|
||||||
{
|
{
|
||||||
@ -16,28 +24,34 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
if (path == null)
|
if (path == null)
|
||||||
{
|
{
|
||||||
path = Regex.Split(name, @"[/|\\]");
|
path = Name.Split('/', StringSplitOptions.RemoveEmptyEntries);
|
||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public MetaGroupAttribute(string name)
|
public MetaGroup(string name)
|
||||||
{
|
{
|
||||||
name = Regex.Replace(name, @"^[/|\\]+|[/|\\]+$", "");
|
if (string.IsNullOrEmpty(name))
|
||||||
this.name = name;
|
{
|
||||||
}
|
Name = string.Empty;
|
||||||
public MetaGroup GetData()
|
return;
|
||||||
{
|
}
|
||||||
return new MetaGroup(this);
|
name = name.Replace('\\', '/');
|
||||||
|
if (name[name.Length - 1] != '/')
|
||||||
|
{
|
||||||
|
name += '/';
|
||||||
|
}
|
||||||
|
Name = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public readonly struct MetaGroup
|
|
||||||
|
public readonly struct ReadonlyMetaGroup
|
||||||
{
|
{
|
||||||
public static readonly MetaGroup Empty = new MetaGroup(MetaGroupAttribute.Empty);
|
public static readonly ReadonlyMetaGroup Empty = new ReadonlyMetaGroup(MetaGroup.Empty);
|
||||||
private readonly MetaGroupAttribute _source;
|
private readonly MetaGroup _source;
|
||||||
public string Name
|
public string Name
|
||||||
{
|
{
|
||||||
get { return _source.name; }
|
get { return _source.Name; }
|
||||||
}
|
}
|
||||||
public IReadOnlyCollection<string> Splited
|
public IReadOnlyCollection<string> Splited
|
||||||
{
|
{
|
||||||
@ -47,9 +61,14 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
get { return _source == null; }
|
get { return _source == null; }
|
||||||
}
|
}
|
||||||
public MetaGroup(MetaGroupAttribute source)
|
public ReadonlyMetaGroup(MetaGroup source)
|
||||||
{
|
{
|
||||||
_source = source;
|
_source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static implicit operator ReadonlyMetaGroup(MetaGroup group)
|
||||||
|
{
|
||||||
|
return new ReadonlyMetaGroup(group);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user