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
    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.º 3
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);
                }
            }
        }
Exemplo n.º 5
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.º 6
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;

                // 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())
                    {
                        m_warning = WarningTypes.FontAtlasMismatch;
                        EditorApplication.update += EditorUpdate;
                        m_warningTimeStamp        = EditorApplication.timeSinceStartup + 15;
                        m_warningMsg              = "\nThe Font Atlas of the new material <color=yellow>" + newMaterial.name + "</color> does not match the Font Atlas of the currently assigned Font Asset. Select a material which was duplicated from this current Font Asset.\n";
                    }
                    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)
                    {
                        Undo.RecordObject(go.GetComponent <TextMeshPro>(), "Material Assignment");
                        go.GetComponent <TextMeshPro>().fontSharedMaterial = newMaterial;
                    }

#if UNITY_4_6 || UNITY_5
                    if (go.GetComponent <TextMeshProUGUI>() != null)
                    {
                        Undo.RecordObject(go.GetComponent <TextMeshProUGUI>(), "Material Assignment");
                        go.GetComponent <TextMeshProUGUI>().fontSharedMaterial = newMaterial;
                    }
#endif
                }

                TMPro_EventManager.ON_DRAG_AND_DROP_MATERIAL_CHANGED(go, currentMaterial, newMaterial);
                //SceneView.RepaintAll();
                EditorUtility.SetDirty(go);
            }

            evt.Use();
            break;
        }
    }