using System.Collections; using System.Collections.Generic; using UnityEngine; using Unity.Mathematics; using BITKit; using System.IO; using System; using BITFALL.Items; using BITKit.Entities; // ReSharper disable UnassignedField.Global namespace BITFALL { public interface ICustomItemBehavior { void Inject(IEntity entity); bool TryUse(IBasicItem item); void OnUse(IBasicItem item); } /// /// 计数器 /// public interface ICount { int Count { get; } } [Serializable] public record ItemWeight : IProperty { public double Weight=1; public static implicit operator double(ItemWeight self) { return self.Weight; } } [Serializable] public record AddInventoryMaxWeight: IProperty { public float AddWeight = 1; } [Serializable] public record Cellable : IProperty { public float2 size; } public class AssetableItem : ScriptableObject,IAssetableItem { #region 字段 [Header(nameof(IAddressable))] [SerializeField] private ulong addressableId =RandomUlong.NextUlong; [Header(Constant.Header.Settings)] [SerializeField] private string displayName; [SerializeField] private string description; [SerializeField] private string addressablePath; [SerializeField] private WorldItem prefab; [SerializeField] private Texture2D squareIcon; [SerializeField] private Texture2D rectangleIcon; [SerializeField] private ItemQuality quality; /// /// 是否为不可储存的即兴物品 /// [SerializeField] private bool isImprovised; /// /// 允许被击倒时使用 /// [SerializeField] private bool allowUseWhileKnocked; [Header(Constant.Header.Property)] [SerializeReference, SubclassSelector] private IProperty[] factoryProperties; [SerializeReference, SubclassSelector] private IProperty[] runtimeProperties; private Property property => new(factoryProperties); #endregion #region 接口实现 public ulong AddressableId { get => addressableId; set { addressableId = value; #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(this); #endif } } public int Id => -1; public bool IsImprovised => isImprovised; public ItemQuality Quality => quality; public string Name => displayName; public string Description => description; public string AddressablePath => addressablePath; public bool AllowUseWhileKnocked => allowUseWhileKnocked; public bool Contains() => property.Contains(); public T GetOrAddProperty(Func addFactory) =>throw new NotImplementedException("资产不支持动态更改"); public T GetOrCreateProperty() => throw new NotImplementedException("资产不支持动态更改"); public object[] GetProperties() => property.GetProperties(); public bool TryGetProperty(out T value) => property.TryGetProperty(out value); public bool TryRemoveProperty() => throw new NotImplementedException("资产不支持动态更改"); public bool TrySetProperty(T value) => throw new NotImplementedException("资产不支持动态更改"); public void Read(BinaryReader r) { throw new NotImplementedException("资产不支持动态更改"); } public void Write(BinaryWriter w) { throw new NotImplementedException("资产不支持动态更改"); } public bool CopyItemsFrom(IBasicItem item) { throw new NotImplementedException("资产不支持动态更改"); } public bool ClearProperties() { throw new NotImplementedException("资产不支持动态更改"); } public bool CopyPropertiesFrom(IPropertable propertable) { throw new NotImplementedException("资产不支持动态更改"); } #endregion #region 本地方法 public WorldItem GetPrefab() => prefab; public Texture2D SquareIcon => squareIcon; public Texture2D RectangleIcon=>rectangleIcon; public IProperty[] RuntimeProperties => runtimeProperties; #endregion public object Clone() { var item = new ManagedItem(); item.CopyItemsFrom(this); item.Id = Guid.NewGuid().GetHashCode(); foreach (var x in runtimeProperties) { item.GetOrAddProperty(()=>x); } return item; } } }