51 lines
1.0 KiB
C#
51 lines
1.0 KiB
C#
using Crosstales.Radio.Util;
|
|
using UnityEngine;
|
|
|
|
namespace Crosstales.Radio.Tool
|
|
{
|
|
[HelpURLAttribute("https://www.crosstales.com/media/data/assets/radio/api/class_crosstales_1_1_radio_1_1_tool_1_1_survive_scene_switch.html")]
|
|
[DisallowMultipleComponent]
|
|
public class SurviveSceneSwitch : MonoBehaviour
|
|
{
|
|
public GameObject[] Survivors;
|
|
|
|
private Transform tf;
|
|
|
|
private const float ensureParentTime = 1.5f;
|
|
|
|
private float ensureParentTimer;
|
|
|
|
public void Awake()
|
|
{
|
|
tf = base.transform;
|
|
Object.DontDestroyOnLoad(tf.root.gameObject);
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
ensureParentTimer = 1.5f;
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
ensureParentTimer += Time.deltaTime;
|
|
if (Survivors != null && ensureParentTimer > 1.5f)
|
|
{
|
|
ensureParentTimer = 0f;
|
|
GameObject[] survivors = Survivors;
|
|
foreach (GameObject gameObject in survivors)
|
|
{
|
|
if (gameObject != null)
|
|
{
|
|
gameObject.transform.SetParent(tf);
|
|
}
|
|
}
|
|
}
|
|
if (Helper.isEditorMode)
|
|
{
|
|
base.name = "SurviveSceneSwitch";
|
|
}
|
|
}
|
|
}
|
|
}
|