Пример #1
0
        IEnumerator SendMessageWithAckOrTimeoutCr <T>(T message, DieMessageType ackType, float timeOut, System.Action <DieMessage> ackAction, System.Action timeoutAction, System.Action errorAction)
            where T : DieMessage
        {
            DieMessage ackMessage            = null;
            float      startTime             = Time.time;
            MessageReceivedDelegate callback = (ackMsg) =>
            {
                ackMessage = ackMsg;
            };

            AddMessageHandler(ackType, callback);
            byte[] msgBytes = DieMessages.ToByteArray(message);
            DicePool.Instance.WriteDie(this, msgBytes, msgBytes.Length, null);
            while (ackMessage == null && Time.time < startTime + timeOut)
            {
                yield return(null);
            }
            RemoveMessageHandler(ackType, callback);
            if (ackMessage != null)
            {
                ackAction?.Invoke(ackMessage);
            }
            else
            {
                timeoutAction?.Invoke();
            }
        }
Пример #2
0
        public void OnData(byte[] data)
        {
            // Process the message coming from the actual die!
            var message = DieMessages.FromByteArray(data);

            if (message != null)
            {
                MessageReceivedDelegate del;
                if (messageDelegates.TryGetValue(message.type, out del))
                {
                    del.Invoke(message);
                }
            }
        }
Пример #3
0
 void PostMessage <T>(T message)
     where T : DieMessage
 {
     byte[] msgBytes = DieMessages.ToByteArray(message);
     DicePool.Instance.WriteDie(this, msgBytes, msgBytes.Length, null);
 }