public IEntityComponent EntityComponentCreateOrUpdateWithModel(string entityId, CLASS_ID_COMPONENT classId, object data) { IDCLEntity entity = GetEntityForUpdate(entityId); if (entity == null) { Debug.LogError($"scene '{sceneData.id}': Can't create entity component if the entity {entityId} doesn't exist!"); return(null); } IEntityComponent newComponent = null; if (classId == CLASS_ID_COMPONENT.UUID_CALLBACK) { OnPointerEvent.Model model = JsonUtility.FromJson <OnPointerEvent.Model>(data as string); classId = model.GetClassIdFromType(); } if (!entity.components.ContainsKey(classId)) { var factory = Environment.i.world.componentFactory; newComponent = factory.CreateComponent((int)classId) as IEntityComponent; if (newComponent != null) { entity.components.Add(classId, newComponent); OnComponentAdded?.Invoke(newComponent); newComponent.Initialize(this, entity); if (data is string json) { newComponent.UpdateFromJSON(json); } else { newComponent.UpdateFromModel(data as BaseModel); } } } else { newComponent = EntityComponentUpdate(entity, classId, data as string); } if (newComponent != null && newComponent is IOutOfSceneBoundariesHandler) { Environment.i.world.sceneBoundsChecker?.AddEntityToBeChecked(entity); } OnChanged?.Invoke(); Environment.i.platform.physicsSyncController.MarkDirty(); Environment.i.platform.cullingController.MarkDirty(); return(newComponent); }
public IEnumerator NotCreateCollidersOnLoadingShape() { // 1. Instantiate entity and add an OnPointerDown component string entityId = "1"; var entity = TestHelpers.CreateSceneEntity(scene, entityId); string onPointerId = "pointerevent-1"; var model = new OnPointerEvent.Model() { type = OnPointerDown.NAME, uuid = onPointerId }; var onPointerDownComponent = TestHelpers.EntityComponentCreate <OnPointerDown, OnPointerEvent.Model>(scene, entity, model, CLASS_ID_COMPONENT.UUID_CALLBACK); // 2. Attach a shape var shapeModel = new LoadableShape.Model(); shapeModel.src = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb"; var componentId = TestHelpers.CreateAndSetShape(scene, entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeObject(shapeModel)); // 3. Change a shape component property while it loads shapeModel.visible = false; TestHelpers.UpdateShape(scene, componentId, JsonConvert.SerializeObject(shapeModel)); var pointerEventColliders = onPointerDownComponent.pointerEventHandler.eventColliders.colliders; Assert.IsTrue(pointerEventColliders == null || pointerEventColliders.Length == 0); LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(scene.entities[entityId]); yield return(new WaitUntil(() => gltfShape.alreadyLoaded)); // 4. Check if the PointerEvent colliders were created pointerEventColliders = onPointerDownComponent.pointerEventHandler.eventColliders.colliders; Assert.IsTrue(pointerEventColliders != null && pointerEventColliders.Length > 0); }
public BaseComponent EntityComponentCreateOrUpdate(string entityId, string name, int classIdNum, string data, out CleanableYieldInstruction yieldInstruction) { yieldInstruction = null; SceneController.i.OnMessageDecodeStart?.Invoke("UpdateEntityComponent"); createEntityComponentMessage.name = name; createEntityComponentMessage.classId = classIdNum; createEntityComponentMessage.entityId = entityId; createEntityComponentMessage.json = data; SceneController.i.OnMessageDecodeEnds?.Invoke("UpdateEntityComponent"); DecentralandEntity entity = GetEntityForUpdate(createEntityComponentMessage.entityId); if (entity == null) { Debug.LogError($"scene '{sceneData.id}': Can't create entity component if the entity {createEntityComponentMessage.entityId} doesn't exist!"); return(null); } CLASS_ID_COMPONENT classId = (CLASS_ID_COMPONENT)createEntityComponentMessage.classId; if (classId == CLASS_ID_COMPONENT.TRANSFORM) { MessageDecoder.DecodeTransform(data, ref DCLTransform.model); if (entity.OnTransformChange != null) { entity.OnTransformChange.Invoke(DCLTransform.model); } else { entity.gameObject.transform.localPosition = DCLTransform.model.position; entity.gameObject.transform.localRotation = DCLTransform.model.rotation; entity.gameObject.transform.localScale = DCLTransform.model.scale; SceneController.i.boundariesChecker?.AddEntityToBeChecked(entity); } return(null); } BaseComponent newComponent = null; DCLComponentFactory factory = ownerController.componentFactory; Assert.IsNotNull(factory, "Factory is null?"); // HACK: (Zak) will be removed when we separate each // uuid component as a different class id if (classId == CLASS_ID_COMPONENT.UUID_CALLBACK) { string type = ""; OnPointerEvent.Model model = JsonUtility.FromJson <OnPointerEvent.Model>(createEntityComponentMessage.json); type = model.type; if (!entity.uuidComponents.ContainsKey(type)) { //NOTE(Brian): We have to contain it in a gameObject or it will be pooled with the components attached. var go = new GameObject("UUID Component"); go.transform.SetParent(entity.gameObject.transform, false); switch (type) { case OnClick.NAME: newComponent = Utils.GetOrCreateComponent <OnClick>(go); break; case OnPointerDown.NAME: newComponent = Utils.GetOrCreateComponent <OnPointerDown>(go); break; case OnPointerUp.NAME: newComponent = Utils.GetOrCreateComponent <OnPointerUp>(go); break; } if (newComponent != null) { UUIDComponent uuidComponent = newComponent as UUIDComponent; if (uuidComponent != null) { uuidComponent.Setup(this, entity, model); entity.uuidComponents.Add(type, uuidComponent); } else { Debug.LogError("uuidComponent is not of UUIDComponent type!"); } } else { Debug.LogError("EntityComponentCreateOrUpdate: Invalid UUID type!"); } } else { newComponent = EntityUUIDComponentUpdate(entity, type, model); } } else { if (!entity.components.ContainsKey(classId)) { newComponent = factory.CreateItemFromId <BaseComponent>(classId); if (newComponent != null) { newComponent.scene = this; newComponent.entity = entity; entity.components.Add(classId, newComponent); newComponent.transform.SetParent(entity.gameObject.transform, false); newComponent.UpdateFromJSON(createEntityComponentMessage.json); } } else { newComponent = EntityComponentUpdate(entity, classId, createEntityComponentMessage.json); } } if (newComponent != null && newComponent.isRoutineRunning) { yieldInstruction = newComponent.yieldInstruction; } return(newComponent); }
public BaseComponent EntityComponentCreateOrUpdateFromUnity(string entityId, CLASS_ID_COMPONENT classId, object data) { DecentralandEntity entity = GetEntityForUpdate(entityId); if (entity == null) { Debug.LogError($"scene '{sceneData.id}': Can't create entity component if the entity {entityId} doesn't exist!"); return(null); } if (classId == CLASS_ID_COMPONENT.TRANSFORM) { if (!(data is DCLTransform.Model)) { Debug.LogError("Data is not a DCLTransform.Model type!"); return(null); } DCLTransform.Model modelRecovered = (DCLTransform.Model)data; if (!entity.components.ContainsKey(classId)) { entity.components.Add(classId, null); } if (entity.OnTransformChange != null) { entity.OnTransformChange.Invoke(modelRecovered); } else { entity.gameObject.transform.localPosition = modelRecovered.position; entity.gameObject.transform.localRotation = modelRecovered.rotation; entity.gameObject.transform.localScale = modelRecovered.scale; Environment.i.world.sceneBoundsChecker?.AddEntityToBeChecked(entity); } Environment.i.platform.physicsSyncController.MarkDirty(); Environment.i.platform.cullingController.MarkDirty(); return(null); } BaseComponent newComponent = null; IRuntimeComponentFactory factory = ownerController.componentFactory; Assert.IsNotNull(factory, "Factory is null?"); if (classId == CLASS_ID_COMPONENT.UUID_CALLBACK) { string type = ""; if (!(data is OnPointerEvent.Model)) { Debug.LogError("Data is not a DCLTransform.Model type!"); return(null); } OnPointerEvent.Model model = (OnPointerEvent.Model)data; type = model.type; if (!entity.uuidComponents.ContainsKey(type)) { //NOTE(Brian): We have to contain it in a gameObject or it will be pooled with the components attached. var go = new GameObject("UUID Component"); go.transform.SetParent(entity.gameObject.transform, false); switch (type) { case OnClick.NAME: newComponent = go.GetOrCreateComponent <OnClick>(); break; case OnPointerDown.NAME: newComponent = go.GetOrCreateComponent <OnPointerDown>(); break; case OnPointerUp.NAME: newComponent = go.GetOrCreateComponent <OnPointerUp>(); break; } if (newComponent != null) { UUIDComponent uuidComponent = newComponent as UUIDComponent; if (uuidComponent != null) { uuidComponent.Setup(this, entity, model); entity.uuidComponents.Add(type, uuidComponent); } else { Debug.LogError("uuidComponent is not of UUIDComponent type!"); } } else { Debug.LogError("EntityComponentCreateOrUpdate: Invalid UUID type!"); } } else { newComponent = EntityUUIDComponentUpdate(entity, type, model); } } else { if (!entity.components.ContainsKey(classId)) { newComponent = factory.CreateItemFromId <BaseComponent>(classId); if (newComponent != null) { newComponent.scene = this; newComponent.entity = entity; entity.components.Add(classId, newComponent); newComponent.transform.SetParent(entity.gameObject.transform, false); newComponent.UpdateFromJSON((string)data); } } else { newComponent = EntityComponentUpdate(entity, classId, (string)data); } } Environment.i.platform.physicsSyncController.MarkDirty(); Environment.i.platform.cullingController.MarkDirty(); return(newComponent); }