Exemplo n.º 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 void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);

            SerializedProperty root = property.GetMemberProperty <ParticleController>(p => p.RootParticleSystem);

            EditorGUI.PropertyField(position, root, label);
        }
Exemplo n.º 3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);
            EditorGUI.PropertyField(position, property, label);

            var unitAttribute = attribute as UnitAttribute;

            DrawUnit(position, unitAttribute.text, unitAttribute.style);
        }
Exemplo n.º 4
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);

            var readOnlyAttribute = attribute as ReadOnlyAttribute;

            EditorGUI.BeginDisabledGroup(!readOnlyAttribute.onlyInPlaymode || EditorApplication.isPlayingOrWillChangePlaymode);
            EditorGUI.PropertyField(position, property, label, true);
            EditorGUI.EndDisabledGroup();
        }
Exemplo n.º 5
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);

            position = position.Right(-16.0f);

            float buttonWidth = 40.0f;
            Rect  preButtonRect, buildButtonRect, postButtonRect;

            Rect propertyRect = position
                                .Right(buttonWidth, out postButtonRect)
                                .Right(buttonWidth, out buildButtonRect)
                                .Right(buttonWidth, out preButtonRect);

            UMakeTarget target;

            UMakeTargetEditor.BuildAction action;

            using (new ChangeIndentLevel(0))
            {
                EditorGUI.PropertyField(propertyRect, property, GUIContent.none);

                target = property.objectReferenceValue as UMakeTarget;
                action = UMakeTargetEditor.BuildAction.None;

                GUI.enabled = target != null && UMakeTargetEditor.CanBuild;

                if (GUI.Button(preButtonRect, "Pre", EditorStyles.miniButtonLeft))
                {
                    action = UMakeTargetEditor.BuildAction.PreActions;
                }

                if (GUI.Button(buildButtonRect, "Build", EditorStyles.miniButtonMid))
                {
                    action = UMakeTargetEditor.BuildAction.Build;
                }

                if (GUI.Button(postButtonRect, "Post", EditorStyles.miniButtonRight))
                {
                    action = UMakeTargetEditor.BuildAction.PostActions;
                }

                GUI.enabled = true;
            }

            property.serializedObject.ApplyModifiedProperties();

            UMake umake;

            if (UMake.Get().TryGet(out umake) && target != null)
            {
                UMakeTargetEditor.ExecuteAction(target, action);
            }
        }
Exemplo n.º 6
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);
            EditorGUI.PropertyField(position, property, label);

            var exponentInfoAttribute = attribute as ExponentInfoAttribute;

            string exp = string.Empty;

            if (property.propertyType == SerializedPropertyType.Integer)
            {
                var value = property.intValue;
                if (Mathf.Abs(value) < 1000)
                {
                    return;
                }

                exp = value.ToString("G2", CultureInfo.InvariantCulture);
            }
            else if (property.propertyType.Equals("long"))
            {
                var value = property.longValue;
                if (Mathf.Abs(value) < 1000)
                {
                    return;
                }

                exp = value.ToString("G2", CultureInfo.InvariantCulture);
            }
            else if (property.propertyType == SerializedPropertyType.Float)
            {
                var value = property.floatValue;
                if (Mathf.Abs(value) < 1000 &&
                    value.ToString(CultureInfo.InvariantCulture).Length < 5)
                {
                    return;
                }

                exp = value.ToString("G2", CultureInfo.InvariantCulture);
            }
            else if (property.type.Equals("double"))
            {
                var value = property.doubleValue;
                if (System.Math.Abs(value) < 1000 &&
                    value.ToString(CultureInfo.InvariantCulture).Length < 5)
                {
                    return;
                }

                exp = value.ToString("G2", CultureInfo.InvariantCulture);
            }

            UnitDrawer.DrawUnit(position, exp, exponentInfoAttribute.style);
        }
Exemplo n.º 7
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);
            var lengthProperty = property.GetMemberProperty <Timer>(t => t.Length);

            EditorGUI.PropertyField(position, lengthProperty, label);
            GUI.Label(position.Right(52.0f), "seconds", EditorStyles.centeredGreyMiniLabel);

            if (lengthProperty.floatValue < 0.0f)
            {
                lengthProperty.floatValue = 0.0f;
                property.serializedObject.ApplyModifiedProperties();
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);

            if (property.propertyType == SerializedPropertyType.Integer && !EditorApplication.isPlaying)
            {
                EditorGUI.BeginProperty(position, label, property);
                property.intValue = EditorGUI.LayerField(position, label, property.intValue);
                EditorGUI.EndProperty();
            }
            else
            {
                EditorGUI.PropertyField(position, property, label);
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);

            if (property.propertyType == SerializedPropertyType.String)
            {
                EditorGUI.BeginProperty(position, label, property);
                property.stringValue = EditorGUI.TagField(position, label, property.stringValue);
                EditorGUI.EndProperty();
            }
            else
            {
                EditorGUI.PropertyField(position, property, label);
            }
        }
