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
|
||||
|
||||
#region GetGroup
|
||||
public static MetaGroup GetGroup(object obj)
|
||||
public static ReadonlyMetaGroup GetGroup(object obj)
|
||||
{
|
||||
return GetTypeMeta(obj).Group;
|
||||
}
|
||||
public static MetaGroup GetGroup<T>()
|
||||
public static ReadonlyMetaGroup GetGroup<T>()
|
||||
{
|
||||
return GetTypeMeta<T>().Group;
|
||||
}
|
||||
public static MetaGroup GetGroup(Type type)
|
||||
public static ReadonlyMetaGroup GetGroup(Type type)
|
||||
{
|
||||
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);
|
||||
group = meta.Group;
|
||||
return group.IsNull;
|
||||
}
|
||||
public static bool TryGetGroup<T>(out MetaGroup group)
|
||||
public static bool TryGetGroup<T>(out ReadonlyMetaGroup group)
|
||||
{
|
||||
TypeMeta meta = GetTypeMeta<T>();
|
||||
group = meta.Group;
|
||||
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);
|
||||
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;
|
||||
|
||||
@ -319,7 +327,7 @@ namespace DCFApixels.DragonECS
|
||||
private string _name;
|
||||
private MetaColor _color;
|
||||
private string _description;
|
||||
private MetaGroup _group;
|
||||
private ReadonlyMetaGroup _group;
|
||||
private IReadOnlyCollection<string> _tags;
|
||||
private int _typeCode;
|
||||
|
||||
@ -409,7 +417,7 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region Group
|
||||
public MetaGroup Group
|
||||
public ReadonlyMetaGroup Group
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -539,9 +547,9 @@ namespace DCFApixels.DragonECS.Internal
|
||||
#endregion
|
||||
|
||||
#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
|
||||
|
||||
|
@ -1,14 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class MetaGroupAttribute : EcsMetaAttribute
|
||||
{
|
||||
public static readonly MetaGroupAttribute Empty = new MetaGroupAttribute("");
|
||||
public readonly string name;
|
||||
public readonly MetaGroup Data;
|
||||
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;
|
||||
public IReadOnlyCollection<string> Splited
|
||||
{
|
||||
@ -16,28 +24,34 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
if (path == null)
|
||||
{
|
||||
path = Regex.Split(name, @"[/|\\]");
|
||||
path = Name.Split('/', StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
||||
public MetaGroupAttribute(string name)
|
||||
public MetaGroup(string name)
|
||||
{
|
||||
name = Regex.Replace(name, @"^[/|\\]+|[/|\\]+$", "");
|
||||
this.name = name;
|
||||
}
|
||||
public MetaGroup GetData()
|
||||
{
|
||||
return new MetaGroup(this);
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
Name = string.Empty;
|
||||
return;
|
||||
}
|
||||
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);
|
||||
private readonly MetaGroupAttribute _source;
|
||||
public static readonly ReadonlyMetaGroup Empty = new ReadonlyMetaGroup(MetaGroup.Empty);
|
||||
private readonly MetaGroup _source;
|
||||
public string Name
|
||||
{
|
||||
get { return _source.name; }
|
||||
get { return _source.Name; }
|
||||
}
|
||||
public IReadOnlyCollection<string> Splited
|
||||
{
|
||||
@ -47,9 +61,14 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
get { return _source == null; }
|
||||
}
|
||||
public MetaGroup(MetaGroupAttribute source)
|
||||
public ReadonlyMetaGroup(MetaGroup source)
|
||||
{
|
||||
_source = source;
|
||||
}
|
||||
|
||||
public static implicit operator ReadonlyMetaGroup(MetaGroup group)
|
||||
{
|
||||
return new ReadonlyMetaGroup(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user