private void DrawEnumedName() { var rect = _rect; var valueTypings = fieldInfo.GetCustomAttributes(typeof(ValueTypeAttribute), true) as ValueTypeAttribute[]; bool hasTyping = valueTypings != null && valueTypings.Length > 0; BlackboardProperty propType = _property.type.Contains("Setter") ? BlackboardProperty.Setter : BlackboardProperty.Getter; string[] names = hasTyping ? _currentBB.GetNamesTyped(propType, valueTypings[0].CompatableTypes) : _currentBB.GetNames(propType); if (names != null && names.Length > 0) { var options = names.Select(n => new GUIContent(n)).ToArray(); var currentNameProp = _property.FindPropertyRelative("_name"); int currentNameIndex = Array.IndexOf(names, currentNameProp.stringValue); currentNameIndex = Mathf.Clamp(currentNameIndex, 0, names.Length - 1); currentNameIndex = EditorGUI.Popup(rect, _label, currentNameIndex, options); currentNameProp.stringValue = names[currentNameIndex]; } else { string message = hasTyping ? "No Compatable value" : "Blackboard Empty"; EditorGUI.LabelField(rect, _label, $"[{message}]"); } }
private void UpdateNames(SerializedProperty property) { if (_serializedTargetObject is IBlackboardProvider bbProvider) { _currentBB = bbProvider.Blackboard; } var valueTypings = FieldInfo.GetCustomAttributes(typeof(ValueTypeAttribute), true) as ValueTypeAttribute[]; bool hasTyping = valueTypings != null && valueTypings.Length > 0; BlackboardProperty propType = property.type.Contains("Setter") ? BlackboardProperty.Setter : BlackboardProperty.Getter; string[] names = hasTyping ? _currentBB.GetNamesTyped(propType, valueTypings[0].CompatableTypes) : _currentBB.GetNames(propType); _availableNames = new string[] { "None" }.Concat(names).ToArray(); }
internal static string[] GetNamesTyped(this Blackboard blackboard, BlackboardProperty typeMask, params Type[] compatableTypes) { if (blackboard != null && compatableTypes != null && compatableTypes.Length > 0) { var result = new List <string>(); var names = blackboard.GetNames(typeMask); foreach (var n in names) { Type type = null; if (typeMask.IncludesGetter()) { if (blackboard.GetterValues.TryGetValue(n, out var getAccessor)) { type = getAccessor.PropertyType; } } else if (typeMask.IncludesSetter()) { if (blackboard.SetterValues.TryGetValue(n, out var setAccessor)) { type = setAccessor.PropertyType; } } if (type != null) { if (TypeArrayContainsTypeOrBaseType(compatableTypes, type)) { result.Add(n); } } } return(result.ToArray()); } return(s_emptyNames); }
internal static string[] GetNames(this Blackboard blackboard, BlackboardProperty typeMask) { if (blackboard == null || blackboard.GetterValues == null || blackboard.SetterValues == null) { return(s_emptyNames); } string[] namesResult = new string[0]; if (typeMask.IncludesGetter()) { var names = blackboard.GetterValues.Keys.Where(key => !string.IsNullOrEmpty(key)); namesResult = namesResult.Concat(names).ToArray(); } if (typeMask.IncludesSetter()) { var names = blackboard.SetterValues.Keys.Where(key => !string.IsNullOrEmpty(key) && !namesResult.Contains(key)); namesResult = namesResult.Concat(names).ToArray(); } return(namesResult); }
internal static bool IncludesSetter(this BlackboardProperty type) { return(type == BlackboardProperty.Setter || type == BlackboardProperty.GetterOrSetter); }
set => SetValue(BlackboardProperty, value);