Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 13 additions & 23 deletions com.unity.toonshader/Runtime/Scripts/Utilities/ToonEnumUtility.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,31 @@

using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;

namespace Unity.Rendering.Toon {

internal static class ToonEnumUtility {
internal static GUIContent[] ToInspectorNamesAsGUIContent(Type t) {
MemberInfo[] members = t.GetMembers(BindingFlags.Static | BindingFlags.Public);

int numMembers = members.Length;
GUIContent[] ret = new GUIContent[numMembers];
for (int i = 0; i < numMembers; i++) {
InspectorNameAttribute inspectorNameAttribute = (InspectorNameAttribute)Attribute.GetCustomAttribute(
members[i], typeof(InspectorNameAttribute));
if (inspectorNameAttribute == null) {
ret[i] = new GUIContent(members[i].Name);
} else {
ret[i] = new GUIContent(inspectorNameAttribute.displayName);
}
string[] names = Enum.GetNames(t);
GUIContent[] ret = new GUIContent[names.Length];
for (int i = 0; i < names.Length; i++) {
FieldInfo field = t.GetField(names[i], BindingFlags.Public | BindingFlags.Static);
InspectorNameAttribute attr = field != null
? (InspectorNameAttribute)Attribute.GetCustomAttribute(field, typeof(InspectorNameAttribute))
: null;
ret[i] = new GUIContent(attr != null ? attr.displayName : names[i]);
}
Comment thread
sindharta marked this conversation as resolved.

return ret;
}

internal static int[] ToIndices(Type t) {
Comment thread
sindharta marked this conversation as resolved.
Outdated

MemberInfo[] members = t.GetMembers(BindingFlags.Static | BindingFlags.Public);
int numMembers = members.Length;
int[] indices = new int[numMembers];
for (int i = 0; i < numMembers; ++i) {
indices[i] = i;
}

Array values = Enum.GetValues(t);
int numValues = values.Length;
int[] indices = new int[numValues];
for (int i = 0; i < numValues; i++)
indices[i] = Convert.ToInt32(values.GetValue(i));
return indices;
Comment thread
sindharta marked this conversation as resolved.
Outdated
Comment thread
sindharta marked this conversation as resolved.
Outdated
Comment thread
sindharta marked this conversation as resolved.
Outdated

}

}
Expand Down