125 lines
5.3 KiB
C#
125 lines
5.3 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using Convention;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
namespace Demo.Game
|
|||
|
|
{
|
|||
|
|
public abstract class IEffectHookObject : ScriptableObject, IHookInteraction
|
|||
|
|
{
|
|||
|
|
public enum InteractiveEffectType
|
|||
|
|
{
|
|||
|
|
VisibleDuration = 3,
|
|||
|
|
InteractiveDuration = 2,
|
|||
|
|
InteractableScoreInterval = 1,
|
|||
|
|
InteractableIntervalThatCanScoreBest = 0
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[Content, SerializeField] private IInteraction MyInteractionModule;
|
|||
|
|
[Content, SerializeField] private InteractiveEffectType MyInteractiveLevel = default;
|
|||
|
|
|
|||
|
|
public abstract void OnBegin();
|
|||
|
|
public abstract void OnEnd();
|
|||
|
|
|
|||
|
|
public override IEnumerator LoadScript(string script)
|
|||
|
|
{
|
|||
|
|
yield return base.LoadScript(script);
|
|||
|
|
if (MyInteractionModule == null)
|
|||
|
|
MyInteractionModule = Parent.GetComponent<IInteraction>();
|
|||
|
|
switch (MyInteractiveLevel)
|
|||
|
|
{
|
|||
|
|
case InteractiveEffectType.VisibleDuration:
|
|||
|
|
{
|
|||
|
|
MyInteractionModule.VisibleDurationBeginEvent.AddListener(OnBegin);
|
|||
|
|
MyInteractionModule.VisibleDurationEndEvent.AddListener(OnEnd);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case InteractiveEffectType.InteractiveDuration:
|
|||
|
|
{
|
|||
|
|
MyInteractionModule.InteractiveDurationBeginEvent.AddListener(OnBegin);
|
|||
|
|
MyInteractionModule.InteractiveDurationEndEvent.AddListener(OnEnd);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case InteractiveEffectType.InteractableScoreInterval:
|
|||
|
|
{
|
|||
|
|
MyInteractionModule.InteractableScoreIntervalBeginEvent.AddListener(OnBegin);
|
|||
|
|
MyInteractionModule.InteractableScoreIntervalEndEvent.AddListener(OnEnd);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case InteractiveEffectType.InteractableIntervalThatCanScoreBest:
|
|||
|
|
{
|
|||
|
|
MyInteractionModule.InteractableIntervalThatCanScoreBestBeginEvent.AddListener(OnBegin);
|
|||
|
|
MyInteractionModule.InteractableIntervalThatCanScoreBestEndEvent.AddListener(OnEnd);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override IEnumerator UnloadScript()
|
|||
|
|
{
|
|||
|
|
// 如果是父物体那么在此处执行前就会重新生成对应的event
|
|||
|
|
// 但通过绑定得到的其他物体并不能保证顺序关系
|
|||
|
|
// 因此此处仍需要对象自行清理
|
|||
|
|
switch (MyInteractiveLevel)
|
|||
|
|
{
|
|||
|
|
case InteractiveEffectType.VisibleDuration:
|
|||
|
|
{
|
|||
|
|
MyInteractionModule.VisibleDurationBeginEvent.RemoveListener(OnBegin);
|
|||
|
|
MyInteractionModule.VisibleDurationEndEvent.RemoveListener(OnEnd);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case InteractiveEffectType.InteractiveDuration:
|
|||
|
|
{
|
|||
|
|
MyInteractionModule.InteractiveDurationBeginEvent.RemoveListener(OnBegin);
|
|||
|
|
MyInteractionModule.InteractiveDurationEndEvent.RemoveListener(OnEnd);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case InteractiveEffectType.InteractableScoreInterval:
|
|||
|
|
{
|
|||
|
|
MyInteractionModule.InteractableScoreIntervalBeginEvent.RemoveListener(OnBegin);
|
|||
|
|
MyInteractionModule.InteractableScoreIntervalEndEvent.RemoveListener(OnEnd);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case InteractiveEffectType.InteractableIntervalThatCanScoreBest:
|
|||
|
|
{
|
|||
|
|
MyInteractionModule.InteractableIntervalThatCanScoreBestBeginEvent.RemoveListener(OnBegin);
|
|||
|
|
MyInteractionModule.InteractableIntervalThatCanScoreBestEndEvent.RemoveListener(OnEnd);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
MyInteractionModule = null;
|
|||
|
|
yield return base.UnloadScript();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 绑定IInteraction对象,若不手动绑定则会自动绑定到父物体的IInteraction
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="path"></param>
|
|||
|
|
[ScriptableCall(@"
|
|||
|
|
<summary>
|
|||
|
|
绑定IInteraction对象,若不手动绑定则会自动绑定到父物体的IInteraction
|
|||
|
|
</summary>
|
|||
|
|
")]
|
|||
|
|
public void Bind(string path)
|
|||
|
|
{
|
|||
|
|
MyInteractionModule = FindWithPath(path) as IInteraction;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 设置监听状态,当目标进入指定监听的状态时触发启动事件,退出时触发结束事件
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="type">VisibleDuration,InteractiveDuration,InteractableScoreInterval,InteractableIntervalThatCanScoreBest</param>
|
|||
|
|
[ScriptableCall(@"
|
|||
|
|
<summary>
|
|||
|
|
设置监听状态,当目标进入指定监听的状态时触发启动事件,退出时触发结束事件
|
|||
|
|
</summary>
|
|||
|
|
<param name=""type"">VisibleDuration,InteractiveDuration,InteractableScoreInterval,InteractableIntervalThatCanScoreBest</param>
|
|||
|
|
")]
|
|||
|
|
public void SetInteractiveEffectType(string type)
|
|||
|
|
{
|
|||
|
|
MyInteractiveLevel = Enum.Parse<InteractiveEffectType>(type);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|