protected void DrawContext(Rect position, SerializedProperty property, GUIContent label, System.Type type)
 {
     using (var check = new EditorGUI.ChangeCheckScope())
     {
         BlackboardEditorGUI.DrawContext(m_BlackboardList, position, property, label, type);
         if (check.changed)
         {
             ChangeData();
         }
     }
 }
        public void DrawSetting(IReadOnlyList <Blackboard> blackborads)
        {
            SerializedObject.Update();

            using (new EditorGUILayout.VerticalScope(GUI.skin.box))
            {
                EditorGUILayout.LabelField("Sequence Paramater");
                using (new EditorGUILayout.VerticalScope(GUI.skin.box))
                {
                    var fieldInfos = Utility.CollectFields <SharedValueContext>(Asset);
                    for (int i = 0; i < fieldInfos.Count; i++)
                    {
                        var field    = fieldInfos[i];
                        var name     = field.Name;
                        var prop     = SerializedObject.FindProperty(name);
                        var instance = (SharedValueContext)field.GetValue(Asset);
                        var rect     = GUILayoutUtility.GetRect(1f, EditorGUIUtility.singleLineHeight, GUILayout.ExpandWidth(true));
                        BlackboardEditorGUI.DrawContext(blackborads, rect, prop, new GUIContent(prop.displayName), instance.ValueType, EditorGUIUtility.labelWidth);
                    }
                }
            }

            SerializedObject.ApplyModifiedProperties();
        }
Exemple #3
0
        public void Draw(IReadOnlyList <Blackboard> blackboards)
        {
            if (blackboards == null)
            {
                return;
            }

            using (new EditorGUILayout.VerticalScope(GUI.skin.box))
            {
                m_IsFoldout = EditorGUIEx.Foldout(m_IsFoldout, new GUIContent("Blackboard"));
                if (!m_IsFoldout)
                {
                    return;
                }

                using (new EditorGUILayout.VerticalScope(GUI.skin.box))
                {
                    for (int bi = 0; bi < blackboards.Count; bi++)
                    {
                        var blackboard = blackboards[bi];
                        if (blackboard == null)
                        {
                            continue;
                        }

                        var serializedObject = new SerializedObject(blackboard);
                        serializedObject.Update();

                        using (new EditorGUILayout.VerticalScope(GUI.skin.box))
                        {
                            var foldoutProp = serializedObject.FindProperty(Blackboard.PropNameFoldout);
                            foldoutProp.boolValue = EditorGUIEx.Foldout(foldoutProp.boolValue, new GUIContent(blackboard.GetType().Name));
                            if (!foldoutProp.boolValue)
                            {
                                serializedObject.ApplyModifiedProperties();
                                continue;
                            }

                            var feilds = BlackboardEditorGUI.CollectFields(blackboard);

                            for (int i = 0; i < feilds.Count; i++)
                            {
                                var field     = feilds[i];
                                var attr      = field.GetCustomAttribute <MenuTitle>();
                                var typeName  = attr == null ? field.FieldType.Name : attr.Name;
                                var fieldProp = serializedObject.FindProperty(field.Name);
                                if (fieldProp == null)
                                {
                                    continue;
                                }

                                var propValue = fieldProp.FindPropertyRelative(SharedValue.PropNameValue);

                                var height     = EditorGUIEx.GetPropertyHeight(propValue);
                                var secureRect = GUILayoutUtility.GetRect(1f, height + 2f, GUILayout.ExpandWidth(true));
                                var rect       = new Rect(secureRect.x, secureRect.y, secureRect.width, height);

                                var labelRect = new Rect(rect.x, rect.y, EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight);
                                EditorGUI.LabelField(labelRect, new GUIContent(fieldProp.displayName));

                                var itemWidth    = (rect.width - labelRect.width) * 0.5f;
                                var propName     = fieldProp.FindPropertyRelative(SharedValue.PropNamePropertyName);
                                var propNameRect = new Rect(rect.x + labelRect.width, rect.y, itemWidth * 0.95f, EditorGUIUtility.singleLineHeight);
                                propName.stringValue = EditorGUI.TextField(propNameRect, propName.stringValue);

                                var valueType = field.FieldType.BaseType.GetField(SharedValue.PropNameValue, BindingFlags.Instance | BindingFlags.NonPublic).FieldType;
                                var valueRect = new Rect(propNameRect.x + itemWidth, rect.y, itemWidth, rect.height);
                                var valueName = propValue.propertyType == SerializedPropertyType.Generic ? valueType.Name : "";
                                EditorGUIEx.PropertyField(valueRect, propValue, new GUIContent(valueName), true, valueType);
                            }

                            serializedObject.ApplyModifiedProperties();
                        }
                        EditorGUILayout.Space();
                    }
                }
            }
        }