Exemplo n.º 1
0
        private void PerformDrop(Material droppedMaterial)
        {
            Texture texture = droppedMaterial.GetTexture(ShaderUtilities.ID_MainTex);

            if (!texture)
            {
                return;
            }
            Texture       texture2      = material.GetTexture(ShaderUtilities.ID_MainTex);
            TMP_FontAsset tMP_FontAsset = null;

            if (texture != texture2)
            {
                tMP_FontAsset = TMP_EditorUtility.FindMatchingFontAsset(droppedMaterial);
                if (!tMP_FontAsset)
                {
                    return;
                }
            }
            GameObject[] gameObjects = Selection.gameObjects;
            foreach (GameObject gameObject in gameObjects)
            {
                if ((bool)tMP_FontAsset)
                {
                    TMP_Text component = gameObject.GetComponent <TMP_Text>();
                    if ((bool)(UnityEngine.Object)(object) component)
                    {
                        Undo.RecordObject((UnityEngine.Object)(object) component, "Font Asset Change");
                        component.font = tMP_FontAsset;
                    }
                }
                TMPro_EventManager.ON_DRAG_AND_DROP_MATERIAL_CHANGED(gameObject, material, droppedMaterial);
                EditorUtility.SetDirty(gameObject);
            }
        }
Exemplo n.º 2
0
        static void PasteMaterialProperties(MenuCommand command)
        {
            if (m_copiedProperties == null)
            {
                Debug.LogWarning("No Material Properties to Paste. Use Copy Material Properties first.");
                return;
            }

            Material mat = (Material)command.context;

            Undo.RecordObject(mat, "Paste Material");
            if (mat.HasProperty(ShaderUtilities.ID_GradientScale))
            {
                // Preserve unique SDF properties from destination material.
                m_copiedProperties.SetTexture(ShaderUtilities.ID_MainTex, mat.GetTexture(ShaderUtilities.ID_MainTex));
                m_copiedProperties.SetFloat(ShaderUtilities.ID_GradientScale, mat.GetFloat(ShaderUtilities.ID_GradientScale));
                m_copiedProperties.SetFloat(ShaderUtilities.ID_TextureWidth, mat.GetFloat(ShaderUtilities.ID_TextureWidth));
                m_copiedProperties.SetFloat(ShaderUtilities.ID_TextureHeight, mat.GetFloat(ShaderUtilities.ID_TextureHeight));
            }

            EditorShaderUtilities.CopyMaterialProperties(m_copiedProperties, mat);

            // Copy ShaderKeywords from one material to the other.
            mat.shaderKeywords = m_copiedProperties.shaderKeywords;

            // Let TextMeshPro Objects that this mat has changed.
            TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, mat);
        }
Exemplo n.º 3
0
        static void ResetSettings(MenuCommand command)
        {
            Material mat = (Material)command.context;

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

            Material tmp_mat = new Material(mat.shader);

            if (mat.HasProperty(ShaderUtilities.ID_GradientScale))
            {
                // Copy unique properties of the SDF Material over to the temp material.
                tmp_mat.mainTexture = mat.mainTexture;
                tmp_mat.SetFloat(ShaderUtilities.ID_GradientScale, mat.GetFloat(ShaderUtilities.ID_GradientScale));
                tmp_mat.SetFloat(ShaderUtilities.ID_TextureWidth, mat.GetFloat(ShaderUtilities.ID_TextureWidth));
                tmp_mat.SetFloat(ShaderUtilities.ID_TextureHeight, mat.GetFloat(ShaderUtilities.ID_TextureHeight));

                mat.CopyPropertiesFromMaterial(tmp_mat);

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

            DestroyImmediate(tmp_mat);

            TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, mat);
        }
Exemplo n.º 4
0
        private static void ResetSettings(MenuCommand command)
        {
            Material material = null;

            material = ((command.context.GetType() != typeof(Material)) ? Selection.activeGameObject.GetComponent <CanvasRenderer>().GetMaterial() : ((Material)command.context));
            Undo.RecordObject(material, "Reset Material");
            Material material2 = new Material(material.shader);

            ShaderUtilities.GetShaderPropertyIDs();
            if (material.HasProperty(ShaderUtilities.ID_GradientScale))
            {
                material2.SetTexture(ShaderUtilities.ID_MainTex, material.GetTexture(ShaderUtilities.ID_MainTex));
                material2.SetFloat(ShaderUtilities.ID_GradientScale, material.GetFloat(ShaderUtilities.ID_GradientScale));
                material2.SetFloat(ShaderUtilities.ID_TextureWidth, material.GetFloat(ShaderUtilities.ID_TextureWidth));
                material2.SetFloat(ShaderUtilities.ID_TextureHeight, material.GetFloat(ShaderUtilities.ID_TextureHeight));
                material2.SetFloat(ShaderUtilities.ID_StencilID, material.GetFloat(ShaderUtilities.ID_StencilID));
                material2.SetFloat(ShaderUtilities.ID_StencilComp, material.GetFloat(ShaderUtilities.ID_StencilComp));
                material.CopyPropertiesFromMaterial(material2);
                material.shaderKeywords = new string[0];
            }
            else
            {
                material.CopyPropertiesFromMaterial(material2);
            }
            Object.DestroyImmediate(material2);
            TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, material);
        }
