Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GameLoader : MonoBehaviour//, IHostable, ILateInitializable
- {
- /// <summary>
- /// Determines the conditions when a load should be attempted from the drive / server. If Not Yet Attempted is default
- /// </summary>
- public LoadDataOptions loadDataWhen = LoadDataOptions.LoadNotYetAttempted;
- /// <summary>
- /// Determines if LateInitialize should be declared
- /// </summary>
- public bool lateInitialization = true;
- /// <summary>
- /// Determines whether or not this class can host initialization, late initialization, save/load and other ProSaver operations. True by default.
- /// </summary>
- public bool CanHost { get; set; } = true;
- /// <summary>
- /// Subscribes to when initialiation finished with a function that loads data and/or starts late initialization depending on settings.
- /// </summary>
- public virtual void Awake()
- {
- if(CanHost)
- if(ProSaver.CoroutineHost == null)
- ProSaver.CoroutineHost = this;
- ProSaver.WhenInitializationFinished += PrepLoadAndLateLoad;
- }
- private void PrepLoadAndLateLoad()
- {
- ProSaver.WhenInitializationFinished -= PrepLoadAndLateLoad;
- switch(loadDataWhen)
- {
- case LoadDataOptions.Never:
- if(lateInitialization)
- ProSaver.StartLateInitializationNow();
- else
- ProSaver.FinishScenePrepNow();
- return;
- case LoadDataOptions.Always:
- if(lateInitialization)
- ProSaver.StartLateInitializationAfterLoad();
- else
- ProSaver.SkipLateInitializationAfterLoad();
- ProSaver.LoadGame();
- return;
- case LoadDataOptions.LoadNotYetAttempted:
- if(ProSaver.LoadAttempted)
- {
- if(lateInitialization)
- ProSaver.StartLateInitializationNow();
- else
- ProSaver.FinishScenePrepNow();
- }
- else
- {
- if(lateInitialization)
- ProSaver.StartLateInitializationAfterLoad();
- else
- ProSaver.SkipLateInitializationAfterLoad();
- ProSaver.LoadGame();
- }
- return;
- case LoadDataOptions.LoadNotYetSuccessful:
- if(ProSaver.LoadSuccessful)
- {
- if(lateInitialization)
- ProSaver.StartLateInitializationNow();
- else
- ProSaver.FinishScenePrepNow();
- }
- else
- {
- if(lateInitialization)
- ProSaver.StartLateInitializationAfterLoad();
- else
- ProSaver.SkipLateInitializationAfterLoad();
- ProSaver.LoadGame();
- }
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement