Esempio n. 1
0
        public override bool OnGUI(SerializedParameter serializedParameterOverride, GUIContent title, Attribute attribute)
        {
            var attr     = (MinMaxAttribute)attribute;
            var property = serializedParameterOverride.value;

            if (property.propertyType == SerializedPropertyType.Float)
            {
                float v = EditorGUILayout.FloatField(title, property.floatValue);
                property.floatValue = Mathf.Clamp(v, attr.min, attr.max);
                return(true);
            }

            if (property.propertyType == SerializedPropertyType.Integer)
            {
                int v = EditorGUILayout.IntField(title, property.intValue);
                property.intValue = Mathf.Clamp(v, (int)attr.min, (int)attr.max);
                return(true);
            }

            if (property.propertyType == SerializedPropertyType.Vector2)
            {
                var v = property.vector2Value;
                EditorGUILayout.MinMaxSlider(title, ref v.x, ref v.y, attr.min, attr.max);
                property.vector2Value = v;
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        public void OnEnable()
        {
            envCube            = FindProperty(x => x.envCube);
            skyMat             = FindProperty(x => x.SkyBoxMat);
            hdrScale           = FindProperty(x => x.hdrScale);
            hdrPow             = FindProperty(x => x.hdrPow);
            hdrAlpha           = FindProperty(x => x.hdrAlpha);
            iblLevel           = FindProperty(x => x.iblLevel);
            iblLevel.intValue  = 1;
            lightmapShadowMask = FindParameter(x => x.lightmapShadowMask);
            shadowIntensity    = FindParameter(x => x.shadowIntensity);
            fogEnable          = FindProperty(x => x.fogEnable);

            roleLight0 = FindProperty(x => x.roleLight0);
            roleLight1 = FindProperty(x => x.roleLight1);

            shadowMapLevel    = FindProperty(x => x.shadowMapLevel);
            shadowBound       = FindProperty(x => x.shadowBound);
            lookTarget        = FindProperty(x => x.lookTarget);
            drawShadowLighing = FindProperty(x => x.drawShadowLighing);
            showObjects       = FindProperty(x => x.showObjects);
            debugMode         = FindProperty(x => x.debugContext.debugMode);
            debugDisplayType  = FindProperty(x => x.debugContext.debugDisplayType);
            splitAngle        = FindParameter(x => x.debugContext.splitAngle);
            splitPos          = FindProperty(x => x.debugContext.splitPos);

            AssetsConfig.RefreshShaderDebugNames();
        }
Esempio n. 3
0
        public override bool OnGUI(SerializedParameter serializedParameterOverride, GUIContent title, Attribute attribute)
        {
            var attr = (ResPathAttribute)attribute;
            var resSerializedParameterOverride = serializedParameterOverride as ResSerializedParameterOverride;
            var property = resSerializedParameterOverride.value;
            var rawParam = resSerializedParameterOverride.rawParam;

            if (property.propertyType != SerializedPropertyType.String)
            {
                return(false);
            }

            int buttonWidth = 80;

            float indentOffset = EditorGUI.indentLevel * 15f;
            var   lineRect     = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight);

            var labelRect  = new Rect(lineRect.x, lineRect.y, EditorGUIUtility.labelWidth - indentOffset, lineRect.height);
            var fieldRect  = new Rect(labelRect.xMin, lineRect.y, lineRect.width - labelRect.width, lineRect.height);
            var buttonRect = new Rect(lineRect.x, lineRect.y + EditorGUIUtility.singleLineHeight, buttonWidth, lineRect.height);

            EditorGUI.PrefixLabel(labelRect, title);
            EditorGUI.ObjectField(fieldRect, rawParam.asset, attr.type, false);
            if (!string.IsNullOrEmpty(attr.buttonName))
            {
                if (GUI.Button(buttonRect, EditorUtilities.GetContent(attr.buttonName), EditorStyles.miniButton))
                {
                    if (resSerializedParameterOverride.onButton != null)
                    {
                        resSerializedParameterOverride.onButton();
                    }
                }
            }
            if (!string.IsNullOrEmpty(attr.buttonName2))
            {
                buttonRect.x += 80;
                if (GUI.Button(buttonRect, EditorUtilities.GetContent(attr.buttonName2), EditorStyles.miniButton))
                {
                    if (resSerializedParameterOverride.onButton2 != null)
                    {
                        resSerializedParameterOverride.onButton2();
                    }
                }
            }
            if (!string.IsNullOrEmpty(attr.buttonName3))
            {
                buttonRect.x += 80;
                if (GUI.Button(buttonRect, EditorUtilities.GetContent(attr.buttonName3), EditorStyles.miniButton))
                {
                    if (resSerializedParameterOverride.onButton3 != null)
                    {
                        resSerializedParameterOverride.onButton3();
                    }
                }
            }
            return(true);
        }
Esempio n. 4
0
        public override bool OnGUI(SerializedParameter serializedParameterOverride, GUIContent title, Attribute attribute)
        {
            var attr     = (ColorUsageAttribute)attribute;
            var property = serializedParameterOverride.value;

            if (property.propertyType != SerializedPropertyType.Color)
            {
                return(false);
            }

            property.colorValue = EditorGUILayout.ColorField(title, property.colorValue, true, attr.showAlpha, attr.hdr);

            return(true);
        }
Esempio n. 5
0
        public override bool OnGUI(SerializedParameter serializedParameterOverride, GUIContent title, Attribute attribute)
        {
            var attr     = (RangeAttribute)attribute;
            var property = serializedParameterOverride.value;

            if (property.propertyType == SerializedPropertyType.Float)
            {
                property.floatValue = EditorGUILayout.Slider(title, property.floatValue, attr.min, attr.max);
                return(true);
            }

            if (property.propertyType == SerializedPropertyType.Integer)
            {
                property.intValue = EditorGUILayout.IntSlider(title, property.intValue, (int)attr.min, (int)attr.max);
                return(true);
            }

            return(false);
        }
Esempio n. 6
0
        public override bool OnGUI(SerializedParameter serializedParameterOverride, GUIContent title, Attribute attribute)
        {
            var attr     = (MaxAttribute)attribute;
            var property = serializedParameterOverride.value;

            if (property.propertyType == SerializedPropertyType.Float)
            {
                float v = EditorGUILayout.FloatField(title, property.floatValue);
                property.floatValue = Mathf.Min(v, attr.max);
                return(true);
            }

            if (property.propertyType == SerializedPropertyType.Integer)
            {
                int v = EditorGUILayout.IntField(title, property.intValue);
                property.intValue = Mathf.Min(v, (int)attr.max);
                return(true);
            }

            return(false);
        }
Esempio n. 7
0
        protected void PropertyField(SerializedParameter property, GUIContent title)
        {
            // Check for DisplayNameAttribute first
            var displayNameAttr = property.GetAttribute <DisplayNameAttribute>();

            if (displayNameAttr != null)
            {
                title.text = displayNameAttr.displayName;
            }

            // Add tooltip if it's missing and an attribute is available
            if (string.IsNullOrEmpty(title.tooltip))
            {
                var tooltipAttr = property.GetAttribute <TooltipAttribute>();
                if (tooltipAttr != null)
                {
                    title.tooltip = tooltipAttr.tooltip;
                }
            }

            // Look for a compatible attribute decorator
            AttributeDecorator decorator = null;
            Attribute          attribute = null;

            foreach (var attr in property.attributes)
            {
                // Use the first decorator we found
                if (decorator == null)
                {
                    decorator = EditorUtilities.GetDecorator(attr.GetType());
                    attribute = attr;
                }

                // Draw unity built-in Decorators (Space, Header)
                if (attr is PropertyAttribute)
                {
                    if (attr is SpaceAttribute)
                    {
                        EditorGUILayout.GetControlRect(false, (attr as SpaceAttribute).height);
                    }
                    else if (attr is HeaderAttribute)
                    {
                        var rect = EditorGUILayout.GetControlRect(false, 24f);
                        rect.y += 8f;
                        rect    = EditorGUI.IndentedRect(rect);
                        EditorGUI.LabelField(rect, (attr as HeaderAttribute).header, Styling.labelHeader);
                    }
                }
            }

            bool invalidProp = false;

            if (decorator != null && !decorator.IsAutoProperty())
            {
                if (decorator.OnGUI(property, title, attribute))
                {
                    return;
                }

                invalidProp = true;
            }

            using (new EditorGUILayout.HorizontalScope())
            {
                {
                    if (decorator != null && !invalidProp)
                    {
                        if (decorator.OnGUI(property, title, attribute))
                        {
                            return;
                        }
                    }

                    // Default unity field
                    if (property.value.hasVisibleChildren &&
                        property.value.propertyType != SerializedPropertyType.Vector2 &&
                        property.value.propertyType != SerializedPropertyType.Vector3)
                    {
                        GUILayout.Space(12f);
                        EditorGUILayout.PropertyField(property.value, title, true);
                    }
                    else
                    {
                        EditorGUILayout.PropertyField(property.value, title);
                    }
                }
            }
        }
Esempio n. 8
0
        protected void PropertyField(SerializedParameter property)
        {
            var title = EditorUtilities.GetContent(property.displayName);

            PropertyField(property, title);
        }
Esempio n. 9
0
 public abstract bool OnGUI(SerializedParameter serializedParameterOverride, GUIContent title, Attribute attribute);
Esempio n. 10
0
        protected void PropertyField(SerializedParameter property, GUIContent title)
        {
            var displayNameAttr = property.GetAttribute <DisplayNameAttribute>();

            if (displayNameAttr != null)
            {
                title.text = displayNameAttr.displayName;
            }
            if (string.IsNullOrEmpty(title.tooltip))
            {
                var tooltipAttr = property.GetAttribute <TooltipAttribute>();
                if (tooltipAttr != null)
                {
                    title.tooltip = tooltipAttr.tooltip;
                }
            }

            AttributeDecorator decorator = null;
            Attribute          attribute = null;

            foreach (var attr in property.attributes)
            {
                if (decorator == null)
                {
                    decorator = EditorUtility.GetDecorator(attr.GetType());
                    attribute = attr;
                }
                if (attr is PropertyAttribute)
                {
                    if (attr is SpaceAttribute)
                    {
                        EditorGUILayout.GetControlRect(false, (attr as SpaceAttribute).height);
                    }
                    else if (attr is HeaderAttribute)
                    {
                        var rect = EditorGUILayout.GetControlRect(false, 24f);
                        rect.y += 8f;
                        rect    = EditorGUI.IndentedRect(rect);
                        EditorGUI.LabelField(rect, (attr as HeaderAttribute).header, EditorStyles.miniLabel);
                    }
                }
            }

            bool invalidProp = false;

            if (decorator != null && !decorator.IsAutoProperty())
            {
                if (decorator.OnGUI(property, title, attribute))
                {
                    return;
                }

                invalidProp = true;
            }

            using (new EditorGUILayout.HorizontalScope())
            {
                {
                    if (decorator != null && !invalidProp)
                    {
                        if (decorator.OnGUI(property, title, attribute))
                        {
                            return;
                        }
                    }
                    if (property.value.hasVisibleChildren &&
                        property.value.propertyType != SerializedPropertyType.Vector2 &&
                        property.value.propertyType != SerializedPropertyType.Vector3)
                    {
                        GUILayout.Space(12f);
                        EditorGUILayout.PropertyField(property.value, title, true);
                    }
                    else
                    {
                        EditorGUILayout.PropertyField(property.value, title);
                    }
                }
            }
        }