Forum rules - please read before posting.

Using an Hotspot with UCC

It is good to see there is finally a good example but i think things are missing from it like when clicked on a hotspot or if people want a key to press like f for example then it goes in inventory and when clicked on inventory item like a pistol for example it gets equiped. so with the new integration how would I do this because i had this working when it was the old integration where i had to call a custom action i scipted.

Comments

  • edited November 2020

    The updated integration supports using both AC Hotspots and UCC Interactables.

    See the included FirstAndThirdPerson example scene: the dummies are AC Hotspots and can be interacted with using the InteractionA input, while the button at the end is a UCC Interactable and can be interacted with using the Action input.

    This UCC button also demontrates how inventory items can be used on UCC Interactables. When used, the ActionList it runs uses the Inventory: Check selected Action to determine which item the player is holding.

    Item syncing in the example is handled via the AC_UCC_Item component, which gets attached to Item objects. This syncing working by having AC items react to UCC items - so if a UCC item gets picked up, the associated AC item also gets picked up, and so on.

    This is achieved by hooking into UCC's inventory events. For the reverse - i.e., collecting an AC item results in you picking up its associated UCC item - you can instead hook into AC's inventory events:

    using AC;
    using UnityEngine;
    
    public class InventoryEvents : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            EventManager.OnInventoryAdd += OnInventoryAdd;
            EventManager.OnInventoryRemove += OnInventoryRemove;
            EventManager.OnInventorySelect += OnInventorySelect;
            EventManager.OnInventoryDeselect += OnInventoryDeselect;
        }
    
        private void OnDisable ()
        {
            EventManager.OnInventoryAdd -= OnInventoryAdd;
            EventManager.OnInventoryRemove -= OnInventoryRemove;
            EventManager.OnInventorySelect -= OnInventorySelect;
            EventManager.OnInventoryDeselect -= OnInventoryDeselect;
        }
    
        private void OnInventoryAdd (InvItem invItem, int value)
        {
            int itemID = invItem.id;
            // AC item added
        }
    
        private void OnInventoryRemove (InvItem invItem, int value)
        {
            int itemID = invItem.id;
            // AC item removed
        }
    
        private void OnInventorySelect (InvItem invItem)
        {
            int itemID = invItem.id;
            // AC item selected
        }
    
        private void OnInventoryDeselect (InvItem invItem)
        {
            int itemID = invItem.id;
            // AC item deselected
        }
    
    }
    

    You'd then just need to fill in these functions with the relevant UCC code to update the UCC inventory, i.e. select the UCC item, add the UCC item to the UCC inventory, etc. See UCC's own docs for details on how to access the UCC inventory through script.

    When combining two game-wide assets such as AC and UCC, though, the finer details of an integration will come down to the specific needs of your project. If you need more advice on bridging the two together, you'll need to share more detail about exactly what it is you're looking to do.

  • I really don't know how to script properly sorry but I did this in an action.
    /*
    *
    * Adventure Creator
    * by Chris Burton, 2013-2020
    *
    * "ActionTemplate.cs"
    *
    * This is a blank action template.
    *
    */

    using UnityEngine;
    using Opsive.UltimateCharacterController.Inventory;
    using System.Collections.Generic;

    if UNITY_EDITOR

    using UnityEditor;

    endif

    namespace AC
    {

    [System.Serializable]
    public class ActionUCCPickup : Action
    {
    
        // Declare variables here
        [SerializeField] protected bool isPlayer;
        [Tooltip("The character that should pickup the item.")]
        [SerializeField] protected GameObject m_Character;
        [Tooltip("The ItemType that the character should pickup.")]
        [SerializeField] protected ItemType m_ItemType;
        [Tooltip("The number of ItemType that the character should pickup.")]
        [SerializeField] protected int m_Count = 1;
        [Tooltip("Immediately picks up the item.")]
        [SerializeField] protected bool immediatePickup;
        [Tooltip("Forces the equip.")]
        [SerializeField] protected bool forceEquip;
    
        public ActionUCCPickup ()
        {
            this.isDisplayed = true;
            category = ActionCategory.Custom;
            title = "Pickup Item";
            description = "Adds item to UCC inventory.";
        }
    
    
        public override float Run ()
        {
            /* 
             * This function is called when the action is performed.
             * 
             * The float to return is the time that the game
             * should wait before moving on to the next action.
             * Return 0f to make the action instantenous.
             * 
             * For actions that take longer than one frame,
             * you can return "defaultPauseTime" to make the game
             * re-run this function a short time later. You can
             * use the isRunning boolean to check if the action is
             * being run for the first time, eg: 
             */
    
            var inventory = m_Character.GetComponent<InventoryBase>();
    
    
            // Adds the specified amount of the ItemType to the inventory.
            // m_ItemType: The ItemType to pick up.
            // m_Amount: The amount of ItemType to pick up.
            // -1: The slot ID that picked up the item. A -1 value will indicate no specified slot.
            // true: Should the item be picked up immediately? If false the EquipUnequip ability may not switch to the newly picked up item.
            // false: Should the item be force equipped?
            inventory.Pickup(m_ItemType, m_Count, 0, immediatePickup, forceEquip);
    
            if (!isRunning)
            {
                isRunning = true;
                return defaultPauseTime;
            }
            else
            {
                isRunning = false;
                return 0f;
            }
        }
    
    
        public override void Skip ()
        {
            /*
             * This function is called when the Action is skipped, as a
             * result of the player invoking the "EndCutscene" input.
             * 
             * It should perform the instructions of the Action instantly -
             * regardless of whether or not the Action itself has been run
             * normally yet.  If this method is left blank, then skipping
             * the Action will have no effect.  If this method is removed,
             * or if the Run() method call is left below, then skipping the
             * Action will cause it to run itself as normal.
             */
    
             Run ();
        }
    
    
        #if UNITY_EDITOR
    
        public override void ShowGUI ()
        {
            // Action-specific Inspector GUI code here
            isPlayer = EditorGUILayout.Toggle("Is player?", isPlayer);
            immediatePickup = EditorGUILayout.Toggle("Immediate Pickup", immediatePickup);
            forceEquip = EditorGUILayout.Toggle("Force Equip", forceEquip);
            if (!isPlayer)
            {
                m_Character = (GameObject)EditorGUILayout.ObjectField("Character:", m_Character, typeof(GameObject), true);
            }
    
            m_ItemType = (ItemType)EditorGUILayout.ObjectField("Item type:", m_ItemType, typeof(ItemType), true);
            m_Count = EditorGUILayout.IntField("Count:", m_Count);
    
            AfterRunningOption ();
        }
    
    
        public override string SetLabel ()
        {
            // (Optional) Return a string used to describe the specific action's job.
    
            return string.Empty;
        }
    
        #endif
    
    }
    

    }

    I did it so if I click on the pistol in inventory it gets equiped. It does work still.

  • You'll be getting a Console error if you don't have "Is player?" checked, because you need to set m_Character to be the Player if so.

    Here's a cleaned-up and fixed version:

    using UnityEngine;
    using Opsive.UltimateCharacterController.Inventory;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionUCCPickup : Action
        {
    
            [SerializeField] protected bool isPlayer;
            [SerializeField] protected GameObject m_Character;
            [SerializeField] protected ItemType m_ItemType;
            [SerializeField] protected int m_Count = 1;
            [SerializeField] protected bool immediatePickup;
            [SerializeField] protected bool forceEquip;
    
            public ActionUCCPickup ()
            {
                this.isDisplayed = true;
                category = ActionCategory.Custom;
                title = "Pickup Item";
                description = "Adds item to UCC inventory.";
            }
    
    
            public override float Run ()
            {
                if (isPlayer) m_Character = KickStarter.player.gameObject;
                if (m_Character == null) return 0f;
    
                var inventory = m_Character.GetComponent<InventoryBase>();
    
                // Adds the specified amount of the ItemType to the inventory.
                // m_ItemType: The ItemType to pick up.
                // m_Amount: The amount of ItemType to pick up.
                // -1: The slot ID that picked up the item. A -1 value will indicate no specified slot.
                // true: Should the item be picked up immediately? If false the EquipUnequip ability may not switch to the newly picked up item.
                // false: Should the item be force equipped?
                inventory.Pickup(m_ItemType, m_Count, 0, immediatePickup, forceEquip);
                Debug.Log (m_Character + " picked up UCC item " + m_ItemType + ", Count: " + m_Count + ", Slot: 0, ForceEquip: " + forceEquip);
                return 0f;
            }
    
    
            #if UNITY_EDITOR
    
            public override void ShowGUI ()
            {
                isPlayer = EditorGUILayout.Toggle("Is player?", isPlayer);
                immediatePickup = EditorGUILayout.Toggle("Immediate Pickup", immediatePickup);
                forceEquip = EditorGUILayout.Toggle("Force Equip", forceEquip);
                if (!isPlayer)
                {
                    m_Character = (GameObject)EditorGUILayout.ObjectField("Character:", m_Character, typeof(GameObject), true);
                }
    
                m_ItemType = (ItemType)EditorGUILayout.ObjectField("Item type:", m_ItemType, typeof(ItemType), true);
                m_Count = EditorGUILayout.IntField("Count:", m_Count);
    
                AfterRunningOption ();
            }
    
            #endif
    
        }
    
    }
    

    That'll also report the result of the Action in the Console. If it's showing, but the UCC character has no change, you'll need to look into it on the UCC side of things.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.