Пример #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);

            var lengthProperty = property.GetMemberProperty <Timer>(t => t.length);
            var timer          = SerializedPropertyHelper.GetValue(fieldInfo, property) as Timer;

            if (timer != null && timer.IsRunning)
            {
                GUI.color = Color.cyan;
                Rect progressPosition = position.Right(-EditorGUIUtility.labelWidth);
                progressPosition.width *= timer.Progress;
                GUI.Box(progressPosition, GUIContent.none);
                GUI.color = Color.white;
            }

            EditorGUI.PropertyField(position, lengthProperty, label);
            UnitDrawer.DrawUnit(position, "seconds", new None());

            if (lengthProperty.floatValue < 0.0f)
            {
                lengthProperty.floatValue = 0.0f;
                property.serializedObject.ApplyModifiedProperties();
            }
        }
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            var referencesBase = SerializedPropertyHelper.GetValue(fieldInfo, property) as ReferencesBase;

            if (referencesBase.ContainsNullReference)
            {
                return(EditorGUIUtility.singleLineHeight * 3.0f);
            }

            return(EditorGUIUtility.singleLineHeight * 2.0f);
        }
Пример #3
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 (new ChangeLabelWidth(56.0f))
                using (new ChangeIndentLevel(0))
                {
                    EditorGUI.BeginChangeCheck();
                    EditorGUI.PropertyField(originalPosition, originalValue, new GUIContent("Original"));
                    modified = EditorGUI.EndChangeCheck();

                    using (new DisabledGroup(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();
            }
        }
Пример #4
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);

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

            Rect labelPosition = new Rect(position);
            Rect minPosition   = new Rect(position);
            Rect maxPosition   = new Rect(position);

            labelPosition.width = EditorGUIUtility.labelWidth;
            minPosition.x       = labelPosition.xMax;
            minPosition.width   = (minPosition.width - labelPosition.width) * 0.5f;
            maxPosition.x       = labelPosition.xMax + minPosition.width;
            maxPosition.width   = minPosition.width;

            EditorGUI.LabelField(labelPosition, label);

            SerializedProperty max = property.GetMemberProperty <IntBounds>(b => b.Max);
            SerializedProperty min = property.GetMemberProperty <IntBounds>(b => b.Min);

            EditorHelper.BeginChangeLabelWidth(32.0f);
            EditorHelper.BeginChangeIndentLevel(0);

            EditorGUI.BeginChangeCheck();
            DelayedPropertyField(minPosition, min);
            DelayedPropertyField(maxPosition, max);
            if (EditorGUI.EndChangeCheck())
            {
                min.serializedObject.ApplyModifiedProperties();
                max.serializedObject.ApplyModifiedProperties();

                var validatable = SerializedPropertyHelper.GetValue(fieldInfo, property) as IValidatable;
                validatable.Validate();

                min.serializedObject.Update();
                max.serializedObject.Update();
            }

            EditorHelper.EndChangeIndentLevel();
            EditorHelper.EndChangeLabelWidth();
        }
Пример #5
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // Bugged Unity... hacks :(
            if (!property.type.StartsWith("Modifiable"))
            {
                return;
            }

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

            EditorGUI.LabelField(labelPosition, label);

            SerializedProperty originalValue = property.FindPropertyRelative("originalValue");
            SerializedProperty modifiedValue = property.FindPropertyRelative("modifiedValue");

            EditorHelper.BeginChangeLabelWidth(56.0f);
            EditorHelper.BeginChangeIndentLevel(0);

            EditorGUI.BeginChangeCheck();
            EditorGUI.PropertyField(originalPosition, originalValue, new GUIContent("Original"));
            bool modified = EditorGUI.EndChangeCheck();

            EditorGUI.BeginDisabledGroup(true);
            EditorGUI.PropertyField(modifiedPosition, modifiedValue, new GUIContent("Modified"));
            EditorGUI.EndDisabledGroup();

            EditorHelper.EndChangeIndentLevel();
            EditorHelper.EndChangeLabelWidth();

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

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

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

            var referencesBase = SerializedPropertyHelper.GetValue(fieldInfo, property) as ReferencesBase;

            Rect labelRect;
            Rect referenceCountRect = position.Row(0)
                                      .Left(EditorGUIUtility.labelWidth, out labelRect);

            Rect buttonRect;
            Rect rootFolderRect = position.Row(1).Right(-14.0f)
                                  .Right(108.0f, out buttonRect);

            if (referencesBase.ContainsNullReference)
            {
                Rect warningRect = position.Row(2).Right(-14.0f);
                GUI.Box(warningRect, GUIContent.none);
                var style = new GUIStyle(EditorStyles.centeredGreyMiniLabel);
                style.normal.textColor = Color.red;
                GUI.Label(warningRect, "Null references found! Please, update the references.", style);
            }

            EditorGUI.LabelField(labelRect, label);

            string referenceCountLabel = string.Format("{0} references of <{1}>", referencesBase.ReferenceCount, referencesBase.ReferencedType.Name);

            EditorGUI.LabelField(referenceCountRect, referenceCountLabel, EditorStyles.centeredGreyMiniLabel);

            EditorHelper.BeginChangeLabelWidth(72.0f);
            SerializedProperty rootFolderProperty = property.GetMemberProperty <ReferencesBase>(r => r.rootFolder);

            EditorGUI.PropertyField(rootFolderRect, rootFolderProperty);
            EditorHelper.EndChangeLabelWidth();

            if (GUI.Button(buttonRect, "Update References", EditorStyles.miniButton))
            {
                referencesBase.UpdateReferences();
                property.serializedObject.ApplyModifiedProperties();
            }
        }