| | 1 | | using DCL.Configuration; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityGLTF; |
| | 6 | |
|
| | 7 | | namespace DCL |
| | 8 | | { |
| | 9 | | public class Asset_GLTF : Asset_WithPoolableContainer |
| | 10 | | { |
| | 11 | | public string name; |
| 202 | 12 | | public bool visible = true; |
| | 13 | |
|
| 2232 | 14 | | public override GameObject container { get; set; } |
| | 15 | |
|
| 202 | 16 | | public HashSet<Mesh> meshes = new HashSet<Mesh>(); |
| 202 | 17 | | public Dictionary<Mesh, int> meshToTriangleCount = new Dictionary<Mesh, int>(); |
| 202 | 18 | | public HashSet<Renderer> renderers = new HashSet<Renderer>(); |
| 202 | 19 | | public HashSet<Material> materials = new HashSet<Material>(); |
| 202 | 20 | | public HashSet<Texture> textures = new HashSet<Texture>(); |
| | 21 | | public int totalTriangleCount = 0; |
| | 22 | | public long animationClipSize = 0; |
| | 23 | | public long meshDataSize = 0; |
| | 24 | |
|
| | 25 | | Coroutine showCoroutine; |
| | 26 | |
|
| 202 | 27 | | public Asset_GLTF() |
| | 28 | | { |
| 202 | 29 | | container = new GameObject("Asset_GLTF Container"); |
| 202 | 30 | | visible = true; |
| 202 | 31 | | } |
| | 32 | |
|
| | 33 | | public override object Clone() |
| | 34 | | { |
| 131 | 35 | | Asset_GLTF result = this.MemberwiseClone() as Asset_GLTF; |
| 131 | 36 | | result.visible = true; |
| 131 | 37 | | result.meshes = new HashSet<Mesh>(meshes); |
| 131 | 38 | | result.renderers = new HashSet<Renderer>(renderers); |
| 131 | 39 | | result.materials = new HashSet<Material>(materials); |
| 131 | 40 | | result.textures = new HashSet<Texture>(textures); |
| 131 | 41 | | result.meshToTriangleCount = new Dictionary<Mesh, int>(meshToTriangleCount); |
| 131 | 42 | | return result; |
| | 43 | | } |
| | 44 | |
|
| | 45 | | public override void Cleanup() |
| | 46 | | { |
| | 47 | | #if UNITY_STANDALONE || UNITY_EDITOR |
| 203 | 48 | | if (DataStore.i.common.isApplicationQuitting.Get()) |
| 0 | 49 | | return; |
| | 50 | | #endif |
| | 51 | |
|
| 203 | 52 | | Object.Destroy(container); |
| 203 | 53 | | } |
| | 54 | |
|
| | 55 | | public void Hide() |
| | 56 | | { |
| 3 | 57 | | if (container != null) |
| | 58 | | { |
| 3 | 59 | | container.transform.parent = null; |
| 3 | 60 | | container.transform.position = EnvironmentSettings.MORDOR; |
| | 61 | | } |
| | 62 | |
|
| 3 | 63 | | visible = false; |
| 3 | 64 | | } |
| | 65 | |
|
| | 66 | | public void CancelShow() |
| | 67 | | { |
| 103 | 68 | | if (showCoroutine != null) |
| 1 | 69 | | CoroutineStarter.Stop(showCoroutine); |
| 103 | 70 | | } |
| | 71 | |
|
| | 72 | | public void Show(bool useMaterialTransition, System.Action OnFinish) |
| | 73 | | { |
| 32 | 74 | | if (showCoroutine != null) |
| 0 | 75 | | CoroutineStarter.Stop(showCoroutine); |
| | 76 | |
|
| 32 | 77 | | if (!visible) |
| | 78 | | { |
| 0 | 79 | | OnFinish?.Invoke(); |
| 0 | 80 | | return; |
| | 81 | | } |
| | 82 | |
|
| 32 | 83 | | bool renderingEnabled = CommonScriptableObjects.rendererState.Get(); |
| | 84 | |
|
| 32 | 85 | | if (!renderingEnabled || !useMaterialTransition) |
| | 86 | | { |
| 9 | 87 | | container.SetActive(true); |
| 9 | 88 | | OnFinish?.Invoke(); |
| 9 | 89 | | return; |
| | 90 | | } |
| | 91 | |
|
| 23 | 92 | | showCoroutine = CoroutineStarter.Start(ShowCoroutine(OnFinish)); |
| 23 | 93 | | } |
| | 94 | |
|
| | 95 | | public IEnumerator ShowCoroutine(System.Action OnFinish) |
| | 96 | | { |
| | 97 | | // NOTE(Brian): This fixes seeing the object in the scene 0,0 for a frame |
| 23 | 98 | | yield return new WaitForSeconds(Random.Range(0, 0.05f)); |
| | 99 | |
|
| | 100 | | // NOTE(Brian): This GameObject can be removed by distance after the delay |
| 22 | 101 | | if (container == null) |
| | 102 | | { |
| 0 | 103 | | OnFinish?.Invoke(); |
| 0 | 104 | | yield break; |
| | 105 | | } |
| | 106 | |
|
| 22 | 107 | | container?.SetActive(true); |
| 22 | 108 | | OnFinish?.Invoke(); |
| 22 | 109 | | } |
| | 110 | | } |
| | 111 | | } |