public IEnumerator BeDestroyedCorrectlyWhenReceivingComponentDestroyMessage()
        {
            var        shape  = TestHelpers.CreateEntityWithBoxShape(scene, Vector3.zero, true);
            IDCLEntity entity = shape.attachedEntities.First();

            yield return(shape.routine);

            string onPointerId = "pointerevent-1";
            var    model       = new OnClick.Model()
            {
                type = OnClick.NAME,
                uuid = onPointerId
            };

            TestHelpers.EntityComponentCreate <OnClick, OnClick.Model>(scene, entity,
                                                                       model, CLASS_ID_COMPONENT.UUID_CALLBACK);

            model.type = OnPointerDown.NAME;

            TestHelpers.EntityComponentCreate <OnPointerDown, OnPointerDown.Model>(scene, entity,
                                                                                   model, CLASS_ID_COMPONENT.UUID_CALLBACK);

            model.type = OnPointerUp.NAME;

            TestHelpers.EntityComponentCreate <OnPointerUp, OnPointerUp.Model>(scene, entity,
                                                                               model, CLASS_ID_COMPONENT.UUID_CALLBACK);

            Assert.IsTrue(entity.components.ContainsKey(CLASS_ID_COMPONENT.UUID_ON_CLICK));
            Assert.IsTrue(entity.components.ContainsKey(CLASS_ID_COMPONENT.UUID_ON_UP));
            Assert.IsTrue(entity.components.ContainsKey(CLASS_ID_COMPONENT.UUID_ON_DOWN));

            scene.EntityComponentRemove(entity.entityId, OnPointerDown.NAME);
            scene.EntityComponentRemove(entity.entityId, OnPointerUp.NAME);
            scene.EntityComponentRemove(entity.entityId, OnClick.NAME);

            Assert.IsFalse(entity.components.ContainsKey(CLASS_ID_COMPONENT.UUID_ON_CLICK));
            Assert.IsFalse(entity.components.ContainsKey(CLASS_ID_COMPONENT.UUID_ON_UP));
            Assert.IsFalse(entity.components.ContainsKey(CLASS_ID_COMPONENT.UUID_ON_DOWN));
        }
Example #2
0
        public static IEnumerator TestShapeOnPointerEventCollider(DecentralandEntity entity)
        {
            Renderer[] renderers = entity.meshesInfo.renderers;

            Assert.IsTrue(renderers.Length > 0);

            var onClickComponentModel = new OnClick.Model()
            {
                type = OnClick.NAME,
                uuid = "onClick"
            };

            ParcelScene scene = entity.scene as ParcelScene;

            var onClickComponent = TestHelpers.EntityComponentCreate <OnClick, OnClick.Model>(scene, entity, onClickComponentModel, CLASS_ID_COMPONENT.UUID_CALLBACK);

            yield return(onClickComponent.routine);

            Collider onPointerEventCollider;

            for (int i = 0; i < renderers.Length; i++)
            {
                Assert.IsTrue(renderers[i].transform.childCount > 0, "OnClick collider should exist as this mesh's child");

                onPointerEventCollider = renderers[i].transform.GetChild(0).GetComponent <Collider>();
                Assert.IsTrue(onPointerEventCollider != null);
                Assert.IsTrue(onPointerEventCollider.gameObject.layer == PhysicsLayers.onPointerEventLayer);

                // check the onClick collide enabled state is the same as the renderer's state
                Assert.IsTrue(onPointerEventCollider.enabled == renderers[i].enabled);
            }

            scene.EntityComponentRemove(
                entity.entityId,
                onClickComponent.name
                );
            yield return(null);
        }
Example #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;
                }
            }
        }