47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
using System.Collections;
|
||
using Convention;
|
||
using UnityEngine;
|
||
|
||
namespace Demo.Game
|
||
{
|
||
public abstract class IJudgementHookObject : ScriptableObject, IHookInteraction
|
||
{
|
||
|
||
[Content, SerializeField] private IInteraction MyInteractionModule;
|
||
|
||
public abstract void OnJudgement(int level);
|
||
|
||
public override IEnumerator LoadScript(string script)
|
||
{
|
||
yield return base.LoadScript(script);
|
||
if (MyInteractionModule == null)
|
||
MyInteractionModule = Parent.GetComponent<IInteraction>();
|
||
MyInteractionModule.JudgementEvent.AddListener(OnJudgement);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 绑定IInteraction对象,若不手动绑定则会自动绑定到父物体的IInteraction
|
||
/// </summary>
|
||
/// <param name="path"></param>
|
||
[ScriptableCall(@"
|
||
<summary>
|
||
绑定IInteraction对象,若不手动绑定则会自动绑定到父物体的IInteraction
|
||
</summary>
|
||
")]
|
||
public void Bind(string path)
|
||
{
|
||
MyInteractionModule = FindWithPath(path) as IInteraction;
|
||
}
|
||
|
||
public override IEnumerator UnloadScript()
|
||
{
|
||
// 如果是父物体那么在此处执行前就会重新生成对应的event
|
||
// 但通过绑定得到的其他物体并不能保证顺序关系
|
||
// 因此此处仍需要对象自行清理
|
||
MyInteractionModule.JudgementEvent.RemoveListener(OnJudgement);
|
||
MyInteractionModule = null;
|
||
yield return base.UnloadScript();
|
||
}
|
||
}
|
||
}
|