using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityScene = UnityEngine.SceneManagement.Scene;
using UnitySceneManager = UnityEngine.SceneManagement.SceneManager;
namespace FishNet.Managing.Scened
{
public abstract class SceneProcessorBase : MonoBehaviour
{
#region Protected.
///
/// SceneManager for this processor.
///
protected SceneManager SceneManager;
///
/// Scene used to store objects while they are being moved from one scene to another.
///
protected Scene MovedObjectsScene;
///
/// Scene used to store objects queued for destruction but cannot be destroyed until the clientHost gets the despawn packet.
///
protected Scene DelayedDestroyScene;
///
/// Scene used as the active scene when the user does not specify which scene to set active and the scenemanager cannot determine one without error.
/// This is primarily used so scenes with incorrect or unexpected lighting are not set as the active scene given this may disrupt visuals.
///
protected Scene FallbackActiveScene;
#endregion
///
/// Initializes this script for use.
///
/// SceneManager which will be utilizing this class.
public virtual void Initialize(SceneManager manager)
{
SceneManager = manager;
}
///
/// Called when scene loading has begun.
///
public virtual void LoadStart(LoadQueueData queueData) { }
///
/// Called when scene loading has ended.
///
public virtual void LoadEnd(LoadQueueData queueData) { }
///
/// Called when scene unloading has begun within a load operation.
///
public virtual void UnloadStart(LoadQueueData queueData) { }
///
/// Called when scene unloading has ended within a load operation.
///
public virtual void UnloadEnd(LoadQueueData queueData) { }
///
/// Called when scene unloading has begun within an unload operation.
///
public virtual void UnloadStart(UnloadQueueData queueData) { }
///
/// Called when scene unloading has ended within an unload operation.
///
public virtual void UnloadEnd(UnloadQueueData queueData) { }
///
/// Begin loading a scene using an async method.
///
/// Scene name to load.
public abstract void BeginLoadAsync(string sceneName, LoadSceneParameters parameters);
///
/// Begin unloading a scene using an async method.
///
/// Scene name to unload.
public abstract void BeginUnloadAsync(Scene scene);
///
/// Returns if a scene load or unload percent is done.
///
///
public abstract bool IsPercentComplete();
///
/// Returns the progress on the current scene load or unload.
///
///
public abstract float GetPercentComplete();
///
/// Gets the scene last loaded by the processor.
///
/// This is called after IsPercentComplete returns true.
public virtual Scene GetLastLoadedScene() => default;
///
/// Adds a scene to loaded scenes.
///
/// Scene loaded.
public virtual void AddLoadedScene(Scene scene) { }
///
/// Returns scenes which were loaded during a load operation.
///
public abstract List GetLoadedScenes();
///
/// Activates scenes which were loaded.
///
public abstract void ActivateLoadedScenes();
///
/// Returns if all asynchronized tasks are considered IsDone.
///
///
public abstract IEnumerator AsyncsIsDone();
///
/// Returns the MovedObjectsScene.
///
///
public virtual Scene GetMovedObjectsScene()
{
//Create moved objects scene. It will probably be used eventually. If not, no harm either way.
if (string.IsNullOrEmpty(MovedObjectsScene.name))
MovedObjectsScene = FindOrCreateScene("MovedObjectsHolder");
return MovedObjectsScene;
}
///
/// Returns the DelayedDestroyScene.
///
///
public virtual Scene GetDelayedDestroyScene()
{
//Create moved objects scene. It will probably be used eventually. If not, no harm either way.
if (string.IsNullOrEmpty(DelayedDestroyScene.name))
DelayedDestroyScene = FindOrCreateScene("DelayedDestroy");
return DelayedDestroyScene;
}
///
/// Returns the FallbackActiveScene.
///
///
public virtual Scene GetFallbackActiveScene()
{
if (string.IsNullOrEmpty(FallbackActiveScene.name))
FallbackActiveScene = FindOrCreateScene("FallbackActiveScene");
return FallbackActiveScene;
}
///
/// Tries to find a scene by name and if it does not exist creates an empty scene of name.
///
/// Name of the scene to find or create.
///
public virtual Scene FindOrCreateScene(string name)
{
Scene result = UnitySceneManager.GetSceneByName(name);
if (!result.IsValid())
result = UnitySceneManager.CreateScene(name);
return result;
}
}
}