Ejemplo n.º 1
0
    public DCLBuilderInWorldEntity CreateEmptyEntity(ParcelScene parcelScene, Vector3 entryPoint, Vector3 editionGOPosition, bool notifyEntityList = true)
    {
        IDCLEntity newEntity = parcelScene.CreateEntity(Guid.NewGuid().ToString());

        DCLTransform.model.position = WorldStateUtils.ConvertUnityToScenePosition(entryPoint, parcelScene);

        Vector3 pointToLookAt = Camera.main.transform.position;

        pointToLookAt.y = editionGOPosition.y;
        Quaternion lookOnLook = Quaternion.LookRotation(editionGOPosition - pointToLookAt);

        DCLTransform.model.rotation = lookOnLook;
        DCLTransform.model.scale    = newEntity.gameObject.transform.lossyScale;

        parcelScene.EntityComponentCreateOrUpdateWithModel(newEntity.entityId, CLASS_ID_COMPONENT.TRANSFORM, DCLTransform.model);

        DCLBuilderInWorldEntity convertedEntity = SetupEntityToEdit(newEntity, true);

        hudController?.UpdateSceneLimitInfo();

        if (notifyEntityList)
        {
            EntityListChanged();
        }
        return(convertedEntity);
    }
Ejemplo n.º 2
0
        public static DecentralandEntity CreateSceneEntity(ParcelScene scene)
        {
            entityCounter++;
            string id = $"{entityCounter}";

            return(scene.CreateEntity(id));
        }
Ejemplo n.º 3
0
        public static DecentralandEntity CreateSceneEntity(ParcelScene scene)
        {
            Assert.IsNotNull(scene, "Can't create entity for null scene!");

            entityCounter++;
            string id = $"{entityCounter}";

            return(scene.CreateEntity(id));
        }
    public DecentralandEntity CreateEntityFromJSON(string entityJson)
    {
        EntityData data = BuilderInWorldUtils.ConvertJSONToEntityData(entityJson);

        DecentralandEntity newEntity = sceneToEdit.CreateEntity(data.entityId);


        if (data.transformComponent != null)
        {
            DCLTransform.model.position = data.transformComponent.position;
            DCLTransform.model.rotation = Quaternion.Euler(data.transformComponent.rotation);
            DCLTransform.model.scale    = data.transformComponent.scale;
            sceneToEdit.EntityComponentCreateOrUpdateFromUnity(newEntity.entityId, CLASS_ID_COMPONENT.TRANSFORM, DCLTransform.model);
        }

        foreach (ProtocolV2.GenericComponent component in data.components)
        {
            sceneToEdit.EntityComponentCreateOrUpdateFromUnity(newEntity.entityId, (CLASS_ID_COMPONENT)component.componentId, component.data);
        }


        foreach (ProtocolV2.GenericComponent component in data.sharedComponents)
        {
            sceneToEdit.SharedComponentAttach(newEntity.entityId, component.classId);
        }


        if (data.nftComponent != null)
        {
            NFTShape nftShape = (NFTShape)sceneToEdit.SharedComponentCreate(data.nftComponent.id, Convert.ToInt32(CLASS_ID.NFT_SHAPE));
            nftShape.model         = new NFTShape.Model();
            nftShape.model.color   = data.nftComponent.color.ToColor();
            nftShape.model.src     = data.nftComponent.src;
            nftShape.model.assetId = data.nftComponent.assetId;

            sceneToEdit.SharedComponentAttach(newEntity.entityId, nftShape.id);
        }

        SetupEntityToEdit(newEntity, true);
        EntityListChanged();
        return(newEntity);
    }
Ejemplo n.º 5
0
        /// <summary>
        /// Instantiates an entity with an AvatarShape component, with randomized wearables, at the given position
        /// </summary>
        /// <param name="position">The world position of the randomized bot</param>
        void InstantiateBot(Vector3 position)
        {
            string entityId = "BOT-" + instantiatedBots.Count;

            AvatarModel avatarModel = new AvatarModel()
            {
                id        = entityId,
                name      = entityId,
                hairColor = Color.white,
                eyeColor  = Color.white,
                skinColor = Color.white,
                bodyShape = Random.Range(0, 2) == 0 ? WearableLiterals.BodyShapes.FEMALE : WearableLiterals.BodyShapes.MALE,
                wearables = GetRandomizedWearablesSet()
            };

            globalScene.CreateEntity(entityId);
            globalScene.EntityComponentCreateOrUpdateWithModel(entityId, CLASS_ID_COMPONENT.AVATAR_SHAPE, avatarModel);
            UpdateEntityTransform(globalScene, entityId, position, Quaternion.identity, Vector3.one);

            instantiatedBots.Add(entityId);
        }
    public DCLBuilderInWorldEntity CreateEmptyEntity(ParcelScene parcelScene, Vector3 entryPoint, Vector3 editionGOPosition)
    {
        DecentralandEntity newEntity = parcelScene.CreateEntity(Guid.NewGuid().ToString());

        DCLTransform.model.position = Environment.i.world.state.ConvertUnityToScenePosition(entryPoint, parcelScene);

        Vector3 pointToLookAt = Camera.main.transform.position;

        pointToLookAt.y = editionGOPosition.y;
        Quaternion lookOnLook = Quaternion.LookRotation(editionGOPosition - pointToLookAt);

        DCLTransform.model.rotation = lookOnLook;
        DCLTransform.model.scale    = newEntity.gameObject.transform.lossyScale;

        parcelScene.EntityComponentCreateOrUpdateFromUnity(newEntity.entityId, CLASS_ID_COMPONENT.TRANSFORM, DCLTransform.model);

        DCLBuilderInWorldEntity convertedEntity = SetupEntityToEdit(newEntity, true);

        HUDController.i.builderInWorldMainHud.UpdateSceneLimitInfo();

        EntityListChanged();
        return(convertedEntity);
    }
Ejemplo n.º 7
0
 public static DecentralandEntity CreateSceneEntity(ParcelScene scene, string id)
 {
     return(scene.CreateEntity(id));
 }
Ejemplo n.º 8
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;
                }
            }
        }