private void AddNewParam(SerializedType type)
    {
        string typename  = KnownType.GetDisplayedName(type.Type);
        string paramName = StringUtils.MakeUnique($"New {typename}", Parameters.Select(p => p.Name));

        Parameters.Add
        (
            new GenericParameter(type)
        {
            Name = paramName
        }
        );
    }
        private void AddNewVariant(SerializedType type, List <Variant> list)
        {
            string typename  = KnownType.GetDisplayedName(type.Type);
            string paramName = StringUtils.MakeUnique($"New {typename}", list.Select(p => p.Name));

            list.Add
            (
                new Variant(type)
            {
                Name = paramName
            }
            );
        }
示例#3
0
        private void OnAddInput(UnityEditorInternal.ReorderableList list)
        {
            string typename  = KnownType.GetDisplayedName(Node.InputType.Type);
            string paramName = StringUtils.MakeUnique($"New {typename}", Node.Inputs.Select(p => p.Input.Name));

            ProxyList.Add(1);
            Node.Inputs.Add
            (
                new ActionSelector.EntryPoint()
            {
                Input = new Variant(Node.InputType)
                {
                    Name = paramName
                }
            }
            );
        }
        private bool Initialize(ref Rect position, SerializedProperty property, GUIContent label,
                                FieldInfo fieldInfo, PropertyAttribute attribute)
        {
            position.height = EditorGUI.GetPropertyHeight(property, label);

            View.Target = property.serializedObject.targetObject;

            View.AsParametrized = View.Target as IBaseObject;

            View.DataProvider = View.AsParametrized?.GetProvider();

            if (View.DataProvider == null)
            {
                EditorGUI.HelpBox(position, $"{property.name}: Unable to get instance of IDataSetProvider!", MessageType.Error);
                return(false);
            }

            View.Parameters = View.DataProvider.GetParameters((p) => fieldInfo.FieldType.IsAssignableFrom(p.HoldType.Type));

            View.Typename = KnownType.GetDisplayedName(fieldInfo.FieldType);
            if (View.Typename == null)
            {
                EditorGUI.HelpBox(position, string.Format("Type {0} is not a known type!", fieldInfo.FieldType), MessageType.Error);
                return(false);
            }

            if (!View.DataProvider.HasObject(View.Target))
            {
                EditorGUI.HelpBox(position, "Unable to edit this object!", MessageType.Error);
                return(false);
            }

            if (!(attribute is Parametrized))
            {
                EditorGUI.HelpBox(position, "Unable to get Parametrized attribute!", MessageType.Error);
                return(false);
            }

            return(true);
        }
示例#5
0
    private bool Initialize(ref Rect position, SerializedProperty property, GUIContent label)
    {
        position.height = base.GetPropertyHeight(property, label);

        Editor = BehaviourTreeEditor.GetInstance();
        if (!Editor)
        {
            EditorGUI.HelpBox(position, "Unable to get BehaviourTreeEditor instance!", MessageType.Error);
            return(false);
        }

        Parameters = Editor.GetCurrentAsset().Parameters.Where(p => p.HoldType.Type == fieldInfo.FieldType).ToList();

        AsNode = (BehaviourTreeNode)property.serializedObject.targetObject;

        Typename = KnownType.GetDisplayedName(fieldInfo.FieldType);
        if (Typename == null)
        {
            EditorGUI.HelpBox(position, string.Format("Type {0} is not a known type!", fieldInfo.FieldType), MessageType.Error);
            return(false);
        }

        if (!Editor.CanEditNode(AsNode))
        {
            EditorGUI.HelpBox(position, "Unable to edit this node!", MessageType.Error);
            return(false);
        }

        if (!(attribute is Blackboard.Required))
        {
            EditorGUI.HelpBox(position, "Unable to get Required attribute!", MessageType.Error);
            return(false);
        }

        SetContentForParameters();

        return(true);
    }
