How Can We Help?

Basic Inventory

While you can use any inventory solution you want, I’ve included a ‘Basic Inventory’ solution for you.

By using an Input Source and enabling the component, Basic Inventory can be used to equip and store weapon sets directly.

 

 

 

 

Allow Motion Tests – Determines if the Basic Equip and Basic Store motions will activate on their own using their TestActivate() functions.

Sync Number Keys – When checked, pressing ‘1’ will activate the first weapon set, pressing ‘2’ will activate the second weapon set, etc.

Toggle Set Alias – Unity Input Manager entry for toggling the current weapon set on and off.

Shift Set Alias – Unity Input Manager entry for cycling through the list of weapon sets (forward and backwards).

 

Items

Items that the character owns can be described in this list. This provides information about the item including the prefab used to instantiate the instance at run-time.

The Equip Motion and Store Motion properties define the motion to use when equipping and storing the item. The associated “Form” property defines which animation to use with the motion.

You can customize the motions to use any animations you want. However, I’ve defaulted to these values here.

 

 

 

 

Type – This is a string you can use to classify the item. It can be anything you want.

Instance – If an instance of the item already exists in the scene, you can place that here. This is great for having the sword or bow be stored on the character’s back.

In this case, when the item is equipped we won’t create a new instance. Instead, we’ll use the one specified. When it is stored, we won’t destroy it. Instead, we’ll place it back at the original position and rotation.

Resource Path – Path within Unity’s Resources folder where the prefab exists. When there is no Instance set, this is what we’ll use to create the item at run-time.

Local Properties – These properties override the local properties on the Item Core component and allow us to customize how the item is equipped for each individual character.

 

Slots

Slots help us define where things go. When we equip an item, we’ll parent it to one of these slots.

The ‘ID’ of the slot serves a couple of purposes:

First, it is a unique identifier.

Second, it’s actually the location we’ll put the item.

 

 

 

 

When equipping items, we’ll use the value of the ID as follows:

  1. We’ll search for a Unity Human Body Bone that roughly matches the name
  2. We’ll search for a transform that roughly matches the name

If we find a valid transform using the approaches above, that’s where we’ll equip the item.

Once equipped, we’ll enter the item’s ID in the field automatically.

 

Weapon Sets

Weapon sets allow us to equip and store groups of items at once. For example, we could be equipping a sword and shield at once, two swords, or maybe a helm, hammer, and shield.

While it was originally built for weapons, you can use these sets for non-weapons too.

The list contains an order list of weapon sets that can be equipped and stored. The order matters because it corresponds with the Sync Number Keys property described above.

Each weapon set includes some basic properties:

Is Enabled – Determines if we can equip and store the whole weapon set

Name – Friendly name

StanceActor Core State to set once all the items are equipped

Default FormActor Core State to set once all the items are equipped

 

The second part of the weapon set defines the items to equip and store and which slots those items will be placed in.

In some cases, you may want the weapon set to clear an already equipped item. To do this, simply add an ‘item’ that has no Item ID value.

In this way, we’ll store existing items before we equip the new ones.

 

Events

As we move forward, more and more of the ootii assets will support sending messages through Unity Events. This is a great way for you to add customized code to react to in-game actions.

You can also use Reactors to react to these messages and events as well.

The Basic Inventory supports the following messages.

Item Equipped – Sent each time an individual item is equipped.

Item Stored – Sent each time an individual item is stored.

Weapon Set Equipped – Sent when a weapon set has completed equipping all items.

Weapon Set Stored – Sent when a weapon set has completed storing all items.

 

 

 

Code

To equip and store items and weapon sets through code, we can do the following:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using UnityEngine;
using com.ootii.Actors.Inventory;

public class SampleComponent : MonoBehaviour
{
    public void SomeFunction()
    {
        BasicInventory lInventory = gameObject.GetComponent<BasicInventory>();

        lInventory.EquipWeaponSet(0);

        lInventory.StoreWeaponSet();

        lInventory.ToggleWeaponSet(0);

        lInventory.EquipItem("Sword_01", "RIGHT_HAND");

        lInventory.StoreItem("RIGHT_HAND");

        BasicInventorySlot lSlot = lInventory.GetInventorySlot("RIGHT_HAND");

        string lItemID = lInventory.GetItemID("RIGHT_HAND");

        BasicInventoryItem lItem = lInventory.GetInventoryItem("Sword_01");

        string lPath = lInventory.GetItemPropertyValue<string>("Sword_01", "Resource Path");
    }
}

Notes

Any inventory solution you use will need to implement the IInventorySource interface. This interface provides the basic blueprint for how to get item properties, equip items, etc.

 

Page Contents