1. 程式人生 > >Unity3D通過委託 一個類訪問到另一個類中的方法

Unity3D通過委託 一個類訪問到另一個類中的方法

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

public class class1 : MonoBehaviour {

    public static class1 Instance
    {
        private set;
        get;
    }

    void Awake()
    {
        Instance = this;
    }

    void OnDestroy()
    {
        if (Instance != null
) { Instance = null; } } public delegate void FunVoid(); public delegate void FunString(string str); public FunVoid delFun; public FunString delFunString; // Use this for initialization void Start () { delFun(); delFunString("11111"
); } // Update is called once per frame void Update () { } }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class class2 : MonoBehaviour {

    public static class2 Instance
    {
        private set;
        get;
    }

    void Awake()
    {
        Instance = this
; } void Start() { class1.Instance.delFun += class2Fun; class1.Instance.delFunString += class2FunString; } void OnDestroy() { if (Instance != null) { Instance = null; } class1.Instance.delFun -= class2Fun; class1.Instance.delFunString -= class2FunString; } // Use this for initialization // Update is called once per frame void Update () { } void class2Fun() { Debug.Log("class2Fun()"); } void class2FunString(string str) { Debug.Log("class2FunString()"); } }

相關推薦

Unity3D通過委託 一個訪問一個方法

using System.Collections; using System.Collections.Generic; using UnityEngine; public class clas

Unity 3D:訪問一個C#的屬性或方法

在開發Unity 3D 遊戲的過程中,經常遇到在某個C#類中訪問另一個C#類中的方法或屬性;比如:在Eenmy.cs中訪問PlayAttack.cs指令碼中的TakeDamage(int damage

php一個引用一個方法的寫法

default.php: <?php namespace SiteInfo{ class Site{ var $url; var $title; function setUrl($par){ $thi

C++一個訪問另外一個的成員變數或者成員函式

1.在一個類中定義另外一個類的成員為指標型別。並用this指標管理物件的記憶體,實現資料的傳遞。 #include <stdio.h> class A { public: A(); ~A(); void SetData(int year, int month, int day);

C++一個包含一個

一個類裡面包含另外一個類,建構函式呼叫的先後關係。 1)A類的物件是B類的私有成員: #include <iostream>  using namespace std; class A { public:     int mInt;     A()     {

內容提供者實現應用訪問一個應用的資料庫

實現這麼個需求:應用1建立資料庫Account.db,應用2對Account.db進行操作 有兩個辦法。 首先記錄第一個不合常理的方法:將建立的資料庫的許可權改為公開的可讀可寫的,然後其他應用就可以訪問了。當然沒人會這麼做,太不安全還麻煩。在這裡就不詳細說了,之提供一個方法可以在程式碼裡寫shell命令:

Word VBA 把一個Word檔案的內容通過字串操作複製到一個Word檔案內(要求不允許出現空行)

Sub 巨集1() ' ' 巨集1 巨集 ' Documents.Open FileName:="D:\VBA\被插入文字的檔案.docx", ConfirmConversions:=False, ReadOnly _ :=False, AddToRe

c#學習筆記三 如何訪問一個頁面的控制元件資料

      在Vs2005中新建一個Web專案,新增兩個Web窗體(Default、Default2),在Default窗體上新增兩個標準控制元件,一個TextBox(TextBox1)、一個Button(Button1),設定Button1的PostBackUrl屬性指向D

一個MFC工程移植對話方塊一個MFC工程

轉載於:https://blog.csdn.net/wowoandlyn/article/details/2937785         今天碰到模組移植問題了,自己做的對話方塊類(繼承於CDialo

NodeJs第二篇一個模組想訪問一個模組的變數

在node中一個模組想訪問另一個模組中的變數。 第一種方式是作為global物件的引數。global.a = a; 不推薦 第二種方式用模組的module.exports來用儲存變數。

QT 一個呼叫一個方法 (樣式表例子)

① 新建一個類 ②新宣告的類cal 程式碼如下 cal.h #ifndef CAL_H #define CAL_H #include <QString> class Cal { public: Cal(); ~Cal(

Android 通過一個app 啟動一個app

PackageManager packageManager = getPackageManager(); String packname="";//此處為包名 if (checkPackInfo(packname)) {//檢查是否有要開啟的app Intent intent = packag

一個呼叫一個的static方法

編譯方法:gcc -c mgrdemo.cpp -o mgr.o gcc -g mgr.o viewdemo.cpp -I. -o view #include "MgrDemo.hpp" void CMgr::Initialize(int val) {  m_val =

不同專案,如何java模擬ajax訪問一個專案的controller

直接上碼 package com.ultrapower.zq.iscloud.web.boc.api.utils; /**  * create by liujie  2017年6月15日上午9:38:14  *  *   */ import java.io.Buffered

C++ 一個呼叫一個的成員變數/成員函式

有時候,兩個類之間並沒有繼承的關係,但是其中一個類需要引用另一個類中的成員變數或者成員函式。怎樣辦到呢? 假設已經新建了兩個類A、B。 class A { public: A(); ~A();

java String-獲取一個字串在一個字串出現的次數

<pre name="code" class="html">//另一種方法 class StringTest3_1 { public static void main(String[]

圖的深度優先查找一個頂點到一個點的路徑

next push ostream pre sta temp creat light read // // Created by liuyubobobo on 9/22/16. // #ifndef INC_06_FINDING_A_PATH_PATH_H

算法總結之 用一個棧實現一個棧的排序

new 算法總結 cnblogs peek 如果 全部 class integer 排序 用一個棧實現另一個棧的排序 一個棧中元素的類型為整型,現在想將該棧從頂到底按從大到小的順序排序。只允許申請一個棧。除此之外可以申請新的變量,但不能申請額外數據結構 思路: 將要

mysql用一個表更新一個

document eat sid select 更新 dal mysq service req 寫法: UPDATE Document, ObservationRequestSET Document.CreateOrganizationName = ObservationR

POJ 3126 Prime Path【從一個素數變為一個素數的最少步數/BFS】

lan mem 奇數 offices ring finance primes iostream int Prime Path Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26475 Accepted: