BITFALL/Assets/Artists/Scripts/Item/WorldItem.cs

89 lines
2.8 KiB
C#
Raw Normal View History

2023-06-08 14:09:50 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BITKit;
using System.IO;
using UnityEngine.UIElements;
using UnityEngine.AddressableAssets;
namespace BITFALL
{
2023-10-24 23:37:59 +08:00
public class WorldItem : MonoBehaviour,IBasicItem,IDescription
2023-06-08 14:09:50 +08:00
{
#region
[Header(Constant.Header.Settings)]
2023-10-20 19:31:12 +08:00
[SerializeField]private AssetableItem asset;
2023-06-08 14:09:50 +08:00
#endregion
#region
public int Id => GetInstanceID();
public string Name => asset.name;
public string Description => asset.Description;
public ItemQuality Quality => asset.Quality;
2023-09-01 14:33:54 +08:00
public string AddressablePath => asset.AddressablePath;
2023-06-08 14:09:50 +08:00
private readonly Property property = new();
public bool Contains<T>() => property.Contains<T>();
public T GetOrAddProperty<T>(Func<T> addFactory) => property.GetOrAddProperty<T>(addFactory);
public T GetOrCreateProperty<T>() => property.GetOrCreateProperty<T>();
public object[] GetProperties() => property.GetProperties();
public bool TryGetProperty<T>(out T value) => property.TryGetProperty<T>(out value);
public bool TryRemoveProperty<T>() => property.TryRemoveProperty<T>();
public bool TrySetProperty<T>(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)
{
2023-10-20 19:31:12 +08:00
if(item is ManagedItem serializableItem)
2023-06-08 14:09:50 +08:00
{
2023-09-01 14:33:54 +08:00
asset = Addressables.LoadAssetAsync<AssetableItem>(item.AddressablePath).WaitForCompletion();
2023-06-08 14:09:50 +08:00
}
return true;
}
public bool ClearProperties()=>property.ClearProperties();
public bool CopyPropertiesFrom(IPropertable propertable)=>property.CopyPropertiesFrom(propertable);
#endregion
#region
public AssetableItem Assetable => asset;
2023-10-20 19:31:12 +08:00
public ManagedItem Pick()
{
2023-10-29 15:27:13 +08:00
var managedItem = new ManagedItem();
managedItem.CopyItemsFrom(this);
return managedItem;
2023-06-08 14:09:50 +08:00
}
public void Picked()
{
Destroy(gameObject);
}
#endregion
}
#if UNITY_EDITOR
2023-10-24 23:37:59 +08:00
[UnityEditor.CustomEditor(typeof(WorldItem))]
public class WorldItemInspector:BITInspector<WorldItem>
2023-06-08 14:09:50 +08:00
{
public override VisualElement CreateInspectorGUI()
{
CreateSubTitle(Constant.Header.Data);
var label = root.Create<Label>();
label.text = agent.Id.ToString();
FillDefaultInspector();
CreateSubTitle(Constant.Header.Debug);
return root;
}
}
#endif
}