1
This commit is contained in:
@@ -20,7 +20,7 @@ namespace BITKit
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true, Inherited = true)]
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, AllowMultiple = true, Inherited = true)]
|
||||
public class CustomTypeAttribute : System.Attribute
|
||||
{
|
||||
public readonly Type Type;
|
||||
|
@@ -40,7 +40,7 @@ namespace BITKit
|
||||
/// <summary>
|
||||
/// 基础物品
|
||||
/// </summary>
|
||||
public interface IBasicItem :IPropertable
|
||||
public interface IBasicItem :IPropertable,ICloneable
|
||||
{
|
||||
/// <summary>
|
||||
/// 唯一Id
|
||||
@@ -76,7 +76,7 @@ namespace BITKit
|
||||
/// 被托管的物品
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public record ManagedItem : IBasicItem
|
||||
public class ManagedItem : IBasicItem
|
||||
{
|
||||
#region 字段
|
||||
public int Id;
|
||||
@@ -135,8 +135,14 @@ namespace BITKit
|
||||
{
|
||||
return property.CopyPropertiesFrom(propertable);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
var item = MemberwiseClone() as ManagedItem;
|
||||
item!.Id = Id;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
102
Assets/BITKit/Core/Modification/IModification.cs
Normal file
102
Assets/BITKit/Core/Modification/IModification.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace BITKit.Modification
|
||||
{
|
||||
/// <summary>
|
||||
/// 不兼容的改装
|
||||
/// </summary>
|
||||
public class IncompatibleModifyException : InGameException
|
||||
{
|
||||
public IncompatibleModifyException(IModifyElement[] errorElements) : base()
|
||||
{
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 没有前置改装
|
||||
/// </summary>
|
||||
public class NotRequireModifyException : InGameException
|
||||
{
|
||||
public NotRequireModifyException(IModifyElement[] errorElements) : base()
|
||||
{
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 不支持的改装
|
||||
/// </summary>
|
||||
public class NotSupportModifyException : InGameException
|
||||
{
|
||||
public NotSupportModifyException(IModifyElement[] errorElements) : base()
|
||||
{
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 改装元素
|
||||
/// </summary>
|
||||
public interface IModifyElement
|
||||
{
|
||||
IModifyElement[] Require { get; }
|
||||
IModifyElement[] Incompatible { get; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 改装管理器
|
||||
/// </summary>
|
||||
public interface IModifyManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取所有改装
|
||||
/// </summary>
|
||||
IDictionary<IModifyElement,object> Modifies { get; }
|
||||
/// <summary>
|
||||
/// 获取所有已改装
|
||||
/// </summary>
|
||||
IDictionary<IModifyElement,object> Modified { get; }
|
||||
/// <summary>
|
||||
/// 添加改装
|
||||
/// </summary>
|
||||
/// <param name="modify"></param>
|
||||
void Add(IModifyElement modify,object obj);
|
||||
/// <summary>
|
||||
/// 移除改装
|
||||
/// </summary>
|
||||
/// <param name="modify"></param>
|
||||
void Remove(IModifyElement modify,out object obj);
|
||||
}
|
||||
public class ModifyManager : IModifyManager
|
||||
{
|
||||
public virtual IDictionary<IModifyElement, object> Modifies { get;private set; } =new Dictionary<IModifyElement,object>();
|
||||
public virtual IDictionary<IModifyElement, object> Modified => new Dictionary<IModifyElement, object>(Modifies.Where(x=>x.Value is not null));
|
||||
|
||||
public virtual void Add(IModifyElement modify, object obj)
|
||||
{
|
||||
var list = new List<IModifyElement>();
|
||||
list.AddRange(Modified.Keys);
|
||||
list.Add(modify);
|
||||
|
||||
if(list.All(x=>x.Require?.Any(y=>list.Contains(y)) is false))
|
||||
throw new NotRequireModifyException(list.ToArray());
|
||||
|
||||
var incompatible = list.Where(x=>x.Incompatible is not null).SelectMany(x => x.Incompatible).ToArray();
|
||||
if(MathE.Contains(incompatible,list))
|
||||
throw new IncompatibleModifyException(incompatible);
|
||||
|
||||
Modified.Add(modify,obj);
|
||||
}
|
||||
|
||||
public virtual void Remove(IModifyElement modify,out object obj)
|
||||
{
|
||||
var list = new List<IModifyElement>();
|
||||
list.AddRange(Modified.Keys);
|
||||
list.Remove(modify);
|
||||
|
||||
var requires = list.Where(x=>x.Require is not null).SelectMany(x => x.Require).ToArray();
|
||||
if(requires.Contains(modify))
|
||||
throw new NotRequireModifyException(requires);
|
||||
|
||||
obj = Modified[modify];
|
||||
Modified.Remove(modify);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@ namespace BITKit
|
||||
/// </summary>
|
||||
public interface IProperty
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 属性接口
|
||||
@@ -71,11 +70,7 @@ namespace BITKit
|
||||
{
|
||||
foreach (var x in factory)
|
||||
{
|
||||
properties.Add(x.GetType()!.FullName, x);
|
||||
foreach (var att in x.GetType().GetCustomAttributes<CustomTypeAttribute>())
|
||||
{
|
||||
properties.Add(att.Type!.FullName, x);
|
||||
}
|
||||
AddPropertyInternal(x);
|
||||
}
|
||||
}
|
||||
Dictionary<string, object> properties=new();
|
||||
@@ -104,7 +99,8 @@ namespace BITKit
|
||||
}
|
||||
else
|
||||
{
|
||||
properties.Add(typeof(T).FullName, x = addFactory.Invoke());
|
||||
AddPropertyInternal(addFactory.Invoke());
|
||||
//properties.Add(typeof(T).FullName, x = addFactory.Invoke());
|
||||
return (T)x;
|
||||
}
|
||||
}
|
||||
@@ -132,17 +128,24 @@ namespace BITKit
|
||||
}
|
||||
public bool TrySetProperty<T>(T value)
|
||||
{
|
||||
if (properties.TryGetValue(typeof(T).FullName, out var x))
|
||||
bool result = false;
|
||||
foreach (var pair in properties.Where(x=>x.Value is T).ToArray())
|
||||
{
|
||||
properties[typeof(T).FullName] = value;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
properties[pair.Key] = value;
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
// if (properties.TryGetValue(typeof(T).FullName, out var x))
|
||||
// {
|
||||
// properties[typeof(T).FullName] = value;
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
public object[] GetProperties()=>properties.Values.ToArray();
|
||||
public object[] GetProperties()=>properties.Values.Distinct().ToArray();
|
||||
|
||||
public void Read(BinaryReader r)
|
||||
{
|
||||
@@ -168,9 +171,21 @@ namespace BITKit
|
||||
ClearProperties();
|
||||
foreach (var x in propertable.GetProperties())
|
||||
{
|
||||
properties.Add(x.GetType().FullName, x);
|
||||
AddPropertyInternal(x);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void AddPropertyInternal(object value)
|
||||
{
|
||||
if (value is ICloneable cloneable)
|
||||
{
|
||||
value = cloneable.Clone();
|
||||
}
|
||||
properties.Set(value.GetType().FullName, value);
|
||||
foreach (var att in value.GetType().GetCustomAttributes<CustomTypeAttribute>())
|
||||
{
|
||||
properties.Set(att.Type!.FullName, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/BITKit/Core/UX/IUXPopUp.cs
Normal file
11
Assets/BITKit/Core/UX/IUXPopUp.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public interface IUXPopup
|
||||
{
|
||||
void Popup(string content,float duration=3f);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user