call up a menu at any time by right-clicking

All about user interface, be it customizing built-in UIs or adding new ones.
Post Reply
KK2M
Posts: 6
Joined: 06 Jul 2021 08:06

call up a menu at any time by right-clicking

Post by KK2M »

During the game, I want the player to call up a menu at any time by right-clicking on the screen,and to pause the text printer.
Also, I realize that a pauseUI has been created in the plugin. How do I get the player to call it in the game

thanks

idaot
support
Posts: 262
Joined: 01 Aug 2020 08:25

Re: call up a menu at any time by right-clicking

Post by idaot »

You can add your own custom input binding through a simple bit of C# scripting. You can use the listener scripts showcased in the Inventory Example project (https://github.com/Naninovel/Inventory/ ... UI.cs#L215) as the basis for this.

I also recommend checking out Engine Services, specifically IUIManager which contains publicly available methods for calling UI's in C#. https://naninovel.com/guide/engine-serv ... e-services

KK2M
Posts: 6
Joined: 06 Jul 2021 08:06

Re: call up a menu at any time by right-clicking

Post by KK2M »

idaot wrote: 07 Jul 2021 18:43

You can add your own custom input binding through a simple bit of C# scripting. You can use the listener scripts showcased in the Inventory Example project (https://github.com/Naninovel/Inventory/ ... UI.cs#L215) as the basis for this and when done correctly, the new binding will show up under Naninovel's input configuration which you can bind to several inputs.

I also recommend checking out Engine Services, specifically IUIManager which contains publicly available methods for calling UI's in C#. https://naninovel.com/guide/engine-serv ... e-services

Oh!I've learned :D

fyrrion
Posts: 11
Joined: 02 Aug 2020 16:25

Re: call up a menu at any time by right-clicking

Post by fyrrion »

idaot wrote: 07 Jul 2021 18:43

You can add your own custom input binding through a simple bit of C# scripting. You can use the listener scripts showcased in the Inventory Example project (https://github.com/Naninovel/Inventory/ ... UI.cs#L215) as the basis for this and when done correctly, the new binding will show up under Naninovel's input configuration which you can bind to several inputs.

I also recommend checking out Engine Services, specifically IUIManager which contains publicly available methods for calling UI's in C#. https://naninovel.com/guide/engine-serv ... e-services

Is there no easier option to implement this? This is such a basic and elementary functionality for the convenience of players, which is needed in almost any novel. It's sad if you have to bother so much technically for such a simple function.: (

idaot
support
Posts: 262
Joined: 01 Aug 2020 08:25

Re: call up a menu at any time by right-clicking

Post by idaot »

fyrrion wrote: 12 Jul 2021 15:29
idaot wrote: 07 Jul 2021 18:43

You can add your own custom input binding through a simple bit of C# scripting. You can use the listener scripts showcased in the Inventory Example project (https://github.com/Naninovel/Inventory/ ... UI.cs#L215) as the basis for this and when done correctly, the new binding will show up under Naninovel's input configuration which you can bind to several inputs.

I also recommend checking out Engine Services, specifically IUIManager which contains publicly available methods for calling UI's in C#. https://naninovel.com/guide/engine-serv ... e-services

Is there no easier option to implement this? This is such a basic and elementary functionality for the convenience of players, which is needed in almost any novel. It's sad if you have to bother so much technically for such a simple function.: (

As far as C# is concerned, this is very simple. I highly recommend learning a bit of C# as the engine services provided with Naninovel will open up a lot of possibilities.

Here's a code that can be attached to a custom UI. Make sure to create a sampler within Input Configuration that corresponds with the string given in GetSampler.

Code: Select all

using UnityEngine;
using Naninovel;
using Naninovel.UI;

public class CallUIInput : CustomUI
{

private IInputManager inputManager;

protected override void Awake()
{
    base.Awake(); // make sure the required objects are assigned in the inspector
    inputManager = Engine.GetService<IInputManager>();

}

protected override void OnEnable()
{
    base.OnEnable();

    // Start listening for `ToggleInventory` input event to toggle UI's visibility.
    var toggleSampler = inputManager.GetSampler("ToggleSamplerUI");
    if (toggleSampler != null)
        toggleSampler.OnStart += ToggleVisibility;
}

protected override void OnDisable()
{
    base.OnDisable();

    // Stop listening for `ToggleInventory` input event.
    var toggleSampler = inputManager?.GetSampler("ToggleSamplerUI");
    if (toggleSampler != null)
        toggleSampler.OnStart -= ToggleVisibility;
}
}
Post Reply