Exemplo n.º 1
0
        public static Dictionary <string, List <SerializedProperty> > GatherProperties(
            SerializedObject serializedObject, string defaultFoldoutName = "Misc")
        {
            var results = new Dictionary <string, List <SerializedProperty> >();

            var it = serializedObject.GetIterator(); it.Next(true);

            while (it.NextVisible(false))
            {
                if (it.name == HedgehogEditorGUIUtility.ScriptPropertyName)
                {
                    continue;
                }

                var attr = HedgehogEditorGUIUtility.GetAttribute <FoldoutAttribute>(it);
                var type = attr == null ? defaultFoldoutName : attr.Name;

                (results.ContainsKey(type) ? results[type] : (results[type] = new List <SerializedProperty>()))
                .Add(it.Copy());
            }

            foreach (var field in serializedObject.targetObject.GetType().GetFields(
                         BindingFlags.NonPublic | BindingFlags.Instance))
            {
                var property = serializedObject.FindProperty(field.Name);
                if (property == null)
                {
                    continue;
                }
                if (HedgehogEditorGUIUtility.GetAttribute <HideInInspector>(field) != null)
                {
                    continue;
                }

                foreach (var propertyLists in results.Values)
                {
                    if (propertyLists.Contains(property))
                    {
                        continue;
                    }
                }

                var attr = HedgehogEditorGUIUtility.GetAttribute <FoldoutAttribute>(field);
                var type = attr == null ? defaultFoldoutName : attr.Name;

                (results.ContainsKey(type) ? results[type] : (results[type] = new List <SerializedProperty>()))
                .Add(property);
            }

            return(results);
        }
Exemplo n.º 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var tooltip = HedgehogEditorGUIUtility.GetAttribute <TooltipAttribute>(property);

            if (tooltip != null)
            {
                property.stringValue = EditorGUI.TagField(position,
                                                          new GUIContent(ObjectNames.NicifyVariableName(property.name), tooltip.tooltip), property.stringValue);
            }
            else
            {
                property.stringValue = EditorGUI.TagField(position, ObjectNames.NicifyVariableName(property.name),
                                                          property.stringValue);
            }
        }
Exemplo n.º 3
0
        private bool IsFirst(SerializedProperty property, string foldoutName)
        {
            var it = property.serializedObject.GetIterator(); it.Next(true);

            while (it.NextVisible(true))
            {
                if (it.name == property.name)
                {
                    break;
                }

                var attr = HedgehogEditorGUIUtility.GetAttribute <FoldoutAttribute>(it);
                if (attr != null && attr.Name == foldoutName)
                {
                    return(false);
                }
            }

            return(true);
        }