swb_shared/IInventory.cs

Inventory interface and inventory item interface for the game. IInventory defines a networked list of GameObjects as items, an active GameObject and an active IInventoryItem, and basic inventory operations (Add, AddClone, Has, SetActive by object or name, Clear). IInventoryItem describes metadata and lifecycle hooks for items, including slot, icon, display name, mobility modifier, and carry start/stop handlers and a check to allow switching.

Networking
namespace SWB.Shared;

public interface IInventory
{
	public NetList<GameObject> Items { get; set; }
	public GameObject Active { get; set; }
	public IInventoryItem ActiveItem { get; set; }

	public void Add( GameObject gameObject, bool makeActive = false );
	public GameObject AddClone( GameObject gamePrefab, bool makeActive = true );
	public bool Has( GameObject gameObject );
	public void SetActive( GameObject gameObject );
	public void SetActive( string name );
	public void Clear();
}

public interface IInventoryItem : IValid
{
	/// <summary>Inventory slot</summary>
	public int Slot { get; set; }

	/// <summary>Image that represent the item on the HUD</summary>
	public string Icon { get; set; }

	/// <summary>Name that represent the item on the HUD</summary>
	public string DisplayName { get; set; }

	/// <summary>The movement speed modifier while this item is active</summary>
	public float Mobility { get; set; }

	/// <summary>Called on the GameObject that will be the new active one (Broadcast for networked gameObjects!)</summary>
	public void OnCarryStart();

	/// <summary>Called when the GameObject stops being the active one (Broadcast for networked gameObjects!)</summary>
	public void OnCarryStop();

	/// <summary>Can the GameObject be switched out</summary>
	public bool CanCarryStop();
}