diff --git a/Assets/MixedRealityToolkit/UX/Scripts/Buttons/Profiles/ButtonIconProfile.cs b/Assets/MixedRealityToolkit/UX/Scripts/Buttons/Profiles/ButtonIconProfile.cs
index fa80ce89aa5..73f9fe70c63 100644
--- a/Assets/MixedRealityToolkit/UX/Scripts/Buttons/Profiles/ButtonIconProfile.cs
+++ b/Assets/MixedRealityToolkit/UX/Scripts/Buttons/Profiles/ButtonIconProfile.cs
@@ -2,6 +2,7 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System.Collections.Generic;
+using System.Collections.ObjectModel;
using UnityEngine;
namespace MixedRealityToolkit.UX.Buttons.Profiles
@@ -42,7 +43,7 @@ public abstract class ButtonIconProfile : ButtonProfile
/// Gets a list of icon names - used primarily by editor scripts
///
///
- public virtual List GetIconKeys()
+ public virtual ReadOnlyCollection GetIconKeys()
{
return null;
}
diff --git a/Assets/MixedRealityToolkit/UX/Scripts/Buttons/Profiles/ButtonIconProfileTexture.cs b/Assets/MixedRealityToolkit/UX/Scripts/Buttons/Profiles/ButtonIconProfileTexture.cs
index 2a1f4d1cd59..fdf4329e774 100644
--- a/Assets/MixedRealityToolkit/UX/Scripts/Buttons/Profiles/ButtonIconProfileTexture.cs
+++ b/Assets/MixedRealityToolkit/UX/Scripts/Buttons/Profiles/ButtonIconProfileTexture.cs
@@ -3,6 +3,7 @@
using MixedRealityToolkit.Utilities.Attributes;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
using UnityEngine;
#if ENABLE_WINMD_SUPPORT && !UNITY_EDITOR
@@ -99,20 +100,23 @@ public override bool GetIcon(string iconName, MeshRenderer targetRenderer, MeshF
///
/// (Icons starting with '_' will not be included in icon list)
///
- public override List GetIconKeys()
+ public override ReadOnlyCollection GetIconKeys()
{
Initialize();
- return new List(iconKeys);
+ return iconKeys.AsReadOnly();
}
private void Initialize()
{
- if (iconLookup != null)
- return;
+ if (iconLookup == null)
+ {
+ iconLookup = new Dictionary();
+ iconKeys = new List();
+ }
- iconLookup = new Dictionary();
- iconKeys = new List();
+ iconLookup.Clear();
+ iconKeys.Clear();
// Store all icons in iconLookup via reflection
#if ENABLE_WINMD_SUPPORT && !UNITY_EDITOR
@@ -148,16 +152,17 @@ private void Initialize()
public override string DrawIconSelectField(string iconName)
{
int selectedIconIndex = -1;
- List iconKeys = GetIconKeys();
+ ReadOnlyCollection iconKeys = GetIconKeys();
+ string[] dropdownKeys = new string[iconKeys.Count];
for (int i = 0; i < iconKeys.Count; i++)
{
if (iconName == iconKeys[i])
{
selectedIconIndex = i;
- break;
}
+ dropdownKeys[i] = iconKeys[i];
}
- int newIconIndex = UnityEditor.EditorGUILayout.Popup("Icon", selectedIconIndex, iconKeys.ToArray());
+ int newIconIndex = UnityEditor.EditorGUILayout.Popup("Icon", selectedIconIndex, dropdownKeys);
// This will automatically set the icon in the editor view
iconName = (newIconIndex < 0 ? string.Empty : iconKeys[newIconIndex]);
return iconName;
diff --git a/Assets/MixedRealityToolkit/UX/Scripts/Buttons/Utilities/CompoundButtonIcon.cs b/Assets/MixedRealityToolkit/UX/Scripts/Buttons/Utilities/CompoundButtonIcon.cs
index eacc37889f8..e888ec29303 100644
--- a/Assets/MixedRealityToolkit/UX/Scripts/Buttons/Utilities/CompoundButtonIcon.cs
+++ b/Assets/MixedRealityToolkit/UX/Scripts/Buttons/Utilities/CompoundButtonIcon.cs
@@ -59,8 +59,8 @@ public float Alpha
{
alphaTarget = value;
if (Application.isPlaying)
- {
- if (Mathf.Abs (alpha - alphaTarget) < AlphaThreshold)
+ {
+ if (Mathf.Abs(alpha - alphaTarget) < AlphaThreshold)
{
return;
}
@@ -100,8 +100,8 @@ public MeshFilter IconMeshFilter
return targetIconRenderer != null ? targetIconRenderer.GetComponent() : null;
}
}
-
- #if UNITY_EDITOR
+
+#if UNITY_EDITOR
///
/// Called by CompoundButtonSaveInterceptor
/// Prevents saving a scene with instanced materials / meshes
@@ -111,10 +111,10 @@ public void OnWillSaveScene()
ClearInstancedAssets();
SetIconName(iconName);
-
+
}
- #endif
-
+#endif
+
public string IconName
{
get
@@ -130,20 +130,27 @@ public string IconName
private void SetIconName(string newName)
{
// Avoid exploding if possible
- if (Profile == null) {
+ if (Profile == null)
+ {
return;
}
- if (targetIconRenderer == null) {
+ // Set the name regardless
+ iconName = newName;
+
+ if (targetIconRenderer == null)
+ {
return;
}
- if (DisableIcon) {
+ if (DisableIcon)
+ {
targetIconRenderer.enabled = false;
return;
}
- if (Profile.IconMaterial == null || Profile.IconMesh == null) {
+ if (Profile.IconMaterial == null || Profile.IconMesh == null)
+ {
return;
}
@@ -156,7 +163,7 @@ private void SetIconName(string newName)
};
}
targetIconRenderer.sharedMaterial = instantiatedMaterial;
-
+
// Instantiate our local mesh now, if we don't have one
if (instantiatedMesh == null)
{
@@ -179,9 +186,8 @@ private void SetIconName(string newName)
if (string.IsNullOrEmpty(newName))
{
targetIconRenderer.enabled = false;
- iconName = newName;
return;
- }
+ }
// Moment of truth - try to get our icon
if (!Profile.GetIcon(newName, targetIconRenderer, IconMeshFilter, true))
@@ -191,7 +197,6 @@ private void SetIconName(string newName)
}
// If we've made it this far we're golden
- iconName = newName;
targetIconRenderer.enabled = true;
RefreshAlpha();
}