示例#6
0
    public override void OnInspectorGUI()
    {
        if (!Initialize())
        {
            return;
        }

        InspectorUtils.DrawDefaultScriptField(serializedObject);

        GUILayout.Label("Description", EditorStyles.boldLabel);
        EditorGUILayout.TextArea(Node.Description, EditorStyles.wordWrappedLabel);

        EditorGUILayout.Space();
        GUILayout.Label("Settings", EditorStyles.boldLabel);

        InspectorUtils.DrawDefaultInspectorWithoutScriptField(serializedObject);

        EditorGUILayout.Space();
        GUILayout.Label("Parameters", EditorStyles.boldLabel);

        EditorGUI.BeginChangeCheck();

        EditorGUIUtility.labelWidth -= FieldLeftShift;
        var requiredParameters = Node.GetType().GetProperties().Where(p => System.Attribute.IsDefined(p, typeof(Blackboard.Required)));

        foreach (PropertyInfo propertyInfo in requiredParameters)
        {
            if (!propertyInfo.CanRead || !propertyInfo.CanWrite)
            {
                EditorGUILayout.HelpBox(string.Format("Property '{0}' must be both readable and writable", propertyInfo.Name), MessageType.Error);
                continue;
            }

            var typename = KnownType.GetDisplayedName(propertyInfo.PropertyType);
            if (typename == null)
            {
                EditorGUILayout.HelpBox(string.Format("Type {0} is not a known type!", propertyInfo.PropertyType), MessageType.Error);
                continue;
            }

            var matchingParameters = Parameters.Where(p => p.GetHoldType().Type == propertyInfo.PropertyType).ToList();

            int  oldIndex    = -1;//Node.GetGenericParameterIndex(propertyInfo.Name, propertyInfo.PropertyType, matchingParameters);
            bool wasConstant = Node.IsGenericParameterConstant(propertyInfo.Name);

            BeginPanelBackground(wasConstant, oldIndex == -1);
            {
                GUILayout.BeginHorizontal();
                {
                    DrawLabel(propertyInfo.Name);

                    var fieldRect = EditorGUILayout.GetControlRect(true, LockSize, SpaceEditorStyles.LightObjectField);
                    var lockRect  = new Rect(fieldRect.x + fieldRect.width - LockSize, fieldRect.y + 2, LockSize, fieldRect.height);

                    bool isConstant = EditorGUI.Toggle(lockRect, wasConstant, SpaceEditorStyles.LockButton);

                    fieldRect.width -= LockSize;

                    if (isConstant)
                    {
//                        Variant parameter = wasConstant
//                            ? Node.ParametrizedProperties[propertyInfo.Name].Parameter
//                            : new Variant(propertyInfo.PropertyType);
//
//                        VariantUtils.DrawParameter(fieldRect, parameter, false);
//
//                        Node.SetRequiredParameter(propertyInfo.Name, parameter, true);
                    }
                    else
                    {
                        fieldRect.y += 2;

                        /*var paramListContent = BuildParameterGUIList(typename, matchingParameters);
                         * int newIndex = EditorGUI.Popup(fieldRect, GUIContent.none, oldIndex + 1, paramListContent.ToArray(), SpaceEditorStyles.LightObjectField);
                         *
                         * if (!Editor.ExecuteInRuntime() && (oldIndex != (newIndex - 1) || (isConstant != wasConstant)))
                         * {
                         *  ProcessSelectionResult(newIndex, propertyInfo, matchingParameters);
                         * }*/
                    }
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();
        }

        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
        }
    }
示例#7
0
        bool Initialize(ref Rect position, ref bool displayLock, SerializedProperty property, Framework.Parameter asGeneric)
        {
            Type           targetType       = property.serializedObject.targetObject.GetType();
            SerializedType isTypeRestricted = null;

            var       path           = property.GetPath();
            FieldInfo paramFieldInfo = path.MaterializeToFieldInfo(targetType);

            var typeAttribute = paramFieldInfo.GetCustomAttribute <TypeRestricted>();

            if (typeAttribute != null)
            {
                switch (typeAttribute.Source)
                {
                case TypeRestricted.TypeSource.Value:
                {
                    isTypeRestricted = new SerializedType(typeAttribute.Type);
                    break;
                }

                case TypeRestricted.TypeSource.Field:
                {
                    var field = targetType.GetField(typeAttribute.SourceValue);
                    if (field != null)
                    {
                        var typeValue = field.GetValue(property.serializedObject.targetObject);
                        switch (typeValue)
                        {
                        case SerializedType asSerialized:
                        {
                            isTypeRestricted = asSerialized;
                            break;
                        }

                        case Type asSystem:
                        {
                            isTypeRestricted = new SerializedType(asSystem);
                            break;
                        }
                        }
                        break;
                    }

                    return(false);
                }

                default:
                    return(false);
                }
            }

            View.Target         = property.serializedObject.targetObject;
            View.AsParametrized = View.Target as IBaseObject;
            View.DataProvider   = View.AsParametrized?.GetProvider();

            if (isTypeRestricted != null && isTypeRestricted.Type != null)
            {
                displayLock     = true;
                View.Parameters = View.DataProvider.GetParameters(t =>
                {
                    if (string.IsNullOrEmpty(isTypeRestricted.Metadata))
                    {
                        return(isTypeRestricted.Type.IsAssignableFrom(t.GetHoldType().Type));
                    }
                    else
                    {
                        return(isTypeRestricted.Equals(t.GetHoldType()));
                    }
                });
                View.Typename = KnownType.GetDisplayedName(isTypeRestricted.Type);
            }
            else
            {
                displayLock     = false;
                View.Parameters = View.DataProvider.GetParameters();
                View.Typename   = "Parameter";
            }

            if (asGeneric.GetHoldType() != isTypeRestricted)
            {
                asGeneric.Value.HoldType = isTypeRestricted;
            }

            if (View.Typename == null)
            {
                EditorGUI.HelpBox(position, string.Format("Type {0} is not a known type!", fieldInfo.FieldType), MessageType.Error);
                return(false);
            }

            if (!View.DataProvider.HasObject(View.Target))
            {
                EditorGUI.HelpBox(position, "Unable to edit this object!", MessageType.Error);
                return(false);
            }

            if (View.DataProvider == null)
            {
                EditorGUI.HelpBox(position, $"{property.name}: Unable to get instance of IDataSetProvider!", MessageType.Error);
                return(false);
            }

            return(true);
        }