How to attach a Rollback function to a UI button?
Posted: 27 Jun 2022 08:36
by Daarg
Hello!
How do I do this? I've used all of the functions like Auto, Skip, etc from the control panel attached to the dialogue (or any other) printer with my customized UI buttons. But now I need a button that makes a one-step-back rewind just as when you scroll a mouse wheel up. I know how to setup Input to call a Rollback form a keyboard or a joystick. But right now I need the function to start by pressing a UI button. Is there a way to do it?
Re: How to attach a Rollback function to a UI button?
Posted: 27 Jun 2022 09:23
by idaot
You can use RollbackAsync via IStateManager, however you need to specify a suitable playback spot to rollback to; eg, to rollback to the previous spot which allows player rollback (similar to what happens when activating rollback input), use:
Code: Select all
stateManager.RollbackAsync(s => s.PlayerRollbackAllowed);
Re: How to attach a Rollback function to a UI button?
Posted: 28 Jun 2022 07:41
by Daarg
Thank you very much! I took one of the functions as an example and created the following function:
namespace Naninovel.UI
{
public class ButtonRollback : ScriptableButton
{
private IStateManager stateManager;
Code: Select all
protected override void Awake ()
{
base.Awake();
stateManager = Engine.GetService<IStateManager>();
}
protected override void OnButtonClick () => RollbackAsync();
private async void RollbackAsync ()
{
UIComponent.interactable = false;
await stateManager.RollbackAsync(s => s.PlayerRollbackAllowed);
UIComponent.interactable = true;
}
}
}
Then I just dragged this function to my UI button. Works great!