Exemplo n.º 10
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);

            var lengthProperty = property.GetMemberProperty <Timer.Duration>(d => d.length);

            EditorGUI.PropertyField(position, lengthProperty, label);
            UnitDrawer.DrawUnit(position, "seconds", EditorStyles.centeredGreyMiniLabel);

            if (lengthProperty.floatValue < Mathf.Epsilon)
            {
                lengthProperty.floatValue = Mathf.Epsilon;
                property.serializedObject.ApplyModifiedProperties();
            }
        }
Exemplo n.º 11
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();
            }
        }
Exemplo n.º 12
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();
        }
Exemplo n.º 13
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);

            var behaviour = property.serializedObject.targetObject as MonoBehaviour;

            Animator animator     = null;
            var      nameProperty = property.GetMemberProperty <AnimationParameter>(p => p.name);

            if (behaviour != null)
            {
                AnimatorFieldAttribute animatorField;
                if (fieldInfo.GetAttribute <AnimatorFieldAttribute>(false).TryGet(out animatorField))
                {
                    var animatorProperty = property.serializedObject.FindProperty(animatorField.animatorFieldName);
                    if (animatorProperty != null)
                    {
                        animator = animatorProperty.objectReferenceValue as Animator;
                    }
                }
                else
                {
                    animator = behaviour.GetComponent <Animator>();
                }
            }

            if (animator == null || animator.parameterCount == 0)
            {
                EditorGUI.PropertyField(position, nameProperty, label);
            }
            else
            {
                AnimatorControllerParameter[] parameters = FilterParameters(property, animator);
                var popupOptions = parameters.Select(x => new GUIContent(x.name)).ToArray();
                int currentIndex = Array.FindIndex(parameters, x => x.name == nameProperty.stringValue);

                EditorGUI.BeginChangeCheck();
                currentIndex = EditorGUI.Popup(position, label, currentIndex, popupOptions);

                if (EditorGUI.EndChangeCheck())
                {
                    nameProperty.stringValue = parameters[currentIndex].name;
                    property.serializedObject.ApplyModifiedProperties();
                }
            }
        }
Exemplo n.º 14
0
        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();
            }
        }
Exemplo n.º 15
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);

            var requireInterfaceAttribute = attribute as RequireInterfaceAttribute;

            if (requireInterfaceAttribute == null)
            {
                base.OnGUI(position, property, label);
                return;
            }

            EditorGUI.BeginChangeCheck();
            var objectValue = EditorGUI.ObjectField(position, label, property.objectReferenceValue, requireInterfaceAttribute.interfaceType, true);

            if (EditorGUI.EndChangeCheck())
            {
                property.objectReferenceValue = objectValue;
                property.serializedObject.ApplyModifiedProperties();
            }
        }
Exemplo n.º 16
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);

            var nullableAttribute = fieldInfo.GetAttribute <NullableAttribute>(false);

            Object target = property.serializedObject.targetObject;
            bool   isFromMonoBehaviour = target != null && target is MonoBehaviour;

            if (!nullableAttribute.IsSome && isFromMonoBehaviour && IsNull(property))
            {
                GUI.color = Color.red;
                EditorGUI.PropertyField(position, property, label, true);
                GUI.color = Color.white;

                DrawFieldWarning(position);
            }
            else
            {
                EditorGUI.PropertyField(position, property, label, true);
            }
        }
Exemplo n.º 17
0
        public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);

            SerializedProperty valueProp = prop.GetMemberProperty <SecureInt>(i => i.Value);

            if (EditorApplication.isPlaying)
            {
                var self = fieldInfo.GetValue(prop.serializedObject.targetObject) as SecureInt;
                EditorGUI.BeginChangeCheck();
                int value = EditorGUI.IntField(position, label, self.Value);
                if (EditorGUI.EndChangeCheck())
                {
                    self.Value         = value;
                    valueProp.intValue = self.EncryptedValue;
                }
            }
            else
            {
                EditorGUI.PropertyField(position, valueProp, label);
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyDrawerHelper.LoadAttributeTooltip(this, label);

            FolderPathAttribute pathAttribute = attribute as FolderPathAttribute;

            if (pathAttribute == null)
            {
                return;
            }
            if (property.propertyType != SerializedPropertyType.String)
            {
                EditorGUI.PropertyField(position, property, label);
                return;
            }
            string path = property.stringValue;

            position.width -= buttonWidth + padding;
            EditorGUI.PropertyField(position, property, label);
            position.x    += position.width + padding;
            position.width = buttonWidth;
            if (GUI.Button(position, EditorGUIUtility.FindTexture("Project"), folderButtonStyle))
            {
                path = EditorUtility.OpenFolderPanel("Select folder", (pathAttribute.PathRelativeToProject) ? ToAbsolutePath(path) : path, string.Empty);
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }
                if (!pathAttribute.PathRelativeToProject)
                {
                    property.stringValue = path;
                    return;
                }
                property.stringValue = ToRelativePath(path);
            }
        }
Exemplo n.º 19
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();
        }