Example #1
0
        static void ResetSettings(MenuCommand command)
        {
            Material mat = null;

            if (command.context.GetType() == typeof(Material))
            {
                mat = (Material)command.context;
            }
            else
            {
                mat = Selection.activeGameObject.GetComponent <CanvasRenderer>().GetMaterial();
            }

            Undo.RecordObject(mat, "Reset Material");

            ShaderUtilities.GetShaderPropertyIDs(); // Make sure we have valid Property IDs
            if (mat.HasProperty(ShaderUtilities.ID_GradientScale))
            {
                // Copy unique properties of the SDF Material
                var texture       = mat.GetTexture(ShaderUtilities.ID_MainTex);
                var gradientScale = mat.GetFloat(ShaderUtilities.ID_GradientScale);
                var texWidth      = mat.GetFloat(ShaderUtilities.ID_TextureWidth);
                var texHeight     = mat.GetFloat(ShaderUtilities.ID_TextureHeight);
                var stencilId     = mat.GetFloat(ShaderUtilities.ID_StencilID);
                var stencilComp   = mat.GetFloat(ShaderUtilities.ID_StencilComp);
                var normalWeight  = mat.GetFloat(ShaderUtilities.ID_WeightNormal);
                var boldWeight    = mat.GetFloat(ShaderUtilities.ID_WeightBold);

                // Reset the material
                Unsupported.SmartReset(mat);

                // Reset ShaderKeywords
                mat.shaderKeywords = new string[0]; // { "BEVEL_OFF", "GLOW_OFF", "UNDERLAY_OFF" };

                // Copy unique material properties back to the material.
                mat.SetTexture(ShaderUtilities.ID_MainTex, texture);
                mat.SetFloat(ShaderUtilities.ID_GradientScale, gradientScale);
                mat.SetFloat(ShaderUtilities.ID_TextureWidth, texWidth);
                mat.SetFloat(ShaderUtilities.ID_TextureHeight, texHeight);
                mat.SetFloat(ShaderUtilities.ID_StencilID, stencilId);
                mat.SetFloat(ShaderUtilities.ID_StencilComp, stencilComp);
                mat.SetFloat(ShaderUtilities.ID_WeightNormal, normalWeight);
                mat.SetFloat(ShaderUtilities.ID_WeightBold, boldWeight);
            }
            else
            {
                Unsupported.SmartReset(mat);
            }

            TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, mat);
        }
        public void ColorPalette_EditorReset_ColorsMatchWithDefaultPaletteDefinition()
        {
            // Get a copy of the original default colors
            var colors = new List<Color>(m_Palette.colors);

            // add 2 colors, and remove one
            // to make sure palette is actually reset
            m_Palette.colors.Add(Color.blue);
            m_Palette.colors.RemoveAt(3);
            m_Palette.colors.Insert(1, Color.green);

            // This is equivalent to calling Reset from the inspector
            Unsupported.SmartReset(m_Palette);

            // Should still have all the default colors after resetting
            var resetColors = m_Palette.colors;
            Assert.That(resetColors.Count, Is.EqualTo(colors.Count));
            // Check that the reset colors match the original
            Assert.That(resetColors, Is.EquivalentTo(colors));
        }