Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- T GetKeyword<T>(Dictionary<T, string> keywords) where T : Enum
- {
- T[] types = (T[])Enum.GetValues(typeof(T));
- T toSet = types.ToList().Find(t => !keywords.Keys.Contains(t));
- foreach (KeyValuePair<T, string> kvp in keywords)
- {
- if (target.IsKeywordEnabled(kvp.Value)) toSet = kvp.Key;
- }
- return toSet;
- }
- void KeywordDropdown<T>(Dictionary<T, string> keywords, T current,
- string displayName = null, string tooltip = null) where T : Enum
- {
- GUIContent label = new GUIContent(displayName, tooltip);
- EditorGUI.BeginChangeCheck();
- current = (T)EditorGUILayout.EnumPopup(label, current);
- if (EditorGUI.EndChangeCheck())
- {
- foreach (KeyValuePair<T, string> kvp in keywords)
- {
- if (kvp.Key.Equals(current)) target.EnableKeyword(kvp.Value);
- else target.DisableKeyword(kvp.Value);
- }
- }
- }
- void KeywordDropdown<T>(Dictionary<T, string> keywords, string displayName = null,
- string tooltip = null) where T : Enum
- {
- T current = GetKeyword<T>(keywords);
- KeywordDropdown<T>(keywords, current, displayName, tooltip);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement