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); }
private void SetHitInfo(ref HitInfo hitInfo, RaycastHit hit, IParcelScene scene) { hitInfo.point = WorldStateUtils.ConvertUnityToScenePosition(hit.point, scene); hitInfo.distance = hit.distance; hitInfo.normal = hit.normal; hitInfo.collider = hit.collider; }
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)); }
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()); }
public DecentralandEntity DuplicateEntity(DecentralandEntity entity) { if (!entities.ContainsKey(entity.entityId)) { return(null); } DecentralandEntity newEntity = CreateEntity(System.Guid.NewGuid().ToString()); if (entity.children.Count > 0) { using (var iterator = entity.children.GetEnumerator()) { while (iterator.MoveNext()) { DecentralandEntity childDuplicate = DuplicateEntity(iterator.Current.Value); childDuplicate.SetParent(newEntity); } } } if (entity.parent != null) { SetEntityParent(newEntity.entityId, entity.parent.entityId); } DCLTransform.model.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position); DCLTransform.model.rotation = entity.gameObject.transform.rotation; DCLTransform.model.scale = entity.gameObject.transform.lossyScale; foreach (KeyValuePair <CLASS_ID_COMPONENT, BaseComponent> component in entity.components) { EntityComponentCreateOrUpdateFromUnity(newEntity.entityId, component.Key, DCLTransform.model); } foreach (KeyValuePair <System.Type, BaseDisposable> component in entity.GetSharedComponents()) { BaseDisposable baseDisposable = SharedComponentCreate(System.Guid.NewGuid().ToString(), component.Value.GetClassId()); string jsonModel = Newtonsoft.Json.JsonConvert.SerializeObject(component.Value.GetModel()); baseDisposable.UpdateFromJSON(jsonModel); SharedComponentAttach(newEntity.entityId, baseDisposable.id); } //NOTE: (Adrian) Evaluate if all created components should be handle as equals instead of different foreach (KeyValuePair <string, UUIDComponent> component in entity.uuidComponents) { EntityComponentCreateOrUpdateFromUnity(newEntity.entityId, CLASS_ID_COMPONENT.UUID_CALLBACK, component.Value.model); } return(newEntity); }
public void UpdateInfo(BIWEntity entity) { if (entity != null && entity.rootEntity.gameObject != null) { Vector3 positionConverted = WorldStateUtils.ConvertUnityToScenePosition(entity.rootEntity.gameObject.transform.position, parcelScene); Vector3 currentRotation = entity.rootEntity.gameObject.transform.rotation.eulerAngles; Vector3 currentScale = entity.rootEntity.gameObject.transform.lossyScale; currentRotation = entity.GetEulerRotation(); entityInformationView.SetPositionAttribute(positionConverted); entityInformationView.SetRotationAttribute(currentRotation); entityInformationView.SetScaleAttribute(currentScale); } }
public static IDCLEntity DuplicateEntity(ParcelScene scene, IDCLEntity entity) { if (!scene.entities.ContainsKey(entity.entityId)) { return(null); } IDCLEntity newEntity = scene.CreateEntity(System.Guid.NewGuid().ToString()); if (entity.children.Count > 0) { using (var iterator = entity.children.GetEnumerator()) { while (iterator.MoveNext()) { IDCLEntity childDuplicate = DuplicateEntity(scene, iterator.Current.Value); childDuplicate.SetParent(newEntity); } } } if (entity.parent != null) { scene.SetEntityParent(newEntity.entityId, entity.parent.entityId); } DCLTransform.model.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position); DCLTransform.model.rotation = entity.gameObject.transform.rotation; DCLTransform.model.scale = entity.gameObject.transform.lossyScale; foreach (KeyValuePair <CLASS_ID_COMPONENT, IEntityComponent> component in entity.components) { scene.EntityComponentCreateOrUpdateWithModel(newEntity.entityId, component.Key, component.Value.GetModel()); } foreach (KeyValuePair <System.Type, ISharedComponent> component in entity.sharedComponents) { ISharedComponent sharedComponent = scene.SharedComponentCreate(System.Guid.NewGuid().ToString(), component.Value.GetClassId()); sharedComponent.UpdateFromModel(component.Value.GetModel()); scene.SharedComponentAttach(newEntity.entityId, sharedComponent.id); } return(newEntity); }
public void UpdateInfo(DCLBuilderInWorldEntity entity) { if (entity != null && entity.gameObject != null) { Vector3 positionConverted = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position, parcelScene); Vector3 currentRotation = entity.gameObject.transform.rotation.eulerAngles; Vector3 currentScale = entity.gameObject.transform.localScale; var newEuler = currentRotation; newEuler.x = RepeatWorking(newEuler.x - currentRotation.x + 180.0F, 360.0F) + currentRotation.x - 180.0F; newEuler.y = RepeatWorking(newEuler.y - currentRotation.y + 180.0F, 360.0F) + currentRotation.y - 180.0F; newEuler.z = RepeatWorking(newEuler.z - currentRotation.z + 180.0F, 360.0F) + currentRotation.z - 180.0F; currentRotation = newEuler; entityInformationView.SetPositionAttribute(positionConverted); entityInformationView.SetRotationAttribute(currentRotation); entityInformationView.SetScaleAttribute(currentScale); } }
public void EntityTransformReport(IDCLEntity entity, ParcelScene scene) { entitySingleComponentPayload.entityId = entity.entityId; entitySingleComponentPayload.componentId = (int)CLASS_ID_COMPONENT.TRANSFORM; entityTransformComponentModel.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position, scene); entityTransformComponentModel.rotation = new QuaternionRepresentation(entity.gameObject.transform.rotation); entityTransformComponentModel.scale = entity.gameObject.transform.localScale; entitySingleComponentPayload.data = entityTransformComponentModel; modifyEntityComponentEvent.payload = entitySingleComponentPayload; WebInterface.SceneEvent <ModifyEntityComponentEvent> sceneEvent = new WebInterface.SceneEvent <ModifyEntityComponentEvent>(); sceneEvent.sceneId = scene.sceneData.id; sceneEvent.eventType = BuilderInWorldSettings.STATE_EVENT_NAME; sceneEvent.payload = modifyEntityComponentEvent; //Note (Adrian): We use Newtonsoft instead of JsonUtility because we need to deal with super classes, JsonUtility doesn't encode them string message = JsonConvert.SerializeObject(sceneEvent); WebInterface.BuilderInWorldMessage(BuilderInWorldSettings.SCENE_EVENT_NAME, message); }