AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
CycleTextures.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using UnityEngine;
5 using System.Collections;
6 
7 namespace HoloToolkit.Examples.Prototyping
8 {
12  public class CycleTextures : CycleArray<Texture>
13  {
14  private Material mMaterial;
15 
19  override protected void Awake()
20  {
21  base.Awake();
22 
23  Renderer renderer = TargetObject.GetComponent<Renderer>();
24  if (renderer != null)
25  {
26  mMaterial = renderer.material;
27  }
28  else
29  {
30  Debug.LogError("CycleTexture requires a renderer and material on the assigned GameObject!");
31  Destroy(this);
32  }
33  }
34 
39  public override void SetIndex(int index)
40  {
41  base.SetIndex(index);
42 
43  if (index > -1 && index < Array.Length)
44  {
45  if (mMaterial != null)
46  {
47  mMaterial.SetTexture("_MainTex", Array[index]);
48  }
49  }
50  }
51 
56  public void SetNewArray(Texture[] arr)
57  {
58  Array = arr;
59  SetIndex(0);
60  }
61 
65  private void OnDestroy()
66  {
67  if (mMaterial != null)
68  {
69  Destroy(mMaterial);
70  }
71  }
72  }
73 }
CycleArray is a class for incrementing through component properties sequentially or assigning specifi...
Definition: CycleArray.cs:15
void SetNewArray(Texture[] arr)
Update the current set of textures
override void Awake()
get the material to assign textures to
override void SetIndex(int index)
set the texture
sets the texture of a material based on the selected item in the array