🧪 Sample Scripts¶
This folder contains example MonoBehaviours and editor utilities demonstrating how to integrate with the Inventory system.
These are not part of the runtime framework — they exist to show practical usage patterns.
🎯 Purpose¶
This folder demonstrates:
- How to interact with
SceneInventoryService - How to construct and give
ItemStacks - How to build simple world pickups
- How to generate compile-time constants from data (
KnownItemspattern)
👉 Everything here uses public, supported APIs only
📦 Contents¶
🧩 World (Gameplay Example)¶
| Script | Description |
|---|---|
WorldItemToInventory2D |
Minimal trigger-based pickup that adds items via the service |
🧰 Tools (Editor Workflow)¶
| Script | Description |
|---|---|
KnownItemsList |
ScriptableObject mapping names → ItemDefinition |
KnownItemsGenerator |
Editor tool that generates GUID constants from KnownItemsList |
🚀 Key Patterns¶
1. Service-first inventory interaction¶
var svc = InventoryResolve.ServiceFrom(this);
var stack = new ItemStack { def = item, quantity = quantity };
var result = svc.GiveExact(target, stack, containerId);
✔ No direct container access ✔ No internal APIs ✔ Respects authority, validation, and container rules
2. World pickup flow¶
private void OnTriggerEnter2D(Collider2D other)
{
var svc = InventoryResolve.ServiceFrom(this);
if (svc == null) return;
var stack = new ItemStack { def = item, quantity = quantity };
var res = svc.GiveExact(other.gameObject, stack, container);
if (res.Success)
Destroy(gameObject);
}
✔ Minimal ✔ Predictable ✔ Matches real gameplay usage
👉 This is example gameplay code, not a built-in framework system
3. Known Items (GUID constants)¶
Generate strongly-typed constants from data:
public const string WOOD = "a1b2c3...";
Benefits:
- No magic strings
- IDE autocomplete
- Safer refactoring
- Decouples gameplay code from asset references
⚠️ Important Notes¶
These are examples¶
- Safe to delete
- Not required by the framework
- Not used internally by runtime systems
Gameplay scripts are not framework features¶
Scripts like WorldItemToInventory2D are:
- Simple usage examples
- Not part of the Inventory API
- Not required for pickups to work
👉 You are expected to build your own gameplay logic using the same public APIs
Namespace is your responsibility¶
Generated files default to:
namespace RevGaming.Game
👉 Change this to your own game namespace before using it
Avoid duplication¶
Only one pickup pattern is needed.
If multiple examples exist:
👉 Keep one 👉 Delete the rest
Editor-only tooling¶
KnownItemsGenerator:
- Runs in the Unity Editor only
- Generates normal C# files
- Output should be committed to source control
🧠 Design Notes¶
These samples intentionally:
- Use service-based APIs
- Avoid internal container access
- Avoid reflection or hidden behaviour
- Mirror real gameplay code paths
If these scripts work in your project:
👉 your integration is correct
📎 Related¶
- Inventory Runtime → container + service logic
- Inventory Data →
ItemDefinition,ItemStack - Inventory Use → item use execution
- Inventory Teachables → guided usage examples