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