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