• 关于unity中委托等的用法


    不多说,直接上代码,不足之处,多多指教

     1 using System;
     2 using System.Collections;
     3 using System.Collections.Generic;
     4 using UnityEngine;
     5 using UnityEngine.Events;
     6 
     7 public class ActionAndUnityEvent : MonoBehaviour {
     8 
     9     public delegate int m_delegate(int a,int b, int c);
    10     m_delegate m_mydelegate;
    11     event m_delegate m_event;
    12        
    13     public Action<int, int> m_action;
    14 
    15     public UnityAction<int, int> m_unityAction;
    16 
    17     public UnityEvent m_unityEvent = new UnityEvent();
    18     void Start()
    19     {
    20 
    21 
    22         m_unityEvent.AddListener(() => ListenerAdd(10,10));
    23         m_unityEvent.Invoke();
    24 
    25 
    26 
    27         m_mydelegate += Add;
    28         if (m_mydelegate != null)
    29         {
    30             m_mydelegate(1, 2, 3);
    31         }
    32 
    33 
    34 
    35         m_event += Add;
    36         if (m_event!=null)
    37         {
    38             m_event(1,3,5);
    39         }
    40 
    41 
    42 
    43         m_unityAction += Add;
    44         if (m_unityAction!=null)
    45         {
    46             m_unityAction(3, 5);
    47         }
    48 
    49 
    50 
    51         m_action += Add;
    52         if (m_action!=null)
    53         {
    54             m_action(2, 3);
    55         }
    56     }
    57 
    58 
    59     public  void Add(int a, int b)
    60     {
    61         Debug.Log(a + b);
    62     }
    63 
    64 
    65 
    66     public int Add(int a, int b, int c)
    67     {
    68         Debug.Log(a + b + c);
    69         return a + b + c;
    70     }
    71 
    72 
    73 
    74 
    75     public  void  ListenerAdd(int a,int b)
    76     {
    77         Debug.Log(a + b);
    78     }
    79 }
  • 相关阅读:
    LIB和DLL
    string
    Lists
    ctypes常用dll
    tomcat的安装配置注意事项
    tomcat6的简单安装
    存储GFS 学习笔记
    进程是否启动查看命令方法
    (转载)最新linux搭建gfs系统iscsi+GFS实现网络存储
    推荐两款支持在linux下运行ASP.NET网站的国产免费WEB服务器软件
  • 原文地址:https://www.cnblogs.com/nanyang0310/p/9055905.html
Copyright © 2020-2023  润新知