游戏开发(UnityC#)总结32 - Action委托

  • 时间:
  • 浏览:
  • 来源:互联网
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Demo : MonoBehaviour
{
    //无参数无返回值委托
    Action action;
    //带int参数的无返回值委托,参数最多16个
    Action<int> action2;
    // Start is called before the first frame update
    void Start()
    {
        action += new Action(MyAction);
        action();

        action2 += new Action<int>(MyAction2);
        action2(20);
    }

    public void MyAction() {
        print("MyAction");
    }

    public void MyAction2(int num)
    {
        print("num = "+ num);
    }
}

demo下载

https://gitlab.com/demofile1/uploadfile/-/tree/main

本文链接http://metronic.net.cn/metronic/show-16430.html