| | 1 | | using DCL.Components; |
| | 2 | | using DCL.Models; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace DCL.Controllers |
| | 6 | | { |
| | 7 | | public static class DCLVideoTextureUtils |
| | 8 | | { |
| | 9 | | public static float GetClosestDistanceSqr(ISharedComponent disposableComponent, Vector3 fromPosition) |
| | 10 | | { |
| 9 | 11 | | float dist = int.MaxValue; |
| | 12 | |
|
| 9 | 13 | | if (disposableComponent.GetAttachedEntities().Count <= 0) |
| 0 | 14 | | return dist; |
| | 15 | |
|
| 9 | 16 | | using (var iterator = disposableComponent.GetAttachedEntities().GetEnumerator()) |
| | 17 | | { |
| 18 | 18 | | while (iterator.MoveNext()) |
| | 19 | | { |
| 9 | 20 | | IDCLEntity entity = iterator.Current; |
| | 21 | |
|
| 9 | 22 | | if (IsEntityVisible(iterator.Current)) |
| | 23 | | { |
| 9 | 24 | | var entityDist = (entity.meshRootGameObject.transform.position - fromPosition).sqrMagnitude; |
| 9 | 25 | | if (entityDist < dist) |
| 9 | 26 | | dist = entityDist; |
| | 27 | | } |
| | 28 | | } |
| 9 | 29 | | } |
| | 30 | |
|
| 9 | 31 | | return dist; |
| | 32 | | } |
| | 33 | |
|
| | 34 | | public static bool IsComponentVisible(ISharedComponent disposableComponent) |
| | 35 | | { |
| 32 | 36 | | if (disposableComponent.GetAttachedEntities().Count <= 0) |
| 11 | 37 | | return false; |
| | 38 | |
|
| 21 | 39 | | using (var iterator = disposableComponent.GetAttachedEntities().GetEnumerator()) |
| | 40 | | { |
| 33 | 41 | | while (iterator.MoveNext()) |
| | 42 | | { |
| 21 | 43 | | bool isEntityVisible = IsEntityVisible(iterator.Current); |
| | 44 | |
|
| 21 | 45 | | if (isEntityVisible) |
| 9 | 46 | | return true; |
| | 47 | | } |
| 12 | 48 | | } |
| | 49 | |
|
| 12 | 50 | | return false; |
| 9 | 51 | | } |
| | 52 | |
|
| | 53 | | public static bool IsEntityVisible(IDCLEntity entity) |
| | 54 | | { |
| 30 | 55 | | if (entity.meshesInfo == null) |
| 0 | 56 | | return false; |
| | 57 | |
|
| 30 | 58 | | if (entity.meshesInfo.currentShape == null) |
| 10 | 59 | | return false; |
| | 60 | |
|
| 20 | 61 | | return entity.meshesInfo.currentShape.IsVisible(); |
| | 62 | | } |
| | 63 | |
|
| | 64 | | public static void UnsubscribeToEntityShapeUpdate(ISharedComponent component, |
| | 65 | | System.Action<IDCLEntity> OnUpdate) |
| | 66 | | { |
| 3 | 67 | | if (component.GetAttachedEntities().Count <= 0) |
| 1 | 68 | | return; |
| | 69 | |
|
| 2 | 70 | | using (var iterator = component.GetAttachedEntities().GetEnumerator()) |
| | 71 | | { |
| 4 | 72 | | while (iterator.MoveNext()) |
| | 73 | | { |
| 2 | 74 | | var entity = iterator.Current; |
| 2 | 75 | | entity.OnShapeUpdated -= OnUpdate; |
| | 76 | | } |
| 2 | 77 | | } |
| 2 | 78 | | } |
| | 79 | |
|
| | 80 | | public static void SubscribeToEntityUpdates(ISharedComponent component, System.Action<IDCLEntity> OnUpdate) |
| | 81 | | { |
| 13 | 82 | | if (component.GetAttachedEntities().Count <= 0) |
| 2 | 83 | | return; |
| | 84 | |
|
| 11 | 85 | | using (var iterator = component.GetAttachedEntities().GetEnumerator()) |
| | 86 | | { |
| 22 | 87 | | while (iterator.MoveNext()) |
| | 88 | | { |
| 11 | 89 | | var entity = iterator.Current; |
| 11 | 90 | | entity.OnShapeUpdated -= OnUpdate; |
| 11 | 91 | | entity.OnShapeUpdated += OnUpdate; |
| | 92 | | } |
| 11 | 93 | | } |
| 11 | 94 | | } |
| | 95 | | } |
| | 96 | | } |