Forum rules - please read before posting.

Objectives InventoryBox Slot Background and Numbering Objectives

edited January 5 in Technical Q&A

Hi there,

I'm trying to change the background of individual slots in my AC Objectives Menu. I've created a Custom Action which now can change the complete Background Texture of the Objective list (Inventory Box):

menuElement.backgroundTexture = (Texture2D) runtimeNewTexture;

But i can't figure out how to change the Background Texture of an indivudual slot like this:

Oh is it also possible to at a prefix number to a slot in the label? Like:

  1. Objective A
  2. Objective B
  3. etc

Thanks a bunch!

Kind regards

Daniël

Comments

  • edited January 5
    Sorry the images on Dropbox apparently don’t load:
    ![](https://ibb.co/wBmjWLW)
    ![](https://ibb.co/h9knwXc)
  • The per-slot texture of an Objectives list is based on the texture assigned in the Objective's properties in the Inventory Manager - it can't be set in the Menu Element itself like a regular background texture.

    What you'll need to do is have a separate Image component that gets displayed at the correct time (presumably, once an Objective is completed).

    First, make sure you're using Unity UI for the Menu's Source. You can then add your "scratch" image as a separate child object for each slot, and attach the following script to control its visibility:

    using UnityEngine;
    using UnityEngine.UI;
    using AC;
    
    public class ObjectiveScratch : MonoBehaviour
    {
    
        public string menuName = "Objectives";
        public string elementName = "ObjectivesList";
        public Image image;
        public int slotIndex;
        private MenuInventoryBox inventoryBox;
    
        public void Update ()
        {
            if (inventoryBox == null)
            {
                inventoryBox = PlayerMenus.GetElementWithName (menuName, elementName) as MenuInventoryBox;
                if (inventoryBox == null) return;
            }
    
            var objectiveInstance = inventoryBox.GetObjective (slotIndex);
            bool showImage = (objectiveInstance != null && objectiveInstance.CurrentState.stateType == ObjectiveStateType.Complete);
            image.enabled = showImage;
        }
    
    }
    

    (This runs in an Update loop which might not be the most efficient, but check that this all works first if you'd like to optimise it later.)

    is it also possible to at a prefix number to a slot in the label?

    Currently, you'd have to rely on a similar script to show a separate Text component that has the number added to it, but it's a good suggestion and I'll look into the possibility of adding an option for this officially.

  • edited January 6

    Hi Chris, thanks for your quick reply!

    Ah i was hoping to stick to the AC menu, i grew quite fond of them, i was using Unity UI first, but switched back to AC menu's recently.

    I will try out your script on a Unity UI menu, thanks!

    Last question on this Objectives subject: is it possible to show only Objectives from the 'Main' category? Like this:

  • Ah i was hoping to stick to the AC menu, i grew quite fond of them, i was using Unity UI first, but switched back to AC menu's recently.

    Yeah, AC menus are easier/quicker to work with, but UUI is generally necessary whenever custom work is needed. Generally speaking, I recommend AC for rapid-prototyping, and UUI for final design.

    is it possible to show only Objectives from the 'Main' category?

    You can filter them out from the "main" block by checking the main element's Limit by category? and unchecking the sub-Objective category/ies.

  • Hi Chris,

    You can filter them out from the "main" block by checking the main element's Limit by category? and unchecking the sub-Objective category/ies.

    Sorry i completely missed that checkbox o:)

    Generally speaking, I recommend AC for rapid-prototyping, and UUI for final design.

    Good to know, today i'll build the menu myself with Unity UI and try out your script.
    Thanks once again for your help and explanation :)

  • Your script works perfect! Is there an Event Listener for Objectives that can be used instead of Update?
  • Yes, there's an OnObjectiveUpdate custom event that is called when an Objective's state is changed.

    However, you shouldn't need this if Objectives are never updated while the Menu is open. If you only need it to update at the moment the Menu turns on, you should be able to update the UI in OnEnable.

  • Perfect! Thank you Chris
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.