Forum rules - please read before posting.

Custom Unity UI control

I recently try to make custom looking menus following this tutorial:
https://adventurecreator.org/tutorials/creating-inventory-bar-unity-ui

It is great and informative, and I created the menu appearance. But I am not able to control it. I am using direct control and don't want to use the mouse. I can control the default Inventory Menu by keyboard direction key and Interaction A; but when the custom Inventory Menu is open, I cannot do anything with it.

Then I realize if I change the default Inventory Menu source to Unity Prefab, it also cannot be controlled. How may I solve this?

Thank you.
«1

Comments

  • You need to define an element to select first in the Menu Manager, and - if the Menu does not pause the game - allow direct-navigation during gameplay using the Engine: Manage systems Action.

    Full details can be found in the "Navigating menus directly" chapter of the Manual.
  • I think I have done everything in the "Navigating menus directly" chapter

    I checked the Auto-select first visible element and Pause game when enable, and also put an action list in ActionList when turn on that Enable Control in-game Menus. It works well when the source is set to AC, but cannot work when using Unity Ui Prefab.

    Then when using source Unity UI Prefab, if I add to the action list an action of Menu: Select element, with the Menu containing element = Inventory, and the Element to select = ShiftLeft or InventoryBox, then it gives an error:

    NullReferenceException: Object reference not set to an instance of an object
    AC.PlayerMenus+<SelectUIElementCoroutine>c__Iterator2.MoveNext () (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2751)
    UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    AC.PlayerMenus:SelectUIElement(GameObject) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2745)
    AC.Menu:Select(String, Int32) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:2401)
    AC.ActionMenuSelect:Run() (at Assets/AdventureCreator/Scripts/Actions/ActionMenuSelect.cs:63)
    AC.<RunAction>c__Iterator2:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:342)
    UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
    AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:306)
    AC.ActionList:ProcessActionEnd(ActionEnd, Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:522)
    AC.ActionList:EndAction(Action) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:435)
    AC.<RunAction>c__Iterator2:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:404)
    UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
    AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:306)
    AC.ActionList:ProcessActionEnd(ActionEnd, Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:517)
    AC.ActionList:EndAction(Action) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:435)
    AC.<RunAction>c__Iterator2:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:404)
    UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
    AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:306)
    AC.RuntimeActionList:BeginActionList(Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/RuntimeActionList.cs:116)
    AC.ActionList:Interact(Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:185)
    AC.RuntimeActionList:DownloadActions(ActionListAsset, Conversation, Int32, Boolean, Boolean, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/RuntimeActionList.cs:105)
    AC.AdvGame:RunActionListAsset(ActionListAsset, Conversation, Int32, Boolean, Boolean) (at Assets/AdventureCreator/Scripts/Static/AdvGame.cs:299)
    AC.AdvGame:RunActionListAsset(ActionListAsset, Int32, Int32) (at Assets/AdventureCreator/Scripts/Static/AdvGame.cs:179)
    AC.Menu:TurnOn(Boolean) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:1746)
    AC.PlayerMenus:UpdateMenu(Menu, Int32, Boolean, Boolean) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1144)
    AC.PlayerMenus:UpdateAllMenus() (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1987)
    AC.StateHandler:Update() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:334)

    I am using AC v1.61.2

    Thanks for your help
  • When are you running the ActionList?  If you've already checked the Auto-select first visible element? it should not be necessary - only if you want it to change based on a previous menu option (e.g. When entering "Pause" from "Options", you want the "Options" button in the Pause menu to be auto-selected).

    Have you defined an Event system prefab in your Menu Manager?  If not, make sure there is none in your scene file, as AC will create one automatically.

    If the menu is paused, there'll be no need for any Engine: Manage systems Action - just that Directly-navigate Menus when paused? is checked at the top of the Menu Manager.

    Try loading in the Demo_MenuManager asset file.  Switch the Pause Menu's Source to Unity Ui Prefab (a UI Canvas will already be assigned to it), and check Auto-select first visible element?.  Can that be directly-navigated when opened by pressing Escape?
  • edited April 2018
    After updating to v1.62.2, I can see the selected element's graphic is darken. (or maybe it also worked before but I didn't notice..)

    But I dunno how to change the selected element's display method, such as having a green background texture (like the default AC Inventory display method), or display the Active Graphic of the item. Can you point me to the right direction?

    Thanks for the help
  • The active effects are handled in the UI's Button component - there you can set the transition effects when selected.  That's a Unity workflow - not one specific to AC.

    Having the active graphic show should just be a case of defining one in the item's properties in the Inventory Manager, and checking Show Active FX when Cursor hovers over Item in Menu? in the Settings Manager.
  • edited April 2018
    Thanks. Now I understand how it works for the Inventory display style.

    Then I begun to customize the Subtitle menu. What I did are:
    1. Created a Panel.
    2. Created a Text as a child of the Panel.
    3. Added a Horizontal Layout Group & a Content Size Fitter to the Panel. All the Content Size Fitter options are set to Preferred Size.
    4. Added a Content Size Fitter to the Text. All the Content Size Fitter options are set to Preferred Size.

    After linking the Canvas, Panel and Text in the Subtitle Menu, the subtitle text can be display in the UI elements I created.

    However, both the Panel and Text are initialized with 0 size and expanded when the subtitle words roll out. I wish to have the Panel and the Text initialized to have the size of the finished subtitle, just like the default Adventure Creator Subtitle menu. How may I achieve that?
  • In future, please post unrelated questions in new threads so that others with similar issues can more easily find them.

    The default AC menu doesn't have the correct size to begin with - it's just large enough to accommodate it.  What you're looking for isn't something that AC does.

    What you could try, however, is creating a "dummy" Text component that displays the same speech text instantly (no scrolling), only with an invisible colour.  That would also be a child of the Panel, and therefore expand it to the correct size.

    You'd then just need a simple script that updates the Text component with the currently-spoken speech text.  This can be done by hooking into the OnStartSpeech custom event:

    http://pasteall.org/925786/csharp

    Paste that in a new C# script named UpdateDummyText.cs, attach it to your Text component and fill in the field.

  • edited April 2018
    Thanks. It works except that for the first dialog in any Interaction Lists, the DummyText does not update accordingly, and stays the same as before. This gives a wrong panel size as it has the size of the last dialog before the Interaction List starts.

    This can be solved by removing the line:
    EventManager.OnStartSpeech -= GetSpeech;

    But would this cause problems in the long run such as memory leak?
  • I don't think it'd be anything to worry about.
  • edited April 2018
    I just found an issue that if I checked the Duplicate for each line? option, the DummyText doesn't get updated by the script anymore. Can you please help me on this one?
  • If you're duplicating the menu, yes - it'll need a different script.

    The necessary script will also require some tweaks made to AC itself - please bump this thread when the next update is out, and I'll see about giving you such a script.
  • I see. Thanks in advance
  • edited April 2018
    Hi, thanks for the new update. May I ask is the recent v1.62.5 able to handle the above issue?
  • edited April 2018
    Thanks. But when I pasted the code an error says 'AC.PlayerMenus' does not contain a definition for 'GetMenuWithCanvas'...very strange. I am pretty sure I imported v1.62.5 (although when I check check on update it still says I need to update, which is another strange issue but I don't if it matters)
  • Your version number is listed at the bottom of each Manager tab.

    The GetMenuWithCanvas method should be in PlayerMenus.cs, around line 2761.
  • My bad for the mistake, now the version is correctly updated.

    But there is a Null Reference exception on line 15: Speech speech = menu.speech;. It seems it cannot find the speech menu.
  • Should've mentioned - you need to put this on the root Canvas object, not where the Text component is.  The "Dummy Text Box" field will then need to be assigned in the Inspector.
  • edited May 2018
    I think I have attached the script to the root canvas (as shown in the image), but the exception still persist:
  • Are you removing the Canvas from the scene before runtime (so that it is spawned in by the Menu Manager)?
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.