コード例 #1
0
 public DecalLayer()
 {
     _layerMaskScale  = new Vector2(1, 1);
     _layerMaskOffset = new Vector2(0, 0);
     _channel1        = new DecalLayerChannel {
         Mode = DecalLayerChannel.DecalChannelMode.SimpleRangeRemap
     };
     _channel2 = new DecalLayerChannel();
     _channel3 = new DecalLayerChannel();
     _channel4 = new DecalLayerChannel();
 }
コード例 #2
0
            public void Draw([NotNull] SerializedProperty property, [CanBeNull] SerializedProperty mask)
            {
                var modeProperty = property.FindPropertyRelative(_channelModeProperty);

                using (new VerticalStripContext(_color, lineWidth: 2))
                {
                    // Show mode property and show no more UI if it's disabled
                    if (modeProperty != null)
                    {
                        EditorGUILayout.PropertyField(modeProperty);

                        if ((DecalLayerChannel.DecalChannelMode)modeProperty.enumValueIndex == DecalLayerChannel.DecalChannelMode.Disabled)
                        {
                            return;
                        }
                    }

                    using (new EditorGUI.IndentLevelScope())
                    {
                        // Show advanced settings if we're explicitly in advanced mode (or we can't tell what the mode is)
                        var mode = modeProperty != null ? (DecalLayerChannel.DecalChannelMode)modeProperty.enumValueIndex : DecalLayerChannel.DecalChannelMode.AdvancedRangeRemap;

                        var inThreshold = property.FindPropertyRelative(_inputThresholdProperty);
                        var inSoftness  = property.FindPropertyRelative(_inputSoftnessProperty);
                        var outRange    = property.FindPropertyRelative(_outputRangeProperty);

                        // Show basic settings
                        var showInputRange = mode == DecalLayerChannel.DecalChannelMode.SimpleRangeRemap || mode == DecalLayerChannel.DecalChannelMode.AdvancedRangeRemap;
                        if (showInputRange)
                        {
                            EditorGUILayout.PropertyField(inThreshold);
                            EditorGUILayout.PropertyField(inSoftness);
                        }

                        // Show advanced settings if in advanced mode
                        var showOutputRange = mode == DecalLayerChannel.DecalChannelMode.AdvancedRangeRemap;
                        if (showOutputRange)
                        {
                            EditorGUILayout.PropertyField(outRange);
                        }

                        // If we were given no mask then no preview can be rendered, early exit
                        if (mask == null)
                        {
                            return;
                        }

                        // Create a list of reasons the visualiser cannot be displayed
                        var reasons = new List <string>();
                        if (mask.hasMultipleDifferentValues)
                        {
                            reasons.Add("'Layer Mask'");
                        }

                        if (showInputRange)
                        {
                            if (inThreshold.hasMultipleDifferentValues)
                            {
                                reasons.Add("'Input Threshold'");
                            }

                            if (inSoftness.hasMultipleDifferentValues)
                            {
                                reasons.Add("'Input Softness'");
                            }
                        }

                        if (showOutputRange)
                        {
                            if (outRange.hasMultipleDifferentValues)
                            {
                                reasons.Add("'Output Range'");
                            }
                        }

                        if (reasons.Count > 0)
                        {
                            EditorGUILayout.HelpBox(string.Format("Levels Visualiser unavailable with mixed {0} values", string.Join(", ", reasons.ToArray())), MessageType.Warning);
                        }
                        else
                        {
                            // Show a foldout section for the preview
                            if (modeProperty == null || (DecalLayerChannel.DecalChannelMode)modeProperty.enumValueIndex != DecalLayerChannel.DecalChannelMode.Disabled)
                            {
                                _showPreview = EditorGUILayout.Foldout(_showPreview, "Levels Visualizer");
                            }
                            else
                            {
                                _showPreview = false;
                            }

                            // Show the preview
                            if (_showPreview)
                            {
                                // Can't initialise this in a field initialiser because Unity won't less this be called in certan contexts
                                if (_renderUtility == null)
                                {
                                    _renderUtility = new PreviewRenderUtility(false);
                                }

                                // Calculate the area to draw the preview in
                                const float aspectRatio = 2.2f;
                                var         width       = EditorGUIUtility.currentViewWidth - EditorGUIUtility.labelWidth;
                                var         height      = width / aspectRatio;
                                var         area        = EditorGUILayout.GetControlRect(false, height);
                                area.yMax -= EditorGUIUtility.singleLineHeight / 2;
                                area.xMin += EditorGUIUtility.labelWidth;

                                var iRange = DecalLayerChannel.EvaluateInputRange(mode, inThreshold.floatValue, inSoftness.floatValue);
                                var oRange = DecalLayerChannel.EvaluateOutputRange(mode, outRange.vector2Value);
                                DrawLayerPreview(area, _renderUtility, LayerPreview, (Texture2D)mask.objectReferenceValue, iRange, oRange, _weights);
                            }
                        }
                    }
                }
            }