首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >统一-向检验员公开某项职能

统一-向检验员公开某项职能
EN

Game Development用户
提问于 2017-02-07 17:40:48
回答 1查看 7K关注 0票数 0

我希望向检查人员公开脚本的功能,但我不知道如何。我发现了一些关于Invoke()的东西,这是一个开始,但还不清楚如何完成。

我的课程代码:

代码语言:javascript
运行
复制
 [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)函数。我想把这件事告诉编辑。多么?

编辑:

像这样的事情会更好:

EN

回答 1

Game Development用户

回答已采纳

发布于 2017-02-07 19:07:36

您要寻找的是统一事件类。参见下面的示例。这将出现在编辑器中,就像你的截图一样。

代码语言:javascript
运行
复制
using UnityEngine;
using UnityEngine.Events;
using System.Collections;

public class InvokeOnAwake : MonoBehaviour {

    public UnityEvent invokeMethod;//set in editor

    void Awake(){
        invokeMethod.Invoke();
    }

}
票数 1
EN
页面原文内容由Game Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://gamedev.stackexchange.com/questions/136996

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档