Exemple #1
0
        /// <summary>
        /// Registers callbacks for OnStart & gets handle to
        /// MmSwitchResponder attached to the same GameObject.
        /// </summary>
        public virtual void Awake()
        {
            MmLogger.LogFramework("MmTestManager Awake");

            _rootSwitchResponder = GetComponent <MmSwitchResponder>();
            _rootSwitchResponder.MmRegisterStartCompleteCallback(TestSetup);
        }
        /// <summary>
        /// Iterates through RoutingTable list and assigns
        /// this MmRelayNode as a parent to child MmResponders.
        /// </summary>
        public void RefreshParents()
        {
            MmLogger.LogFramework("Refreshing parents on MmRelayNode: " + gameObject.name);

            foreach (var child in RoutingTable.Where(x => x.Level == MmLevelFilter.Child))
            {
                var childNode = child.Responder.GetRelayNode();
                childNode.AddParent(this);
                childNode.RefreshParents();
            }

            //Optimize later
            foreach (var parent in MmParentList)
            {
                //bool foundItem = RoutingTable.Select ((x) => x.Responder).Any (responder => responder == parent);
                MmRoutingTableItem foundItem = RoutingTable.First(x => x.Responder == parent);
                if (foundItem == null)
                {
                    MmAddToRoutingTable(parent, MmLevelFilter.Parent);
                }
                else
                {
                    foundItem.Level = MmLevelFilter.Parent;
                }
            }
        }
        /// <summary>
        /// Attempt to register handlers to client/server objects
        /// Invokes MmStart on listeners.
        /// </summary>
        public virtual void Start()
        {
            MmLogger.LogResponder(gameObject.name + ": MmNetworkManager Started");

            if (NetworkClient == null && NetworkManager.singleton != null)
            {
                NetworkClient = NetworkManager.singleton.client;
            }

            if (NetworkClient != null)
            {
                foreach (var value in Enum.GetValues(typeof(MmMessageType)).Cast <short>())
                {
                    NetworkClient.RegisterHandler(value, ReceivedMessage);
                }
            }

            if (isServer)
            {
                foreach (var value in Enum.GetValues(typeof(MmMessageType)).Cast <short>())
                {
                    NetworkServer.RegisterHandler(value, ReceivedMessage);
                }
            }

            if (MmStart != null)
            {
                MmStart();
            }

            //NetworkManager.singleton.globalConfig.MaxPacketSize = 2500;
        }
Exemple #4
0
        /// <summary>
        /// Attempts to register the this responder with the
        /// MmNetworkManager.
        /// Also calls the post-start callback.
        /// </summary>
        public virtual void Start()
        {
            MmLogger.LogFramework(gameObject.name + ": Network Responder Started");

            if (MmStart != null)
            {
                MmStart();
            }
        }
        /// <summary>
        /// Invoke MmAwake on listeners.
        /// </summary>
        public virtual void Awake()
        {
            MmLogger.LogResponder(gameObject.name + ": MmNetworkManager Awake");

            Instance = this;

            if (MmAwake != null)
            {
                MmAwake();
            }
        }
        /// <summary>
        /// Awake gets the MmRelayNode, if one is present.
        /// Also calls the post-awake callback.
        /// </summary>
        public virtual void Awake()
        {
            MmLogger.LogFramework(gameObject.name + ": Network Responder Awake");

            MmRelayNode = GetComponent <MmRelayNode>();

            if (MmAwake != null)
            {
                MmAwake();
            }
        }
        /// <summary>
        /// Grab attached MmNetworkResponder, if present.
        /// Detect and refresh parents.
        /// Instantiate any cloneable MmResponders.
        /// </summary>
        public override void Awake()
        {
            MmNetworkResponder = GetComponent <IMmNetworkResponder>();

            InitializeNode();

            InstantiateSubResponders();

            base.Awake();

            MmLogger.LogFramework(gameObject.name + " MmRelayNode Awake called.");
        }
        /// <summary>
        /// Calls MmOnStartComplete through MmResponder Start.
        /// </summary>
        public override void Start()
        {
            base.Start();

            MmLogger.LogFramework(gameObject.name + " MmRelayNode Start called.");

            //Show all items currently in the RoutingTable list.
            //Debug.Log(gameObject.name + " MmRelayNode start called. With " +
            //    RoutingTable.Count +
            //    " items in the MmResponder List: " +
            //    String.Join("\n", RoutingTable.GetMmNames(MmRoutingTable.ListFilter.All,
            //    MmLevelFilterHelper.SelfAndBidirectional).ToArray()));
        }
        /// <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);
            }
        }
        /// <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);
            }
        }
        /// <summary>
        /// Method serializes message and sends it to server.
        /// </summary>
        /// <param name="msgType">Type of message. This specifies
        /// the type of the payload. This is important in
        /// networked scenarios, when proper deseriaization into
        /// the correct type requires knowing what was
        /// used to serialize the object originally.
        /// </param>
        /// <param name="msg">The message to send.
        /// This utilises UNET's MessageBase so it is
        /// Auto [de]serialized by UNET.
        /// This also allows us to send messages that are not
        /// part of Mercury XM</param>
        public virtual void MmSendMessageToServer(short msgType, MessageBase msg)
        {
            if (MmNetworkManager.Instance.NetworkClient == null)
            {
                MmLogger.LogFramework("No client present on host");
                return;
            }

            NetworkWriter writer = new NetworkWriter();

            writer.StartMessage(msgType);
            msg.Serialize(writer);
            writer.FinishMessage();

            MmNetworkManager.Instance.NetworkClient.SendWriter(writer, Channels.DefaultReliable);
        }
Exemple #12
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="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);
            }
        }
        /// <summary>
        /// Start: Invokes MmOnStartComplete
        /// </summary>
        public virtual void Start()
        {
            MmLogger.LogResponder(gameObject.name + " responder started.");

            MmOnStartComplete();
        }
        /// <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);
            }
        }
Exemple #16
0
        /// <summary>
        /// Calls MmOnStartComplete through MmResponder Start.
        /// </summary>
        public override void Start()
        {
            MmLogger.LogFramework(gameObject.name + " MmRelaySwitchNode Start");

            base.Start();
        }
        /// <summary>
        /// Awake: Invokes MmOnAwakeComplete
        /// </summary>
        public virtual void Awake()
        {
            MmLogger.LogResponder(gameObject.name + " responder awoken.");

            MmOnAwakeComplete();
        }
Exemple #18
0
        /// <summary>
        /// Handle MmMethod: SetActive
        /// </summary>
        /// <param name="active">Value of active state.</param>
        public virtual void SetActive(bool active)
        {
            gameObject.SetActive(active);

            MmLogger.LogResponder("SetActive(" + active + ") called on " + gameObject.name);
        }
Exemple #19
0
 /// <summary>
 /// Handle MmMethod: Initialize
 /// Initialize allows you to provide additional initialization logic
 /// in-between calls to Monobehavior provided Awake() and Start() calls.
 /// </summary>
 public virtual void Initialize()
 {
     MmLogger.LogResponder("Initialize called on " + gameObject.name);
 }
Exemple #20
0
 /// <summary>
 /// Handle MmMethod: Refresh
 /// </summary>
 /// <param name="transformList">List of transforms needed in refreshing an MmResponder.</param>
 public virtual void Refresh(List <MmTransform> transformList)
 {
     MmLogger.LogResponder("Refresh called on " + gameObject.name);
 }