コード例 #1
0
 public void OnEnable()
 {
     font_atlas_prop            = base.serializedObject.FindProperty("atlas");
     font_material_prop         = base.serializedObject.FindProperty("material");
     fontWeights_prop           = base.serializedObject.FindProperty("fontWeights");
     m_list                     = new ReorderableList(base.serializedObject, base.serializedObject.FindProperty("fallbackFontAssets"), true, true, true, true);
     m_list.drawElementCallback = delegate(Rect rect, int index, bool isActive, bool isFocused)
     {
         SerializedProperty arrayElementAtIndex = m_list.serializedProperty.GetArrayElementAtIndex(index);
         rect.y += 2f;
         EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), arrayElementAtIndex, GUIContent.none);
     };
     m_list.drawHeaderCallback = delegate(Rect rect)
     {
         EditorGUI.LabelField(rect, "<b>Fallback Font Asset List</b>", TMP_UIStyleManager.Label);
     };
     font_normalStyle_prop   = base.serializedObject.FindProperty("normalStyle");
     font_normalSpacing_prop = base.serializedObject.FindProperty("normalSpacingOffset");
     font_boldStyle_prop     = base.serializedObject.FindProperty("boldStyle");
     font_boldSpacing_prop   = base.serializedObject.FindProperty("boldSpacing");
     font_italicStyle_prop   = base.serializedObject.FindProperty("italicStyle");
     font_tabSize_prop       = base.serializedObject.FindProperty("tabSize");
     m_fontInfo_prop         = base.serializedObject.FindProperty("m_fontInfo");
     m_glyphInfoList_prop    = base.serializedObject.FindProperty("m_glyphInfoList");
     m_kerningInfo_prop      = base.serializedObject.FindProperty("m_kerningInfo");
     m_kerningPair_prop      = base.serializedObject.FindProperty("m_kerningPair");
     m_fontAsset             = (base.target as TMP_FontAsset);
     m_kerningTable          = m_fontAsset.kerningInfo;
     m_materialPresets       = TMP_EditorUtility.FindMaterialReferences(m_fontAsset);
     TMP_UIStyleManager.GetUIStyles();
     m_searchList = new List <int>();
 }
コード例 #2
0
        /// <summary>
        /// Method to retrieve the material presets that match the currently selected font asset.
        /// </summary>
        protected GUIContent[] GetMaterialPresets()
        {
            TMP_FontAsset fontAsset = m_FontAssetProp.objectReferenceValue as TMP_FontAsset;

            if (fontAsset == null)
            {
                return(null);
            }

            m_MaterialPresets     = TMP_EditorUtility.FindMaterialReferences(fontAsset);
            m_MaterialPresetNames = new GUIContent[m_MaterialPresets.Length];

            for (int i = 0; i < m_MaterialPresetNames.Length; i++)
            {
                m_MaterialPresetNames[i] = new GUIContent(m_MaterialPresets[i].name);

                if (m_TargetMaterial.GetInstanceID() == m_MaterialPresets[i].GetInstanceID())
                {
                    m_MaterialPresetSelectionIndex = i;
                }
            }

            m_IsPresetListDirty = false;

            return(m_MaterialPresetNames);
        }
コード例 #3
0
        /// <summary>
        /// Method to retrieve the material presets that match the currently selected font asset.
        /// </summary>
        private string[] GetMaterialPresets()
        {
            TMP_FontAsset fontAsset = fontAsset_prop.objectReferenceValue as TMP_FontAsset;

            if (fontAsset == null)
            {
                return(null);
            }

            m_materialPresets     = TMP_EditorUtility.FindMaterialReferences(fontAsset);
            m_materialPresetNames = new string[m_materialPresets.Length];

            for (int i = 0; i < m_materialPresetNames.Length; i++)
            {
                m_materialPresetNames[i] = m_materialPresets[i].name;

                if (m_targetMaterial.GetInstanceID() == m_materialPresets[i].GetInstanceID())
                {
                    m_materialPresetSelectionIndex = i;
                }
            }

            m_isPresetListDirty = false;

            return(m_materialPresetNames);
        }
