using FishNet.Object;
using FishNet.Serializing.Helping;
using System.Collections.Generic;
using System.IO;
using UnityEngine.SceneManagement;
namespace FishNet.Managing.Scened
{
///
/// Data about which scenes to load.
///
public class SceneLoadData
{
///
/// When specified this scene will be set as the active scene after loading occurs.
///
public SceneLookupData PreferredActiveScene = null;
///
/// SceneLookupData for each scene to load.
///
public SceneLookupData[] SceneLookupDatas = new SceneLookupData[0];
///
/// NetworkObjects to move to the new scenes. Objects will be moved to the first scene.
///
public NetworkObject[] MovedNetworkObjects = new NetworkObject[0];
///
/// How to replace current scenes with new ones. When replacing scenes the first scene loaded will be set as the active scene, and the rest additive.
///
public ReplaceOption ReplaceScenes = ReplaceOption.None;
///
/// Parameters which may be set and will be included in load callbacks.
///
public LoadParams Params = new LoadParams();
///
/// Additional options to use for loaded scenes.
///
public LoadOptions Options = new LoadOptions();
public SceneLoadData() { }
///
///
///
/// Scene to load.
public SceneLoadData(Scene scene) : this(new Scene[] { scene }, null) { }
///
///
///
/// Scene to load by name.
public SceneLoadData(string sceneName) : this(new string[] { sceneName }, null) { }
///
///
///
/// Scene to load by handle.
public SceneLoadData(int sceneHandle) : this(new int[] { sceneHandle }, null) { }
///
///
///
/// Scene to load by handle.
/// Scene to load by name.
public SceneLoadData(int sceneHandle, string sceneName) : this(new SceneLookupData(sceneHandle, sceneName)) { }
///
///
///
/// Scene to load by SceneLookupData.
public SceneLoadData(SceneLookupData sceneLookupData) : this(new SceneLookupData[] { sceneLookupData }) { }
///
///
///
/// Scenes to load.
public SceneLoadData(List scenes) : this(scenes.ToArray(), null) { }
///
///
///
/// Scenes to load by name.
public SceneLoadData(List sceneNames) : this(sceneNames.ToArray(), null) { }
///
///
///
/// Scenes to load by handle.
public SceneLoadData(List sceneHandles) : this(sceneHandles.ToArray(), null) { }
///
///
///
/// Scenes to load.
public SceneLoadData(Scene[] scenes) : this(scenes, null) { }
///
///
///
/// Scenes to load by name.
public SceneLoadData(string[] sceneNames) : this(sceneNames, null) { }
///
///
///
/// Scenes to load by handle.
public SceneLoadData(int[] sceneHandles) : this(sceneHandles, null) { }
///
///
///
/// Scenes to load by SceneLookupDatas.
public SceneLoadData(SceneLookupData[] sceneLookupDatas) : this(sceneLookupDatas, null) { }
///
///
///
/// Scene to load.
/// NetworkObjects to move to the first specified scene.
public SceneLoadData(Scene scene, NetworkObject[] movedNetworkObjects)
{
SceneLookupData data = SceneLookupData.CreateData(scene);
Construct(new SceneLookupData[] { data }, movedNetworkObjects);
}
///
///
///
/// Scenes to load.
/// NetworkObjects to move to the first specified scene.
public SceneLoadData(Scene[] scenes, NetworkObject[] movedNetworkObjects)
{
SceneLookupData[] datas = SceneLookupData.CreateData(scenes);
Construct(datas, movedNetworkObjects);
}
///
///
///
/// Scenes to load by Name.
/// NetworkObjects to move to the first specified scene.
public SceneLoadData(string[] sceneNames, NetworkObject[] movedNetworkObjects)
{
SceneLookupData[] datas = SceneLookupData.CreateData(sceneNames);
Construct(datas, movedNetworkObjects);
}
///
///
///
/// Scenes to load by handle.
/// NetworkObjects to move to the first specified scene.
public SceneLoadData(int[] sceneHandles, NetworkObject[] movedNetworkObjects)
{
SceneLookupData[] datas = SceneLookupData.CreateData(sceneHandles);
Construct(datas, movedNetworkObjects);
}
///
///
///
/// Scenes to load by SceneLookupDatas.
/// NetworkObjects to move to the first specified scene.
public SceneLoadData(SceneLookupData[] sceneLookupDatas, NetworkObject[] movedNetworkObjects)
{
Construct(sceneLookupDatas, movedNetworkObjects);
}
///
/// Called at the end of every constructor.
///
private void Construct(SceneLookupData[] datas, NetworkObject[] movedNetworkObjects)
{
SceneLookupDatas = datas;
if (movedNetworkObjects == null)
movedNetworkObjects = new NetworkObject[0];
MovedNetworkObjects = movedNetworkObjects;
}
///
/// Gets the first Scene in SceneLookupDatas.
///
///
public Scene GetFirstLookupScene()
{
foreach (SceneLookupData sld in SceneLookupDatas)
{
Scene result = sld.GetScene(out _);
if (!string.IsNullOrEmpty(result.name))
return result;
}
return default;
}
///
/// Returns if any data is invalid, such as null entries.
///
///
internal bool DataInvalid()
{
//Null values.
if (Params == null || MovedNetworkObjects == null || SceneLookupDatas == null ||
Options == null)
return true;
//No lookups.
if (SceneLookupDatas.Length == 0)
return true;
return false;
}
}
}