| | 1 | | using DCL.Configuration; |
| | 2 | | using DCL.Controllers; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using DCL.Models; |
| | 5 | | using UnityEngine; |
| | 6 | | using Decentraland.Sdk.Ecs6; |
| | 7 | |
|
| | 8 | | namespace DCL.Components |
| | 9 | | { |
| | 10 | | public abstract class BaseShape : BaseDisposable, IShape |
| | 11 | | { |
| | 12 | | [System.Serializable] |
| | 13 | | public class Model : BaseModel |
| | 14 | | { |
| 1091 | 15 | | public bool withCollisions = true; |
| 1091 | 16 | | public bool isPointerBlocker = true; |
| 1091 | 17 | | public bool visible = true; |
| | 18 | |
|
| | 19 | | public override BaseModel GetDataFromJSON(string json) => |
| 0 | 20 | | Utils.SafeFromJson<Model>(json); |
| | 21 | |
|
| | 22 | | public override BaseModel GetDataFromPb(ComponentBodyPayload pbModel) => |
| 0 | 23 | | default; |
| | 24 | | } |
| | 25 | |
|
| 242 | 26 | | protected BaseShape() |
| | 27 | | { |
| 242 | 28 | | model = new Model(); |
| 242 | 29 | | } |
| | 30 | |
|
| | 31 | | public new Model GetModel() => |
| 7 | 32 | | (Model) model; |
| | 33 | |
|
| | 34 | | public override void AttachTo(IDCLEntity entity, System.Type overridenAttachedType = null) |
| | 35 | | { |
| 255 | 36 | | if (attachedEntities.Contains(entity)) |
| 0 | 37 | | return; |
| | 38 | |
|
| | 39 | | //NOTE(Brian): This assignation must be before the base.AttachTo call, or the OnAttach events will receive e |
| | 40 | | // and fail to generate colliders randomly. |
| 255 | 41 | | entity.meshesInfo.currentShape = this; |
| | 42 | |
|
| 255 | 43 | | base.AttachTo(entity, typeof(BaseShape)); |
| 255 | 44 | | } |
| | 45 | |
|
| | 46 | | public override void DetachFrom(IDCLEntity entity, System.Type overridenAttachedType = null) |
| | 47 | | { |
| 195 | 48 | | if (!attachedEntities.Contains(entity)) |
| 0 | 49 | | return; |
| | 50 | |
|
| | 51 | | // We do this instead of OnDetach += because it is required to run after every OnDetach listener |
| 195 | 52 | | entity.meshesInfo.currentShape = null; |
| | 53 | |
|
| 195 | 54 | | base.DetachFrom(entity, typeof(BaseShape)); |
| | 55 | |
|
| 195 | 56 | | entity.OnShapeUpdated?.Invoke(entity); |
| 195 | 57 | | } |
| | 58 | |
|
| 0 | 59 | | public virtual bool IsVisible() { return false; } |
| | 60 | |
|
| 0 | 61 | | public virtual bool HasCollisions() { return false; } |
| | 62 | |
|
| | 63 | | public static void ConfigureVisibility(GameObject meshGameObject, bool shouldBeVisible, Renderer[] meshRenderers |
| | 64 | | { |
| 297 | 65 | | if (meshGameObject == null) |
| 0 | 66 | | return; |
| | 67 | |
|
| 297 | 68 | | if (meshRenderers == null) |
| 0 | 69 | | meshRenderers = meshGameObject.GetComponentsInChildren<Renderer>(true); |
| | 70 | |
|
| 1358 | 71 | | for (var i = 0; i < meshRenderers.Length; i++) |
| | 72 | | { |
| 382 | 73 | | if (meshRenderers[i] == null) |
| | 74 | | continue; |
| | 75 | |
|
| 382 | 76 | | meshRenderers[i].enabled = shouldBeVisible; |
| 382 | 77 | | Transform meshRendererT = meshRenderers[i].transform; |
| | 78 | |
|
| 802 | 79 | | for (int j = 0; j < meshRendererT.transform.childCount; j++) |
| | 80 | | { |
| 19 | 81 | | Collider onPointerEventCollider = meshRendererT.GetChild(j).GetComponent<Collider>(); |
| | 82 | |
|
| 19 | 83 | | if (onPointerEventCollider != null && onPointerEventCollider.gameObject.layer == PhysicsLayers.onPoi |
| 19 | 84 | | onPointerEventCollider.enabled = shouldBeVisible; |
| | 85 | | } |
| | 86 | | } |
| 297 | 87 | | } |
| | 88 | |
|
| | 89 | | protected int CalculateCollidersLayer(Model model) |
| | 90 | | { |
| | 91 | | // We can't enable this layer changer logic until we redeploy all the builder and street scenes with the cor |
| | 92 | | /* if (!model.withCollisions && model.isPointerBlocker) |
| | 93 | | return PhysicsLayers.onPointerEventLayer; |
| | 94 | | else */ |
| 271 | 95 | | if (model.withCollisions && !model.isPointerBlocker) |
| 2 | 96 | | return PhysicsLayers.characterOnlyLayer; |
| | 97 | |
|
| 269 | 98 | | return PhysicsLayers.defaultLayer; |
| | 99 | | } |
| | 100 | | } |
| | 101 | | } |