public void Initialize(DCLBuilderEntity builderEntity, Renderer renderer) { if (renderer == null) { return; } ownerEntity = builderEntity; gameObject.layer = LayerMask.NameToLayer(LAYER_BUILDER_POINTER_CLICK); Transform t = gameObject.transform; t.SetParent(renderer.transform); t.ResetLocalTRS(); var meshCollider = gameObject.AddComponent <MeshCollider>(); if (renderer is SkinnedMeshRenderer) { if (meshColliderForSkinnedMesh) { Object.Destroy(meshColliderForSkinnedMesh); } meshColliderForSkinnedMesh = new Mesh(); (renderer as SkinnedMeshRenderer).BakeMesh(meshColliderForSkinnedMesh); meshCollider.sharedMesh = meshColliderForSkinnedMesh; t.localScale = new Vector3(1 / transform.lossyScale.x, 1 / transform.lossyScale.y, 1 / transform.lossyScale.z); } else { meshCollider.sharedMesh = renderer.GetComponent <MeshFilter>().sharedMesh; } meshCollider.enabled = renderer.enabled; }
private void ProcessEntityPressed(DCLBuilderEntity pressedEntity, Vector3 hitPoint) { if (CanSelect(pressedEntity)) { MarkSelected(pressedEntity); } }
private DCLBuilderEntity AddBuilderEntityComponent(DecentralandEntity entity) { DCLBuilderEntity builderComponent = Utils.GetOrCreateComponent <DCLBuilderEntity>(entity.gameObject); builderComponent.SetEntity(entity); return(builderComponent); }
private void OnEntityAdded(DCLBuilderEntity entity) { if (!entities.ContainsKey(entity.rootEntity.entityId)) { entities.Add(entity.rootEntity.entityId, entity); } }
private void OnBuilderSelectEntity(string[] entitiesId) { List <DCLBuilderEntity> entitiesToDeselect = new List <DCLBuilderEntity>(selectedEntities); for (int i = 0; i < entitiesId.Length; i++) { if (entities.ContainsKey(entitiesId[i])) { DCLBuilderEntity entity = entities[entitiesId[i]]; if (!SelectionParentHasChild(entity.transform)) { Select(entity); } else { entitiesToDeselect.Remove(entity); } } } for (int i = 0; i < entitiesToDeselect.Count; i++) { Deselect(entitiesToDeselect[i]); } }
private void MarkSelected(DCLBuilderEntity entity) { if (entity == null) { return; } OnMarkObjectSelected?.Invoke(entity, gizmosManager.GetSelectedGizmo()); }
private void OnEntityRemoved(DCLBuilderEntity entity) { if (selectedEntities.Contains(entity)) { Deselect(entity); } if (entities.ContainsKey(entity.rootEntity.entityId)) { entities.Remove(entity.rootEntity.entityId); } }
public void SendEntitySelected(DCLBuilderEntity entity, string gizmoType, string sceneId) { onGizmoEventPayload.type = "gizmoSelected"; onGizmoEventPayload.entities = entity ? new string[] { entity.rootEntity.entityId } : null; onGizmoEventPayload.gizmoType = gizmoType != null ? gizmoType : DCLGizmos.Gizmo.NONE; onGizmoEventPayload.transforms = null; if (LOG_MESSAGES) { Debug.Log($"SEND: NotifyGizmosSelectedEvent {JsonUtility.ToJson(onGizmoEventPayload)}"); } WebInterface.SendSceneEvent(sceneId, "gizmoEvent", onGizmoEventPayload); }
private void Deselect(DCLBuilderEntity entity) { if (entity != null) { SelectionParentRemoveEntity(entity); OnDeselectedObject?.Invoke(entity); entity.SetDefaultLayer(); } if (selectedEntities.Contains(entity)) { selectedEntities.Remove(entity); } isDirty = true; }
private void OnEntityPressed(DCLBuilderEntity entity, Vector3 hitPoint) { if (selectedEntities == null || !selectedEntities.Contains(entity)) { return; } OnDraggingObjectStart?.Invoke(); initialHitPoint = hitPoint; targetOffset = selectedEntitiesParent.position - hitPoint; builderRaycast.SetEntityHitPlane(hitPoint.y); isDragging = true; }
private void OnMouseDown(int buttonId, Vector3 mousePosition) { if (buttonId != 0) { return; } bool gizmoOrEntityPressed = false; RaycastHit hit; if (builderRaycast.Raycast(mousePosition, builderRaycast.defaultMask | builderRaycast.gizmoMask, out hit, CompareSelectionHit)) { DCLBuilderGizmoAxis gizmosAxis = hit.collider.gameObject.GetComponent <DCLBuilderGizmoAxis>(); if (gizmosAxis != null) { OnGizmosAxisPressed?.Invoke(gizmosAxis); gizmoOrEntityPressed = true; } else { var builderSelectionCollider = hit.collider.gameObject.GetComponent <DCLBuilderSelectionCollider>(); DCLBuilderEntity pressedEntity = null; if (builderSelectionCollider != null) { pressedEntity = builderSelectionCollider.ownerEntity; } if (pressedEntity != null && CanSelect(pressedEntity)) { SetLastPressedEntity(pressedEntity, hit.point); OnEntityPressed?.Invoke(pressedEntity, hit.point); gizmoOrEntityPressed = true; } } } if (gizmoOrEntityPressed) { groundClickTime = 0; } else { groundClickTime = Time.unscaledTime; } }
private void Select(DCLBuilderEntity entity) { if (entity == null) { return; } if (!selectedEntities.Contains(entity)) { selectedEntities.Add(entity); } SelectionParentAddEntity(entity); entity.SetSelectLayer(); OnSelectedObject?.Invoke(entity, gizmosManager.GetSelectedGizmo()); isDirty = true; }
private void ProcessEntityBoundaries(DCLBuilderEntity entity) { string entityId = entity.rootEntity.entityId; int entityIndexInList = outOfBoundariesEntitiesId.IndexOf(entityId); bool wasInsideSceneBoundaries = entityIndexInList == -1; bool isInsideSceneBoundaries = entity.IsInsideSceneBoundaries(); if (wasInsideSceneBoundaries && !isInsideSceneBoundaries) { outOfBoundariesEntitiesId.Add(entityId); } else if (!wasInsideSceneBoundaries && isInsideSceneBoundaries) { outOfBoundariesEntitiesId.RemoveAt(entityIndexInList); } Environment.i.world.sceneBoundsChecker?.EvaluateEntityPosition(entity.rootEntity); }
private void NotifyGizmosSelectedEvent(DCLBuilderEntity entity, string gizmoType) { builderWebInterface.SendEntitySelected(entity, gizmoType, currentScene.sceneData.id); }
private void OnObjectSelected(DCLBuilderEntity entity, string gizmoType) { NotifyGizmosSelectedEvent(entity, gizmoType); }
private void SelectionParentRemoveEntity(DCLBuilderEntity entity) { SelectionParentRemoveEntity(entity.transform); }
private void SetLastPressedEntity(DCLBuilderEntity pressedEntity, Vector3 hitPoint) { lastPressedEntityInfo.pressedEntity = pressedEntity; lastPressedEntityInfo.pressedTime = Time.unscaledTime; lastPressedEntityInfo.hitPoint = hitPoint; }
private bool CanSelect(DCLBuilderEntity entity) { return(entity.hasGizmoComponent); }
private DCLBuilderEntity AddBuilderEntityComponent(IDCLEntity entity) { DCLBuilderEntity builderComponent = Utils.GetOrCreateComponent<DCLBuilderEntity>(entity.gameObject); builderComponent.SetEntity(entity); return builderComponent; }