Exemplo n.º 5
0
        private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            foreach (var asset in importedAssets)
            {
                // Return if imported asset path is outside of the project.
                if (asset.StartsWith("Assets/", StringComparison.OrdinalIgnoreCase) == false)
                {
                    continue;
                }

                if (AssetDatabase.GetMainAssetTypeAtPath(asset) == typeof(TMP_FontAsset))
                {
                    TMP_FontAsset fontAsset = AssetDatabase.LoadAssetAtPath(asset, typeof(TMP_FontAsset)) as TMP_FontAsset;

                    if (fontAsset != null)
                    {
                        TMP_EditorResourceManager.RegisterFontAssetForDefinitionRefresh(fontAsset);
                    }
                }

                if (AssetDatabase.GetMainAssetTypeAtPath(asset) == typeof(Texture2D))
                {
                    Texture2D tex = AssetDatabase.LoadAssetAtPath(asset, typeof(Texture2D)) as Texture2D;

                    if (tex != null)
                    {
                        TMPro_EventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(true, tex);
                    }
                }
            }
        }
Exemplo n.º 6
0
        void PrepareGUI()

        {
            isNewGUI = false;

            TMP_UIStyleManager.GetUIStyles();

            ShaderUtilities.GetShaderPropertyIDs();

            // New GUI just got constructed. This happens in response to a selection,

            // but also after undo/redo events.

            if (lastSeenUndoRedoCount != undoRedoCount)

            {
                // There's been at least one undo/redo since the last time this GUI got constructed.

                // Maybe the undo/redo was for this material? Assume that is was.

                TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, material as Material);
            }

            lastSeenUndoRedoCount = undoRedoCount;
        }
Exemplo n.º 7
0
        public override void OnInspectorGUI()

        {
            serializedObject.Update();



            GUILayout.Label("<b>TextMeshPro - Color Gradient Preset</b>", TMP_UIStyleManager.Section_Label);



            EditorGUILayout.BeginVertical(TMP_UIStyleManager.SquareAreaBox85G);



            EditorGUILayout.PropertyField(topLeftColor, new GUIContent("Top Left"));

            EditorGUILayout.PropertyField(topRightColor, new GUIContent("Top Right"));

            EditorGUILayout.PropertyField(bottomLeftColor, new GUIContent("Bottom Left"));

            EditorGUILayout.PropertyField(bottomRightColor, new GUIContent("Bottom Right"));



            EditorGUILayout.EndVertical();



            if (serializedObject.ApplyModifiedProperties())
            {
                TMPro_EventManager.ON_COLOR_GRAIDENT_PROPERTY_CHANGED(target as TMP_ColorGradient);
            }
        }
