Files
DuckovMods/SceneSnapshot/ModBehaviour.cs
2025-11-01 15:18:34 +08:00

40 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Reflection;
using UnityEngine;
namespace SceneSnapshot
{
public class ModBehaviour : Duckov.Modding.ModBehaviour
{
protected override void OnAfterSetup()
{
AddPrintToolToScene();
}
protected override void OnBeforeDeactivate()
{
RemovePrintToolFromScene();
}
/// <summary>
/// 检查场景中是否已存在PrintTool如果不存在则添加一个新的。
/// </summary>
private void AddPrintToolToScene()
{
if (GameObject.FindObjectOfType<PrintTool>() == null)
{
var printToolGO = new GameObject("PrintTool_Monitor");
printToolGO.transform.SetParent(this.transform);
printToolGO.AddComponent<PrintTool>();
}
}
private void RemovePrintToolFromScene()
{
var printTool = GameObject.FindObjectOfType<PrintTool>();
if (printTool != null)
{
GameObject.Destroy(printTool.gameObject);
}
}
}
}