using UnityEngine;
using System.Collections;
public class One : MonoBehaviour {
public delegate int Sum( int num1, int num2); // 只有参数,不去实现
public int SumAll(Sum sum) // SumAll 返回类型与 Sum一致
{
return sum(1, 3); // 回调SumAll 内传递的参数
}
}
///
using UnityEngine;
using System.Collections;
public class Two : MonoBehaviour {
One one;
void Start()
{
one = gameObject.GetComponent<One>();
}
void Update () {
if (Input.GetKeyUp(KeyCode.A))
{
print("num = "+ one.SumAll(GetSum)); //在此处调用 One中的 SumAll 方法,
}
}
private int GetSum(int a, int b) //将要被回调的方法,该方法返回类型和参数类型要与 SumAll的参数方法的参数形同,返回类型相同
{
return a + b;
}
}
using System.Collections;
public class One : MonoBehaviour {
public delegate int Sum( int num1, int num2); // 只有参数,不去实现
public int SumAll(Sum sum) // SumAll 返回类型与 Sum一致
{
return sum(1, 3); // 回调SumAll 内传递的参数
}
}
///
using UnityEngine;
using System.Collections;
public class Two : MonoBehaviour {
One one;
void Start()
{
one = gameObject.GetComponent<One>();
}
void Update () {
if (Input.GetKeyUp(KeyCode.A))
{
print("num = "+ one.SumAll(GetSum)); //在此处调用 One中的 SumAll 方法,
}
}
private int GetSum(int a, int b) //将要被回调的方法,该方法返回类型和参数类型要与 SumAll的参数方法的参数形同,返回类型相同
{
return a + b;
}
}