Ejemplo n.º 1
0
 //Interprets the signal: Always does lights if there are any, and otherwise, runs a different job depending on the type.
 public void ProcessSignal(ReceiveSignal signal)
 {
     TrafficLightBehaviour[] lightsBuffer = trafficLightChildren;
     foreach (TrafficLightData lightSignal in signal.trafficLights)
     {
         foreach (TrafficLightBehaviour light in lightsBuffer)
         {
             if (light.lightID == lightSignal.id)
             {
                 light.ChangeLight(lightSignal.lightStatus);
             }
         }
     }
     if (signal.type == "BridgeData")
     {
         bridgeChild.signalChange = true;
     }
 }
Ejemplo n.º 2
0
    //Reads a JSON message from the socket, if any have appeared, and processes it.
    void ReadFromSocket()
    {
        string serverSays = tcp.readSocket();

        if (serverSays != "")
        {
            string[] messages = serverSays.Split('\n');

            foreach (string message in messages)
            {
                if (message[0] == '{')
                {
                    ReceiveSignal received = JsonUtility.FromJson <ReceiveSignal>(message);
                    ProcessSignal(received);
                    Debug.Log("[SERVER]" + serverSays);
                }
            }
        }
    }
Ejemplo n.º 3
0
 /// <summary>
 /// Construct an actor <see cref="Behavior{TMessage}"/> that can react to lifecycle signals only.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="behavior"></param>
 /// <param name="onSignal"></param>
 /// <returns></returns>
 public static Behavior <T> ReceiveSignal <T>(ReceiveSignal <T> onSignal) =>
 new ReceiveMessageBehavior <T>(async _ => Same <T>()).ReceiveSignal(onSignal);
Ejemplo n.º 4
0
 public ReceiveMessageBehavior <TMessage> ReceiveSignal(ReceiveSignal <TMessage> onSignal) =>
 new ReceiveMessageBehavior <TMessage>(_onMessage, onSignal);
Ejemplo n.º 5
0
 public ReceiveMessageBehavior(ReceiveMessage <TMessage> onMessage, ReceiveSignal <TMessage> onSignal = null)
 {
     _onMessage = onMessage;
     _onSignal  = onSignal ?? Behavior <TMessage> .UnhandledSignal;
 }
Ejemplo n.º 6
0
 public ReceiveBehavior(Receive <TMessage> onMessage, ReceiveSignal <TMessage> onSignal = null)
 {
     _onMessage = onMessage;
     _onSignal  = onSignal;
 }