unity 内置的事件,unityevent 的 使用。最多使用四个参数。且参数类型有限制,只能使用简单的Bool值,int值,string等类型,不支持自定义类的作为形参。
using UnityEngine;
using System.Collections;
using UnityEngine.Events;
using System;
public class EventTry : MonoBehaviour {
public Events_Bool currentChanged;
// Use this for initialization
// bool isc;
void Start () {
currentChanged.AddListener(isOK);
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.S))
{
// isc = true;
currentChanged.Invoke(true);
}
if (Input.GetKeyUp(KeyCode.D))
{
// isc = false;
currentChanged.Invoke(false);
}
}
public void isOK(bool I)
{
if (I)
{
print("is Ok");
}
else
{
print("not is ok");
}
}
[Serializable]
public class Events_Bool : UnityEvent<bool> { };
}
使用方式如下
未完待续 unity action