본문 바로가기

게임 개발 공부 정리

[C#] 델리 게이트 + 콜백 메서드 코드 메모

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

public class Delegate : MonoBehaviour
{
    delegate int MyDelegate(int n1, int n2);

    void Cal (int a, int b, MyDelegate de_var)
	{
        Debug.Log(de_var(a, b));
	}

    public int Plus (int a, int b)
	{
        return a + b;
	}

    public int Minus (int a, int b)
	{
        return a - b;
	}
    void Start()
    {
        MyDelegate dele_plus_var1 = new MyDelegate(Plus);
        MyDelegate dele_minus_var1 = new MyDelegate(Minus);

        Cal(1, 2, dele_plus_var1);
        Cal(5, 1, dele_minus_var1);
    }

    void Update()
    {
        
    }
}