Exemplo n.º 8
0
    private void DragAndDropGUI()
    {
        Event evt = Event.current;

        Rect dropArea = new Rect(m_inspectorStartRegion.x, m_inspectorStartRegion.y, m_inspectorEndRegion.width, m_inspectorEndRegion.y - m_inspectorStartRegion.y);

        switch (evt.type)
        {
        case EventType.dragUpdated:
        case EventType.DragPerform:
            if (!dropArea.Contains(evt.mousePosition))
            {
                break;
            }

            DragAndDrop.visualMode = DragAndDropVisualMode.Generic;

            if (evt.type == EventType.DragPerform)
            {
                DragAndDrop.AcceptDrag();

                // Do something
                Material currentMaterial = target as Material;

                Material newMaterial = DragAndDrop.objectReferences[0] as Material;
                //Debug.Log("Drag-n-Drop Material is " + newMaterial + ". Target Material is " + currentMaterial); // + ".  Canvas Material is " + m_uiRenderer.GetMaterial()  );

                // Check to make sure we have a valid material and that the font atlases match.
                if (!newMaterial || newMaterial == currentMaterial || newMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID() != currentMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID())
                {
                    if (newMaterial && newMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID() != currentMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID())
                    {
                        Debug.LogWarning("Drag-n-Drop Material [" + newMaterial.name + "]'s Atlas does not match the Atlas of the currently assigned Font Asset's Atlas.");
                    }
                    break;
                }

                // Check if this material is assigned to an object and active.
                GameObject go = Selection.activeGameObject;
                if (go != null && !go.activeInHierarchy)
                {
                    if (go.GetComponent <TextMeshPro>() != null)
                    {
                        go.GetComponent <TextMeshPro>().fontSharedMaterial = newMaterial;
                    }
                    if (go.GetComponent <TextMeshProUGUI>() != null)
                    {
                        go.GetComponent <TextMeshProUGUI>().fontSharedMaterial = newMaterial;
                    }
                }

                TMPro_EventManager.ON_DRAG_AND_DROP_MATERIAL_CHANGED(currentMaterial, newMaterial);
                EditorUtility.SetDirty(target);
            }

            evt.Use();
            break;
        }
    }
Exemplo n.º 9
0
        private void OnPostprocessTexture(Texture2D texture)
        {
            Texture2D texture2D = AssetDatabase.LoadAssetAtPath(base.assetPath, typeof(Texture2D)) as Texture2D;

            if (texture2D != null)
            {
                TMPro_EventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(true, texture2D);
            }
        }
Exemplo n.º 10
0
        static void ForceFontAssetUpgrade(MenuCommand command)
        {
            TMP_FontAsset fontAsset = command.context as TMP_FontAsset;

            if (fontAsset != null)
            {
                fontAsset.UpgradeFontAsset();
                TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, fontAsset);
            }
        }
        void OnPostprocessTexture(Texture2D texture)
        {
            Texture2D tex = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D)) as Texture2D;

            // Send Event Sub Objects
            if (tex != null)
            {
                TMPro_EventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(true, tex);
            }
        }
Exemplo n.º 12
0
    private void OnUndoRedo()
    {
        int currentGroup = Undo.GetCurrentGroup();
        int eventID      = m_eventID;

        if (currentGroup != eventID)
        {
            TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, base.target as Material);
            m_eventID = currentGroup;
        }
    }
Exemplo n.º 13
0
 private void PrepareGUI()
 {
     isNewGUI = false;
     TMP_UIStyleManager.GetUIStyles();
     ShaderUtilities.GetShaderPropertyIDs();
     if (lastSeenUndoRedoCount != undoRedoCount)
     {
         TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, material);
     }
     lastSeenUndoRedoCount = undoRedoCount;
 }
Exemplo n.º 14
0
        void PerformDrop(Material droppedMaterial)

        {
            Texture droppedTex = droppedMaterial.GetTexture(ShaderUtilities.ID_MainTex);

            if (!droppedTex)

            {
                return;
            }



            Texture currentTex = material.GetTexture(ShaderUtilities.ID_MainTex);

            TMP_FontAsset requiredFontAsset = null;

            if (droppedTex != currentTex)

            {
                requiredFontAsset = TMP_EditorUtility.FindMatchingFontAsset(droppedMaterial);

                if (!requiredFontAsset)

                {
                    return;
                }
            }



            foreach (GameObject o in Selection.gameObjects)

            {
                if (requiredFontAsset)

                {
                    TMP_Text textComponent = o.GetComponent <TMP_Text>();

                    if (textComponent)

                    {
                        Undo.RecordObject(textComponent, "Font Asset Change");

                        textComponent.font = requiredFontAsset;
                    }
                }

                TMPro_EventManager.ON_DRAG_AND_DROP_MATERIAL_CHANGED(o, material, droppedMaterial);

                EditorUtility.SetDirty(o);
            }
        }
Exemplo n.º 15
0
    // Special Handling of Undo / Redo Events.
    private void OnUndoRedo()
    {
        int UndoEventID     = Undo.GetCurrentGroup();
        int LastUndoEventID = m_eventID;

        if (UndoEventID != LastUndoEventID)
        {
            //Debug.Log("Undo Redo Event Performed in Material Editor. Event ID:" + UndoEventID + ".  Target ID: " + m_modifiedProperties.target.GetInstanceID() + "  Current Material: " + m_modifiedProperties.objectReference + "  New Material: " + (m_modifiedProperties.target as Renderer).sharedMaterial);
            TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, target as Material);
            m_eventID = UndoEventID;
        }
    }
Exemplo n.º 16
0
        void OnPostprocessTexture(Texture2D texture)
        {
            //var importer = assetImporter as TextureImporter;

            Texture2D tex = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D)) as Texture2D;

            // Send Event Sub Objects
            //Debug.Log(tex.GetInstanceID());
            if (tex != null)
            {
                TMPro_EventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(true, tex);
            }
        }
Exemplo n.º 17
0
        static void ClearFontAssetData(MenuCommand command)
        {
            TMP_FontAsset fontAsset = command.context as TMP_FontAsset;

            if (fontAsset != null && Selection.activeObject != fontAsset)
            {
                Selection.activeObject = fontAsset;
            }

            fontAsset.ClearFontAssetData(true);

            TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, fontAsset);
        }
Exemplo n.º 18
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 override void OnInspectorGUI()
        {
            serializedObject.Update();

            // Get a reference to the current material.
            SerializedProperty material_prop   = m_Materials.GetArrayElementAtIndex(0);
            Material           currentMaterial = material_prop.objectReferenceValue as Material;

            EditorGUI.BeginChangeCheck();
            base.OnInspectorGUI();
            if (EditorGUI.EndChangeCheck())
            {
                material_prop = m_Materials.GetArrayElementAtIndex(0);

                TMP_FontAsset newFontAsset = null;
                Material      newMaterial  = null;

                if (material_prop != null)
                {
                    newMaterial = material_prop.objectReferenceValue as Material;
                }

                // Check if the new material is referencing a different font atlas texture.
                if (newMaterial != null && currentMaterial.GetInstanceID() != newMaterial.GetInstanceID())
                {
                    // Search for the Font Asset matching the new font atlas texture.
                    newFontAsset = TMP_EditorUtility.FindMatchingFontAsset(newMaterial);
                }


                GameObject[] objects = Selection.gameObjects;

                for (int i = 0; i < objects.Length; i++)
                {
                    // Assign new font asset
                    if (newFontAsset != null)
                    {
                        TMP_Text textComponent = objects[i].GetComponent <TMP_Text>();

                        if (textComponent != null)
                        {
                            Undo.RecordObject(textComponent, "Font Asset Change");
                            textComponent.font = newFontAsset;
                        }
                    }

                    TMPro_EventManager.ON_DRAG_AND_DROP_MATERIAL_CHANGED(objects[i], currentMaterial, newMaterial);
                }
            }
        }
Exemplo n.º 20
0
        private void OnUndoRedo()
        {
            int currentGroup = Undo.GetCurrentGroup();
            int eventID      = m_eventID;

            if (currentGroup != eventID)
            {
                for (int i = 0; i < base.targets.Length; i++)
                {
                    TMPro_EventManager.ON_TEXTMESHPRO_PROPERTY_CHANGED(true, base.targets[i] as TextMeshPro);
                    m_eventID = currentGroup;
                }
            }
        }
Exemplo n.º 21
0
    private void DragAndDropGUI()
    {
        Event     current = Event.current;
        Rect      rect    = new Rect(m_inspectorStartRegion.x, m_inspectorStartRegion.y, m_inspectorEndRegion.width, m_inspectorEndRegion.y - m_inspectorStartRegion.y);
        EventType type    = current.type;

        if ((uint)(type - 9) > 1u || !rect.Contains(current.mousePosition))
        {
            return;
        }
        DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
        if (current.type == EventType.DragPerform)
        {
            DragAndDrop.AcceptDrag();
            Material      material      = base.target as Material;
            Texture       texture       = material.GetTexture(ShaderUtilities.ID_MainTex);
            Material      material2     = DragAndDrop.objectReferences[0] as Material;
            Texture       texture2      = material2.GetTexture(ShaderUtilities.ID_MainTex);
            TMP_FontAsset tMP_FontAsset = null;
            if (material2 == null || material2 == material || material2 == null || texture2 == null)
            {
                return;
            }
            if (texture2.GetInstanceID() != texture.GetInstanceID())
            {
                tMP_FontAsset = TMP_EditorUtility.FindMatchingFontAsset(material2);
                if (tMP_FontAsset == null)
                {
                    return;
                }
            }
            GameObject[] gameObjects = Selection.gameObjects;
            for (int i = 0; i < gameObjects.Length; i++)
            {
                if (tMP_FontAsset != null)
                {
                    TMP_Text component = gameObjects[i].GetComponent <TMP_Text>();
                    if ((UnityEngine.Object)(object) component != null)
                    {
                        Undo.RecordObject((UnityEngine.Object)(object) component, "Font Asset Change");
                        component.font = tMP_FontAsset;
                    }
                }
                TMPro_EventManager.ON_DRAG_AND_DROP_MATERIAL_CHANGED(gameObjects[i], material, material2);
                EditorUtility.SetDirty(gameObjects[i]);
            }
        }
        current.Use();
    }
