protected override void DrawContent()
        {
            if (Node.Anim)
            {
                GUI.Box(drawRect, GUIContent.none, EditorStyles.helpBox);

                int index     = -1;
                var paramList = Node.Anim.parameters.ToList();
                var param     = paramList.FirstOrDefault(p => p.name == Node.AnimParam.Name);
                if (param != null)
                {
                    index = paramList.IndexOf(param);
                }

                drawRect.x    += ContentMargin;
                drawRect.width = drawRect.width - ContentMargin * 2;

                drawRect.height = GenericParamUtils.FieldHeight;
                int newIndex = EditorGUI.Popup(drawRect, index, paramList.Select(p => p.name).ToArray());
                if (newIndex != index)
                {
                    SetNewParam(paramList[newIndex]);
                }

                if (string.IsNullOrWhiteSpace(Node.AnimParam?.HoldType?.Metadata))
                {
                    drawRect.y += drawRect.height;
                    GenericParamUtils.DrawParameter(drawRect, Node.AnimParam, false);
                }
            }
            else
            {
                EditorGUI.HelpBox(drawRect, "AnimController is required!", MessageType.Error);
            }
        }
Esempio n. 2
0
    public void Recreate()
    {
        GenericParamUtils.SetDrawersForKnownTypes();

        _drawerList = new ReorderableList
                      (
            Parameters, typeof(GenericParameter),
            true, false, true, true
                      );

        DrawerList.drawHeaderCallback += rect =>
        {
            rect.x     += ReorderableListOffset;
            rect.width -= ReorderableListOffset;

            var original = rect;

            rect.width *= 0.5f;
            GUI.Label(rect, "Name");


            rect.x     = original.x + GenericParamUtils.LabelWidth * 1.35f;
            rect.width = GenericParamUtils.FieldWidth;
            GUI.Label(rect, "Default value");
        };

        if (!CustomAdd)
        {
            DrawerList.onAddDropdownCallback += OnAddParameter;
        }

        DrawerList.drawElementCallback += OnDrawParameter;
    }
        private void OnDrawParameter(Rect rect, int index, bool active, bool focused)
        {
            var parameter = TreeAsset.Parameters[index];

            rect.height = GenericParamUtils.FieldHeight;
            rect.y     += 2;

            GenericParamUtils.DrawParameter(rect, parameter);
        }
        private void GenericParameterDrawer(Rect rect, SerializedProperty element, GUIContent label, int index, bool selected, bool focused)
        {
            var param = element.GetAs <GenericParameter>();

            if (param != null)
            {
                GenericParamUtils.DrawParameter(rect, param);
            }
            else
            {
                GUI.Label(rect, "Unable to render as GenericParameter!");
            }
        }
