我希望向检查人员公开脚本的功能,但我不知道如何。我发现了一些关于Invoke()
的东西,这是一个开始,但还不清楚如何完成。
我的课程代码:
[System.Serializable]
class MoveAction : UnityEvent<MonoBehaviour>, IUIAnimationEvent
{
#region Move
public MoveAction()
{
}
//to ensure only one mover coroutine can be active.
IEnumerator moveRoutine = null;
#region Solution 2: using fields and not parameters
Transform from;
Transform to;
float overTime;
public delegate void UIchain(MonoBehaviour mono);
public event UIchain NEXT_FUNCTION;
public MoveAction(Transform from, Transform to, float overTime, IUIAnimationEvent chain)
{
this.from = from;
this.to = to;
this.overTime = overTime;
}
public void Move(MonoBehaviour mono)
{
if (moveRoutine != null)
{
mono.StopCoroutine(moveRoutine);
}
moveRoutine = _Move(from, to, overTime, mono);
mono.StartCoroutine(moveRoutine);
Invoke(mono);
}
IEnumerator _Move(Transform from, Transform to, float overTime, MonoBehaviour mono)
{
Vector2 original = from.position;
float timer = 0.0f;
while (timer < overTime)
{
float step = Vector2.Distance(original, to.position) * (Time.deltaTime / overTime);
from.position = Vector2.MoveTowards(from.position, to.position, step);
timer += Time.deltaTime;
yield return null;
}
if(NEXT_FUNCTION != null)
{
NEXT_FUNCTION(mono);
}
}
这是很多代码,但有趣的部分是Move(MonoBehaviour mono)
函数。我想把这件事告诉编辑。多么?
像这样的事情会更好:
发布于 2017-02-07 19:07:36
您要寻找的是统一事件类。参见下面的示例。这将出现在编辑器中,就像你的截图一样。
using UnityEngine;
using UnityEngine.Events;
using System.Collections;
public class InvokeOnAwake : MonoBehaviour {
public UnityEvent invokeMethod;//set in editor
void Awake(){
invokeMethod.Invoke();
}
}
https://gamedev.stackexchange.com/questions/136996
复制相似问题