AssetImporter for importing Fonts.

Inheritance: AssetImporter
示例#1
0
        private void SetFontNames(string fontNames)
        {
            string[] array;
            if (fontNames == this.m_DefaultFontNamesString)
            {
                array = new string[0];
            }
            else
            {
                array = fontNames.Split(new char[]
                {
                    ','
                });
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = array[i].Trim();
                }
            }
            this.m_FontNamesArraySize.intValue = array.Length;
            SerializedProperty serializedProperty = this.m_FontNamesArraySize.Copy();

            for (int j = 0; j < array.Length; j++)
            {
                serializedProperty.Next(false);
                serializedProperty.stringValue = array[j];
            }
            TrueTypeFontImporter trueTypeFontImporter = this.target as TrueTypeFontImporter;

            Font[] array2 = trueTypeFontImporter.LookupFallbackFontReferences(array);
            this.m_FallbackFontReferencesArraySize.intValue = array2.Length;
            SerializedProperty serializedProperty2 = this.m_FallbackFontReferencesArraySize.Copy();

            for (int k = 0; k < array2.Length; k++)
            {
                serializedProperty2.Next(false);
                serializedProperty2.objectReferenceValue = array2[k];
            }
        }
示例#2
0
        private string GetFontNames()
        {
            TrueTypeFontImporter trueTypeFontImporter = this.target as TrueTypeFontImporter;
            string text = string.Empty;

            string[] fontNames = trueTypeFontImporter.fontNames;
            for (int i = 0; i < fontNames.Length; i++)
            {
                text += fontNames[i];
                if (i < fontNames.Length - 1)
                {
                    text += ", ";
                }
            }
            if (text == string.Empty)
            {
                text = this.m_DefaultFontNamesString;
            }
            else
            {
                this.m_GotFontNamesFromImporter = true;
            }
            return(text);
        }
        private string GetDefaultFontNames()
        {
            TrueTypeFontImporter trueTypeFontImporter = this.target as TrueTypeFontImporter;

            return(trueTypeFontImporter.fontTTFName);
        }
 public override void OnInspectorGUI()
 {
     if (!this.m_FormatSupported.HasValue)
     {
         this.m_FormatSupported = new bool?(true);
         UnityEngine.Object[] targets = base.targets;
         for (int i = 0; i < targets.Length; i++)
         {
             UnityEngine.Object   @object = targets[i];
             TrueTypeFontImporter trueTypeFontImporter = @object as TrueTypeFontImporter;
             if (trueTypeFontImporter == null || !trueTypeFontImporter.IsFormatSupported())
             {
                 this.m_FormatSupported = new bool?(false);
             }
         }
     }
     if (this.m_FormatSupported == false)
     {
         this.ShowFormatUnsupportedGUI();
         return;
     }
     EditorGUILayout.PropertyField(this.m_FontSize, new GUILayoutOption[0]);
     if (this.m_FontSize.intValue < 1)
     {
         this.m_FontSize.intValue = 1;
     }
     if (this.m_FontSize.intValue > 500)
     {
         this.m_FontSize.intValue = 500;
     }
     EditorGUILayout.IntPopup(this.m_FontRenderingMode, TrueTypeFontImporterInspector.kRenderingModeStrings, TrueTypeFontImporterInspector.kRenderingModeValues, new GUIContent("Rendering Mode"), new GUILayoutOption[0]);
     EditorGUILayout.IntPopup(this.m_TextureCase, TrueTypeFontImporterInspector.kCharacterStrings, TrueTypeFontImporterInspector.kCharacterValues, new GUIContent("Character"), new GUILayoutOption[0]);
     if (!this.m_TextureCase.hasMultipleDifferentValues)
     {
         if (this.m_TextureCase.intValue != -2)
         {
             if (this.m_TextureCase.intValue == 3)
             {
                 EditorGUI.BeginChangeCheck();
                 GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                 EditorGUILayout.PrefixLabel("Custom Chars");
                 EditorGUI.showMixedValue = this.m_CustomCharacters.hasMultipleDifferentValues;
                 string text = EditorGUILayout.TextArea(this.m_CustomCharacters.stringValue, GUI.skin.textArea, new GUILayoutOption[]
                 {
                     GUILayout.MinHeight(32f)
                 });
                 EditorGUI.showMixedValue = false;
                 GUILayout.EndHorizontal();
                 if (EditorGUI.EndChangeCheck())
                 {
                     text = new string(text.Distinct <char>().ToArray <char>());
                     text = text.Replace("\n", string.Empty);
                     text = text.Replace("\r", string.Empty);
                     this.m_CustomCharacters.stringValue = text;
                 }
             }
         }
         else
         {
             EditorGUILayout.PropertyField(this.m_IncludeFontData, new GUIContent("Incl. Font Data"), new GUILayoutOption[0]);
             if (base.targets.Length == 1)
             {
                 EditorGUI.BeginChangeCheck();
                 GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                 EditorGUILayout.PrefixLabel("Font Names");
                 GUI.SetNextControlName("fontnames");
                 this.m_FontNamesString = EditorGUILayout.TextArea(this.m_FontNamesString, "TextArea", new GUILayoutOption[]
                 {
                     GUILayout.MinHeight(32f)
                 });
                 GUILayout.EndHorizontal();
                 GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                 GUILayout.FlexibleSpace();
                 EditorGUI.BeginDisabledGroup(this.m_FontNamesString == this.m_DefaultFontNamesString);
                 if (GUILayout.Button("Reset", "MiniButton", new GUILayoutOption[0]))
                 {
                     GUI.changed = true;
                     if (GUI.GetNameOfFocusedControl() == "fontnames")
                     {
                         GUIUtility.keyboardControl = 0;
                     }
                     this.m_FontNamesString = this.m_DefaultFontNamesString;
                 }
                 EditorGUI.EndDisabledGroup();
                 GUILayout.EndHorizontal();
                 if (EditorGUI.EndChangeCheck())
                 {
                     this.SetFontNames(this.m_FontNamesString);
                 }
             }
         }
     }
     base.ApplyRevertGUI();
 }
 public override void OnInspectorGUI()
 {
     if (!this.m_FormatSupported.HasValue)
     {
         this.m_FormatSupported = true;
         foreach (UnityEngine.Object obj2 in base.targets)
         {
             TrueTypeFontImporter importer = obj2 as TrueTypeFontImporter;
             if ((importer == null) || !importer.IsFormatSupported())
             {
                 this.m_FormatSupported = false;
             }
         }
     }
     if (this.m_FormatSupported == false)
     {
         this.ShowFormatUnsupportedGUI();
     }
     else
     {
         EditorGUILayout.PropertyField(this.m_FontSize, new GUILayoutOption[0]);
         if (this.m_FontSize.intValue < 1)
         {
             this.m_FontSize.intValue = 1;
         }
         if (this.m_FontSize.intValue > 500)
         {
             this.m_FontSize.intValue = 500;
         }
         EditorGUILayout.IntPopup(this.m_FontRenderingMode, kRenderingModeStrings, kRenderingModeValues, new GUIContent("Rendering Mode"), new GUILayoutOption[0]);
         EditorGUILayout.IntPopup(this.m_TextureCase, kCharacterStrings, kCharacterValues, new GUIContent("Character"), new GUILayoutOption[0]);
         if (!this.m_TextureCase.hasMultipleDifferentValues)
         {
             if (this.m_TextureCase.intValue != -2)
             {
                 if (this.m_TextureCase.intValue == 3)
                 {
                     EditorGUI.BeginChangeCheck();
                     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                     EditorGUILayout.PrefixLabel("Custom Chars");
                     EditorGUI.showMixedValue = this.m_CustomCharacters.hasMultipleDifferentValues;
                     GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MinHeight(32f) };
                     string            source  = EditorGUILayout.TextArea(this.m_CustomCharacters.stringValue, GUI.skin.textArea, options);
                     EditorGUI.showMixedValue = false;
                     GUILayout.EndHorizontal();
                     if (EditorGUI.EndChangeCheck())
                     {
                         source = new string(source.Distinct <char>().ToArray <char>());
                         source = source.Replace("\n", string.Empty).Replace("\r", string.Empty);
                         this.m_CustomCharacters.stringValue = source;
                     }
                 }
             }
             else
             {
                 EditorGUILayout.PropertyField(this.m_IncludeFontData, new GUIContent("Incl. Font Data"), new GUILayoutOption[0]);
                 if (base.targets.Length == 1)
                 {
                     EditorGUI.BeginChangeCheck();
                     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                     EditorGUILayout.PrefixLabel("Font Names");
                     GUI.SetNextControlName("fontnames");
                     GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.MinHeight(32f) };
                     this.m_FontNamesString = EditorGUILayout.TextArea(this.m_FontNamesString, "TextArea", optionArray2);
                     GUILayout.EndHorizontal();
                     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                     GUILayout.FlexibleSpace();
                     EditorGUI.BeginDisabledGroup(this.m_FontNamesString == this.m_DefaultFontNamesString);
                     if (GUILayout.Button("Reset", "MiniButton", new GUILayoutOption[0]))
                     {
                         GUI.changed = true;
                         if (GUI.GetNameOfFocusedControl() == "fontnames")
                         {
                             GUIUtility.keyboardControl = 0;
                         }
                         this.m_FontNamesString = this.m_DefaultFontNamesString;
                     }
                     EditorGUI.EndDisabledGroup();
                     GUILayout.EndHorizontal();
                     if (EditorGUI.EndChangeCheck())
                     {
                         this.SetFontNames(this.m_FontNamesString);
                     }
                     this.m_ReferencesExpanded = EditorGUILayout.Foldout(this.m_ReferencesExpanded, "References to other fonts in project");
                     if (this.m_ReferencesExpanded)
                     {
                         EditorGUILayout.HelpBox("These are automatically generated by the inspector if any of the font names you supplied match fonts present in your project, which will then be used as fallbacks for this font.", MessageType.Info);
                         if (this.m_FallbackFontReferencesArraySize.intValue > 0)
                         {
                             SerializedProperty property = this.m_FallbackFontReferencesArraySize.Copy();
                             while (property.NextVisible(true) && (property.depth == 1))
                             {
                                 EditorGUILayout.PropertyField(property, true, new GUILayoutOption[0]);
                             }
                         }
                         else
                         {
                             EditorGUI.BeginDisabledGroup(true);
                             GUILayout.Label("No references to other fonts in project.", new GUILayoutOption[0]);
                             EditorGUI.EndDisabledGroup();
                         }
                     }
                 }
             }
         }
         base.ApplyRevertGUI();
     }
 }
 public override void OnInspectorGUI()
 {
     if (!this.m_FormatSupported.HasValue)
     {
         this.m_FormatSupported = new bool?(true);
         UnityEngine.Object[] targets = base.targets;
         for (int i = 0; i < targets.Length; i++)
         {
             UnityEngine.Object   @object = targets[i];
             TrueTypeFontImporter trueTypeFontImporter = @object as TrueTypeFontImporter;
             if (trueTypeFontImporter == null || !trueTypeFontImporter.IsFormatSupported())
             {
                 this.m_FormatSupported = new bool?(false);
             }
         }
     }
     if (this.m_FormatSupported == false)
     {
         this.ShowFormatUnsupportedGUI();
     }
     else
     {
         EditorGUILayout.PropertyField(this.m_FontSize, new GUILayoutOption[0]);
         if (this.m_FontSize.intValue < 1)
         {
             this.m_FontSize.intValue = 1;
         }
         if (this.m_FontSize.intValue > 500)
         {
             this.m_FontSize.intValue = 500;
         }
         EditorGUILayout.IntPopup(this.m_FontRenderingMode, TrueTypeFontImporterInspector.kRenderingModeStrings, TrueTypeFontImporterInspector.kRenderingModeValues, EditorGUIUtility.TrTextContent("Rendering Mode", null, null), new GUILayoutOption[0]);
         EditorGUILayout.IntPopup(this.m_TextureCase, TrueTypeFontImporterInspector.kCharacterStrings, TrueTypeFontImporterInspector.kCharacterValues, EditorGUIUtility.TrTextContent("Character", null, null), new GUILayoutOption[0]);
         EditorGUILayout.IntPopup(this.m_AscentCalculationMode, TrueTypeFontImporterInspector.kAscentCalculationModeStrings, TrueTypeFontImporterInspector.kAscentCalculationModeValues, EditorGUIUtility.TrTextContent("Ascent Calculation Mode", null, null), new GUILayoutOption[0]);
         EditorGUILayout.PropertyField(this.m_UseLegacyBoundsCalculation, EditorGUIUtility.TrTextContent("Use Legacy Bounds", null, null), new GUILayoutOption[0]);
         EditorGUILayout.PropertyField(this.m_ShouldRoundAdvanceValue, new GUIContent("Should Round Advance Value"), new GUILayoutOption[0]);
         if (!this.m_TextureCase.hasMultipleDifferentValues)
         {
             if (this.m_TextureCase.intValue != -2)
             {
                 if (this.m_TextureCase.intValue == 3)
                 {
                     EditorGUI.BeginChangeCheck();
                     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                     EditorGUILayout.PrefixLabel("Custom Chars");
                     EditorGUI.showMixedValue = this.m_CustomCharacters.hasMultipleDifferentValues;
                     string source = EditorGUILayout.TextArea(this.m_CustomCharacters.stringValue, GUI.skin.textArea, new GUILayoutOption[]
                     {
                         GUILayout.MinHeight(32f)
                     });
                     EditorGUI.showMixedValue = false;
                     GUILayout.EndHorizontal();
                     if (EditorGUI.EndChangeCheck())
                     {
                         this.m_CustomCharacters.stringValue = new string((from c in source.Distinct <char>()
                                                                           where c != '\n' && c != '\r'
                                                                           select c).ToArray <char>());
                     }
                 }
             }
             else
             {
                 EditorGUILayout.PropertyField(this.m_IncludeFontData, EditorGUIUtility.TrTextContent("Incl. Font Data", null, null), new GUILayoutOption[0]);
                 if (base.targets.Length == 1)
                 {
                     EditorGUI.BeginChangeCheck();
                     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                     EditorGUILayout.PrefixLabel("Font Names");
                     GUI.SetNextControlName("fontnames");
                     this.m_FontNamesString = EditorGUILayout.TextArea(this.m_FontNamesString, "TextArea", new GUILayoutOption[]
                     {
                         GUILayout.MinHeight(32f)
                     });
                     GUILayout.EndHorizontal();
                     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                     GUILayout.FlexibleSpace();
                     using (new EditorGUI.DisabledScope(this.m_FontNamesString == this.m_DefaultFontNamesString))
                     {
                         if (GUILayout.Button("Reset", "MiniButton", new GUILayoutOption[0]))
                         {
                             GUI.changed = true;
                             if (GUI.GetNameOfFocusedControl() == "fontnames")
                             {
                                 GUIUtility.keyboardControl = 0;
                             }
                             this.m_FontNamesString = this.m_DefaultFontNamesString;
                         }
                     }
                     GUILayout.EndHorizontal();
                     if (EditorGUI.EndChangeCheck())
                     {
                         this.SetFontNames(this.m_FontNamesString);
                     }
                     this.m_ReferencesExpanded = EditorGUILayout.Foldout(this.m_ReferencesExpanded, "References to other fonts in project", true);
                     if (this.m_ReferencesExpanded)
                     {
                         EditorGUILayout.HelpBox("These are automatically generated by the inspector if any of the font names you supplied match fonts present in your project, which will then be used as fallbacks for this font.", MessageType.Info);
                         using (new EditorGUI.DisabledScope(true))
                         {
                             if (this.m_FallbackFontReferences != null && this.m_FallbackFontReferences.Length > 0)
                             {
                                 for (int j = 0; j < this.m_FallbackFontReferences.Length; j++)
                                 {
                                     EditorGUILayout.ObjectField(this.m_FallbackFontReferences[j], typeof(Font), false, new GUILayoutOption[0]);
                                 }
                             }
                             else
                             {
                                 GUILayout.Label("No references to other fonts in project.", new GUILayoutOption[0]);
                             }
                         }
                     }
                 }
             }
         }
         base.ApplyRevertGUI();
     }
 }