Ejemplo n.º 1
0
 public static void SetEntityParent(ParcelScene scene, DecentralandEntity child, DecentralandEntity parent)
 {
     scene.SetEntityParent(child.entityId, parent.entityId);
 }
Ejemplo n.º 2
0
 public static void SetEntityParent(ParcelScene scene, string childEntityId, string parentEntityId)
 {
     scene.SetEntityParent(childEntityId, parentEntityId);
 }
Ejemplo n.º 3
0
        private void ProcessMessage(ParcelScene scene, string method, object msgPayload,
                                    out CustomYieldInstruction yieldInstruction)
        {
            yieldInstruction = null;
            IDelayedComponent delayedComponent = 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)
                    {
                        delayedComponent = scene.EntityComponentCreateOrUpdate(payload.entityId,
                                                                               (CLASS_ID_COMPONENT)payload.classId, payload.json) as IDelayedComponent;
                    }

                    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)
                    {
                        delayedComponent = scene.SharedComponentUpdate(payload.componentId, payload.json) as IDelayedComponent;
                    }

                    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)
                    {
                        DataStore.i.onOpenNFTPrompt.Set(new NFTPromptModel(payload.contactAddress, payload.tokenId,
                                                                           payload.comment), true);
                    }
                    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}");
            }

            if (delayedComponent != null)
            {
                if (delayedComponent.isRoutineRunning)
                {
                    yieldInstruction = delayedComponent.yieldInstruction;
                }
            }
        }