Ejemplo n.º 1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);

            var readOnlyAttribute = attribute as ReadOnlyAttribute;

            using (DisabledGroup.Do(!readOnlyAttribute.onlyInPlaymode || EditorApplication.isPlayingOrWillChangePlaymode))
            {
                EditorGUI.PropertyField(position, property, label, true);
            }
        }
Ejemplo n.º 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);

            // Bugged Unity... hacks :(
            if (!property.type.StartsWith("Modifiable"))
            {
                return;
            }

            Rect labelPosition    = position.Left(EditorGUIUtility.labelWidth);
            Rect fieldsPosition   = position.Right(-EditorGUIUtility.labelWidth);
            Rect originalPosition = fieldsPosition.Left(fieldsPosition.width * 0.5f);
            Rect modifiedPosition = fieldsPosition.Right(-fieldsPosition.width * 0.5f);

            EditorGUI.LabelField(labelPosition, label);

            SerializedProperty originalValue = property.GetMemberProperty <ModifiableInt>(m => m.OriginalValue);
            SerializedProperty modifiedValue = property.GetMemberProperty <ModifiableInt>(m => m.ModifiedValue);

            bool modified;

            using (LabelWidth.Do(56.0f))
                using (IndentLevel.Do(0))
                {
                    EditorGUI.BeginChangeCheck();
                    EditorGUI.PropertyField(originalPosition, originalValue, new GUIContent("Original"));
                    modified = EditorGUI.EndChangeCheck();

                    using (DisabledGroup.Do(true))
                    {
                        EditorGUI.PropertyField(modifiedPosition, modifiedValue, new GUIContent("Modified"));
                    }
                }

            if (modified)
            {
                originalValue.serializedObject.ApplyModifiedProperties();
                modifiedValue.serializedObject.ApplyModifiedProperties();

                var modifiable = SerializedPropertyHelper.GetValue(fieldInfo, property) as IModifiable;
                modifiable.UpdateModifiedValues();

                originalValue.serializedObject.Update();
                modifiedValue.serializedObject.Update();
            }
        }
Ejemplo n.º 3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);
            property.serializedObject.Update();

            var nameProperty  = property.GetMemberProperty <TweenShaderProperty>(p => p.name);
            var typeProperty  = property.GetMemberProperty <TweenShaderProperty>(p => p.type);
            var curveProperty = property.GetMemberProperty <TweenShaderProperty>(p => p.curve);
            var fromProperty  = property.GetMemberProperty <TweenShaderProperty>(p => p.from);
            var toProperty    = property.GetMemberProperty <TweenShaderProperty>(p => p.to);

            var mainRow  = position.Row(0);
            var fromRect = position.Row(1).Right(-FromToPadding);
            var toRect   = position.Row(2).Right(-FromToPadding);

            Rect nameRect, typeRect, curveRect;

            nameRect = mainRow.Right(CurveWidth, out curveRect).Right(TypeWidth, out typeRect);

            var tweenShader    = property.serializedObject.targetObject as TweenShader;
            var targetRenderer = tweenShader.targetRenderer;

            if (targetRenderer == null)
            {
                nameProperty.stringValue    = EditorGUI.TextField(nameRect, nameProperty.stringValue);
                typeProperty.enumValueIndex = EditorGUI.Popup(typeRect, typeProperty.enumValueIndex, typeProperty.enumDisplayNames);
            }
            else
            {
                TweenShaderPropertiesCache cache;
                if (!propertiesCache.TryGetValue(targetRenderer, out cache))
                {
                    cache = new TweenShaderPropertiesCache();
                    propertiesCache.Add(targetRenderer, cache);
                }

                cache.UpdateProperties(tweenShader);

                int index = System.Array.IndexOf(cache.propertyNameOptions, nameProperty.stringValue);
                index = EditorGUI.Popup(nameRect, index, cache.propertyNameOptions);

                nameProperty.stringValue    = cache.properties[index].name;
                typeProperty.enumValueIndex = ( int )cache.properties[index].type;

                using (DisabledGroup.Do(true))
                {
                    EditorGUI.Popup(typeRect, typeProperty.enumValueIndex, typeProperty.enumDisplayNames);
                }
            }

            EditorGUI.PropertyField(curveRect, curveProperty, GUIContent.none);

            using (LabelWidth.Do(FromToLabelWidth))
            {
                Vector4 fromVector = fromProperty.vector4Value;
                Vector4 toVector   = toProperty.vector4Value;

                var type = (TweenShaderProperty.Type)typeProperty.enumValueIndex;
                switch (type)
                {
                case TweenShaderProperty.Type.Float:
                    fromVector.x = EditorGUI.FloatField(fromRect, fromLabel, fromVector.x);
                    fromProperty.vector4Value = fromVector;

                    toVector.x = EditorGUI.FloatField(toRect, toLabel, toVector.x);
                    toProperty.vector4Value = toVector;
                    break;

                case TweenShaderProperty.Type.Vector:
                    float labelWidth = EditorGUIUtility.labelWidth;

                    EditorGUI.LabelField(fromRect.Left(labelWidth), fromLabel);
                    fromVector = EditorGUI.Vector4Field(fromRect.Right(-labelWidth).Row(0), "", fromVector);
                    fromProperty.vector4Value = fromVector;

                    EditorGUI.LabelField(toRect.Left(labelWidth), toLabel);
                    toVector = EditorGUI.Vector4Field(toRect.Right(-labelWidth).Row(0), "", toVector);
                    toProperty.vector4Value = toVector;

                    break;

                case TweenShaderProperty.Type.Color:
                    fromVector = EditorGUI.ColorField(fromRect, fromLabel, fromVector, true, true, true, colorPickerConfig);
                    fromProperty.vector4Value = fromVector;

                    toVector = EditorGUI.ColorField(toRect, toLabel, toVector, true, true, true, colorPickerConfig);
                    toProperty.vector4Value = toVector;

                    break;
                }
            }

            property.serializedObject.ApplyModifiedProperties();
        }