| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using DCL.Models; |
| | 6 | | using DCLPlugins.UUIDEventComponentsPlugin.UUIDComponent.Interfaces; |
| | 7 | |
|
| | 8 | | namespace DCL.Components |
| | 9 | | { |
| | 10 | | public class OnPointerHoverEvent : UUIDComponent, IPointerEvent |
| | 11 | | { |
| | 12 | | [Serializable] |
| | 13 | | public new class Model : UUIDComponent.Model |
| | 14 | | { |
| 21 | 15 | | public float distance = 10f; |
| | 16 | |
|
| | 17 | | public override BaseModel GetDataFromJSON(string json) |
| | 18 | | { |
| 21 | 19 | | return Utils.SafeFromJson<Model>(json); |
| | 20 | | } |
| | 21 | | } |
| | 22 | |
|
| | 23 | | internal OnPointerEventColliders pointerEventColliders; |
| | 24 | |
|
| 0 | 25 | | protected override string uuidComponentName { get; } |
| | 26 | |
|
| | 27 | | public override void Initialize(IParcelScene scene, IDCLEntity entity) |
| | 28 | | { |
| 21 | 29 | | base.Initialize(scene, entity); |
| | 30 | |
|
| 21 | 31 | | if (model == null) |
| 21 | 32 | | model = new Model(); |
| | 33 | |
|
| 21 | 34 | | pointerEventColliders = new OnPointerEventColliders(); |
| 21 | 35 | | SetEventColliders(entity); |
| | 36 | |
|
| 21 | 37 | | entity.OnShapeUpdated -= SetEventColliders; |
| 21 | 38 | | entity.OnShapeUpdated += SetEventColliders; |
| 21 | 39 | | } |
| | 40 | |
|
| | 41 | | public virtual void SetHoverState(bool hoverState) |
| | 42 | | { |
| 0 | 43 | | } |
| | 44 | |
|
| | 45 | | void SetEventColliders(IDCLEntity entity) |
| | 46 | | { |
| 33 | 47 | | pointerEventColliders.Initialize(entity); |
| 33 | 48 | | } |
| | 49 | |
|
| | 50 | | public bool IsVisible() |
| | 51 | | { |
| 7 | 52 | | if (entity == null) |
| 0 | 53 | | return false; |
| | 54 | |
|
| 7 | 55 | | bool isVisible = false; |
| | 56 | |
|
| 7 | 57 | | if (entity.meshesInfo != null && |
| | 58 | | entity.meshesInfo.renderers != null && |
| | 59 | | entity.meshesInfo.renderers.Length > 0) |
| | 60 | | { |
| 7 | 61 | | isVisible = entity.meshesInfo.renderers[0].enabled; |
| | 62 | | } |
| | 63 | |
|
| 7 | 64 | | return isVisible; |
| | 65 | | } |
| | 66 | |
|
| | 67 | | public bool IsAtHoverDistance(float distance) |
| | 68 | | { |
| 7 | 69 | | Model model = this.model as Model; |
| 7 | 70 | | return distance <= model.distance; |
| | 71 | | } |
| | 72 | |
|
| | 73 | | public override IEnumerator ApplyChanges(BaseModel newModel) |
| | 74 | | { |
| 21 | 75 | | this.model = newModel ?? new Model(); |
| 21 | 76 | | return null; |
| | 77 | | } |
| | 78 | |
|
| | 79 | | void OnDestroy() |
| | 80 | | { |
| 21 | 81 | | if (entity != null) |
| 21 | 82 | | entity.OnShapeUpdated -= SetEventColliders; |
| | 83 | |
|
| 21 | 84 | | pointerEventColliders.Dispose(); |
| 21 | 85 | | } |
| | 86 | | } |
| | 87 | | } |