예제 #1
0
    IEnumerator InstantiateNFTShape(Vector3 position, int styleIndex)
    {
        var entity = TestHelpers.CreateSceneEntity(scene);

        TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model {
            position = position
        });

        yield return(null);

        var componentModel = new NFTShape.Model()
        {
            src   = "ethereum://0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536",
            color = Color.gray,
            style = styleIndex
        };

        NFTShape component = TestHelpers.SharedComponentCreate <NFTShape, NFTShape.Model>(scene, CLASS_ID.NFT_SHAPE, componentModel);

        yield return(component.routine);

        TestHelpers.SharedComponentAttach(component, entity);

        // Override texture with a local test one
        var nftShape = LoadableShape.GetLoaderForEntity(entity) as LoadWrapper_NFT;

        nftShape.loaderController.UpdateTexture(Resources.Load <Texture2D>("TestTexture"));
        nftShape.loaderController.transform.localScale = new Vector3(1.5f, 1.5f, 1f);
    }
예제 #2
0
        public static IEnumerator NFTShapeIsInvalidatedWhenStartingOutOfBounds(ParcelScene scene)
        {
            var entity = TestHelpers.CreateSceneEntity(scene);

            TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model {
                position = new Vector3(18, 1, 18)
            });

            var componentModel = new NFTShape.Model()
            {
                src = "ethereum://0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536"
            };
            NFTShape component = TestHelpers.SharedComponentCreate <NFTShape, NFTShape.Model>(scene, CLASS_ID.NFT_SHAPE, componentModel);

            yield return(component.routine);

            TestHelpers.SharedComponentAttach(component, entity);

            yield return(null);

            LoadWrapper shapeLoader = NFTShape.GetLoaderForEntity(entity);

            yield return(new WaitUntil(() => shapeLoader.alreadyLoaded));

            Assert.IsTrue(MeshIsInvalid(entity.meshesInfo));
        }
    public IEnumerator ShapeUpdate()
    {
        string entityId = "1";

        TestHelpers.CreateSceneEntity(scene, entityId);

        var entity = scene.entities[entityId];

        Assert.IsTrue(entity.meshRootGameObject == null, "entity mesh object should be null as the NFTShape hasn't been initialized yet");

        var componentModel = new NFTShape.Model()
        {
            src = "ethereum://0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536"
        };

        NFTShape component = TestHelpers.SharedComponentCreate <NFTShape, NFTShape.Model>(scene, CLASS_ID.NFT_SHAPE, componentModel);

        yield return(component.routine);

        TestHelpers.SharedComponentAttach(component, entity);

        Assert.IsTrue(entity.meshRootGameObject != null, "entity mesh object should already exist as the NFTShape already initialized");

        var nftShape = LoadableShape.GetLoaderForEntity(entity) as LoadWrapper_NFT;

        var backgroundMaterial = nftShape.loaderController.backgroundMaterial;

        Assert.IsTrue(backgroundMaterial.GetColor("_BaseColor") == new Color(0.6404918f, 0.611472f, 0.8584906f), "The NFT frame background color should be the default one");

        // Update color and check if it changed
        componentModel.color = Color.yellow;
        yield return(TestHelpers.SharedComponentUpdate(component, componentModel));

        Assert.AreEqual(Color.yellow, backgroundMaterial.GetColor("_BaseColor"), "The NFT frame background color should be yellow");
    }
