Пример #1
0
        public bool ProcessMessage(MessagingBus.QueuedSceneMessage_Scene msgObject, out CleanableYieldInstruction yieldInstruction)
        {
            string sceneId = msgObject.sceneId;
            string method  = msgObject.method;

            yieldInstruction = null;

            ParcelScene scene;
            bool        res = false;

            if (loadedScenes.TryGetValue(sceneId, out scene))
            {
#if UNITY_EDITOR
                if (debugScenes && scene is GlobalScene && ignoreGlobalScenes)
                {
                    return(false);
                }
#endif
                if (!scene.gameObject.activeInHierarchy)
                {
                    return(true);
                }

#if UNITY_EDITOR
                OnMessageProcessInfoStart?.Invoke(sceneId, method);
#endif
                OnMessageProcessStart?.Invoke(method);

                switch (method)
                {
                case MessagingTypes.ENTITY_CREATE:
                {
                    if (msgObject.payload is Protocol.CreateEntity payload)
                    {
                        scene.CreateEntity(payload.entityId);
                    }

                    break;
                }

                case MessagingTypes.ENTITY_REPARENT:
                {
                    if (msgObject.payload is Protocol.SetEntityParent payload)
                    {
                        scene.SetEntityParent(payload.entityId, payload.parentId);
                    }

                    break;
                }

                case MessagingTypes.ENTITY_COMPONENT_CREATE_OR_UPDATE:
                {
                    if (msgObject.payload is Protocol.EntityComponentCreateOrUpdate payload)
                    {
                        scene.EntityComponentCreateOrUpdate(payload.entityId, (CLASS_ID_COMPONENT)payload.classId, payload.json, out yieldInstruction);
                    }

                    break;
                }

                case MessagingTypes.ENTITY_COMPONENT_DESTROY:
                {
                    if (msgObject.payload is Protocol.EntityComponentDestroy payload)
                    {
                        scene.EntityComponentRemove(payload.entityId, payload.name);
                    }

                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_ATTACH:
                {
                    if (msgObject.payload is Protocol.SharedComponentAttach payload)
                    {
                        scene.SharedComponentAttach(payload.entityId, payload.id);
                    }

                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_CREATE:
                {
                    if (msgObject.payload is Protocol.SharedComponentCreate payload)
                    {
                        scene.SharedComponentCreate(payload.id, payload.classId);
                    }

                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_DISPOSE:
                {
                    if (msgObject.payload is Protocol.SharedComponentDispose payload)
                    {
                        scene.SharedComponentDispose(payload.id);
                    }
                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_UPDATE:
                {
                    if (msgObject.payload is Protocol.SharedComponentUpdate payload)
                    {
                        scene.SharedComponentUpdate(payload.componentId, payload.json, out yieldInstruction);
                    }
                    break;
                }

                case MessagingTypes.ENTITY_DESTROY:
                {
                    if (msgObject.payload is Protocol.RemoveEntity payload)
                    {
                        scene.RemoveEntity(payload.entityId);
                    }
                    break;
                }

                case MessagingTypes.INIT_DONE:
                {
                    scene.SetInitMessagesDone();
                    break;
                }

                case MessagingTypes.QUERY:
                {
                    if (msgObject.payload is QueryMessage queryMessage)
                    {
                        ParseQuery(queryMessage.payload, scene.sceneData.id);
                    }
                    break;
                }

                case MessagingTypes.OPEN_EXTERNAL_URL:
                {
                    if (msgObject.payload is Protocol.OpenExternalUrl payload)
                    {
                        OnOpenExternalUrlRequest?.Invoke(scene, payload.url);
                    }
                    break;
                }

                case MessagingTypes.OPEN_NFT_DIALOG:
                {
                    if (msgObject.payload is Protocol.OpenNftDialog payload)
                    {
                        OnOpenNFTDialogRequest?.Invoke(payload.contactAddress, payload.tokenId, payload.comment);
                    }
                    break;
                }

                default:
                    Debug.LogError($"Unknown method {method}");
                    return(true);
                }

                OnMessageProcessEnds?.Invoke(method);

#if UNITY_EDITOR
                OnMessageProcessInfoEnds?.Invoke(sceneId, method);
#endif

                res = true;
            }

            else
            {
                res = false;
            }

            sceneMessagesPool.Enqueue(msgObject);

            return(res);
        }
Пример #2
0
        private void ProcessMessage(ParcelScene scene, string method, object msgPayload,
                                    out CleanableYieldInstruction yieldInstruction)
        {
            yieldInstruction = null;

            try
            {
                switch (method)
                {
                case MessagingTypes.ENTITY_CREATE:
                {
                    if (msgPayload is Protocol.CreateEntity payload)
                    {
                        scene.CreateEntity(payload.entityId);
                    }

                    break;
                }

                case MessagingTypes.ENTITY_REPARENT:
                {
                    if (msgPayload is Protocol.SetEntityParent payload)
                    {
                        scene.SetEntityParent(payload.entityId, payload.parentId);
                    }

                    break;
                }

                case MessagingTypes.ENTITY_COMPONENT_CREATE_OR_UPDATE:
                {
                    if (msgPayload is Protocol.EntityComponentCreateOrUpdate payload)
                    {
                        scene.EntityComponentCreateOrUpdate(payload.entityId,
                                                            (CLASS_ID_COMPONENT)payload.classId, payload.json, out yieldInstruction);
                    }

                    break;
                }

                case MessagingTypes.ENTITY_COMPONENT_DESTROY:
                {
                    if (msgPayload is Protocol.EntityComponentDestroy payload)
                    {
                        scene.EntityComponentRemove(payload.entityId, payload.name);
                    }

                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_ATTACH:
                {
                    if (msgPayload is Protocol.SharedComponentAttach payload)
                    {
                        scene.SharedComponentAttach(payload.entityId, payload.id);
                    }

                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_CREATE:
                {
                    if (msgPayload is Protocol.SharedComponentCreate payload)
                    {
                        scene.SharedComponentCreate(payload.id, payload.classId);
                    }

                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_DISPOSE:
                {
                    if (msgPayload is Protocol.SharedComponentDispose payload)
                    {
                        scene.SharedComponentDispose(payload.id);
                    }
                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_UPDATE:
                {
                    if (msgPayload is Protocol.SharedComponentUpdate payload)
                    {
                        scene.SharedComponentUpdate(payload.componentId, payload.json, out yieldInstruction);
                    }
                    break;
                }

                case MessagingTypes.ENTITY_DESTROY:
                {
                    if (msgPayload is Protocol.RemoveEntity payload)
                    {
                        scene.RemoveEntity(payload.entityId);
                    }
                    break;
                }

                case MessagingTypes.INIT_DONE:
                {
                    scene.sceneLifecycleHandler.SetInitMessagesDone();
                    break;
                }

                case MessagingTypes.QUERY:
                {
                    if (msgPayload is QueryMessage queryMessage)
                    {
                        ParseQuery(queryMessage.payload, scene.sceneData.id);
                    }
                    break;
                }

                case MessagingTypes.OPEN_EXTERNAL_URL:
                {
                    if (msgPayload is Protocol.OpenExternalUrl payload)
                    {
                        OnOpenExternalUrlRequest?.Invoke(scene, payload.url);
                    }
                    break;
                }

                case MessagingTypes.OPEN_NFT_DIALOG:
                {
                    if (msgPayload is Protocol.OpenNftDialog payload)
                    {
                        OnOpenNFTDialogRequest?.Invoke(payload.contactAddress, payload.tokenId,
                                                       payload.comment);
                    }
                    break;
                }

                default:
                    Debug.LogError($"Unknown method {method}");
                    break;
                }
            }
            catch (Exception e)
            {
                throw new Exception(
                          $"Scene message error. scene: {scene.sceneData.id} method: {method} payload: {JsonUtility.ToJson(msgPayload)} {e}");
            }
        }
Пример #3
0
        public bool ProcessMessage(MessagingBus.QueuedSceneMessage_Scene msgObject, out CleanableYieldInstruction yieldInstruction)
        {
            string sceneId = msgObject.sceneId;
            string tag     = msgObject.tag;
            string method  = msgObject.method;

            DCL.Interface.PB_SendSceneMessage payload = msgObject.payload;

            yieldInstruction = null;

            ParcelScene scene;
            bool        res = false;

            if (loadedScenes.TryGetValue(sceneId, out scene))
            {
#if UNITY_EDITOR
                if (debugScenes && scene is GlobalScene && ignoreGlobalScenes)
                {
                    return(false);
                }
#endif
                if (!scene.gameObject.activeInHierarchy)
                {
                    return(true);
                }

#if UNITY_EDITOR
                OnMessageProcessInfoStart?.Invoke(sceneId, method);
#endif
                OnMessageProcessStart?.Invoke(method);

                switch (method)
                {
                case MessagingTypes.ENTITY_CREATE:
                    scene.CreateEntity(tag);
                    break;

                case MessagingTypes.ENTITY_REPARENT:
                    scene.SetEntityParent(payload.SetEntityParent.EntityId, payload.SetEntityParent.ParentId);
                    break;

                //NOTE(Brian): EntityComponent messages
                case MessagingTypes.ENTITY_COMPONENT_CREATE_OR_UPDATE:
                    scene.EntityComponentCreateOrUpdate(payload.UpdateEntityComponent.EntityId, payload.UpdateEntityComponent.Name, payload.UpdateEntityComponent.ClassId, payload.UpdateEntityComponent.Data, out yieldInstruction);
                    break;

                case MessagingTypes.ENTITY_COMPONENT_DESTROY:
                    scene.EntityComponentRemove(payload.ComponentRemoved.EntityId, payload.ComponentRemoved.Name);
                    break;

                //NOTE(Brian): SharedComponent messages
                case MessagingTypes.SHARED_COMPONENT_ATTACH:
                    scene.SharedComponentAttach(payload.AttachEntityComponent.EntityId, payload.AttachEntityComponent.Id, payload.AttachEntityComponent.Name);
                    break;

                case MessagingTypes.SHARED_COMPONENT_CREATE:
                    scene.SharedComponentCreate(payload.ComponentCreated.Id, payload.ComponentCreated.Name, payload.ComponentCreated.Classid);
                    break;

                case MessagingTypes.SHARED_COMPONENT_DISPOSE:
                    scene.SharedComponentDispose(payload.ComponentDisposed.Id);
                    break;

                case MessagingTypes.SHARED_COMPONENT_UPDATE:
                    scene.SharedComponentUpdate(payload.ComponentUpdated.Id, payload.ComponentUpdated.Json, out yieldInstruction);
                    break;

                case MessagingTypes.ENTITY_DESTROY:
                    scene.RemoveEntity(tag);
                    break;

                case MessagingTypes.INIT_DONE:
                    scene.SetInitMessagesDone();
                    break;

                case MessagingTypes.QUERY:
                    ParseQuery(payload.Query.QueryId, payload.Query.Payload, scene.sceneData.id);
                    break;

                case MessagingTypes.OPEN_EXTERNAL_URL:
                    OnOpenExternalUrlRequest?.Invoke(scene, payload.OpenExternalUrl.Url);
                    break;

                case MessagingTypes.OPEN_NFT_DIALOG:
                    OnOpenNFTDialogRequest?.Invoke(payload.OpenNFTDialog.AssetContractAddress, payload.OpenNFTDialog.TokenId, payload.OpenNFTDialog.Comment);
                    break;

                default:
                    Debug.LogError($"Unknown method {method}");
                    return(true);
                }

                OnMessageProcessEnds?.Invoke(method);

#if UNITY_EDITOR
                OnMessageProcessInfoEnds?.Invoke(sceneId, method);
#endif

                res = true;
            }

            else
            {
                res = false;
            }

            sceneMessagesPool.Enqueue(msgObject);

            return(res);
        }