snozbot / fungus

An easy to use Unity 3D library for creating illustrated Interactive Fiction games and more.
MIT License
1.59k stars 291 forks source link

[WIP] Add toggle to run Fungus on unscaled time. #1054

Closed esklarski closed 2 years ago

esklarski commented 2 years ago

Description

These changes enable Fungus to run while Time.timeScale == 0.

What is the current behavior?

If Time.timeScale is set to 0 Fungus is paused and uninteractable

What is the new behavior?

I made these changes, sans switch, for a project where I used Fungus for all the menus. I needed to pause 3d gameplay but have a character come up to act as the pause screen menu.

Behaviour Now:

Important Notes

Other information

Still a work in progress:

breadnone commented 2 years ago

Proly wrap it as extension instead of hard coding it? this way you won't pollute Fungus with bunch of If-elses

esklarski commented 2 years ago

I'm not sure extension methods can do all that this needs.

I'm more wondering, if there is any reason to pause Fungus? The simplest would be to eliminate all of the if/else logics and just run Fungus on unscaled time always.

breadnone commented 2 years ago

That would introduce breaking change, lots of users pausing their games with it

The idea is to keep the current behavior as the default (scaled time), then the other as an option which can be changed by the users themselves if they prefer to

esklarski commented 2 years ago

Well that's why the effort. I hard coded it for my purposes, and didn't need to make a toggle.

esklarski commented 2 years ago

Demo scene added.

esklarski commented 2 years ago

I've done a bit more research and I can clean this up substantively.

Putting a YieldInstruction function like: public static YieldInstruction WaitForAdjustedSeconds(float seconds) => useUnscaledTime ? new WaitForSecondsRealtime(seconds) : new WaitForSeconds(seconds); allows all of the if/else logic to be removed, with scripts only needing to call this one function instead of having a second wait function each and supporting logic: yield return FungusManager.WaitForAdjustedSeconds(value);

It'll be a few days before I can cleanup the commit tree here.