med-material / Whack_A_Mole_VR

Whack-A-Mole in VR
MIT License
3 stars 15 forks source link

LevelFaderScreen: Fade in the therapist UI too #198

Open bastianilso opened 1 year ago

bastianilso commented 1 year ago

LevelFaderScreen was introduced to add a fade-in between the black unity logo and our environment. There are some additional points we should address here:

lucasmnt commented 1 year ago

Here is an update for the fade effects and fading class :

At first I thought that we should have a "FaderManager" that would manage all the differents fades effects for different game objects (3D, 2D, Ui, images, Texts, Canvases...). This manager class would also manage the fading effect at launch after Unity's splash screen for the patient and for the therapist.

After doing that, it felt a bit off, so now the idea is to separate the launching fade effects for the splash screen, and the differents fading effects that could occur while playing in two different classes.

Right now there are two classes that you can find in the hierarchy Assets>Scripts>Game :

Here is what the FadingHelper script menu looks like when you add it as a component to a game object (also if you mouse over the differents parameters of the script, a tooltip should appear) :

Capture

bastianilso commented 1 year ago

Hi lucas, nice progress.

I think a FaderHelper class makes a lot of sense. We can attach this component many times onto many different objects, to make them fade.

I think this idea is important: That the object to fade is the object FaderHelper is attached to.

While technically it is possible to put any other object, i think our object hierarchy will be cleaner if we try to maintain this idea.

I think we can achieve a simpler look and simpler technical complexity if we just present a speed and delay once, and not one per object type.the same speed/delay can then be used across all code in FaderHelper. Afterall, if the paradigm is one FaderHelper per object, then most likely the object will only be of one type (3D, Image, ..). And for each instance of FaderHelper, there will be speed and delay. :)

We can discuss tomorrow.

-------- Original Message -------- On Sep 29, 2022, 10:59 AM, lucasmnt wrote:

Here is an update for the fade effects and fading class :

At first I thought that we should have a "FaderManager" that would manage all the differents fades effects for different game objects (3D, 2D, Ui, images, Texts, Canvases...). This manager class would also manage the fading effect at launch after Unity's splash screen for the patient and for the therapist.

After doing that, it felt a bit off, so now the idea is to separate the launching fade effects for the splash screen, and the differents fading effects that could occur while playing in two different classes.

Right now there are two classes that you can find in the hierarchy Assets>Scripts>Game :

  • First one is SplashScreenFading.cs. Its sole purpose is to manage fading effects after Unity's splash screen ;
  • Second one is FadingHelper.cs. Its purpose is to help managing the differents fading effects of 3D & 2D objects, Texts, Canvas Groups, Images. I expect this script to be use multiple times by adding it as a component to differents game objects that would need such fading effects. Right now it is possible to do a fade in, a fade out, and to modify the speed of said effects

Here what looks like the FadingHelper script menu when you add it as a component to a game object (also if you mouse over the differents parameters of the script, a tooltip should appear) :

Capture

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

lucasmnt commented 1 year ago

New update about FaderHelper.cs :

image

As you can see the interface of the script has changed and is now simplified. The option of adding delay have also been added. I keept fade-in and fade-out speed parameters so it can be easily changed on the run.

With this class, you can either do a fade in effect, a fade out effect, or do both with a delay between the two effects for five kind of objects. To be more accurate we can take any game object that has a Text, a Canvas Group, a Mesh Renderer, a Sprite Renderer, or an Image as a component.

The script will try to find at start which of these 5 components is present in a game object then it will be able to call the correct coroutine to do the fade effect depending on the component that has been indentified.

To use this script you have to add it as a component in the game object you want to fade, then drag and drop the game object you want to fade here :

image

I also want to mention that there might be a problem if there are multiple compatible components in the same game object, but I made sure that when the first compatible component is found (i.e Text, CanvasGroup, MeshRenderer, SpriteRenderer, Image) it stops looking for other compatible components. So to work around this, we just have to put the component we are interested in fading first in the hierarchy of the inspector.

Here is an example :

image

Here, it is the first component "Text" that will be saved has the component to use. The sprite renderer wont be used. If we wanted to fade the sprite renderer instead of the text, we would just put the sprite renderer on top of the text in the hierachy.

bastianilso commented 1 year ago

Hi @lucasmnt looks good!

lucasmnt commented 1 year ago

After modifications, here what the updated UI looks like :

image

I kept the name objToFade for the variable since all my other parameters in the script are build like that : "[typeOfTheObject]ToFade"

I have created another function that when called, will look at the new variable "action" visible on the bottom of the new UI (that will allow us to specify if we want fade in/out or both) and will call the corresponding "action" corresponding to our need. See from the code perspective :

image

bastianilso commented 1 year ago

@lucasmnt ah, okay, thanks for taking a look.

I think it's a good idea that fades can be controlled via public functions from code. However, it could also save us code in many cases, if Fading Helper could automatically fade via a call from Start(). Start() is a special Unity function called whenever a GameObject is enabled - and in many cases when a GameObject is enabled, it makes sense to "fade in" the object visually. This could be e.g. controlled via a UI boolean playAutomatically - if this boolean is off, then FadingHelper will wait with fading until its public functions are explicitly called from code. This boolean works a bit like the boolean you also see in Unity's built-in Animation component.

Minor comments:

bastianilso commented 1 year ago

@lucasmnt

https://github.com/med-material/Whack_A_Mole_VR/blob/master/Assets/LoggingManager/LoggingManager.cs#L367

https://github.com/med-material/Whack_A_Mole_VR/blob/master/Assets/LoggingManager/WriteToCSV.cs#L57