| | 1 | | using DCL.ECS7.InternalComponents; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Models; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace ECSSystems.ECSSceneBoundsCheckerSystem |
| | 8 | | { |
| | 9 | | public class ECSOutOfSceneBoundsFeedback_RedWireframe : IECSOutOfSceneBoundsFeedbackStyle |
| | 10 | | { |
| | 11 | | const string WIREFRAME_PREFAB_NAME = "Prefabs/WireframeCubeMesh"; |
| | 12 | |
|
| 0 | 13 | | private Dictionary<IDCLEntity, GameObject> wireframeGameObjects = new Dictionary<IDCLEntity, GameObject>(); |
| | 14 | |
|
| | 15 | | public void ApplyFeedback(IDCLEntity entity, InternalSceneBoundsCheck sbcComponentModel, bool isVisible, bool is |
| | 16 | | { |
| 0 | 17 | | if (isInsideBounds) |
| 0 | 18 | | RemoveInvalidMeshEffect(entity); |
| | 19 | | else |
| 0 | 20 | | AddInvalidMeshEffect(entity, sbcComponentModel); |
| | 21 | |
|
| 0 | 22 | | KeyValueSet<Collider, uint> physicsColliders = sbcComponentModel.physicsColliders; |
| 0 | 23 | | KeyValueSet<Collider, uint> pointerColliders = sbcComponentModel.pointerColliders; |
| | 24 | |
|
| 0 | 25 | | if (physicsColliders != null) |
| | 26 | | { |
| 0 | 27 | | var pairs = physicsColliders.Pairs; |
| 0 | 28 | | for (int i = 0; i < pairs.Count; i++) |
| | 29 | | { |
| 0 | 30 | | pairs[i].key.enabled = isInsideBounds; |
| | 31 | | } |
| | 32 | | } |
| | 33 | |
|
| 0 | 34 | | if (pointerColliders != null) |
| | 35 | | { |
| 0 | 36 | | var pairs = pointerColliders.Pairs; |
| 0 | 37 | | for (int i = 0; i < pairs.Count; i++) |
| | 38 | | { |
| 0 | 39 | | pairs[i].key.enabled = isInsideBounds; |
| | 40 | | } |
| | 41 | | } |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | private void AddInvalidMeshEffect(IDCLEntity entity, InternalSceneBoundsCheck sbcComponentModel) |
| | 45 | | { |
| 0 | 46 | | if (wireframeGameObjects.ContainsKey(entity)) return; |
| | 47 | |
|
| | 48 | | // Wireframe that shows the boundaries to the dev (We don't use the GameObject.Instantiate(prefab, parent) |
| | 49 | | // overload because we need to set the position and scale before parenting, to deal with scaled objects) |
| 0 | 50 | | wireframeGameObjects.Add(entity, PutWireframeAroundObject(sbcComponentModel.entityLocalMeshBounds, entity.ga |
| 0 | 51 | | } |
| | 52 | |
|
| | 53 | | private void RemoveInvalidMeshEffect(IDCLEntity entity) |
| | 54 | | { |
| 0 | 55 | | if (!wireframeGameObjects.ContainsKey(entity)) return; |
| | 56 | |
|
| 0 | 57 | | Utils.SafeDestroy(wireframeGameObjects[entity]); |
| 0 | 58 | | wireframeGameObjects.Remove(entity); |
| 0 | 59 | | } |
| | 60 | |
|
| | 61 | | private GameObject PutWireframeAroundObject(Bounds target, Transform parent) |
| | 62 | | { |
| | 63 | | // Wireframe that shows the boundaries to the dev (We don't use the GameObject.Instantiate(prefab, parent) |
| | 64 | | // overload because we need to set the position and scale before parenting, to deal with scaled objects) |
| 0 | 65 | | GameObject wireframeGO = Object.Instantiate(Resources.Load<GameObject>(WIREFRAME_PREFAB_NAME)); |
| 0 | 66 | | wireframeGO.transform.localScale = target.size * 1.01f; |
| 0 | 67 | | wireframeGO.transform.SetParent(parent); |
| 0 | 68 | | wireframeGO.transform.localPosition = target.min + (target.max - target.min) * 0.5f; |
| 0 | 69 | | return wireframeGO; |
| | 70 | | } |
| | 71 | | } |
| | 72 | | } |