Class ItemContainer
Abstract base class for item containers, providing slot and item management for inventories, equipment, banks, etc. Implements IItemContainer and extends CharacterBehaviour for character association.
public abstract class ItemContainer : CharacterBehaviour, ICharacterBehaviour, IItemContainer
- Inheritance
-
ObjectComponentBehaviourMonoBehaviourNetworkBehaviourItemContainer
- Implements
- Derived
- Inherited Members
-
NetworkBehaviour.IsSpawnedNetworkBehaviour.ComponentIndexNetworkBehaviour.NetworkObjectNetworkBehaviour.MAXIMUM_NETWORKBEHAVIOURSNetworkBehaviour.UNSET_NETWORKBEHAVIOUR_IDNetworkBehaviour.ToString()NetworkBehaviour.Reset()NetworkBehaviour.OnValidate()NetworkBehaviour.IsBehaviourReconcilingNetworkBehaviour.ClearReplicateCache()NetworkBehaviour.CreateReconcile()NetworkBehaviour.Reconcile_Reader<T>(PooledReader, ref T)NetworkBehaviour.OnStartServerCalledNetworkBehaviour.OnStartClientCalledNetworkBehaviour.WritePayload(NetworkConnection, Writer)NetworkBehaviour.ReadPayload(NetworkConnection, Reader)NetworkBehaviour.OnStartNetwork()NetworkBehaviour.OnStopNetwork()NetworkBehaviour.OnStartServer()NetworkBehaviour.OnStopServer()NetworkBehaviour.OnOwnershipServer(NetworkConnection)NetworkBehaviour.OnSpawnServer(NetworkConnection)NetworkBehaviour.OnDespawnServer(NetworkConnection)NetworkBehaviour.OnStartClient()NetworkBehaviour.OnStopClient()NetworkBehaviour.OnOwnershipClient(NetworkConnection)NetworkBehaviour.ClearBuffedRpcs()NetworkBehaviour.ExcludeOwnerFromUnbufferedObserversRpcsNetworkBehaviour.IsClientOnlyNetworkBehaviour.IsServerOnlyNetworkBehaviour.IsHostNetworkBehaviour.IsClientNetworkBehaviour.IsServerNetworkBehaviour.IsDeinitializingNetworkBehaviour.NetworkManagerNetworkBehaviour.ServerManagerNetworkBehaviour.ClientManagerNetworkBehaviour.ObserverManagerNetworkBehaviour.TransportManagerNetworkBehaviour.TimeManagerNetworkBehaviour.SceneManagerNetworkBehaviour.PredictionManagerNetworkBehaviour.RollbackManagerNetworkBehaviour.NetworkObserverNetworkBehaviour.IsClientInitializedNetworkBehaviour.IsClientStartedNetworkBehaviour.IsClientOnlyInitializedNetworkBehaviour.IsClientOnlyStartedNetworkBehaviour.IsServerInitializedNetworkBehaviour.IsServerStartedNetworkBehaviour.IsServerOnlyInitializedNetworkBehaviour.IsServerOnlyStartedNetworkBehaviour.IsHostInitializedNetworkBehaviour.IsHostStartedNetworkBehaviour.IsOfflineNetworkBehaviour.IsNetworkedNetworkBehaviour.GetIsNetworked()NetworkBehaviour.IsManagerReconcilingNetworkBehaviour.ObserversNetworkBehaviour.IsOwnerNetworkBehaviour.IsControllerNetworkBehaviour.HasAuthorityNetworkBehaviour.OwnerNetworkBehaviour.OwnerIdNetworkBehaviour.ObjectIdNetworkBehaviour.LocalConnectionNetworkBehaviour.OwnerMatches(NetworkConnection)NetworkBehaviour.Despawn(GameObject, DespawnType?)NetworkBehaviour.Despawn(NetworkObject, DespawnType?)NetworkBehaviour.Despawn(DespawnType?)NetworkBehaviour.Spawn(GameObject, NetworkConnection, Scene)NetworkBehaviour.Spawn(NetworkObject, NetworkConnection, Scene)NetworkBehaviour.RemoveOwnership()NetworkBehaviour.GiveOwnership(NetworkConnection)NetworkBehaviour.GetInstance<T>()NetworkBehaviour.TryRegisterInstance<T>(T)NetworkBehaviour.UnregisterInstance<T>()NetworkBehaviour.CanLog(LoggingType)MonoBehaviour.IsInvoking()MonoBehaviour.CancelInvoke()MonoBehaviour.StopCoroutine(Coroutine)MonoBehaviour.StopAllCoroutines()MonoBehaviour.destroyCancellationTokenMonoBehaviour.useGUILayoutMonoBehaviour.didStartMonoBehaviour.didAwakeMonoBehaviour.runInEditModeBehaviour.enabledBehaviour.isActiveAndEnabledComponent.GetComponent<T>()Component.TryGetComponent<T>(out T)Component.GetComponentInChildren<T>()Component.GetComponentsInChildren<T>()Component.GetComponentInParent<T>()Component.GetComponentsInParent<T>()Component.GetComponents<T>()Component.GetComponentIndex()Component.CompareTag(TagHandle)Component.transformComponent.transformHandleComponent.gameObjectComponent.tagObject.GetEntityId()Object.GetInstanceID()Object.GetHashCode()Object.InstantiateAsync<T>(T)Object.InstantiateAsync<T>(T, Transform)Object.InstantiateAsync<T>(T, Vector3, Quaternion)Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion, Transform)Object.Instantiate(Object)Object.Instantiate(Object, Scene)Object.Instantiate<T>(T, InstantiateParameters)Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)Object.Instantiate(Object, Transform)Object.Instantiate<T>(T)Object.Instantiate<T>(T, Vector3, Quaternion)Object.Instantiate<T>(T, Vector3, Quaternion, Transform)Object.Instantiate<T>(T, Transform)Object.Destroy(Object)Object.DestroyImmediate(Object)Object.DontDestroyOnLoad(Object)Object.DestroyObject(Object)Object.FindObjectsOfType<T>()Object.FindObjectsByType<T>(FindObjectsSortMode)Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)Object.FindObjectOfType<T>()Object.FindFirstObjectByType<T>()Object.FindAnyObjectByType<T>()Object.FindFirstObjectByType<T>(FindObjectsInactive)Object.FindAnyObjectByType<T>(FindObjectsInactive)Object.FindObjectsByType<T>()Object.FindObjectsByType<T>(FindObjectsInactive)Object.nameObject.hideFlags
Properties
Items
Gets the list of items contained in this container.
public List<Item> Items { get; }
Property Value
Methods
AddSlots(List<Item>, int)
Adds slots to the container, optionally initializing with a list of items.
public void AddSlots(List<Item> items, int amount)
Parameters
CanAddItem(Item)
Determines if the specified item can be added to the container, considering stack sizes and slot availability.
public bool CanAddItem(Item item)
Parameters
itemItemThe item to check.
Returns
- bool
True if the item can be added, false otherwise.
CanManipulate()
Determines if the container can be manipulated (e.g., items moved or swapped). Checks if the character is alive and the items list is not empty.
public virtual bool CanManipulate()
Returns
- bool
True if manipulation is allowed, false otherwise.
Clear()
Clears all items from the container, destroying each item and setting slots to null.
public void Clear()
ContainsItem(BaseItemTemplate)
Checks if the container contains an item with the specified template.
public bool ContainsItem(BaseItemTemplate itemTemplate)
Parameters
itemTemplateBaseItemTemplateThe item template to search for.
Returns
- bool
True if the item is found, false otherwise.
FilledSlots()
Gets the number of filled slots in the container.
public int FilledSlots()
Returns
- int
The number of filled slots.
FreeSlots()
Gets the number of free slots in the container.
public int FreeSlots()
Returns
- int
The number of free slots.
GetItemCount(BaseItemTemplate)
Gets the count of items matching the specified template, including stack sizes.
public int GetItemCount(BaseItemTemplate itemTemplate)
Parameters
itemTemplateBaseItemTemplateThe item template to count.
Returns
- int
The number of items matching the template.
HasFreeSlot()
Checks if the container has at least one free slot.
public bool HasFreeSlot()
Returns
- bool
True if a free slot exists, false otherwise.
IsSlotEmpty(int)
Checks if the specified slot is empty (contains no item).
public bool IsSlotEmpty(int slot)
Parameters
slotintThe slot index to check.
Returns
- bool
True if the slot is empty, false otherwise.
IsSlotLocked(int)
Returns true if the specified slot is currently locked. Locked slots cannot be swapped, removed, or transferred until unlocked.
public bool IsSlotLocked(int slot)
Parameters
slotintThe slot index to check.
Returns
- bool
True if the slot is locked, false otherwise.
IsValidSlot(int)
Checks if the item slot exists (is within valid range).
public bool IsValidSlot(int slot)
Parameters
slotintThe slot index to check.
Returns
- bool
True if the slot is valid, false otherwise.
LockSlot(int)
Locks the specified slot, preventing it from being swapped, removed, or transferred.
public void LockSlot(int slot)
Parameters
slotintThe slot index to lock.
OnDestroying()
Called when the container is being destroyed. Clears event handlers and locks.
public override void OnDestroying()
RemoveItem(int)
Removes an item from the specified slot and returns it. Returns null if the slot was empty. Fails if the slot is locked.
public Item RemoveItem(int slot)
Parameters
slotintThe slot index to remove the item from.
Returns
- Item
The item that was removed, or null if no item was present.
SetItemSlot(Item, int)
Sets the item in the specified slot. Previous item will be lost if not referenced elsewhere.
public bool SetItemSlot(Item item, int slot)
Parameters
Returns
- bool
True if the item was successfully set, false otherwise.
Remarks
Refuses a locked slot. This is the write primitive every other mutation funnels through, and it was the one that did not check the lock — so a cross-container move could overwrite a slot whose item was mid-consumption, and the activation would then complete against an item that had already gone somewhere else. RemoveItem and SwapItemSlots check the lock themselves before calling in here, so this guard is redundant for them by design.
Callers MUST check the return value. It is a genuine refusal, not a formality.
SwapItemSlots(int, int)
Swaps items between two slots.
public bool SwapItemSlots(int from, int to)
Parameters
Returns
- bool
True if the swap was successful, false otherwise.
SwapItemSlots(int, int, out Item, out Item)
Swaps items between two slots and returns the items that were swapped. Fails if either slot is locked.
public bool SwapItemSlots(int from, int to, out Item fromItem, out Item toItem)
Parameters
fromintThe source slot index.
tointThe destination slot index.
fromItemItemThe item originally in the source slot.
toItemItemThe item originally in the destination slot.
Returns
- bool
True if the swap was successful, false otherwise.
TryAddItem(Item, out List<Item>)
Attempts to add an item to the container. Returns true if the entire stack size of the item has been successfully added. All modified items are returned. Handles stacking logic and slot assignment.
public bool TryAddItem(Item item, out List<Item> modifiedItems)
Parameters
itemItemThe item to add.
modifiedItemsList<Item>The list of items modified during the operation.
Returns
- bool
True if the item was successfully added, false otherwise.
TryGetItem(int, out Item)
Attempts to get the item in the specified slot. Returns false if the item doesn't exist.
public bool TryGetItem(int slot, out Item item)
Parameters
Returns
- bool
True if an item was found, false otherwise.
UnlockSlot(int)
Unlocks the specified slot, allowing normal manipulation again.
public void UnlockSlot(int slot)
Parameters
slotintThe slot index to unlock.
Events
OnSlotLockChanged
Event triggered when a slot's lock state changes. Parameters: container, slot index, isLocked.
public event Action<IItemContainer, int, bool> OnSlotLockChanged
Event Type
OnSlotUpdated
Event triggered when an item slot is updated (item added, removed, or changed).
public event Action<IItemContainer, Item, int> OnSlotUpdated