25 lines
1.0 KiB
C#
25 lines
1.0 KiB
C#
using UnityEngine;
|
|
|
|
namespace Ashwild.Core
|
|
{
|
|
/// <summary>
|
|
/// Drop-in component that makes its GameObject survive scene loads. Add it in the editor to any
|
|
/// object that must persist — including third-party prefabs you'd rather not edit (the FishNet
|
|
/// NetworkManager, the Steam manager) — and in Awake it detaches to the scene root and marks
|
|
/// itself persistent (via <see cref="Persistence"/>).
|
|
///
|
|
/// It only handles persistence: duplicate handling stays the job of the object's own singleton
|
|
/// (its guard destroys the extra copy when a scene reloads). Runs very early so the object is
|
|
/// already a persistent root before the other components' Awake.
|
|
/// </summary>
|
|
[DefaultExecutionOrder(-10000)]
|
|
[DisallowMultipleComponent]
|
|
public class PersistentObject : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// Detaches to the root and persists across scene loads.
|
|
/// </summary>
|
|
private void Awake() => Persistence.Persist(gameObject);
|
|
}
|
|
}
|