Forum rules - please read before posting.

Number of menu elements...

Is there a way for me to do a check via an ActionList that would allow me to check whether there are a certain amount of visible elements in a Unity UI menu before deciding on what it should do next? (e.g. if there are less then 10 elements visible in that menu then run another ActionList).

I know there's an ActionList option that can check the number of slots but it doesn't quite do what I need it to do as it requires the element name and using something like an inventory with slots wouldn't work for this.

Comments

  • You can do this with a custom Action.

    For a specific Menu, you can get the number of visible elements with:

    AC.PlayerMenus.GetMenuWithName ("MyMenu").visibleElements.Count
    

    In an Action:

    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionCheckNumVisElements : ActionCheck
        {
    
            public string menuName;
            public int numElements;
    
            public override ActionCategory Category { get { return ActionCategory.Menu; } }
            public override string Title { get { return "Check num visible elements"; }}
    
    
            public override bool CheckCondition ()
            {
                return AC.PlayerMenus.GetMenuWithName(menuName).visibleElements.Count >= numElements;
            }
    
    
    #if UNITY_EDITOR
    
            public override void ShowGUI()
            {
                menuName = EditorGUILayout.TextField("Menu name:", menuName);
                numElements = EditorGUILayout.IntField("# of visible elements:", numElements);
            }
    
            #endif
    
        }
    
    }
    
  • Thanks Chris, this seems just what I need, but I need it to check if the amount of visible elements are less than a certain number, so how would I go about that?

  • Replace >= with <, or just use the "If condition is not met" output socket.

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.