コード例 #1
0
        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}]");
            }
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 internal static bool IncludesSetter(this BlackboardProperty type)
 {
     return(type == BlackboardProperty.Setter || type == BlackboardProperty.GetterOrSetter);
 }
コード例 #6
0
 set => SetValue(BlackboardProperty, value);