private void AddNewParam(Type type)
        {
            string typename  = GenericParameter.GetDisplayedName(type);
            string paramName = StringUtils.MakeUnique(string.Format("New {0}", typename), TreeAsset.Parameters.Select(p => p.Name));

            TreeAsset.Parameters.Add(
                new GenericParameter(type)
            {
                Name = paramName
            }
                );
        }
예제 #2
0
    private void AddNewParam(SerializedType type)
    {
        string typename  = GenericParameter.GetDisplayedName(type.Type);
        string paramName = StringUtils.MakeUnique($"New {typename}", Parameters.Select(p => p.Name));

        Parameters.Add
        (
            new GenericParameter(type)
        {
            Name = paramName
        }
        );
    }
예제 #3
0
        private void OnAddInput(UnityEditorInternal.ReorderableList list)
        {
            string typename  = GenericParameter.GetDisplayedName(Graph.InputType.Type);
            string paramName = StringUtils.MakeUnique($"New {typename}", Graph.Inputs.Select(p => p.Input.Name));

            ProxyList.Add(1);
            Graph.Inputs.Add
            (
                new ActionGraph.EntryPoint()
            {
                Input = new GenericParameter(Graph.InputType)
                {
                    Name = paramName
                }
            }
            );
        }
예제 #4
0
        private bool Initialize(ref Rect position, SerializedProperty property, GUIContent label)
        {
            position.height = base.GetPropertyHeight(property, label);

            Target = property.serializedObject.targetObject;

            AsParametrized = Target as IBaseObject;

            DataProvider = AsParametrized?.GetProvider();

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

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

            Typename = GenericParameter.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 (!DataProvider.HasObject(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);
            }

            SetContentForParameters();

            return(true);
        }
    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 = GenericParameter.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);
    }
    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 = GenericParameter.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.HoldType.Type == propertyInfo.PropertyType).ToList();

            int  oldIndex    = 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)
                    {
                        GenericParameter parameter = wasConstant
                            ? Node.ParametrizedProperties[propertyInfo.Name].Parameter
                            : new GenericParameter(propertyInfo.PropertyType);

                        GenericParamUtils.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();
        }
    }