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