コード例 #4
0
        public void OnEnable()
        {
            font_atlas_prop    = serializedObject.FindProperty("atlas");
            font_material_prop = serializedObject.FindProperty("material");

            fontWeights_prop = serializedObject.FindProperty("fontWeights");

            m_list = new ReorderableList(serializedObject, serializedObject.FindProperty("fallbackFontAssets"), true, true, true, true);

            m_list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                var element = m_list.serializedProperty.GetArrayElementAtIndex(index);
                rect.y += 2;
                EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), element, GUIContent.none);
            };

            m_list.drawHeaderCallback = rect =>
            {
                EditorGUI.LabelField(rect, "<b>Fallback Font Asset List</b>", TMP_UIStyleManager.Label);
            };

            font_normalStyle_prop   = serializedObject.FindProperty("normalStyle");
            font_normalSpacing_prop = serializedObject.FindProperty("normalSpacingOffset");

            font_boldStyle_prop   = serializedObject.FindProperty("boldStyle");
            font_boldSpacing_prop = serializedObject.FindProperty("boldSpacing");

            font_italicStyle_prop = serializedObject.FindProperty("italicStyle");
            font_tabSize_prop     = serializedObject.FindProperty("tabSize");

            m_fontInfo_prop      = serializedObject.FindProperty("m_fontInfo");
            m_glyphInfoList_prop = serializedObject.FindProperty("m_glyphInfoList");
            m_kerningInfo_prop   = serializedObject.FindProperty("m_kerningInfo");
            m_kerningPair_prop   = serializedObject.FindProperty("m_kerningPair");
            m_kerningPairs_prop  = m_kerningInfo_prop.FindPropertyRelative("kerningPairs");

            m_fontAsset    = target as TMP_FontAsset;
            m_kerningTable = m_fontAsset.kerningInfo;

            m_materialPresets = TMP_EditorUtility.FindMaterialReferences(m_fontAsset);

            // Get the UI Skin and Styles for the various Editors
            TMP_UIStyleManager.GetUIStyles();

            m_GlyphSearchList        = new List <int>();
            m_KerningTableSearchList = new List <int>();
        }
