int controlId = GUIUtility.GetControlID(FocusType.Passive); EditingState state = GUIUtility.GetStateObject(typeof(EditingState), controlId) as EditingState; if (state.wannaSet) { currentName = state.selectedType.AssemblyQualifiedName; state.selectedType = null; state.wannaSet = false; this.ValueEntry.SmartValue = currentName; } EditorGUILayout.BeginVertical(); GUIStyle guiStyle = new GUIStyle(EditorStyles.label); guiStyle.alignment = TextAnchor.MiddleLeft; EditorGUILayout.LabelField(this.Property.NiceName, guiStyle);
guiStyle = new GUIStyle(EditorStyles.popup); guiStyle.alignment = TextAnchor.MiddleLeft; if (EditorGUILayout.DropdownButton(new GUIContent($"Preview Enum Type ({enumTypeNiceName})"), FocusType.Keyboard, guiStyle)) { if (EditingState.tempQuery == null) { EditingState.tempQuery = GetTargetEnumTypes(); }
TypeSelector selector = new TypeSelector(EditingState.tempQuery, false); selector.EnableSingleClickToSelect(); selector.ShowInPopup(); selector.SelectionConfirmed += selection => { var resultTypeArray = selection.ToArray(); if (resultTypeArray.Length > 0) { Type selectedType = resultTypeArray.GetValue(0) as Type; EditingState state = GUIUtility.GetStateObject(typeof(EditingState), controlId) as EditingState; state.selectedType = selectedType; state.wannaSet = true; } }; } EditorGUILayout.EndVertical(); }
privatestatic IEnumerable<Type> GetTargetEnumTypes() { // TODO @Hiko here to get actual enum types TypeCache.TypeCollection cache = TypeCache.GetTypesDerivedFrom<Enum>(); var query = cache.Where(t => t.IsEnum && t.IsPublic); return query; }
} // can not find the target preview enum type, draw normal int field EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(this.Property.NiceName); nextValue = EditorGUILayout.IntField(prevValue); this.ValueEntry.SmartValue = nextValue; EditorGUILayout.EndHorizontal(); } }
// test case publicclassTesterA : MonoBehaviour, IIntAsEnumPackHolder { #if UNITY_EDITOR [SerializeField] private IntAsEnumEditorPack intAsEnumEditorPack; public IntAsEnumEditorPack holderData => intAsEnumEditorPack; #endif
[Serializable] publicstruct TempStructA { [IntAsEnum] publicint tempInt; public Color tempColor; }