Tanoda
RendererMeshData.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using System;
10using System.Collections.Generic;
11using UnityEngine;
12#if UNITY_EDITOR
13using UnityEditor;
14#endif
15
17
18 [Serializable]
19 public class RendererMeshData {
20 [SerializeField]
21 private List<Mesh> meshes = new List<Mesh>();
22
23 [System.NonSerialized]
24 private Queue<Mesh> _tempMeshPool = new Queue<Mesh>();
25
26 private void OnDestroy() {
27 foreach (var mesh in meshes) {
28 UnityEngine.Object.DestroyImmediate(mesh);
29 }
30 }
31
32 public void Clear() {
33 foreach (var mesh in meshes) {
34 if (mesh != null) {
35 mesh.Clear(keepVertexLayout: false);
36 _tempMeshPool.Enqueue(mesh);
37 }
38 }
39 meshes.Clear();
40 }
41
42 public Mesh GetMeshFromPoolOrNew() {
43 if (_tempMeshPool.Count > 0) {
44 return _tempMeshPool.Dequeue();
45 } else {
46 return new Mesh();
47 }
48 }
49
50 public void ClearPool() {
51 while (_tempMeshPool.Count > 0) {
52 UnityEngine.Object.DestroyImmediate(_tempMeshPool.Dequeue());
53 }
54 }
55
56 public void AddMesh(Mesh mesh) {
57 mesh.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
58 meshes.Add(mesh);
59 }
60
61 public void RemoveMesh(int index) {
62 Mesh mesh = meshes[index];
63 meshes.RemoveAt(index);
64 UnityEngine.Object.DestroyImmediate(mesh);
65 }
66
67 public void Validate(LeapRenderingMethod renderingMethod) {
68 for (int i = meshes.Count; i-- != 0;) {
69 Mesh mesh = meshes[i];
70 if (mesh == null) {
71 meshes.RemoveAt(i);
72 continue;
73 }
74
75 renderingMethod.PreventDuplication(ref mesh);
76 meshes[i] = mesh;
77 }
78 }
79
80 public int Count {
81 get {
82 return meshes.Count;
83 }
84 }
85
86 public Mesh this[int index] {
87 get {
88 return meshes[index];
89 }
90 set {
91 meshes[index] = value;
92 }
93 }
94 }
95}
void Validate(LeapRenderingMethod renderingMethod)