コード例 #5
0
        private void Save_SDF_FontAsset(string filePath)
        {
            filePath = filePath.Substring(0, filePath.Length - 6);
            string dataPath = Application.dataPath;

            if (filePath.IndexOf(dataPath, StringComparison.InvariantCultureIgnoreCase) == -1)
            {
                Debug.LogError("You're saving the font asset in a directory outside of this project folder. This is not supported. Please select a directory under \"" + dataPath + "\"");
                return;
            }
            string        path                     = filePath.Substring(dataPath.Length - 6);
            string        directoryName            = Path.GetDirectoryName(path);
            string        fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
            string        str           = directoryName + "/" + fileNameWithoutExtension;
            TMP_FontAsset tMP_FontAsset = AssetDatabase.LoadAssetAtPath(str + ".asset", typeof(TMP_FontAsset)) as TMP_FontAsset;

            if (tMP_FontAsset == null)
            {
                tMP_FontAsset = ScriptableObject.CreateInstance <WeaverCore.Assets.TMPro.TMP_FontAsset>();
                AssetDatabase.CreateAsset(tMP_FontAsset, str + ".asset");
                tMP_FontAsset.fontAssetType = TMP_FontAsset.FontAssetTypes.SDF;
                int      scaleFactor = (font_renderMode >= RenderModes.DistanceField16) ? 1 : font_scaledownFactor;
                FaceInfo faceInfo    = GetFaceInfo(m_font_faceInfo, scaleFactor);
                tMP_FontAsset.AddFaceInfo(faceInfo);
                TMP_Glyph[] glyphInfo = GetGlyphInfo(m_font_glyphInfo, scaleFactor);
                tMP_FontAsset.AddGlyphInfo(glyphInfo);
                if (includeKerningPairs)
                {
                    string       assetPath    = AssetDatabase.GetAssetPath(font_TTF);
                    KerningTable kerningTable = GetKerningTable(assetPath, (int)faceInfo.PointSize);
                    tMP_FontAsset.AddKerningInfo(kerningTable);
                }
                tMP_FontAsset.atlas = m_font_Atlas;
                m_font_Atlas.name   = fileNameWithoutExtension + " Atlas";
                AssetDatabase.AddObjectToAsset(m_font_Atlas, tMP_FontAsset);
                Shader   shader   = Shader.Find("TextMeshPro/Distance Field");
                Material material = new Material(shader);
                material.name = fileNameWithoutExtension + " Material";
                material.SetTexture(ShaderUtilities.ID_MainTex, m_font_Atlas);
                material.SetFloat(ShaderUtilities.ID_TextureWidth, m_font_Atlas.width);
                material.SetFloat(ShaderUtilities.ID_TextureHeight, m_font_Atlas.height);
                int num = font_padding + 1;
                material.SetFloat(ShaderUtilities.ID_GradientScale, num);
                material.SetFloat(ShaderUtilities.ID_WeightNormal, tMP_FontAsset.normalStyle);
                material.SetFloat(ShaderUtilities.ID_WeightBold, tMP_FontAsset.boldStyle);
                tMP_FontAsset.material = material;
                AssetDatabase.AddObjectToAsset(material, tMP_FontAsset);
            }
            else
            {
                Material[] array = TMP_EditorUtility.FindMaterialReferences(tMP_FontAsset);
                UnityEngine.Object.DestroyImmediate(tMP_FontAsset.atlas, true);
                tMP_FontAsset.fontAssetType = TMP_FontAsset.FontAssetTypes.SDF;
                int      scaleFactor2 = (font_renderMode >= RenderModes.DistanceField16) ? 1 : font_scaledownFactor;
                FaceInfo faceInfo2    = GetFaceInfo(m_font_faceInfo, scaleFactor2);
                tMP_FontAsset.AddFaceInfo(faceInfo2);
                TMP_Glyph[] glyphInfo2 = GetGlyphInfo(m_font_glyphInfo, scaleFactor2);
                tMP_FontAsset.AddGlyphInfo(glyphInfo2);
                if (includeKerningPairs)
                {
                    string       assetPath2    = AssetDatabase.GetAssetPath(font_TTF);
                    KerningTable kerningTable2 = GetKerningTable(assetPath2, (int)faceInfo2.PointSize);
                    tMP_FontAsset.AddKerningInfo(kerningTable2);
                }
                tMP_FontAsset.atlas              = m_font_Atlas;
                m_font_Atlas.name                = fileNameWithoutExtension + " Atlas";
                m_font_Atlas.hideFlags           = HideFlags.None;
                tMP_FontAsset.material.hideFlags = HideFlags.None;
                AssetDatabase.AddObjectToAsset(m_font_Atlas, tMP_FontAsset);
                tMP_FontAsset.material.SetTexture(ShaderUtilities.ID_MainTex, tMP_FontAsset.atlas);
                for (int i = 0; i < array.Length; i++)
                {
                    array[i].SetTexture(ShaderUtilities.ID_MainTex, m_font_Atlas);
                    array[i].SetFloat(ShaderUtilities.ID_TextureWidth, m_font_Atlas.width);
                    array[i].SetFloat(ShaderUtilities.ID_TextureHeight, m_font_Atlas.height);
                    int num2 = font_padding + 1;
                    array[i].SetFloat(ShaderUtilities.ID_GradientScale, num2);
                    array[i].SetFloat(ShaderUtilities.ID_WeightNormal, tMP_FontAsset.normalStyle);
                    array[i].SetFloat(ShaderUtilities.ID_WeightBold, tMP_FontAsset.boldStyle);
                }
            }
            AssetDatabase.SaveAssets();
            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(tMP_FontAsset));
            tMP_FontAsset.ReadFontDefinition();
            AssetDatabase.Refresh();
            m_font_Atlas = null;
            TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, tMP_FontAsset);
        }