コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: TMP_SubMesh.cs プロジェクト: veboys/UIForia
        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);
        }