Advertisement
Xibanya

get exclusive keyword

Nov 5th, 2019
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1.     T GetKeyword<T>(Dictionary<T, string> keywords) where T : Enum
  2.     {
  3.         T[] types = (T[])Enum.GetValues(typeof(T));
  4.         T toSet = types.ToList().Find(t => !keywords.Keys.Contains(t));
  5.         foreach (KeyValuePair<T, string> kvp in keywords)
  6.         {
  7.             if (target.IsKeywordEnabled(kvp.Value)) toSet = kvp.Key;
  8.         }
  9.         return toSet;
  10.     }
  11. void KeywordDropdown<T>(Dictionary<T, string> keywords, T current,
  12.         string displayName = null, string tooltip = null) where T : Enum
  13.     {
  14.         GUIContent label = new GUIContent(displayName, tooltip);
  15.         EditorGUI.BeginChangeCheck();
  16.         current = (T)EditorGUILayout.EnumPopup(label, current);
  17.         if (EditorGUI.EndChangeCheck())
  18.         {
  19.             foreach (KeyValuePair<T, string> kvp in keywords)
  20.             {
  21.                 if (kvp.Key.Equals(current)) target.EnableKeyword(kvp.Value);
  22.                 else target.DisableKeyword(kvp.Value);
  23.             }
  24.         }
  25.     }
  26.     void KeywordDropdown<T>(Dictionary<T, string> keywords, string displayName = null,
  27.         string tooltip = null) where T : Enum
  28.     {
  29.         T current = GetKeyword<T>(keywords);
  30.         KeywordDropdown<T>(keywords, current, displayName, tooltip);
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement