Esempio 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);
            }
        }
Esempio n. 2
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);
            }
        }
        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);
                }
            }
        }