feat: 场景快照和隐藏角色
This commit is contained in:
39
SceneSnapshot/ModBehaviour.cs
Normal file
39
SceneSnapshot/ModBehaviour.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user