| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL; |
| | 4 | | using DCL.Configuration; |
| | 5 | | using DCL.ECSComponents; |
| | 6 | | using DCL.Helpers; |
| | 7 | | using DCL.Models; |
| | 8 | | using UnityEngine; |
| | 9 | |
|
| | 10 | | public static class ECSComponentsUtils |
| | 11 | | { |
| | 12 | | public static void RemoveMaterialTransition(GameObject go) |
| | 13 | | { |
| 0 | 14 | | MaterialTransitionController[] materialTransitionControllers = go.GetComponentsInChildren<MaterialTransitionCont |
| | 15 | |
|
| 0 | 16 | | for (var i = 0; i < materialTransitionControllers.Length; i++) |
| | 17 | | { |
| 0 | 18 | | GameObject.Destroy(materialTransitionControllers[i]); |
| | 19 | | } |
| 0 | 20 | | } |
| | 21 | |
|
| | 22 | | public static void UpdateMeshInfo(bool isVisible, bool withCollisions, bool isPointerBlocker, MeshesInfo meshesInfo) |
| | 23 | | { |
| 0 | 24 | | foreach (Renderer renderer in meshesInfo.renderers) |
| | 25 | | { |
| 0 | 26 | | renderer.enabled = isVisible; |
| | 27 | | } |
| | 28 | |
|
| 0 | 29 | | UpdateMeshInfoColliders(withCollisions, isPointerBlocker, meshesInfo); |
| 0 | 30 | | } |
| | 31 | |
|
| | 32 | | public static void UpdateMeshInfoColliders(bool withCollisions, bool isPointerBlocker, MeshesInfo meshesInfo) |
| | 33 | | { |
| 0 | 34 | | int colliderLayer = isPointerBlocker ? PhysicsLayers.onPointerEventLayer : PhysicsLayers.defaultLayer; |
| | 35 | |
|
| 0 | 36 | | foreach (Collider collider in meshesInfo.colliders) |
| | 37 | | { |
| 0 | 38 | | if (collider == null) continue; |
| | 39 | |
|
| 0 | 40 | | collider.enabled = withCollisions; |
| 0 | 41 | | collider.gameObject.layer = colliderLayer; |
| | 42 | | } |
| 0 | 43 | | } |
| | 44 | |
|
| | 45 | | public static void RemoveRendereableFromDataStore(string sceneId, Rendereable rendereable) |
| | 46 | | { |
| 1 | 47 | | DataStore.i.sceneWorldObjects.RemoveRendereable(sceneId, rendereable); |
| 1 | 48 | | } |
| | 49 | |
|
| | 50 | | public static Rendereable AddRendereableToDataStore(string sceneId, long entityId, Mesh mesh, GameObject gameObject, |
| | 51 | | { |
| 2 | 52 | | int triangleCount = mesh.triangles.Length; |
| | 53 | |
|
| 2 | 54 | | var newRendereable = |
| | 55 | | new Rendereable() |
| | 56 | | { |
| | 57 | | container = gameObject, |
| | 58 | | totalTriangleCount = triangleCount, |
| | 59 | | meshes = new HashSet<Mesh>() { mesh }, |
| | 60 | | meshToTriangleCount = new Dictionary<Mesh, int>() { { mesh, triangleCount } } |
| | 61 | | }; |
| | 62 | |
|
| 2 | 63 | | newRendereable.renderers = new HashSet<Renderer>(renderers); |
| 2 | 64 | | newRendereable.ownerId = entityId; |
| | 65 | |
|
| 2 | 66 | | DataStore.i.sceneWorldObjects.AddRendereable(sceneId, newRendereable); |
| 2 | 67 | | return newRendereable; |
| | 68 | | } |
| | 69 | |
|
| | 70 | | public static void DisposeMeshInfo(MeshesInfo meshesInfo) |
| | 71 | | { |
| | 72 | | // Dispose renderer |
| 0 | 73 | | foreach (Renderer renderer in meshesInfo.renderers) |
| | 74 | | { |
| 0 | 75 | | Utils.CleanMaterials(renderer); |
| 0 | 76 | | GameObject.Destroy(renderer); |
| | 77 | | } |
| | 78 | |
|
| | 79 | | // Dispose Mesh filter |
| 0 | 80 | | foreach (MeshFilter meshFilter in meshesInfo.meshFilters) |
| | 81 | | { |
| 0 | 82 | | GameObject.Destroy(meshFilter); |
| | 83 | | } |
| | 84 | |
|
| | 85 | | // Dispose collider |
| 0 | 86 | | foreach (Collider collider in meshesInfo.colliders) |
| | 87 | | { |
| 0 | 88 | | if (collider == null) continue; |
| | 89 | |
|
| 0 | 90 | | GameObject.Destroy(collider); |
| | 91 | | } |
| | 92 | |
|
| 0 | 93 | | meshesInfo.CleanReferences(); |
| 0 | 94 | | } |
| | 95 | |
|
| | 96 | | public static int CalculateNFTCollidersLayer(bool withCollisions, bool isPointerBlocker) |
| | 97 | | { |
| | 98 | | // We can't enable this layer changer logic until we redeploy all the builder and street scenes with the correct |
| | 99 | | /* if (!model.withCollisions && model.isPointerBlocker) |
| | 100 | | return PhysicsLayers.onPointerEventLayer; |
| | 101 | | else */ |
| 0 | 102 | | if (withCollisions && !isPointerBlocker) |
| 0 | 103 | | return PhysicsLayers.characterOnlyLayer; |
| | 104 | |
|
| 0 | 105 | | return PhysicsLayers.defaultLayer; |
| | 106 | | } |
| | 107 | |
|
| | 108 | | private static int CalculateCollidersLayer(bool withCollisions, bool isPointerBlocker) |
| | 109 | | { |
| 0 | 110 | | if (isPointerBlocker) |
| 0 | 111 | | return PhysicsLayers.onPointerEventLayer; |
| 0 | 112 | | else if (withCollisions) |
| 0 | 113 | | return PhysicsLayers.characterOnlyLayer; |
| | 114 | |
|
| 0 | 115 | | return PhysicsLayers.defaultLayer; |
| | 116 | | } |
| | 117 | | } |