72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
using System.Collections;
|
||
using System.IO;
|
||
using Convention;
|
||
using UnityEngine;
|
||
|
||
namespace Demo.Game
|
||
{
|
||
namespace ConfigType
|
||
{
|
||
// IJudgementHookObject 配置(抽象基类Config)
|
||
public class IJudgementHookObjectConfig : ScriptLoadableConfig
|
||
{
|
||
public override void Deserialize(BinaryReader reader)
|
||
{
|
||
base.Deserialize(reader);
|
||
}
|
||
|
||
public override void Serialize(BinaryWriter writer)
|
||
{
|
||
base.Serialize(writer);
|
||
}
|
||
}
|
||
}
|
||
|
||
public abstract class IJudgementHookObject : ScriptableObject, IHookInteraction
|
||
{
|
||
|
||
[Content, SerializeField] private IInteraction m_MyInteractionModule;
|
||
private IInteraction MyInteractionModule
|
||
{
|
||
get
|
||
{
|
||
if (m_MyInteractionModule == null)
|
||
m_MyInteractionModule = Parent.GetComponent<IInteraction>();
|
||
return m_MyInteractionModule;
|
||
}
|
||
set
|
||
{
|
||
m_MyInteractionModule = value;
|
||
}
|
||
}
|
||
|
||
public abstract void OnJudgement(IInteraction.JudgementLevel level);
|
||
|
||
protected override IEnumerator DoSomethingDuringApplyScript()
|
||
{
|
||
yield return base.DoSomethingDuringApplyScript();
|
||
MyInteractionModule.JudgementEvent.AddListener(OnJudgement);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 绑定IInteraction对象,若不手动绑定则会自动绑定到父物体的IInteraction
|
||
/// </summary>
|
||
/// <param name="path"></param>
|
||
[Convention.RScript.Variable.Attr.Method]
|
||
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();
|
||
}
|
||
}
|
||
}
|