Tanoda
RendererTextureData.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;
12using UnityEngine.Assertions;
13using Leap.Unity.Query;
14
16
17 [Serializable]
18 public class RendererTextureData {
19 [SerializeField]
20 private List<NamedTexture> packedTextures = new List<NamedTexture>();
21
22 public void Clear() {
23 foreach (var tex in packedTextures) {
24 UnityEngine.Object.DestroyImmediate(tex.texture);
25 }
26 packedTextures.Clear();
27 }
28
29 public void AssignTextures(Texture2D[] textures, string[] propertyNames) {
30 List<NamedTexture> newList = new List<NamedTexture>();
31 Assert.AreEqual(textures.Length, propertyNames.Length);
32
33 for (int i = 0; i < textures.Length; i++) {
34 newList.Add(new NamedTexture() {
35 propertyName = propertyNames[i],
36 texture = textures[i]
37 });
38 }
39
40 foreach (var tex in packedTextures) {
41 if (!newList.Query().Any(p => p.texture == tex.texture)) {
42 UnityEngine.Object.DestroyImmediate(tex.texture);
43 }
44 }
45
46 packedTextures = newList;
47 }
48
49 public Texture2D GetTexture(string propertyName) {
50 return packedTextures.Query().
51 FirstOrDefault(p => p.propertyName == propertyName).texture;
52 }
53
54 public int Count {
55 get {
56 return packedTextures.Count;
57 }
58 }
59
60 public void Validate(LeapRenderingMethod renderingMethod) {
61 for (int i = packedTextures.Count; i-- != 0;) {
62 NamedTexture nt = packedTextures[i];
63 Texture2D tex = nt.texture;
64 if (tex == null) {
65 packedTextures.RemoveAt(i);
66 continue;
67 }
68
69 renderingMethod.PreventDuplication(ref tex);
70 nt.texture = tex;
71 packedTextures[i] = nt;
72 }
73 }
74
75 [Serializable]
76 public struct NamedTexture {
77 public string propertyName;
78 public Texture2D texture;
79 }
80 }
81}
void Validate(LeapRenderingMethod renderingMethod)
void AssignTextures(Texture2D[] textures, string[] propertyNames)