Beispiel #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            GrassPostProcess element = GetElement(property);

            property.isExpanded = EditorGUI.Foldout(new Rect(position.x, position.y, EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight),
                                                    property.isExpanded,
                                                    new GUIContent(NameAttribute.GetNameFromClassType(element.GetType()), NameAttribute.GetDescriptionFromClassType(element.GetType())),
                                                    true);


            if (GUI.changed)
            {
                property.serializedObject.ApplyModifiedProperties();
            }
            if (property.objectReferenceValue == null)
            {
                EditorGUIUtility.ExitGUI();
            }

            if (property.isExpanded)
            {
                const float witdthOffset = 25f;
                var         newRect      = new Rect(position.x, position.y, position.width - position.x - witdthOffset, position.height);
                DrawAllChildrensGUI(newRect, property);
            }
            property.serializedObject.ApplyModifiedProperties();
            EditorGUI.EndProperty();
        }
Beispiel #2
0
        public static string GetDescriptionFromClassType(Type type)
        {
            NameAttribute attr = GetAttributeFromClassType(type);

            if (attr == null || string.IsNullOrEmpty(attr.description))
            {
                return("");
            }
            return(attr.description);
        }
Beispiel #3
0
        public static string GetNameFromClassType(Type type)
        {
            NameAttribute attr = GetAttributeFromClassType(type);

            if (attr == null || string.IsNullOrEmpty(attr.name))
            {
                return(type.Name);
            }
            return(attr.name);
        }
Beispiel #4
0
        private void OnAddDropdownCallback(Rect button, ReorderableList list)
        {
            GenericMenu menu = new GenericMenu();

#if UNITY_2018_2_OR_NEWER
            menu.allowDuplicateNames = true;
#endif
            List <Type> types = AssetsManager.GetListOfType(typeof(GrassPostProcess));
            foreach (Type type in types)
            {
                menu.AddItem(new GUIContent(NameAttribute.GetNameFromClassType(type), NameAttribute.GetDescriptionFromClassType(type)), false, AddPostProcessHandler, type.Name);
            }
            menu.ShowAsContext();
        }