zoukankan      html  css  js  c++  java
  • 委托 事件

    1111

    using UnityEngine;
    using System.Collections;
    
      
    
    public class GlobalManager  {
    
         
    
        private static EventController _eventController=null;
    
        public EventController eventController
        {
    
            get
            {
    
                if(_eventController==null)
                {
    
                    _eventController=new EventController();
                }
                return _eventController;
            }
        }
    
    
    
        public static GlobalManager  _instance  ;
    
        public static GlobalManager instance
        {
            get{
                if( _instance == null ) 
                    _instance = new GlobalManager() ;
    
                return _instance ;
            }
        }
    
    }

    222

    using UnityEngine;
    using System.Collections;
    
    
    
    public class EventController {
    
        
        public delegate  void LogName(  )  ;
        
        public event LogName LogNameEvent  ;
    
        public void  sendLogName()
        { 
            if( LogNameEvent != null )
            { 
                LogNameEvent() ;
            } 
        }
    }

    333

    using UnityEngine;
    using System.Collections;
    
    public class CC : MonoBehaviour {
    
        // Use this for initialization
        void Start () {
            //AA.bb.handleBB+=logName; 
            GlobalManager.instance.eventController.LogNameEvent += logName ;
        }
    
     
        void logName( )
        {
            Debug.Log( "CCCC") ;
        }
    
        // Update is called once per frame
        void Update () {
        
        }
    }

    444

    using UnityEngine;
    using System.Collections;
    
    public class DD : MonoBehaviour {
    
        // Use this for initialization
        void Start () {
            //AA.bb.handleBB+=logName;
            GlobalManager.instance.eventController.LogNameEvent += logName ;
        }
        
        // Update is called once per frame
        void Update () {
        
        }
    
        void logName( )
        {
            Debug.Log( "ddddd") ;
        }
    
        void OnGUI()
        {
            if( GUI.Button( new Rect( 100,100,100,100 ) ,  "event" ))
            {
                //AA.bb.sendEvent();
                GlobalManager.instance.eventController.sendLogName() ;
            }
        }
    }
     
  • 相关阅读:
    函数执行的预解释
    数组的基本知识点
    前端开发概述+JS基础细节知识点
    JS数据类型的转换规则
    call,apply,求最大最小值,平均数等基础编程知识
    JS面向对象程序设计(OOP:Object Oriented Programming)
    C++ 手记
    C++ 在堆中申请内存方法
    vc驿站视频教程笔记4 Cstring 讲解
    vc驿站视频教程笔记2 ansi 和 unicode
  • 原文地址:https://www.cnblogs.com/didiaodexi/p/3483488.html
Copyright © 2011-2022 走看看