| | 1 | | using System; |
| | 2 | | using DCL.Models; |
| | 3 | | using DCLPlugins.DebugPlugins.Commons; |
| | 4 | | using UnityEngine; |
| | 5 | | using Object = UnityEngine.Object; |
| | 6 | |
|
| | 7 | | internal class EntityWireframe : IShapeListener |
| | 8 | | { |
| | 9 | | private const float WIREFRAME_SIZE_MULTIPLIER = 1.01f; |
| | 10 | |
|
| | 11 | | private readonly GameObject wireframeOriginal; |
| | 12 | |
|
| | 13 | | private GameObject entityWireframe; |
| | 14 | |
|
| 0 | 15 | | public EntityWireframe(GameObject wireframeOriginal) |
| | 16 | | { |
| 0 | 17 | | this.wireframeOriginal = wireframeOriginal; |
| 0 | 18 | | } |
| | 19 | |
|
| | 20 | | void IDisposable.Dispose() |
| | 21 | | { |
| 16 | 22 | | CleanWireframe(); |
| 16 | 23 | | } |
| | 24 | |
|
| | 25 | | void IShapeListener.OnShapeUpdated(IDCLEntity entity) |
| | 26 | | { |
| 16 | 27 | | entityWireframe ??= Object.Instantiate(wireframeOriginal); |
| | 28 | |
|
| 16 | 29 | | Transform wireframeT = entityWireframe.transform; |
| | 30 | |
|
| 16 | 31 | | wireframeT.position = entity.meshesInfo.mergedBounds.center; |
| 16 | 32 | | wireframeT.localScale = entity.meshesInfo.mergedBounds.size * WIREFRAME_SIZE_MULTIPLIER; |
| | 33 | |
|
| 16 | 34 | | wireframeT.SetParent(entity.gameObject.transform); |
| 16 | 35 | | entityWireframe.SetActive(true); |
| 16 | 36 | | } |
| | 37 | |
|
| | 38 | | void IShapeListener.OnShapeCleaned(IDCLEntity entity) |
| | 39 | | { |
| 1 | 40 | | CleanWireframe(); |
| 1 | 41 | | } |
| | 42 | |
|
| | 43 | | private void CleanWireframe() |
| | 44 | | { |
| 17 | 45 | | if (entityWireframe == null) |
| 1 | 46 | | return; |
| | 47 | |
|
| 16 | 48 | | entityWireframe.SetActive(false); |
| 16 | 49 | | Object.Destroy(entityWireframe); |
| 16 | 50 | | entityWireframe = null; |
| 16 | 51 | | } |
| | 52 | | } |