AliAch's picture
Refactor inventory system for improved placement logic
35113a1
Raw History Blame Contribute Delete
1.47 kB
using UnityEngine;
public class ItemData : MonoBehaviour
{
public string itemID;
[Header("Grid Size (Width, Height, Depth)")]
public Vector3Int baseFootprint = new Vector3Int(1, 1, 1);
// Variables used by InventoryPlacer
[HideInInspector] public Vector3Int gridPosition;
[HideInInspector] public Vector3Int currentFootprint;
[HideInInspector] public int swapState = 0;
// Defines how the item rotates logically.
// State0: (W, H, D) - default, bulk consumes Y (vertical).
// State1: (H, W, D) - swap W<->H, bulk consumes X (horizontal).
// State2: (W, D, H) - swap H<->D, bulk consumes Z (depth).
// Priority when placing: try State0 first, then State1, then State2 - i.e. prefer vertical,
// then horizontal, then depth.
public Vector3Int FootprintAtState(int state)
{
switch (state)
{
case 0:
return baseFootprint; // Normal (W, H, D) - bulk on Y
case 1:
return new Vector3Int(baseFootprint.y, baseFootprint.x, baseFootprint.z); // Swap Width and Height - bulk on X
case 2:
return new Vector3Int(baseFootprint.x, baseFootprint.z, baseFootprint.y); // Swap Height and Depth - bulk on Z
default:
return baseFootprint;
}
}
public void ApplySwapState(int state)
{
swapState = state;
currentFootprint = FootprintAtState(state);
}
}