Exemplo n.º 22
0
        // Special Handling of Undo / Redo Events.
        private void OnUndoRedo()
        {
            int undoEventID     = Undo.GetCurrentGroup();
            int LastUndoEventID = m_eventID;

            if (undoEventID != LastUndoEventID)
            {
                for (int i = 0; i < targets.Length; i++)
                {
                    //Debug.Log("Undo & Redo Performed detected in Editor Panel. Event ID:" + Undo.GetCurrentGroup());
                    TMPro_EventManager.ON_TEXTMESHPRO_PROPERTY_CHANGED(true, targets[i] as TextMeshPro);
                    m_eventID = undoEventID;
                }
            }
        }
        protected override void OnUndoRedo()
        {
            int undoEventId     = Undo.GetCurrentGroup();
            int lastUndoEventId = s_EventId;

            if (undoEventId != lastUndoEventId)
            {
                for (int i = 0; i < targets.Length; i++)
                {
                    //Debug.Log("Undo & Redo Performed detected in Editor Panel. Event ID:" + Undo.GetCurrentGroup());
                    TMPro_EventManager.ON_TEXTMESHPRO_PROPERTY_CHANGED(true, targets[i] as TextMeshPro);
                    s_EventId = undoEventId;
                }
            }
        }
Exemplo n.º 24
0
    // Special Handling of Undo / Redo Events.
    private void OnUndoRedo()
    {
        //Debug.Log("Undo / Redo Event ID (" + Undo.GetCurrentGroup() + ") occured.");

        int UndoEventID     = Undo.GetCurrentGroup();
        int LastUndoEventID = m_eventID;

        if (UndoEventID != LastUndoEventID)
        {
            //Debug.Log("Undo Redo Event processed by Material Editor. Affected Material is " + target + " with ID " + target.GetInstanceID()); // Event ID:" + UndoEventID + ".  Target ID: " + m_modifiedProperties.target.GetInstanceID() + "  Current Material: " + m_modifiedProperties.objectReference + "  New Material: " + (m_modifiedProperties.target as Renderer).sharedMaterial);
            TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, target as Material);
            //TMPro_EventManager.ON_BASE_MATERIAL_CHANGED(target as Material);
            m_eventID = UndoEventID;
        }
    }
Exemplo n.º 25
0
        static void ResetSettings(MenuCommand command)
        {
            Material mat = null;

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


            //Material mat = (Material)command.context;
            Undo.RecordObject(mat, "Reset Material");

            Material tmp_mat = new Material(mat.shader);

            ShaderUtilities.GetShaderPropertyIDs(); // Make sure we have valid Property IDs
            if (mat.HasProperty(ShaderUtilities.ID_GradientScale))
            {
                // Copy unique properties of the SDF Material over to the temp material.
                tmp_mat.SetTexture(ShaderUtilities.ID_MainTex, mat.GetTexture(ShaderUtilities.ID_MainTex));
                tmp_mat.SetFloat(ShaderUtilities.ID_GradientScale, mat.GetFloat(ShaderUtilities.ID_GradientScale));
                tmp_mat.SetFloat(ShaderUtilities.ID_TextureWidth, mat.GetFloat(ShaderUtilities.ID_TextureWidth));
                tmp_mat.SetFloat(ShaderUtilities.ID_TextureHeight, mat.GetFloat(ShaderUtilities.ID_TextureHeight));
                tmp_mat.SetFloat(ShaderUtilities.ID_StencilID, mat.GetFloat(ShaderUtilities.ID_StencilID));
                tmp_mat.SetFloat(ShaderUtilities.ID_StencilComp, mat.GetFloat(ShaderUtilities.ID_StencilComp));

                mat.CopyPropertiesFromMaterial(tmp_mat);

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

            DestroyImmediate(tmp_mat);

            TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, mat);
        }