Esempio n. 5
0
        void RecreateDrawer()
        {
            GenericParamUtils.SetDrawersForKnownTypes();

            /*ProxyList = new List<int>(Graph.Inputs.Count);
             *
             * DrawerList = new UnityEditorInternal.ReorderableList
             * (
             *  ProxyList, typeof(ActionGraph.EntryPoint),
             *  true, false, true, true
             * );
             *
             * DrawerList.drawHeaderCallback += rect =>
             * {
             *  rect.x      += ParamListDrawer.ReorderableListOffset;
             *  rect.width  -= ParamListDrawer.ReorderableListOffset;
             *
             *  var original = rect;
             *
             *  rect.width *= 0.5f;
             *  GUI.Label(rect, "Name");
             *
             *
             *  rect.x = original.x + GenericParamUtils.LabelWidth * 1.35f;
             *  rect.width = GenericParamUtils.FieldWidth;
             *  GUI.Label(rect, "Input value");
             * };
             *
             * DrawerList.onAddCallback += OnAddInput;
             *
             * DrawerList.drawElementCallback += OnDrawParameter;
             *
             * DrawerList.onCanAddCallback += list => Graph.InputType != null && Graph.InputType.Type != null;
             * DrawerList.onRemoveCallback += list =>
             * {
             *  Presenter.OnRemoveInputAtIndex(list.index);
             * };
             *
             * DrawerList.onReorderCallbackWithDetails += (list, index, newIndex) =>
             * {
             *  float pos = Positions[index];
             *
             *  _positions.RemoveAt(index);
             *  _positions.Insert(newIndex, pos);
             *
             *  Presenter.OnReorderInputAtIndex(index, newIndex);
             * };*/
        }
        void RecreateDrawer()
        {
            GenericParamUtils.SetDrawersForKnownTypes();

            ProxyList = new List <int>(Node.Inputs.Count);

            DrawerList = new UnityEditorInternal.ReorderableList
                         (
                ProxyList, typeof(ActionSelector.EntryPoint),
                true, false, true, true
                         );

            DrawerList.drawHeaderCallback += rect =>
            {
                rect.x     += ParamListDrawer.ReorderableListOffset;
                rect.width -= ParamListDrawer.ReorderableListOffset;

                var original = rect;

                rect.width *= 0.5f;
                GUI.Label(rect, "Name");


                rect.x     = original.x + GenericParamUtils.LabelWidth * 1.35f;
                rect.width = GenericParamUtils.FieldWidth;
                GUI.Label(rect, "Input value");
            };

            DrawerList.onAddCallback += OnAddInput;

            DrawerList.drawElementCallback += OnDrawParameter;

            DrawerList.onCanAddCallback += list => Node.InputType != null && Node.InputType.Type != null;
            DrawerList.onRemoveCallback += list =>
            {
                OnRemoveInputAtIndex(list.index);
            };

            DrawerList.onReorderCallbackWithDetails += (list, index, newIndex) =>
            {
                float pos = Positions[index];

                _positions.RemoveAt(index);
                _positions.Insert(newIndex, pos);

                OnReorderInputAtIndex(index, newIndex);
            };
        }
        private void OnDrawParameter(Rect rect, int index, bool active, bool focused)
        {
            var parameter = Node.Inputs[index];

            if (index == 0)
            {
                FirstPos = rect.y;
            }

            Positions[index] = rect.y - FirstPos;

            rect.height = GenericParamUtils.FieldHeight;
            rect.y     += 2;

            GenericParamUtils.DrawParameter(rect, parameter.Input);
        }
        private void RecreateParameterList()
        {
            if (!TreeAsset)
            {
                return;
            }

            GenericParamUtils.SetDrawersForKnownTypes();

            ParameterList = new UnityEditorInternal.ReorderableList
                            (
                TreeAsset.Parameters, typeof(GenericParameter),
                true, false, true, true
                            );

            ParameterList.drawHeaderCallback += rect =>
            {
                rect.x     += ReorderableListOffset;
                rect.width -= ReorderableListOffset;

                var original = rect;

                rect.width *= 0.5f;
                GUI.Label(rect, "Name");


                rect.x     = original.x + GenericParamUtils.LabelWidth * 1.35f;
                rect.width = GenericParamUtils.FieldWidth;
                GUI.Label(rect, "Default value");
            };

            ParameterList.onAddDropdownCallback += OnAddParameter;
            ParameterList.drawElementCallback   += OnDrawParameter;
            ParameterList.onChangedCallback     += list =>
            {
                Undo.RecordObject(TreeAsset, "Modified Parameters");
                EditorUtility.SetDirty(TreeAsset);
            };
        }
        public void OnGUI(Rect position, SerializedProperty property, GUIContent label,
                          SerializedType fieldType, PropertyAttribute attribute, bool displayLock = true)
        {
            SetContentForParameters();

            int  index       = -1;
            bool wasConstant = false;
            var  setParam    = AsParametrized.GetParameter(property.name, fieldType);

            if (setParam != null)
            {
                index       = Parameters.FindIndex(p => p.Name.Equals(setParam.Name) && p.HoldType.Equals(setParam.HoldType));
                wasConstant = AsParametrized.IsParameterConstant(property.name);
            }

            DrawBackground(position, index != -1 || wasConstant);

            label = EditorGUI.BeginProperty(position, label, property);
            {
                position.y += BoxBackgroundHeight * 0.5f;
                position    = EditorGUI.PrefixLabel(position, new GUIContent(property.displayName));

                EditorGUI.indentLevel = 0;
                EditorGUI.BeginChangeCheck();
                {
                    var fieldRect = position;

                    if (displayLock)
                    {
                        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
                                ? AsParametrized.GetParameter(property.name, fieldType)
                                : new GenericParameter(fieldType);

                            GenericParamUtils.DrawParameter(fieldRect, parameter, false);

                            AsParametrized.SetParameter(property.name, parameter, true);
                        }
                        else
                        {
                            DrawParamField(ref fieldRect, ref index, property, wasConstant != isConstant);
                        }
                    }
                    else
                    {
                        DrawParamField(ref fieldRect, ref index, property);
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    EditorUtility.SetDirty(Target);
                }
            }
            EditorGUI.EndProperty();
        }
Esempio n. 10
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.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();
        }
    }