using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using BITKit; using System.IO; using UnityEngine.UIElements; namespace BITFALL { public class WorldItem : MonoBehaviour,IBasicItem,IDescription { #region 本地字段 [Header(Constant.Header.Settings)] [SerializeField]private AssetableItem asset; [Header(Constant.Header.Optional)] [SerializeReference, SubclassSelector] private IProperty[] initialProperties; #endregion #region 接口实现 public int Id { get; private set; } = Guid.NewGuid().GetHashCode(); public string Name => asset.Name; public string Description => asset.Description; public ItemQuality Quality => asset.Quality; public string AddressablePath => asset.AddressablePath; internal Property property { get { if (BITAppForUnity.IsPlaying is false || asset?.RuntimeProperties is null) { return (initialProperties is null)? new Property() : new Property(initialProperties); } if(_property is not null) return _property; var list = new List(); if (asset?.RuntimeProperties is not null) { list.AddRange(asset.RuntimeProperties); } if(initialProperties is not null) { list.AddRange(initialProperties); } return _property= new Property(list.ToArray()); // return _property ??= (BITAppForUnity.IsPlaying && asset?.RuntimeProperties is not null) // ? new Property(asset.RuntimeProperties) // : new Property(); } set=>_property=value; } private Property _property; public bool Contains() => property.Contains(); public T GetOrAddProperty(Func addFactory) => property.GetOrAddProperty(addFactory); public T GetOrCreateProperty() => property.GetOrCreateProperty(); public object[] GetProperties() => property.GetProperties(); public bool TryGetProperty(out T value) => property.TryGetProperty(out value); public bool TryRemoveProperty() => property.TryRemoveProperty(); public bool TrySetProperty(T value) => property.TrySetProperty(value); public void Read(BinaryReader r) { throw new NotImplementedException(); } public void Write(BinaryWriter w) { throw new NotImplementedException(); } public bool CopyItemsFrom(IBasicItem item) { Id=item.Id; CopyPropertiesFrom(item); return true; } public bool ClearProperties()=>property.ClearProperties(); public bool CopyPropertiesFrom(IPropertable propertable)=>property.CopyPropertiesFrom(propertable); #endregion #region 本地方法 public AssetableItem Assetable => asset; public ManagedItem Pick() { var managedItem = new ManagedItem(); managedItem.CopyItemsFrom(this); return managedItem; } public void Picked() { Destroy(gameObject); } #endregion public object Clone() { return Pick(); } } #if UNITY_EDITOR [UnityEditor.CustomEditor(typeof(WorldItem))] public class WorldItemInspector:BITInspector { public override VisualElement CreateInspectorGUI() { CreateSubTitle(Constant.Header.Data); var label = root.Create