static private CachedSelectionList GetList(FourCCSelectorAttribute inSelector) { CachedSelectionList list; Type cachingType = inSelector.GetCachingType(); if (cachingType != null) { if (!s_CachedLists.TryGetValue(cachingType, out list)) { list = new CachedSelectionList(inSelector); s_CachedLists.Add(cachingType, list); } return(list); } else { return(new CachedSelectionList(inSelector)); } }
private void DropdownInput(Rect inRect, CachedSelectionList inList, SerializedProperty inProperty) { int currentValueIndex; if (inProperty.hasMultipleDifferentValues) { currentValueIndex = -1; } else { currentValueIndex = inList.GetContentIndex(new FourCC(inProperty.intValue)); } EditorGUI.BeginChangeCheck(); int nextValueIndex = EditorGUI.Popup(inRect, currentValueIndex, inList.Contents()); if (EditorGUI.EndChangeCheck() && currentValueIndex != nextValueIndex) { inProperty.intValue = (int)inList.GetValue(nextValueIndex); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { CachedSelectionList list = null; FourCCSelectorAttribute selector = this.attribute as FourCCSelectorAttribute; bool bShowDebug = true; if (selector != null) { list = GetList(selector); bShowDebug = selector.ShowDebug; } SerializedProperty valueProp = property.FindPropertyRelative("m_Value"); Rect labelRect = position; Rect indentedRect = EditorGUI.IndentedRect(labelRect); label = EditorGUI.BeginProperty(labelRect, label, property); if (!string.IsNullOrEmpty(label.text)) { labelRect.width = EditorGUIUtility.labelWidth; indentedRect.x = labelRect.xMax; indentedRect.width = position.xMax - indentedRect.xMin; EditorGUI.LabelField(labelRect, label); } int prevIndent = EditorGUI.indentLevel; { EditorGUI.indentLevel = 0; Rect fieldRect = indentedRect; if (bShowDebug) { fieldRect.width -= VALUE_WIDTH; } if (list != null) { DropdownInput(fieldRect, list, valueProp); } else { StringInput(fieldRect, valueProp); } if (bShowDebug) { Rect valueRect = indentedRect; valueRect.x += valueRect.width - VALUE_WIDTH; valueRect.width = VALUE_WIDTH; ValueDisplay(valueRect, valueProp); } } EditorGUI.indentLevel = prevIndent; EditorGUI.EndProperty(); }