Data/ToolData.cs
using System;
using Clover.Carriable;
using Clover.Inventory;
using Clover.Persistence;
namespace Clover.Data;
[AssetType( Name = "Tool", Extension = "tool" )]
public sealed class ToolData : ItemData
{
[Property, Group( "Tool" )] public GameObject CarryScene { get; set; }
[Property, Group( "Tool" )] public int MaxDurability { get; set; } = 100;
public BaseCarriable SpawnCarriable()
{
if ( !CarryScene.IsValid() ) throw new Exception( $"{ResourceName} has no CarryScene" );
return CarryScene.Clone().GetComponent<BaseCarriable>();
}
public override string GetIcon()
{
return Icon ?? "ui/icons/default_tool.png";
}
public override IEnumerable<ItemAction> GetActions( InventorySlot slot )
{
yield return new ItemAction { Name = "Equip", Icon = "build", Action = slot.Equip };
}
public override void OnPersistentItemInitialize( PersistentItem persistentItem )
{
base.OnPersistentItemInitialize( persistentItem );
persistentItem.SetSaveData( "Durability", MaxDurability );
}
}