UILoadingScreen - jimdroberts/FishMMO GitHub Wiki
The UILoadingScreen
class is a UI control for the FishMMO client that manages the loading screen during scene transitions and network operations. It displays a progress bar, background image, and responds to scene and reconnect events to show or hide the loading screen as needed. It also updates the loading image based on the current scene and provides feedback during reconnect attempts.
-
public Slider LoadingProgress
The slider UI element representing the loading progress.
-
public Image LoadingImage
The image UI element for the loading screen background.
-
public WorldSceneDetailsCache Details
Cache containing details for world scenes, including transition images.
-
public Sprite DefaultLoadingScreenSprite
The default sprite to use for the loading screen.
-
public override void OnStarting()
Subscribes to progress updates and sets the default loading image.
-
public override void OnDestroying()
Unsubscribes from progress updates.
-
public override void OnClientSet()
Subscribes to scene and reconnect events.
-
public override void OnClientUnset()
Unsubscribes from scene and reconnect events.
-
public void OnProgressUpdate(float progress)
Updates the loading progress bar and shows/hides the screen based on progress.
-
public override void Show()
Shows the loading screen and resets the progress bar.
-
public void Client_OnReconnectAttempt(byte attempts, byte maxAttempts)
Resets the loading image and shows the screen during reconnect attempts.
-
public void Client_OnReconnectFailed()
Hides the loading screen on reconnect failure.
-
private void OnSceneStartLoad(SceneLoadStartEventArgs startEvent)
Updates the loading image based on scene details when a scene starts loading.
-
private void OnSceneProgressUpdate(SceneLoadPercentEventArgs percentEvent)
Updates the loading progress bar during scene load progress.
-
private void OnSceneEndLoad(SceneLoadEndEventArgs endEvent)
Hides the loading screen when a scene finishes loading.
-
private void OnSceneStartUnload(SceneUnloadStartEventArgs startEvent)
Resets the loading image and shows the screen when a scene starts unloading.
-
private void OnSceneEndUnload(SceneUnloadEndEventArgs endEvent)
Handles scene unload end (no implementation by default).
- Attach
UILoadingScreen
to a UI panel in your scene. - Assign all required UI references (slider, image, etc.) in the inspector.
- Call
OnStarting()
andOnClientSet()
to initialize event handlers. - The loading screen will automatically show/hide and update progress during scene transitions and reconnects.
// On UI start:
uiLoadingScreen.OnStarting();
// On client ready:
uiLoadingScreen.OnClientSet();
// On client disconnect or scene change:
uiLoadingScreen.OnClientUnset();
- Always clean up event subscriptions in
OnDestroying
andOnClientUnset
to avoid memory leaks. - Use the loading image and progress bar to provide clear feedback during long operations.
- Update the loading image based on the current scene for a more immersive experience.
- Use the reconnect event handlers to provide feedback during network interruptions.
- Customize the loading screen appearance using the configuration and scene details cache.