Esempio n. 1
0
        public override void OnInspectorGUI()
        {
            var referencesObjectBase = target as ReferencesObjectBase;

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

            EditorGUILayout.LabelField(referenceCountLabel, EditorStyles.centeredGreyMiniLabel);

            using (Horizontal.Do())
            {
                using (LabelWidth.Do(72.0f))
                {
                    SerializedProperty rootFolderProperty = serializedObject.GetMemberProperty <ReferencesBase>(r => r.rootFolder);
                    EditorGUILayout.PropertyField(rootFolderProperty);
                }

                if (GUILayout.Button("Update References", EditorStyles.miniButton, GUILayout.Width(108.0f)))
                {
                    referencesObjectBase.UpdateReferences();
                    serializedObject.ApplyModifiedProperties();
                }
            }

            if (referencesObjectBase.ContainsNullReference)
            {
                Rect warningRect = GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.label);

                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);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Internal method. Do not touch it.
        /// </summary>
        /// <param name="host"></param>
        public override void NodeUI(GraphGUI host)
        {
            EditorGUI.BeginChangeCheck();

            using (LabelWidth.Do(84.0f))
            {
                OnShowNode(host);
            }

            var editorGraph = graph as EditorGraph;

            if (EditorGUI.EndChangeCheck() && editorGraph != null)
            {
                editorGraph.controller.OnNodeChanged(this);
            }
        }
Esempio n. 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 (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();
            }
        }
Esempio n. 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 <IntRange>(b => b.Max);
            SerializedProperty min = property.GetMemberProperty <IntRange>(b => b.Min);

            using (LabelWidth.Do(32.0f))
                using (IndentLevel.Do(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();
                    }
                }
        }
Esempio n. 5
0
        private void DrawAnimationListElement(Rect rect, int index, bool isActive, bool isFocused)
        {
            AnimationClip animation = animations[index];

            Undo.RecordObject(animation, "AnimatorControllerEditor");

            EditorGUI.BeginChangeCheck();
            using (LabelWidth.Do(24.0f))
            {
                animation.name = EditorGUI.DelayedTextField(rect, animationIconGuiContent, animation.name);
            }

            if (EditorGUI.EndChangeCheck())
            {
                AssetDatabase.SaveAssets();
                LoadAnimationList();
                EditorUtility.SetDirty(animation);
            }
        }
Esempio n. 6
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);

            using (LabelWidth.Do(72.0f))
            {
                SerializedProperty rootFolderProperty = property.GetMemberProperty <ReferencesBase>(r => r.rootFolder);
                EditorGUI.PropertyField(rootFolderRect, rootFolderProperty);
            }

            if (GUI.Button(buttonRect, "Update References", EditorStyles.miniButton))
            {
                referencesBase.UpdateReferences();
                property.serializedObject.ApplyModifiedProperties();
            }
        }
Esempio n. 7
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();
        }