Ejemplo n.º 1
0
        /// <summary>
        /// Given a GameObject, extract an MmRelayNode if present
        /// and add it to this MmRelayNode's Responder list.
        /// </summary>
        /// <param name="go">GameObject that should have an MmRelayNode attached.</param>
        public virtual void MmAddNodeToList(GameObject go)
        {
            var relayNode = go.GetComponent <MmRelayNode>();

            if (relayNode != null)
            {
                MmAddToRoutingTable(relayNode, go.name);
            }
            else
            {
                MmLogger.LogError("No MmRelayNode present on " + go.name);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Given an MmResponder, extract an MmRelayNode from it's GameObject, if one is present.
        /// </summary>
        /// <param name="iMmResponder">Observed MmResponder</param>
        /// <returns>an MmRelayNode if one is present on the same GameObject.</returns>
        public static MmRelayNode GetRelayNode(IMmResponder iMmResponder)
        {
            var relayNode = ((MonoBehaviour)iMmResponder).GetComponent <MmRelayNode>();

            if (relayNode != null)
            {
                return(relayNode);
            }
            else
            {
                MmLogger.LogError("Could not get MmRelayNode");
                return(null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts the standard MmRoutingTable into a FSM.
        /// Calls MmOnAwakeComplete through MmResponder Awake.
        /// </summary>
        public override void Awake()
        {
            MmLogger.LogFramework(gameObject.name + " MmRelaySwitchNode Awake");

            try
            {
                RespondersFSM =
                    new FiniteStateMachine <MmRoutingTableItem>("RespondersFSM",
                                                                RoutingTable.Where(x => x.Responder is MmRelayNode && x.Level == MmLevelFilter.Child).ToList());
            }
            catch
            {
                MmLogger.LogError(gameObject.name + ": Failed bulding FSM. Missing Node?");
            }

            base.Awake();
        }
        /// <summary>
        /// Process a message and send it to the associated object.
        /// </summary>
        /// <param name="netMsg">UNET network message</param>
        public virtual void ReceivedMessage(NetworkMessage netMsg)
        {
            MmMessageType mmMessageType = (MmMessageType)netMsg.msgType;

            try
            {
                switch (mmMessageType)
                {
                case MmMessageType.MmVoid:
                    MmMessage msg = netMsg.ReadMessage <MmMessage>();
                    MmRelayNodes[msg.NetId].MmInvoke(mmMessageType, msg);
                    break;

                case MmMessageType.MmInt:
                    MmMessageInt msgInt = netMsg.ReadMessage <MmMessageInt>();
                    MmRelayNodes[msgInt.NetId].MmInvoke(mmMessageType, msgInt);
                    break;

                case MmMessageType.MmBool:
                    MmMessageBool msgBool = netMsg.ReadMessage <MmMessageBool>();
                    MmRelayNodes[msgBool.NetId].MmInvoke(mmMessageType, msgBool);
                    break;

                case MmMessageType.MmFloat:
                    MmMessageFloat msgFloat = netMsg.ReadMessage <MmMessageFloat>();
                    MmRelayNodes[msgFloat.NetId].MmInvoke(mmMessageType, msgFloat);
                    break;

                case MmMessageType.MmVector3:
                    MmMessageVector3 msgVector3 = netMsg.ReadMessage <MmMessageVector3>();
                    MmRelayNodes[msgVector3.NetId].MmInvoke(mmMessageType, msgVector3);
                    break;

                case MmMessageType.MmVector4:
                    MmMessageVector4 msgVector4 = netMsg.ReadMessage <MmMessageVector4>();
                    MmRelayNodes[msgVector4.NetId].MmInvoke(mmMessageType, msgVector4);
                    break;

                case MmMessageType.MmString:
                    MmMessageString msgString = netMsg.ReadMessage <MmMessageString>();
                    MmRelayNodes[msgString.NetId].MmInvoke(mmMessageType, msgString);
                    break;

                case MmMessageType.MmByteArray:
                    MmMessageByteArray msgByteArray = netMsg.ReadMessage <MmMessageByteArray>();
                    MmRelayNodes[msgByteArray.NetId].MmInvoke(mmMessageType, msgByteArray);
                    break;

                case MmMessageType.MmTransform:
                    MmMessageTransform msgTransform = netMsg.ReadMessage <MmMessageTransform>();
                    MmRelayNodes[msgTransform.NetId].MmInvoke(mmMessageType, msgTransform);
                    break;

                case MmMessageType.MmTransformList:
                    MmMessageTransformList msgTransformList = netMsg.ReadMessage <MmMessageTransformList>();
                    MmRelayNodes[msgTransformList.NetId].MmInvoke(mmMessageType, msgTransformList);
                    break;

                case MmMessageType.MmSerializable:
                    MmMessageSerializable msgSerializable = netMsg.ReadMessage <MmMessageSerializable>();
                    MmRelayNodes[msgSerializable.NetId].MmInvoke(mmMessageType, msgSerializable);
                    break;

                case MmMessageType.MmGameObject:
                    MmMessageGameObject msgGameObject = netMsg.ReadMessage <MmMessageGameObject>();
                    MmRelayNodes[msgGameObject.NetId].MmInvoke(mmMessageType, msgGameObject);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (Exception e)
            {
                MmLogger.LogError(e.Message);
            }
        }
        /// <summary>
        /// Process a message and send it to the associated object.
        /// </summary>
        /// <param name="photonEvent">Photon RaiseEvent message data</param>
        public virtual void ReceivedMessage(EventData photonEvent)
        {
            short eventCode = (short)photonEvent.Code;

            if (eventCode != 1)
            {
                return;
            }
            MmMessageType mmMessageType = (MmMessageType)(eventCode);

            object[]  data = (object[])photonEvent.CustomData;
            MmMessage msg  = new MmMessage();

            msg.Deserialize(data);
            try
            {
                switch (msg.MmMessageType)
                {
                case MmMessageType.MmVoid:
                    MmRelayNode.MmInvoke(msg);
                    break;

                case MmMessageType.MmInt:
                    MmMessageInt msgInt = new MmMessageInt();
                    msgInt.Deserialize(data);
                    MmRelayNode.MmInvoke(msgInt);
                    break;

                case MmMessageType.MmBool:
                    MmMessageBool msgBool = new MmMessageBool();
                    msgBool.Deserialize(data);
                    MmRelayNode.MmInvoke(msgBool);
                    break;

                case MmMessageType.MmFloat:
                    MmMessageFloat msgFloat = new MmMessageFloat();
                    msgFloat.Deserialize(data);
                    MmRelayNode.MmInvoke(msgFloat);
                    break;

                case MmMessageType.MmVector3:
                    MmMessageVector3 msgVector3 = new MmMessageVector3();
                    msgVector3.Deserialize(data);
                    MmRelayNode.MmInvoke(msgVector3);
                    break;

                case MmMessageType.MmVector4:
                    MmMessageVector4 msgVector4 = new MmMessageVector4();
                    msgVector4.Deserialize(data);
                    MmRelayNode.MmInvoke(msgVector4);
                    break;

                case MmMessageType.MmString:
                    MmMessageString msgString = new MmMessageString();
                    msgString.Deserialize(data);
                    MmRelayNode.MmInvoke(msgString);
                    break;

                case MmMessageType.MmByteArray:
                    MmMessageByteArray msgByteArray = new MmMessageByteArray();
                    msgByteArray.Deserialize(data);
                    MmRelayNode.MmInvoke(msgByteArray);
                    break;

                case MmMessageType.MmTransform:
                    MmMessageTransform msgTransform = new MmMessageTransform();
                    msgTransform.Deserialize(data);
                    MmRelayNode.MmInvoke(msgTransform);
                    break;

                case MmMessageType.MmTransformList:
                    MmMessageTransformList msgTransformList = new MmMessageTransformList();
                    msgTransformList.Deserialize(data);
                    MmRelayNode.MmInvoke(msgTransformList);
                    break;

                case MmMessageType.MmSerializable:
                    MmMessageSerializable msgSerializable = new MmMessageSerializable();
                    msgSerializable.Deserialize(data);
                    MmRelayNode.MmInvoke(msgSerializable);
                    break;

                case MmMessageType.MmGameObject:
                    MmMessageGameObject msgGameObject = new MmMessageGameObject();
                    msgGameObject.Deserialize(data);
                    MmRelayNode.MmInvoke(msgGameObject);
                    break;

                default:
                    Debug.Log(eventCode);
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (Exception e)
            {
                MmLogger.LogError(e.Message);
            }
        }