Exemplo n.º 26
0
    private UndoPropertyModification[] OnUndoRedoEvent(UndoPropertyModification[] modifications)
    {
        PropertyModification modifiedProperties = modifications[0].propertyModification;

        System.Type objType = modifiedProperties.target.GetType();

        if (objType == typeof(MeshRenderer) || objType == typeof(Material)) // && UndoEventID != LastUndoEventID)
        {
            //Debug.Log("OnUndoRedoEvent() received in Material Editor. Event ID:" + UndoEventID + ".  Target ID: " + m_modifiedProperties.target.GetInstanceID() + "  Current Material: " + m_modifiedProperties.objectReference + "  New Material: " + (m_modifiedProperties.target as Renderer).sharedMaterial);
            TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, target as Material);
        }

        if (target != null)
        {
            EditorUtility.SetDirty(target);
        }

        return(modifications);
    }
Exemplo n.º 27
0
 public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
 {
     editor          = materialEditor;
     material        = (materialEditor.target as Material);
     this.properties = properties;
     if (isNewGUI)
     {
         PrepareGUI();
     }
     EditorGUIUtility.labelWidth = 130f;
     EditorGUIUtility.fieldWidth = 50f;
     DoDragAndDropBegin();
     EditorGUI.BeginChangeCheck();
     DoGUI();
     if (EditorGUI.EndChangeCheck())
     {
         TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, material);
     }
     DoDragAndDropEnd();
 }
Exemplo n.º 28
0
        static void PasteMaterialProperties(MenuCommand command)
        {
            if (m_copiedProperties == null)
            {
                Debug.LogWarning("No Material Properties to Paste. Use Copy Material Properties first.");
                return;
            }

            Material mat = null;

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

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

            ShaderUtilities.GetShaderPropertyIDs(); // Make sure we have valid Property IDs
            if (mat.HasProperty(ShaderUtilities.ID_GradientScale))
            {
                // Preserve unique SDF properties from destination material.
                m_copiedProperties.SetTexture(ShaderUtilities.ID_MainTex, mat.GetTexture(ShaderUtilities.ID_MainTex));
                m_copiedProperties.SetFloat(ShaderUtilities.ID_GradientScale, mat.GetFloat(ShaderUtilities.ID_GradientScale));
                m_copiedProperties.SetFloat(ShaderUtilities.ID_TextureWidth, mat.GetFloat(ShaderUtilities.ID_TextureWidth));
                m_copiedProperties.SetFloat(ShaderUtilities.ID_TextureHeight, mat.GetFloat(ShaderUtilities.ID_TextureHeight));
            }

            EditorShaderUtilities.CopyMaterialProperties(m_copiedProperties, mat);

            // Copy ShaderKeywords from one material to the other.
            mat.shaderKeywords = m_copiedProperties.shaderKeywords;

            // Let TextMeshPro Objects that this mat has changed.
            TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, mat);
        }
Exemplo n.º 29
0
        public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
        {
            m_Editor          = materialEditor;
            m_Material        = materialEditor.target as Material;
            this.m_Properties = properties;

            if (m_IsNewGUI)
            {
                PrepareGUI();
            }

            DoDragAndDropBegin();
            EditorGUI.BeginChangeCheck();
            DoGUI();
            if (EditorGUI.EndChangeCheck())
            {
                TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, m_Material);
            }

            DoDragAndDropEnd();
        }
Exemplo n.º 30
0
        private static void PasteMaterialProperties(MenuCommand command)
        {
            if (m_copiedProperties == null)
            {
                Debug.LogWarning("No Material Properties to Paste. Use Copy Material Properties first.");
                return;
            }
            Material material = null;

            material = ((command.context.GetType() != typeof(Material)) ? Selection.activeGameObject.GetComponent <CanvasRenderer>().GetMaterial() : ((Material)command.context));
            Undo.RecordObject(material, "Paste Material");
            ShaderUtilities.GetShaderPropertyIDs();
            if (material.HasProperty(ShaderUtilities.ID_GradientScale))
            {
                m_copiedProperties.SetTexture(ShaderUtilities.ID_MainTex, material.GetTexture(ShaderUtilities.ID_MainTex));
                m_copiedProperties.SetFloat(ShaderUtilities.ID_GradientScale, material.GetFloat(ShaderUtilities.ID_GradientScale));
                m_copiedProperties.SetFloat(ShaderUtilities.ID_TextureWidth, material.GetFloat(ShaderUtilities.ID_TextureWidth));
                m_copiedProperties.SetFloat(ShaderUtilities.ID_TextureHeight, material.GetFloat(ShaderUtilities.ID_TextureHeight));
            }
            EditorShaderUtilities.CopyMaterialProperties(m_copiedProperties, material);
            material.shaderKeywords = m_copiedProperties.shaderKeywords;
            TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, material);
        }