Unity Invoke的另类用法

来源:互联网 发布:淘宝助手缓存清理 编辑:程序博客网 时间:2024/06/06 17:29

主要是invoke实现了替换颜色等功能。。

因为之前弄懂了点,现在又忘了,记录下,相关代码如下:

using System.Collections;

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

[System.Serializable] //序列化类
public class MyColorEvent : UnityEvent<Color>
{
}

[System.Serializable]
public class MyIntEvent : UnityEvent<Texture2D>
{ }

public class test : MonoBehaviour {
    public MyColorEvent m_MyEvent = new MyColorEvent();
    public MyIntEvent m_MyIntEvent = new MyIntEvent();
    public Texture2D _T2D; 
    void Start()
    {
        //if (m_MyEvent == null)
        //    m_MyEvent = new MyIntEvent();


       // m_MyEvent.AddListener(Ping);
    }

    void Update()
    {
        if (Input.anyKeyDown && m_MyEvent != null && m_MyIntEvent != null)
        {
            m_MyEvent.Invoke(Color.red);
            m_MyIntEvent.Invoke(_T2D);
        }
    }

}

功能:


原创粉丝点击