예제 #4
0
    public static string ConvertEntityToJSON(DecentralandEntity entity)
    {
        EntityData builderInWorldEntityData = new EntityData();

        builderInWorldEntityData.entityId = entity.entityId;


        foreach (KeyValuePair <CLASS_ID_COMPONENT, BaseComponent> keyValuePair in entity.components)
        {
            if (keyValuePair.Key == CLASS_ID_COMPONENT.TRANSFORM)
            {
                EntityData.TransformComponent entityComponentModel = new EntityData.TransformComponent();

                entityComponentModel.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position, entity.scene);
                entityComponentModel.rotation = entity.gameObject.transform.localRotation.eulerAngles;
                entityComponentModel.scale    = entity.gameObject.transform.localScale;

                builderInWorldEntityData.transformComponent = entityComponentModel;
            }
            else
            {
                ProtocolV2.GenericComponent entityComponentModel = new ProtocolV2.GenericComponent();
                entityComponentModel.componentId = (int)keyValuePair.Key;
                entityComponentModel.data        = keyValuePair.Value.GetModel();

                builderInWorldEntityData.components.Add(entityComponentModel);
            }
        }

        foreach (KeyValuePair <Type, BaseDisposable> keyValuePair in entity.GetSharedComponents())
        {
            if (keyValuePair.Value.GetClassId() == (int)CLASS_ID.NFT_SHAPE)
            {
                EntityData.NFTComponent nFTComponent = new EntityData.NFTComponent();
                NFTShape.Model          model        = (NFTShape.Model)keyValuePair.Value.GetModel();

                nFTComponent.id      = keyValuePair.Value.id;
                nFTComponent.color   = new ColorRepresentation(model.color);
                nFTComponent.assetId = model.assetId;
                nFTComponent.src     = model.src;
                nFTComponent.style   = model.style;

                builderInWorldEntityData.nftComponent = nFTComponent;
            }
            else
            {
                ProtocolV2.GenericComponent entityComponentModel = new ProtocolV2.GenericComponent();
                entityComponentModel.componentId = keyValuePair.Value.GetClassId();
                entityComponentModel.data        = keyValuePair.Value.GetModel();
                entityComponentModel.classId     = keyValuePair.Value.id;

                builderInWorldEntityData.sharedComponents.Add(entityComponentModel);
            }
        }


        return(JsonConvert.SerializeObject(builderInWorldEntityData));
    }
예제 #5
0
    public void AddEntityOnKernel(IDCLEntity entity, ParcelScene scene)
    {
        List <ComponentPayload> list = new List <ComponentPayload>();

        foreach (KeyValuePair <CLASS_ID_COMPONENT, IEntityComponent> keyValuePair in entity.components)
        {
            ComponentPayload componentPayLoad = new ComponentPayload();
            componentPayLoad.componentId = Convert.ToInt32(keyValuePair.Key);

            if (keyValuePair.Key == CLASS_ID_COMPONENT.TRANSFORM)
            {
                TransformComponent entityComponentModel = new TransformComponent();

                entityComponentModel.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position, scene);
                entityComponentModel.rotation = new QuaternionRepresentation(entity.gameObject.transform.rotation);
                entityComponentModel.scale    = entity.gameObject.transform.localScale;

                componentPayLoad.data = entityComponentModel;
            }
            else
            {
                componentPayLoad.data = keyValuePair.Value.GetModel();
            }

            list.Add(componentPayLoad);
        }

        foreach (KeyValuePair <Type, ISharedComponent> keyValuePairBaseDisposable in entity.sharedComponents)
        {
            ComponentPayload componentPayLoad = new ComponentPayload();

            componentPayLoad.componentId = keyValuePairBaseDisposable.Value.GetClassId();

            if (keyValuePairBaseDisposable.Value.GetClassId() == (int)CLASS_ID.NFT_SHAPE)
            {
                NFTComponent   nftComponent = new NFTComponent();
                NFTShape.Model model        = (NFTShape.Model)keyValuePairBaseDisposable.Value.GetModel();

                nftComponent.color   = new ColorRepresentation(model.color);
                nftComponent.assetId = model.assetId;
                nftComponent.src     = model.src;
                nftComponent.style   = model.style;

                componentPayLoad.data = nftComponent;
            }
            else
            {
                componentPayLoad.data = keyValuePairBaseDisposable.Value.GetModel();
            }


            list.Add(componentPayLoad);
        }

        SendNewEntityToKernel(scene.sceneData.id, entity.entityId, list.ToArray());
    }