본문 바로가기
IT/Unity3D

알다가도 모를 람다

by rapker 2018. 4. 6.
반응형

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

 

public partial interface ICommandMessage

{

    void OnCmdGamePatchComplete();

}

public partial class CommandMessage : MonoBehaviour, ICommandMessage

{

    public virtual void OnCmdGamePatchComplete() { }

}

 

 

public class BaseUIPopupModule : CommandMessage

{

    private void OnEnable()

    {

        CommandHelper.OnConnectCommand(this);

    }

 

    private void OnDisable()

    {

        CommandHelper.OnDisconnectCommand(this);

    }

}

 

public class testMono : BaseUIPopupModule

{

    public override void OnCmdGamePatchComplete()

    {

        Debug.Log("testMono::OnCmdGamePatchComplete()");

    }

 

    public void OnClick_PatchComplete()

    {

        CommandHelper.OnCmdGamePatchComplete();

        //this.Invoke("OnCmdGamePatchComplete", 0.0f);

    }

 

    private void Dispatch(System.Action<ICommandMessage> msg)

    {

        msg.Invoke(this);

    }

}

 

 

 

 

public partial class CommandHelper

{

    protected static List<ICommandMessage> popupMessageCollection = new List<ICommandMessage>();

 

    public static void OnConnectCommand(ICommandMessage message)

    {

        if (popupMessageCollection.Contains(message) == true)

            return;

 

        popupMessageCollection.Add(message);

    }

 

    public static void OnDisconnectCommand(ICommandMessage message)

    {

        if (popupMessageCollection.Contains(message) == true)

        {

            popupMessageCollection.Remove(message);

        }

    }

 

    private static void SendMessage(System.Action<ICommandMessage> sendMessage)

    {

        for (int i = 0; i < popupMessageCollection.Count; i++)

        {

            //sendMessage.Invoke(popupMessageCollection[i]);

            sendMessage(popupMessageCollection[i]);

 

            // <OnCmdGamePatchComplete>(testMono)

            // <OnCmdGamePatchComplete>(testMono2)

        }

    }

 

    public static void OnCmdGamePatchComplete()

    {

        SendMessage(c => c.OnCmdGamePatchComplete());

    }

}

반응형
LIST