private void DrawDitheringSettingsGUI(MaterialEditor materialEditor)
        {
            // Hack:    Get Palette and Pattern objects.
            //          Because it's not possible to save references to other objects within a shader or material object,
            //			This hack saves the instance id's in shader properties, by converting the exact bit setup to vectors.
            //_palette =    BeffioDitherEditorUtilities.GetAssetFromVector(_paletteRefProperty.vectorValue) as Palette;
            //_pattern =    BeffioDitherEditorUtilities.GetAssetFromVector(_patternRefProperty.vectorValue) as Pattern;

            if (_palette == null)
            {
                _palette = AssetDatabase.LoadAssetAtPath <Palette>(_defaultPalettePath);
            }

            if (_pattern == null)
            {
                _pattern = AssetDatabase.LoadAssetAtPath <Pattern>(_defaultPatternPath);
            }

            bool hasPatternTexture = (_hasPatternTextureProperty.floatValue > 0.5f);

            EditorGUI.indentLevel = 2;

            // Palette
            _palette = EditorGUILayout.ObjectField(ContentText.paletteProperty, _palette, typeof(Palette), false) as Palette;
            if (_palette != null)
            {
                _colorCountProperty.floatValue    = _palette.MixedColorCount;
                _paletteHeightProperty.floatValue = _palette.Texture.height;
                _paletteTexProperty.textureValue  = _palette.Texture;
                _paletteRefProperty.vectorValue   = BeffioDitherEditorUtilities.AssetToVector4GUID(_palette);
            }
            else
            {
                _colorCountProperty.floatValue    = 0;
                _paletteHeightProperty.floatValue = Texture2D.whiteTexture.height;
                _paletteTexProperty.textureValue  = Texture2D.whiteTexture;
                _paletteRefProperty.vectorValue   = Vector4.zero;
            }

            // Pattern Asset
            if (!hasPatternTexture)
            {
                EditorGUI.BeginChangeCheck();
                {
                    _pattern = EditorGUILayout.ObjectField(ContentText.patternProperty, _pattern, typeof(Pattern), false) as Pattern;
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (_pattern != null)
                        {
                            _patternSizeProperty.floatValue  = _pattern.Texture.height;
                            _patternTexProperty.textureValue = _pattern.Texture;
                            _patternRefProperty.vectorValue  = BeffioDitherEditorUtilities.AssetToVector4GUID(_pattern);
                        }
                        else
                        {
                            _patternSizeProperty.floatValue  = 0;
                            _patternTexProperty.textureValue = null;
                            _patternRefProperty.vectorValue  = Vector4.zero;
                        }
                        _hasPatternTextureProperty.floatValue = 0;
                    }
                }
            }


            // Pattern Texture
            if (_pattern == null)
            {
                EditorGUI.BeginChangeCheck();
                {
                    EditorGUI.indentLevel = 0;
                    materialEditor.TexturePropertySingleLine(ContentText.patternTextureProperty, _patternTexProperty);
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (_patternTexProperty.textureValue)
                        {
                            _patternSizeProperty.floatValue = _patternTexProperty.textureValue.height;
                        }
                        else
                        {
                            _patternSizeProperty.floatValue = 0;
                        }
                        _hasPatternTextureProperty.floatValue = (_patternTexProperty.textureValue == null ? 0 : 1);
                    }
                }
            }

            EditorGUI.indentLevel = 2;

            // Pattern Scale
            materialEditor.FloatProperty(_patternScaleProperty, ContentText.patternScaleProperty.text);

            // Screen Space Dithering
            EditorGUI.BeginChangeCheck();
            {
                bool enabled = EditorGUILayout.Toggle(ContentText.screenSpaceProperty, _targetMat.IsKeywordEnabled("_SCREENSPACEDITHER"));
                if (EditorGUI.EndChangeCheck())
                {
                    EnableKeyword("_SCREENSPACEDITHER", enabled, ContentText.screenSpaceUndo);
                }
            }

            // Alpha Cutout
            if (_targetMat.HasProperty("_Cutout"))
            {
                materialEditor.ShaderProperty(_cutoutProperty, ContentText.cutoutProperty.text);
            }
        }