Skip to content
Merged
Changes from 1 commit
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++) {
MemberInfo[] members = t.GetMember(names[i]);
InspectorNameAttribute attr = members.Length > 0
? (InspectorNameAttribute)Attribute.GetCustomAttribute(members[0], typeof(InspectorNameAttribute))
: null;
Comment thread
Copilot marked this conversation as resolved.
Outdated
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] = (int)values.GetValue(i);
Comment thread
sindharta-tanuwijaya marked this conversation as resolved.
Outdated
return indices;
Comment thread
sindharta-tanuwijaya marked this conversation as resolved.
Outdated

}

}
Expand Down