1
This commit is contained in:
105
Assets/Artists/Scripts/Item/WorldItem.cs
Normal file
105
Assets/Artists/Scripts/Item/WorldItem.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using System.IO;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace BITFALL
|
||||
{
|
||||
|
||||
public class WorldItem : MonoBehaviour,IBasicItem,IDescription
|
||||
{
|
||||
#region 本地字段
|
||||
[Header(Constant.Header.Settings)]
|
||||
[SerializeField]private AssetableItem asset;
|
||||
|
||||
private new Rigidbody _rigidbody;
|
||||
#endregion
|
||||
#region 接口实现
|
||||
public int Id => GetInstanceID();
|
||||
public string Name => asset.name;
|
||||
public string Description => asset.Description;
|
||||
public ItemQuality Quality => asset.Quality;
|
||||
public string AddressablePath => asset.AddressablePath;
|
||||
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)
|
||||
{
|
||||
if(item is ManagedItem serializableItem)
|
||||
{
|
||||
asset = Addressables.LoadAssetAsync<AssetableItem>(item.AddressablePath).WaitForCompletion();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool ClearProperties()=>property.ClearProperties();
|
||||
public bool CopyPropertiesFrom(IPropertable propertable)=>property.CopyPropertiesFrom(propertable);
|
||||
#endregion
|
||||
#region 本地方法
|
||||
public AssetableItem Assetable => asset;
|
||||
private void Start()
|
||||
{
|
||||
_rigidbody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (!_rigidbody.IsSleeping()) return;
|
||||
_rigidbody.isKinematic = true;
|
||||
enabled = false;
|
||||
}
|
||||
public ManagedItem Pick()
|
||||
{
|
||||
var newitem = new ManagedItem();
|
||||
newitem.CopyItemsFrom(this);
|
||||
return newitem;
|
||||
}
|
||||
public void Picked()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.CustomEditor(typeof(WorldItem))]
|
||||
public class WorldItemInspector:BITInspector<WorldItem>
|
||||
{
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user