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