Esempio n. 1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            position = EditorGUI.PrefixLabel(position, label);

            if (property.propertyType != propertyType_)
            {
                EditorGUI.LabelField(position, String.Format("Error: {0} attribute can be applied only to {1} type", typeof(TAttribute), propertyType_));
                return;
            }

            // User can pass null or empty string as field value in property attribute constructor so GetField can return null or empty string,
            // treat this as not set field - fallback to search of TComponent component attached to inspected object
            var field = GetPropertyPath((TAttribute)attribute);

            if (!String.IsNullOrEmpty(field))
            {
                ObjectFieldPropertyDrawerUtils.DrawObjectFieldPoperty <TComponent>(
                    position, property, field, DrawComponentProperty);
                return;
            }

            var inspectedObjectComponent = property.serializedObject.targetObject as Component;

            if (inspectedObjectComponent == null)
            {
                EditorGUI.LabelField(position, "Error: inspected object type is not Component");
                return;
            }

            var component = inspectedObjectComponent.GetComponent <TComponent>();

            if (component == null)
            {
                EditorGUI.LabelField(position, String.Format("Error: missing {0} component in inspected object", typeof(TComponent)));
                return;
            }

            DrawComponentProperty(position, property, component);
        }
Esempio n. 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            position = EditorGUI.PrefixLabel(position, label);

            if (property.propertyType != SerializedPropertyType.String)
            {
                EditorGUI.LabelField(position, String.Format("Error: {0} attribute can be applied only to {1} type", typeof(SpriteAtlasSpriteNameAttribute), SerializedPropertyType.String));
                return;
            }

            var spriteAtlasField = ((SpriteAtlasSpriteNameAttribute)attribute).SpriteAtlasField;

            if (!String.IsNullOrEmpty(spriteAtlasField))
            {
                ObjectFieldPropertyDrawerUtils.DrawObjectFieldPoperty <SpriteAtlas>(
                    position, property, spriteAtlasField,
                    DrawSpriteNameSelect);
            }
            else
            {
                EditorGUI.LabelField(position, String.Format("Error: sprite atlas field is null or empty for {0} attribute", typeof(SpriteAtlasSpriteNameAttribute)));
            }
        }