public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EnumFlagsAttribute flagSettings = (EnumFlagsAttribute)attribute; Enum targetEnum = GetBaseProperty <Enum>(property); string propName = flagSettings.enumName; Enum enumNew; EditorGUI.BeginProperty(position, label, property); if (string.IsNullOrEmpty(propName)) { #if UNITY_2017_3_OR_NEWER enumNew = EditorGUI.EnumFlagsField(position, label, targetEnum); #else enumNew = EditorGUI.EnumMaskField(position, label, targetEnum); #endif } else { #if UNITY_2017_3_OR_NEWER enumNew = EditorGUI.EnumFlagsField(position, propName, targetEnum); #else enumNew = EditorGUI.EnumMaskField(position, propName, targetEnum); #endif } property.intValue = (int)Convert.ChangeType(enumNew, targetEnum.GetType()); EditorGUI.EndProperty(); }
void SetDimensions(SerializedProperty property, GUIContent label) { flagAttribute = attribute as EnumFlagsAttribute; enumLength = property.enumNames.Length; if (flagAttribute != null && flagAttribute.showLabel == false) { labelWidth = GetIndentWidth(); } else { labelWidth = (label == GUIContent.none ? GetIndentWidth() : EditorGUIUtility.labelWidth); } float estimatedViewWidth = (EditorGUIUtility.currentViewWidth - (label == GUIContent.none ? 60f : EditorGUIUtility.labelWidth) - 25f); if (flagAttribute == null || flagAttribute.numBtnsPerRow < 0) { numBtnsPerRow = Mathf.FloorToInt(estimatedViewWidth / mininumWidth); } else { numBtnsPerRow = flagAttribute.numBtnsPerRow; } numRows = Mathf.CeilToInt((float)enumLength / (float)numBtnsPerRow); }
public override void OnGUI(Rect _position, SerializedProperty _property, GUIContent _lable) { // attribute 是PropertyAttribute類中的一個屬性 // EnumFlagsAttribute中的所有屬性都可以調用 EnumFlagsAttribute flags = attribute as EnumFlagsAttribute; // 枚舉值的數值最後為一個數字,如果要取得其代表的或包含的數值必須通過按位運算來提取 // 繪製出一個下拉菜單,枚舉類型 _property.intValue = EditorGUI.MaskField(_position, flags.text, _property.intValue, _property.enumDisplayNames); }
public void DrawDirectly(SerializedProperty property, CyberAttribute attribute, GUIContent content, GUIStyle style, FieldInfo field) { EditorGUILayout.BeginHorizontal(); TheEditor.DrawPrefix(content, field, style); EnumFlagsAttribute attr = attribute as EnumFlagsAttribute; if (property.intValue < 0) { property.intValue = 0; } void DrawCheckBox(GUIStyle checkStyle) { foreach (var item in Enum.GetValues(CyberEdit.Current.CurrentField.FieldType)) { int val = Convert.ToInt32(item); if (val == 0) { continue; } bool has = (property.intValue | val) == property.intValue; bool toogleRes = GUILayout.Toggle(has, new GUIContent(item.ToString()), checkStyle); if (toogleRes == false && has == true) { property.intValue ^= val; } else if (toogleRes == true && has == false) { property.intValue |= val; } } } switch (attr.EnumFlagOption) { case EnumMode.Classic: property.intValue = EditorGUILayout.MaskField(GUIContent.none, property.intValue, property.enumNames); break; default: DrawCheckBox(attr.EnumFlagOption.GetStyle()); break; } EditorGUILayout.EndHorizontal(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EnumFlagsAttribute flagSettings = (EnumFlagsAttribute)attribute; Enum targetEnum = GetBaseProperty <Enum>(property); string propName = flagSettings.enumName; if (string.IsNullOrEmpty(propName)) { propName = property.name; } EditorGUI.BeginProperty(position, label, property); var enumNew = EditorGUI.EnumFlagsField(position, propName, targetEnum); property.intValue = (int)Convert.ChangeType(enumNew, targetEnum.GetType()); EditorGUI.EndProperty(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EnumFlagsAttribute flagSettings = (EnumFlagsAttribute)attribute; Enum targetEnum = (Enum)fieldInfo.GetValue(property.serializedObject.targetObject); string propName = flagSettings.name; if (string.IsNullOrEmpty(propName)) { propName = ObjectNames.NicifyVariableName(property.name); } EditorGUI.BeginProperty(position, label, property); Enum enumNew = EditorGUI.EnumMaskPopup(position, propName, targetEnum); property.intValue = (int)Convert.ChangeType(enumNew, targetEnum.GetType()); EditorGUI.EndProperty(); }
/// <summary> /// Override this method to make your own GUI for the property. /// </summary> /// <param name="position">Rectangle on the screen to use for the property GUI.</param> /// <param name="property">The SerializedProperty to make the custom GUI for.</param> /// <param name="label">The label of this property.</param> public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EnumFlagsAttribute flagsAttribute = (EnumFlagsAttribute)attribute; Enum targetEnum = GetBaseProperty <Enum>(property); string propertyDisplayName = flagsAttribute.Label; if (string.IsNullOrEmpty(propertyDisplayName)) { propertyDisplayName = property.name; } if (targetEnum != null) { EditorGUI.BeginProperty(position, label, property); Enum enumMask = EditorGUI.EnumMaskField(position, propertyDisplayName, targetEnum); property.intValue = (int)Convert.ChangeType(enumMask, targetEnum.GetType()); EditorGUI.EndProperty(); } }
/// <summary> /// Override Unity OnGUI to make a custom GUI for the property with EnumFlagsAttribute. /// </summary> /// <param name="position">Rectangle on the screen to use for the property GUI.</param> /// <param name="property">The SerializedProperty to make the custom GUI for.</param> /// <param name="label">The label of this property.</param> public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EnumFlagsAttribute flagsAttribute = attribute as EnumFlagsAttribute; string[] itemNames = Enum.GetNames(flagsAttribute.EnumType); int[] itemValues = Enum.GetValues(flagsAttribute.EnumType) as int[]; property.intValue = EditorGUI.MaskField(position, label, property.intValue, itemNames); if (property.intValue == -1) { int maskValue = 0; foreach (int itemValue in itemValues) { maskValue |= itemValue; } property.intValue = maskValue; } }
internal void Initialize(WeaponScript weapon) { if (flipIfFacingAway) { attackSubcomponents.Insert(0, ScriptableObject.CreateInstance <FlipIfFacingAway>()); } if (preventFlipWhileAttacking) { attackSubcomponents.Add(ScriptableObject.CreateInstance <PreventFlipWhileAttacking>()); } for (int i = 0; i < attackSubcomponents.Count; i++) { attackSubcomponents[i] = Instantiate(attackSubcomponents[i]); attackSubcomponents[i].Initialize(weapon); } directionTriggers = EnumFlagsAttribute.ReturnSelectedElements <AttackDirection>((int)directionTriggerFlags) .Select(x => (AttackDirection)x).ToArray(); movementStates = EnumFlagsAttribute.ReturnSelectedElements <MovementState>((int)movementStateFlags) .Select(x => (MovementState)x).ToArray(); if (flipIfFacingAway) { List <AttackDirection> newDirections = new List <AttackDirection>(); foreach (var direction in directionTriggers) { newDirections.Add(direction); var flipped = FlipAttackDirection(direction); if (flipped != direction) { newDirections.Add(flipped); } } directionTriggers = newDirections.ToArray(); } }
public override bool CanCacheInspectorGUI(SerializedProperty property) { flags = attribute as EnumFlagsAttribute; return(base.CanCacheInspectorGUI(property)); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent content) { EnumFlagsAttribute attribute = (EnumFlagsAttribute)base.attribute; property.intValue = EditorGUI.MaskField(position, content, property.intValue, property.enumDisplayNames); }