public abstract class Command
{
public abstract void Execute ( ) ;
}
public class ConcreteCommand1 : Command
{
string param;
public Receiver1 receiver;
public ConcreteCommand1 ( string p, Receiver1 r)
{
this . param = p;
this . receiver = r;
}
public override void Execute ( )
{
receiver. Execute ( param) ;
}
}
using System. Collections;
using System. Collections. Generic;
public class Invoker
{
Queue< Command> _Commands;
public Invoker ( )
{
_Commands = new Queue < Command > ( ) ;
}
public void AddCommand ( Command c)
{
_Commands. Enqueue ( c) ;
}
public void Execute ( )
{
while ( _Commands. Count> 0 )
{
Command c = _Commands. Dequeue ( ) ;
c. Execute ( ) ;
}
}
}
using UnityEngine;
public class Receiver1
{
public void Execute ( string param)
{
Debug. Log ( "this is receive1,param = " + param) ;
}
}