본문 바로가기
프로그래밍/C#

C# Action<> 의 활용

by neive 2021. 10. 15.
728x90
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

public class Test_ClassA
{
    public void Run(string value)
    {
        Debug.Log($"Test_ClassA.Run : {value}");
    }
}

public class Test_ClassB
{
    public event Action<string> m_Run;
    
    public void Run(string value)
    {
        m_Run?.Invoke(value);
    }
}

public class Test_Callback : MonoBehaviour
{
    private Test_ClassA m_A = new Test_ClassA();
    private Test_ClassB m_B = new Test_ClassB();

    private void Awake()
    {
        m_B.m_Run += m_A.Run;
    }

    // Start is called before the first frame update
    void Start()
    {
        m_A.Run("hello world");
        m_B.Run("hello world");
    }
}
728x90

댓글