1
This commit is contained in:
86
Assets/Artists/Scripts/Item/AssetableItem.cs
Normal file
86
Assets/Artists/Scripts/Item/AssetableItem.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Unity.Mathematics;
|
||||
using BITKit;
|
||||
using System.IO;
|
||||
using System;
|
||||
// ReSharper disable UnassignedField.Global
|
||||
|
||||
namespace BITFALL
|
||||
{
|
||||
[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(Constant.Header.Settings)]
|
||||
[SerializeField] private string displayName;
|
||||
[SerializeField] private string description;
|
||||
[SerializeField] private string addressablePath;
|
||||
[SerializeField] private WorldableItem prefab;
|
||||
[SerializeField] private Texture2D squareIcon;
|
||||
[SerializeField] private Texture2D rectangleIcon;
|
||||
[SerializeField] private ItemQuality quality;
|
||||
[Header(Constant.Header.Property)]
|
||||
[SerializeReference, SubclassSelector] public IProperty[] factoryProperties;
|
||||
private Property property => new(factoryProperties);
|
||||
#endregion
|
||||
#region 接口实现
|
||||
public int Id => -1;
|
||||
public ItemQuality Quality => quality;
|
||||
public string Name => displayName;
|
||||
public string Description => description;
|
||||
public string AddressablePath => addressablePath;
|
||||
public bool Contains<T>() => property.Contains<T>();
|
||||
public T GetOrAddProperty<T>(Func<T> addFactory) =>throw new NotImplementedException("资产不支持动态更改");
|
||||
public T GetOrCreateProperty<T>() => throw new NotImplementedException("资产不支持动态更改");
|
||||
public object[] GetProperties() => property.GetProperties();
|
||||
public bool TryGetProperty<T>(out T value) => property.TryGetProperty(out value);
|
||||
public bool TryRemoveProperty<T>() => throw new NotImplementedException("资产不支持动态更改");
|
||||
public bool TrySetProperty<T>(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 WorldableItem GetPrefab() => prefab;
|
||||
public Texture2D SquareIcon => squareIcon;
|
||||
public Texture2D RectangleIcon=>rectangleIcon;
|
||||
#endregion
|
||||
}
|
||||
}
|
24
Assets/Artists/Scripts/Item/BITFALL.Item.asmdef
Normal file
24
Assets/Artists/Scripts/Item/BITFALL.Item.asmdef
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "BITFALL.Item",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0",
|
||||
"GUID:97f799b98a1c33147bf65cada7001568",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:66d2ae14764cc7d49aad4b16930747c0",
|
||||
"GUID:677cd05ca06c46b4395470200b1acdad",
|
||||
"GUID:d8b63aba1907145bea998dd612889d6b",
|
||||
"GUID:9e24947de15b9834991c9d8411ea37cf",
|
||||
"GUID:84651a3751eca9349aac36a66bba901b"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
16
Assets/Artists/Scripts/Item/ItemExtensions.cs
Normal file
16
Assets/Artists/Scripts/Item/ItemExtensions.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using BITFALL;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public static class ItemExtensions
|
||||
{
|
||||
public static AssetableItem GetAssetable(this IBasicItem self)
|
||||
{
|
||||
return Addressables.LoadAssetAsync<AssetableItem>(self.AddressablePath).WaitForCompletion();
|
||||
}
|
||||
}
|
||||
}
|
89
Assets/Artists/Scripts/Item/WorldableItem.cs
Normal file
89
Assets/Artists/Scripts/Item/WorldableItem.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
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 WorldableItem : MonoBehaviour,IBasicItem,IDescription
|
||||
{
|
||||
#region 本地字段
|
||||
[Header(Constant.Header.Settings)]
|
||||
[SerializeField]AssetableItem asset;
|
||||
#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 SerializableItem 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;
|
||||
public SerializableItem Pick()
|
||||
{
|
||||
var newitem = new SerializableItem();
|
||||
newitem.CopyItemsFrom(this);
|
||||
return newitem;
|
||||
}
|
||||
public void Picked()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.CustomEditor(typeof(WorldableItem))]
|
||||
public class WorldableInspector:BITInspector<WorldableItem>
|
||||
{
|
||||
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