using System;
using ExtensibleSaveFormat;
using KKAPI.Utilities;
using Studio;
using UnityEngine;
namespace KKAPI.Studio.SaveLoad
{
///
/// Base type for custom scene/studio extensions.
/// It provides many useful methods that abstract away the nasty hooks needed to figure out when
/// a scene is loaded or imported, or how to save and load your custom data to the scene file.
///
/// This controller is a MonoBehaviour that is created upon registration in .
/// The controller is created only once. If it's created too late it might miss some scene load events.
/// It's recommended to register controllers in your Start method.
///
public abstract class SceneCustomFunctionController : MonoBehaviour
{
///
/// Fired when a scene is successfully changed, either by loading, importing or resetting.
///
/// Operation that caused this event
/// A dictionary of items loaded by this operation and their original IDs.
/// The IDs are identical to the IDs at the time of saving the scene, even during import.
/// Warning: The IDs here might not be the same as IDs of the objects in the scene!
/// To get current scene ID of the object call
protected internal abstract void OnSceneLoad(SceneOperationKind operation, ReadOnlyDictionary loadedItems);
///
/// Fired when a scene is about to be saved and any exteneded data needs to be written.
///
protected internal abstract void OnSceneSave();
///
/// Fired when objects are copied.
///
/// A dictionary of items loaded by this operation and their original IDs.
/// The IDs match the original object in the scene.
/// To get current scene ID of the object call
protected internal virtual void OnObjectsCopied(ReadOnlyDictionary copiedItems) { }
///
/// ID used for extended data by this controller. It's set when registering the controller
/// with
///
public string ExtendedDataId { get; internal set; }
///
/// Get extended data of the last loaded scene by using the ID you specified when registering this controller.
///
public PluginData GetExtendedData()
{
if (ExtendedDataId == null) throw new ArgumentException(nameof(ExtendedDataId));
return ExtendedSave.GetSceneExtendedDataById(ExtendedDataId);
}
///
/// Save your custom data to the scene under the ID you specified when registering this controller.
///
/// Your custom data to be written to the scene. Can be null to remove the data.
public void SetExtendedData(PluginData data)
{
if (ExtendedDataId == null) throw new ArgumentException(nameof(ExtendedDataId));
ExtendedSave.SetSceneExtendedDataById(ExtendedDataId, data);
}
///
/// Get the instance of the Studio game manager object.
///
public global::Studio.Studio GetStudio() => global::Studio.Studio.Instance;
}
}