Beispiel #1
0
        public static TMP_SubMesh AddSubTextObject(TextMeshPro textComponent, MaterialReference materialReference)
        {
            GameObject go = new GameObject("TMP SubMesh [" + materialReference.material.name + "]", typeof(TMP_SubMesh));

            TMP_SubMesh subMesh = go.GetComponent <TMP_SubMesh>();

            go.transform.SetParent(textComponent.transform, false);
            go.transform.localPosition = Vector3.zero;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.layer = textComponent.gameObject.layer;

            subMesh.m_meshFilter = go.GetComponent <MeshFilter>();

            subMesh.m_TextComponent     = textComponent;
            subMesh.m_fontAsset         = materialReference.fontAsset;
            subMesh.m_spriteAsset       = materialReference.spriteAsset;
            subMesh.m_isDefaultMaterial = materialReference.isDefaultMaterial;
            subMesh.SetSharedMaterial(materialReference.material);

            subMesh.renderer.sortingLayerID = textComponent.renderer.sortingLayerID;
            subMesh.renderer.sortingOrder   = textComponent.renderer.sortingOrder;

            return(subMesh);
        }
        /// <summary>
        /// Function to add a new sub text object.
        /// </summary>
        /// <param name="textComponent"></param>
        /// <param name="materialReference"></param>
        /// <returns></returns>
        public static TMP_SubMeshUI AddSubTextObject(TextMeshProUGUI textComponent, MaterialReference materialReference)
        {
            GameObject go = new GameObject("TMP UI SubObject [" + materialReference.material.name + "]", typeof(RectTransform));

            go.transform.SetParent(textComponent.transform, false);
            go.layer = textComponent.gameObject.layer;

            RectTransform rectTransform = go.GetComponent <RectTransform>();

            rectTransform.anchorMin = Vector2.zero;
            rectTransform.anchorMax = Vector2.one;
            rectTransform.sizeDelta = Vector2.zero;
            rectTransform.pivot     = textComponent.rectTransform.pivot;

            TMP_SubMeshUI subMesh = go.AddComponent <TMP_SubMeshUI>();

            subMesh.m_canvasRenderer = subMesh.canvasRenderer;
            subMesh.m_TextComponent  = textComponent;

            subMesh.m_materialReferenceIndex = materialReference.index;
            subMesh.m_fontAsset         = materialReference.fontAsset;
            subMesh.m_spriteAsset       = materialReference.spriteAsset;
            subMesh.m_isDefaultMaterial = materialReference.isDefaultMaterial;
            subMesh.SetSharedMaterial(materialReference.material);

            return(subMesh);
        }
        /// <summary>
        /// Function to add a new material reference and returning its index in the material reference array.
        /// </summary>
        /// <param name="material"></param>
        /// <param name="fontAsset"></param>
        /// <param name="materialReferences"></param>
        /// <param name="materialReferenceIndexLookup"></param>
        /// <returns></returns>
        public static int AddMaterialReference(Material material, TMP_FontAsset fontAsset, MaterialReference[] materialReferences, Dictionary<int, int> materialReferenceIndexLookup)
        {
            int materialID = material.GetInstanceID();
            int index = 0;

            if (materialReferenceIndexLookup.TryGetValue(materialID, out index))
            {
                return index;
            }
            else
            {
                index = materialReferenceIndexLookup.Count;

                // Add new reference index
                materialReferenceIndexLookup[materialID] = index;

                materialReferences[index].index = index;
                materialReferences[index].fontAsset = fontAsset;
                materialReferences[index].spriteAsset = null;
                materialReferences[index].material = material;
                materialReferences[index].isDefaultMaterial = materialID == fontAsset.material.GetInstanceID() ? true : false;
                //materialReferences[index].padding = 0;
                materialReferences[index].referenceCount = 0;

                return index;
            }
        }
        public static TMP_SubMeshUI AddSubTextObject(TextMeshProUGUI textComponent, MaterialReference materialReference)
        {
            GameObject gameObject = new GameObject("TMP UI SubObject [" + materialReference.material.name + "]", new Type[]
            {
                typeof(RectTransform)
            });

            gameObject.transform.SetParent(textComponent.transform, false);
            gameObject.layer = textComponent.gameObject.layer;
            RectTransform component = gameObject.GetComponent <RectTransform>();

            component.anchorMin = Vector2.zero;
            component.anchorMax = Vector2.one;
            component.sizeDelta = Vector2.zero;
            component.pivot     = textComponent.rectTransform.pivot;
            TMP_SubMeshUI tmp_SubMeshUI = gameObject.AddComponent <TMP_SubMeshUI>();

            tmp_SubMeshUI.m_canvasRenderer         = tmp_SubMeshUI.canvasRenderer;
            tmp_SubMeshUI.m_TextComponent          = textComponent;
            tmp_SubMeshUI.m_materialReferenceIndex = materialReference.index;
            tmp_SubMeshUI.m_fontAsset         = materialReference.fontAsset;
            tmp_SubMeshUI.m_spriteAsset       = materialReference.spriteAsset;
            tmp_SubMeshUI.m_isDefaultMaterial = materialReference.isDefaultMaterial;
            tmp_SubMeshUI.SetSharedMaterial(materialReference.material);
            return(tmp_SubMeshUI);
        }
    static int AddSubTextObject(IntPtr L)
    {
        try
        {
            ToLua.CheckArgsCount(L, 2);
            TMPro.TextMeshProUGUI   arg0 = (TMPro.TextMeshProUGUI)ToLua.CheckObject <TMPro.TextMeshProUGUI>(L, 1);
            TMPro.MaterialReference arg1 = StackTraits <TMPro.MaterialReference> .Check(L, 2);

            TMPro.TMP_SubMeshUI o = TMPro.TMP_SubMeshUI.AddSubTextObject(arg0, arg1);
            ToLua.Push(L, o);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
        /// <summary>
        /// Function to add a new sub text object.
        /// </summary>
        /// <param name="textComponent"></param>
        /// <param name="materialReference"></param>
        /// <returns></returns>
        public static TMP_SubMeshUI AddSubTextObject(TextMeshProUGUI textComponent, MaterialReference materialReference)
        {
            GameObject go = new GameObject("TMP UI SubObject [" + materialReference.material.name + "]");

            go.transform.SetParent(textComponent.transform, false);

            RectTransform rectTransform = go.AddComponent<RectTransform>();
            rectTransform.anchorMin = Vector2.zero;
            rectTransform.anchorMax = Vector2.one;
            rectTransform.sizeDelta = Vector2.zero;
            rectTransform.pivot = textComponent.rectTransform.pivot;

            TMP_SubMeshUI subMesh = go.AddComponent<TMP_SubMeshUI>();

            subMesh.m_canvasRenderer = subMesh.canvasRenderer;
            subMesh.m_TextComponent = textComponent;

            subMesh.m_materialReferenceIndex = materialReference.index;
            subMesh.m_fontAsset = materialReference.fontAsset;
            subMesh.m_spriteAsset = materialReference.spriteAsset;
            subMesh.m_isDefaultMaterial = materialReference.isDefaultMaterial;
            subMesh.SetSharedMaterial(materialReference.material);

            return subMesh;
        }
Beispiel #7
0
        public static TMP_SubMesh AddSubTextObject(TextMeshPro textComponent, MaterialReference materialReference)
        {
            GameObject go = new GameObject("TMP SubMesh [" + materialReference.material.name + "]");
            TMP_SubMesh subMesh = go.AddComponent<TMP_SubMesh>();

            go.transform.SetParent(textComponent.transform, false);
            go.transform.localPosition = Vector3.zero;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale = Vector3.one;
            go.layer = textComponent.gameObject.layer;

            subMesh.m_meshFilter = go.GetComponent<MeshFilter>();

            subMesh.m_TextComponent = textComponent;
            subMesh.m_fontAsset = materialReference.fontAsset;
            subMesh.m_spriteAsset = materialReference.spriteAsset;
            subMesh.m_isDefaultMaterial = materialReference.isDefaultMaterial;
            subMesh.SetSharedMaterial(materialReference.material);

            subMesh.renderer.sortingLayerID = textComponent.renderer.sortingLayerID;
            subMesh.renderer.sortingOrder = textComponent.renderer.sortingOrder;

            return subMesh;
        }
        /// <summary>
        /// Function to check if a certain font asset is contained in the material reference array.
        /// </summary>
        /// <param name="materialReferences"></param>
        /// <param name="fontAsset"></param>
        /// <returns></returns>
        public static bool Contains(MaterialReference[] materialReferences, TMP_FontAsset fontAsset)
        {
            int id = fontAsset.GetInstanceID();

            for (int i = 0; i < materialReferences.Length && materialReferences[i].fontAsset != null; i++)
            {
                if (materialReferences[i].fontAsset.GetInstanceID() == id)
                    return true;
            }

            return false;
        }