示例#1
0
        private static List <TMP_Sprite> UpdateSpriteInfo(TMP_SpriteAsset spriteAsset)
        {
            string assetPath = AssetDatabase.GetAssetPath(spriteAsset.spriteSheet);

            Sprite[] array = (from x in AssetDatabase.LoadAllAssetsAtPath(assetPath)
                              select x as Sprite into x
                              where x != null
                              orderby x.rect.y descending, x.rect.x
                              select x).ToArray();
            for (int i = 0; i < array.Length; i++)
            {
                Sprite sprite = array[i];
                int    num    = -1;
                if (spriteAsset.spriteInfoList.Count > i && spriteAsset.spriteInfoList[i].sprite != null)
                {
                    num = spriteAsset.spriteInfoList.FindIndex((TMP_Sprite item) => item.sprite.GetInstanceID() == sprite.GetInstanceID());
                }
                TMP_Sprite tMP_Sprite = (num == -1) ? new TMP_Sprite() : spriteAsset.spriteInfoList[num];
                Rect       rect       = sprite.rect;
                tMP_Sprite.x      = rect.x;
                tMP_Sprite.y      = rect.y;
                tMP_Sprite.width  = rect.width;
                tMP_Sprite.height = rect.height;
                Vector2 vector = new Vector2(0f - sprite.bounds.min.x / (sprite.bounds.extents.x * 2f), 0f - sprite.bounds.min.y / (sprite.bounds.extents.y * 2f));
                tMP_Sprite.pivot = new Vector2(0f - vector.x * rect.width, rect.height - vector.y * rect.height);
                if (num == -1)
                {
                    int[] array2 = spriteAsset.spriteInfoList.Select((TMP_Sprite item) => item.id).ToArray();
                    int   id     = 0;
                    for (int j = 0; j < array2.Length; j++)
                    {
                        if (array2[0] != 0)
                        {
                            break;
                        }
                        if (j > 0 && array2[j] - array2[j - 1] > 1)
                        {
                            id = array2[j - 1] + 1;
                            break;
                        }
                        id = j + 1;
                    }
                    tMP_Sprite.sprite   = sprite;
                    tMP_Sprite.name     = sprite.name;
                    tMP_Sprite.hashCode = TMP_TextUtilities.GetSimpleHashCode(tMP_Sprite.name);
                    tMP_Sprite.id       = id;
                    tMP_Sprite.xAdvance = rect.width;
                    tMP_Sprite.scale    = 1f;
                    tMP_Sprite.xOffset  = tMP_Sprite.pivot.x;
                    tMP_Sprite.yOffset  = tMP_Sprite.pivot.y;
                    spriteAsset.spriteInfoList.Add(tMP_Sprite);
                    spriteAsset.spriteInfoList = spriteAsset.spriteInfoList.OrderBy((TMP_Sprite s) => s.id).ToList();
                }
                else
                {
                    spriteAsset.spriteInfoList[num] = tMP_Sprite;
                }
            }
            return(spriteAsset.spriteInfoList);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filePath"></param>
        void SaveSpriteAsset(string filePath)
        {
            filePath = filePath.Substring(0, filePath.Length - 6); // Trim file extension from filePath.

            string dataPath = Application.dataPath;

            if (filePath.IndexOf(dataPath, System.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 relativeAssetPath = filePath.Substring(dataPath.Length - 6);
            string dirName           = Path.GetDirectoryName(relativeAssetPath);
            string fileName          = Path.GetFileNameWithoutExtension(relativeAssetPath);
            string pathNoExt         = dirName + "/" + fileName;


            // Create new Sprite Asset using this texture
            m_SpriteAsset = CreateInstance <TMP_SpriteAsset>();
            AssetDatabase.CreateAsset(m_SpriteAsset, pathNoExt + ".asset");

            // Compute the hash code for the sprite asset.
            m_SpriteAsset.hashCode = TMP_TextUtilities.GetSimpleHashCode(m_SpriteAsset.name);

            // Assign new Sprite Sheet texture to the Sprite Asset.
            m_SpriteAsset.spriteSheet    = m_SpriteAtlas;
            m_SpriteAsset.spriteInfoList = m_SpriteInfoList;

            // Add new default material for sprite asset.
            AddDefaultMaterial(m_SpriteAsset);
        }
示例#3
0
        private static List <TMP_Sprite> GetSpriteInfo(Texture source)
        {
            string assetPath = AssetDatabase.GetAssetPath(source);

            Sprite[] array = (from x in AssetDatabase.LoadAllAssetsAtPath(assetPath)
                              select x as Sprite into x
                              where x != null
                              orderby x.rect.y descending, x.rect.x
                              select x).ToArray();
            List <TMP_Sprite> list = new List <TMP_Sprite>();

            for (int i = 0; i < array.Length; i++)
            {
                TMP_Sprite tMP_Sprite = new TMP_Sprite();
                Sprite     sprite     = array[i];
                tMP_Sprite.id       = i;
                tMP_Sprite.name     = sprite.name;
                tMP_Sprite.hashCode = TMP_TextUtilities.GetSimpleHashCode(tMP_Sprite.name);
                Rect rect = sprite.rect;
                tMP_Sprite.x      = rect.x;
                tMP_Sprite.y      = rect.y;
                tMP_Sprite.width  = rect.width;
                tMP_Sprite.height = rect.height;
                Vector2 vector = new Vector2(0f - sprite.bounds.min.x / (sprite.bounds.extents.x * 2f), 0f - sprite.bounds.min.y / (sprite.bounds.extents.y * 2f));
                tMP_Sprite.pivot    = new Vector2(0f - vector.x * rect.width, rect.height - vector.y * rect.height);
                tMP_Sprite.sprite   = sprite;
                tMP_Sprite.xAdvance = rect.width;
                tMP_Sprite.scale    = 1f;
                tMP_Sprite.xOffset  = tMP_Sprite.pivot.x;
                tMP_Sprite.yOffset  = tMP_Sprite.pivot.y;
                list.Add(tMP_Sprite);
            }
            return(list);
        }
        public static TMP_FontAsset TMPFontFromUnityFont(Font font)
        {
            var asset = TMP_FontAsset.CreateFontAsset(font);

            asset.name     = font.name;
            asset.hashCode = TMP_TextUtilities.GetSimpleHashCode(asset.name);
            return(asset);
        }
示例#5
0
        private static void PushSprite(EmojiTexture emojiTex)
        {
            if (currentEmojiIndex >= SHEET_TILES * SHEET_TILES)
            {
                var newSheet = CreateTMP_SpriteAsset();
                rootEmojiAsset.fallbackSpriteAssets.Add(newSheet);
                currentEmojiAsset = newSheet;
                currentEmojiIndex = 0;
            }

            int row    = currentEmojiIndex % SHEET_TILES;
            int column = currentEmojiIndex / SHEET_TILES;

            if (EmojiTexture.CanCopyTextures)
            {
                Graphics.CopyTexture(emojiTex, 0, 0, 0, 0, EMOJI_SIZE, EMOJI_SIZE,
                                     currentEmojiAsset.spriteSheet, 0, 0, row * EMOJI_SIZE,
                                     (SHEET_SIZE)-((column + 1) * EMOJI_SIZE));
            }
            else
            {
                //If we can't copy on the GPU, we copy on the CPU
                var pixels = ((Texture2D)emojiTex).GetPixels32(0);
                ((Texture2D)currentEmojiAsset.spriteSheet).SetPixels32(
                    row * EMOJI_SIZE, (SHEET_SIZE)-((column + 1) * EMOJI_SIZE), EMOJI_SIZE, EMOJI_SIZE, pixels, 0);

                //Free CPU copy of the texture (mark as non readable) if it's full
                var makeNoLongerReadable = currentEmojiIndex == SHEET_TILES * SHEET_TILES - 1;
                if (makeNoLongerReadable)
                {
                    ((Texture2D)currentEmojiAsset.spriteSheet).Apply(false, makeNoLongerReadable);
                }
                textureNeedsApply = !makeNoLongerReadable;
            }

            TMP_Sprite tmp_Sprite = new TMP_Sprite();

            tmp_Sprite.hashCode = TMP_TextUtilities.GetSimpleHashCode(emojiTex.Text);
            tmp_Sprite.height   = EMOJI_SIZE;
            tmp_Sprite.id       = currentEmojiIndex;
            tmp_Sprite.name     = emojiTex.Text;
            tmp_Sprite.pivot    = Vector2.one * 0.5f;
            tmp_Sprite.scale    = 1;
            tmp_Sprite.unicode  = emojiTexture.Unicode;
            tmp_Sprite.width    = EMOJI_SIZE;
            tmp_Sprite.x        = row * EMOJI_SIZE;
            tmp_Sprite.xAdvance = EMOJI_SIZE;
            tmp_Sprite.xOffset  = 0;
            tmp_Sprite.y        = (SHEET_SIZE)-((column + 1) * EMOJI_SIZE);
            tmp_Sprite.yOffset  = EMOJI_SIZE * 0.9f;

            currentEmojiAsset.spriteInfoList.Add(tmp_Sprite);
            currentEmojiAsset.UpdateLookupTables();
            currentEmojiIndex++;
        }
示例#6
0
        /// <summary>
        /// Returns the index of the sprite for the given name.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public int GetSpriteIndexFromName(string name)
        {
            if (m_NameLookup == null)
            {
                UpdateLookupTables();
            }

            int hashCode = TMP_TextUtilities.GetSimpleHashCode(name);

            return(GetSpriteIndexFromHashcode(hashCode));
        }
示例#7
0
        /// <summary>
        ///
        /// </summary>
        List <TMP_Sprite> CreateSpriteInfoList(TexturePacker.SpriteDataObject spriteDataObject)
        {
            List <TexturePacker.SpriteData> importedSprites = spriteDataObject.frames;

            List <TMP_Sprite> spriteInfoList = new List <TMP_Sprite>();

            for (int i = 0; i < importedSprites.Count; i++)
            {
                TMP_Sprite sprite = new TMP_Sprite();

                sprite.id       = i;
                sprite.name     = Path.GetFileNameWithoutExtension(importedSprites[i].filename) ?? "";
                sprite.hashCode = TMP_TextUtilities.GetSimpleHashCode(sprite.name);

                // Attempt to extract Unicode value from name
                int unicode;
                int indexOfSeperator = sprite.name.IndexOf('-');
                if (indexOfSeperator != -1)
                {
                    unicode = TMP_TextUtilities.StringToInt(sprite.name.Substring(indexOfSeperator + 1));
                }
                else
                {
                    unicode = TMP_TextUtilities.StringToInt(sprite.name);
                }

                sprite.unicode = unicode;

                sprite.x      = importedSprites[i].frame.x;
                sprite.y      = m_SpriteAtlas.height - (importedSprites[i].frame.y + importedSprites[i].frame.h);
                sprite.width  = importedSprites[i].frame.w;
                sprite.height = importedSprites[i].frame.h;

                //Calculate sprite pivot position
                sprite.pivot = importedSprites[i].pivot;

                // Properties the can be modified
                sprite.xAdvance = sprite.width;
                sprite.scale    = 1.0f;
                sprite.xOffset  = 0 - (sprite.width * sprite.pivot.x);
                sprite.yOffset  = sprite.height - (sprite.height * sprite.pivot.y);

                spriteInfoList.Add(sprite);
            }

            return(spriteInfoList);
        }
        void SaveSpriteAsset(string filePath)
        {
            filePath = filePath.Substring(0, filePath.Length - 6); // Trim file extension from filePath.

            string dataPath = Application.dataPath;

            if (filePath.IndexOf(dataPath, System.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 relativeAssetPath = filePath.Substring(dataPath.Length - 6);
            string dirName           = Path.GetDirectoryName(relativeAssetPath);
            string fileName          = Path.GetFileNameWithoutExtension(relativeAssetPath);
            string pathNoExt         = dirName + "/" + fileName;


            // Create new Sprite Asset using this texture
            m_SpriteAsset = CreateInstance <TMP_EmojiSpriteAsset>();
            AssetDatabase.CreateAsset(m_SpriteAsset, pathNoExt + ".asset");

            // Compute the hash code for the sprite asset.
            m_SpriteAsset.hashCode = TMP_TextUtilities.GetSimpleHashCode(m_SpriteAsset.name);

            // Assign new Sprite Sheet texture to the Sprite Asset.
            m_SpriteAsset.spriteSheet    = m_SpriteAtlas;
            m_SpriteAsset.spriteInfoList = m_SpriteInfoList;

            // Add new default material for sprite asset.
            AddDefaultMaterial(m_SpriteAsset);

#if TMP_1_4_0_OR_NEWER
            //Upgrade Lookup tables (we must set Version to Empty before)
            FieldInfo versionField = typeof(TMP_SpriteAsset).GetField("m_Version", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            if (versionField != null)
            {
                versionField.SetValue(m_SpriteAsset, string.Empty);
            }
            m_SpriteAsset.UpdateLookupTables();
            if (m_SpriteInfoList != null)
            {
                FixLookupTable(m_SpriteAsset, m_globalGlyphScale, m_CreatedWithEmojiJson);
            }
#endif
        }
示例#9
0
        private static List <TMP_Sprite> GetSpriteInfo(Texture source)
        {
            //Debug.Log("Creating new Sprite Asset.");

            string filePath = AssetDatabase.GetAssetPath(source);

            // Get all the Sprites sorted by Index
            Sprite[] sprites = AssetDatabase.LoadAllAssetsAtPath(filePath).Select(x => x as Sprite).Where(x => x != null).OrderByDescending(x => x.rect.y).ThenBy(x => x.rect.x).ToArray();

            List <TMP_Sprite> spriteInfoList = new List <TMP_Sprite>();

            for (int i = 0; i < sprites.Length; i++)
            {
                TMP_Sprite spriteInfo = new TMP_Sprite();
                Sprite     sprite     = sprites[i];

                //spriteInfo.fileID = UnityEditor.Unsupported.GetLocalIdentifierInFile(sprite.GetInstanceID());
                spriteInfo.id       = i;
                spriteInfo.name     = sprite.name;
                spriteInfo.hashCode = TMP_TextUtilities.GetSimpleHashCode(spriteInfo.name);

                Rect spriteRect = sprite.rect;
                spriteInfo.x      = spriteRect.x;
                spriteInfo.y      = spriteRect.y;
                spriteInfo.width  = spriteRect.width;
                spriteInfo.height = spriteRect.height;

                // Compute Sprite pivot position
                Vector2 pivot = new Vector2(0 - (sprite.bounds.min.x) / (sprite.bounds.extents.x * 2), 0 - (sprite.bounds.min.y) / (sprite.bounds.extents.y * 2));
                spriteInfo.pivot = new Vector2(0 - pivot.x * spriteRect.width, spriteRect.height - pivot.y * spriteRect.height);

                spriteInfo.sprite = sprite;

                // Properties the can be modified
                spriteInfo.xAdvance = spriteRect.width;
                spriteInfo.scale    = 1.0f;
                spriteInfo.xOffset  = spriteInfo.pivot.x;
                spriteInfo.yOffset  = spriteInfo.pivot.y;

                spriteInfoList.Add(spriteInfo);
            }

            return(spriteInfoList);
        }
示例#10
0
        //public TMP_Style()
        //{
        //Debug.Log("New Style with Name: " + m_Name + " was created. ID: ");
        //}


        /// <summary>
        /// Function to update the content of the int[] resulting from changes to OpeningDefinition & ClosingDefinition.
        /// </summary>
        public void RefreshStyle()
        {
            m_HashCode = TMP_TextUtilities.GetSimpleHashCode(m_Name);

            m_OpeningTagArray = new int[m_OpeningDefinition.Length];
            for (int i = 0; i < m_OpeningDefinition.Length; i++)
            {
                m_OpeningTagArray[i] = m_OpeningDefinition[i];
            }

            m_ClosingTagArray = new int[m_ClosingDefinition.Length];
            for (int i = 0; i < m_ClosingDefinition.Length; i++)
            {
                m_ClosingTagArray[i] = m_ClosingDefinition[i];
            }

#if UNITY_EDITOR
            // Event to update objects when styles are changed in the editor.
            TMPro_EventManager.ON_TEXT_STYLE_PROPERTY_CHANGED(true);
#endif
        }
示例#11
0
        public CostumeBuilder CostumeSprite(String name, Sprite sprite, float width, float height)
        {
            AddStep("COSTUME_SPRITE", (handler) =>
            {
                // set texture
                var spriteAsset            = ScriptableObject.CreateInstance <TMP_SpriteAsset>();
                spriteAsset.spriteInfoList = new List <TMP_Sprite>();
                spriteAsset.spriteInfoList.Add(new TMP_Sprite()
                {
                    name     = "ui_icon_entertainer_" + name,
                    unicode  = 0,
                    scale    = 1.0f,
                    sprite   = sprite,
                    height   = height,
                    width    = width,
                    pivot    = new Vector2(0, 0),
                    x        = 0,
                    y        = 0,
                    yOffset  = height,
                    xAdvance = width
                });
                spriteAsset.spriteSheet = sprite.texture;
                ShaderUtilities.GetShaderPropertyIDs();
                Material material = new Material(Shader.Find("TextMeshPro/Sprite"));
                material.SetTexture(ShaderUtilities.ID_MainTex, spriteAsset.spriteSheet);
                material.hideFlags   = HideFlags.HideInHierarchy;
                spriteAsset.material = material;
                spriteAsset.hashCode = TMP_TextUtilities.GetSimpleHashCode("ui_icon_entertainer_" + name);
                typeof(TMP_SpriteAsset).GetField("m_FaceInfo",
                                                 BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic)
                ?.SetValue(spriteAsset, FontEngine.GetFaceInfo());
                spriteAsset.UpdateLookupTables();
                MaterialReferenceManager.AddSpriteAsset(spriteAsset);

                handler.Target.costumeSpriteName = name;
                handler.Target.customeSprite     = sprite;
            });
            return(this);
        }
示例#12
0
        public static void CreateTextMeshProObjectPerform()
        {
            Object activeObject = Selection.activeObject;

            if (activeObject == null || activeObject.GetType() != typeof(Texture2D))
            {
                Debug.LogWarning("A texture which contains sprites must first be selected in order to create a TextMesh Pro Sprite Asset.");
                return;
            }
            Texture2D       texture2D = activeObject as Texture2D;
            string          assetPath = AssetDatabase.GetAssetPath(texture2D);
            string          fileName  = Path.GetFileName(assetPath);
            string          fileNameWithoutExtension = Path.GetFileNameWithoutExtension(assetPath);
            string          str             = assetPath.Replace(fileName, "");
            TMP_SpriteAsset tMP_SpriteAsset = AssetDatabase.LoadAssetAtPath(str + fileNameWithoutExtension + ".asset", typeof(TMP_SpriteAsset)) as TMP_SpriteAsset;

            if ((tMP_SpriteAsset == null) ? true : false)
            {
                tMP_SpriteAsset = ScriptableObject.CreateInstance <TMP_SpriteAsset>();
                AssetDatabase.CreateAsset(tMP_SpriteAsset, str + fileNameWithoutExtension + ".asset");
                tMP_SpriteAsset.hashCode       = TMP_TextUtilities.GetSimpleHashCode(tMP_SpriteAsset.name);
                tMP_SpriteAsset.spriteSheet    = texture2D;
                tMP_SpriteAsset.spriteInfoList = GetSpriteInfo(texture2D);
                AddDefaultMaterial(tMP_SpriteAsset);
            }
            else
            {
                tMP_SpriteAsset.spriteInfoList = UpdateSpriteInfo(tMP_SpriteAsset);
                if (tMP_SpriteAsset.material == null)
                {
                    AddDefaultMaterial(tMP_SpriteAsset);
                }
            }
            EditorUtility.SetDirty(tMP_SpriteAsset);
            AssetDatabase.SaveAssets();
            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(tMP_SpriteAsset));
        }
示例#13
0
        /// <summary>
        ///
        /// </summary>
        public void ReadFontDefinition()
        {
            //Debug.Log("Reading Font Definition for " + this.name + ".");
            // Make sure that we have a Font Asset file assigned.
            if (m_fontInfo == null)
            {
                return;
            }

            // Check Font Asset type
            //Debug.Log(name + "   " + fontAssetType);

            // Create new instance of GlyphInfo Dictionary for fast access to glyph info.
            m_characterDictionary = new Dictionary <int, TMP_Glyph>();
            for (int i = 0; i < m_glyphInfoList.Count; i++)
            {
                TMP_Glyph glyph = m_glyphInfoList[i];

                if (!m_characterDictionary.ContainsKey(glyph.id))
                {
                    m_characterDictionary.Add(glyph.id, glyph);
                }

                // Compatibility
                if (glyph.scale == 0)
                {
                    glyph.scale = 1;
                }
            }


            //Debug.Log("PRE: BaseLine:" + m_fontInfo.Baseline + "  Ascender:" + m_fontInfo.Ascender + "  Descender:" + m_fontInfo.Descender); // + "  Centerline:" + m_fontInfo.CenterLine);

            TMP_Glyph temp_charInfo = new TMP_Glyph();

            // Add Character (10) LineFeed, (13) Carriage Return & Space (32) to Dictionary if they don't exists.
            if (m_characterDictionary.ContainsKey(32))
            {
                m_characterDictionary[32].width   = m_characterDictionary[32].xAdvance; // m_fontInfo.Ascender / 5;
                m_characterDictionary[32].height  = m_fontInfo.Ascender - m_fontInfo.Descender;
                m_characterDictionary[32].yOffset = m_fontInfo.Ascender;
                m_characterDictionary[32].scale   = 1;
            }
            else
            {
                //Debug.Log("Adding Character 32 (Space) to Dictionary for Font (" + m_fontInfo.Name + ").");
                temp_charInfo          = new TMP_Glyph();
                temp_charInfo.id       = 32;
                temp_charInfo.x        = 0;
                temp_charInfo.y        = 0;
                temp_charInfo.width    = m_fontInfo.Ascender / 5;
                temp_charInfo.height   = m_fontInfo.Ascender - m_fontInfo.Descender;
                temp_charInfo.xOffset  = 0;
                temp_charInfo.yOffset  = m_fontInfo.Ascender;
                temp_charInfo.xAdvance = m_fontInfo.PointSize / 4;
                temp_charInfo.scale    = 1;
                m_characterDictionary.Add(32, temp_charInfo);
            }

            // Add Non-Breaking Space (160)
            if (!m_characterDictionary.ContainsKey(160))
            {
                temp_charInfo = TMP_Glyph.Clone(m_characterDictionary[32]);
                m_characterDictionary.Add(160, temp_charInfo);
            }

            // Add Zero Width Space (8203)
            if (!m_characterDictionary.ContainsKey(8203))
            {
                temp_charInfo          = TMP_Glyph.Clone(m_characterDictionary[32]);
                temp_charInfo.width    = 0;
                temp_charInfo.xAdvance = 0;
                m_characterDictionary.Add(8203, temp_charInfo);
            }

            //Add Zero Width no-break space (8288)
            if (!m_characterDictionary.ContainsKey(8288))
            {
                temp_charInfo          = TMP_Glyph.Clone(m_characterDictionary[32]);
                temp_charInfo.width    = 0;
                temp_charInfo.xAdvance = 0;
                m_characterDictionary.Add(8288, temp_charInfo);
            }

            // Add Linefeed (10)
            if (m_characterDictionary.ContainsKey(10) == false)
            {
                //Debug.Log("Adding Character 10 (Linefeed) to Dictionary for Font (" + m_fontInfo.Name + ").");

                temp_charInfo          = new TMP_Glyph();
                temp_charInfo.id       = 10;
                temp_charInfo.x        = 0;  // m_characterDictionary[32].x;
                temp_charInfo.y        = 0;  // m_characterDictionary[32].y;
                temp_charInfo.width    = 10; // m_characterDictionary[32].width;
                temp_charInfo.height   = m_characterDictionary[32].height;
                temp_charInfo.xOffset  = 0;  // m_characterDictionary[32].xOffset;
                temp_charInfo.yOffset  = m_characterDictionary[32].yOffset;
                temp_charInfo.xAdvance = 0;
                temp_charInfo.scale    = 1;
                m_characterDictionary.Add(10, temp_charInfo);

                if (!m_characterDictionary.ContainsKey(13))
                {
                    m_characterDictionary.Add(13, temp_charInfo);
                }
            }

            // Add Tab Character to Dictionary. Tab is Tab Size * Space Character Width.
            if (m_characterDictionary.ContainsKey(9) == false)
            {
                //Debug.Log("Adding Character 9 (Tab) to Dictionary for Font (" + m_fontInfo.Name + ").");

                temp_charInfo          = new TMP_Glyph();
                temp_charInfo.id       = 9;
                temp_charInfo.x        = m_characterDictionary[32].x;
                temp_charInfo.y        = m_characterDictionary[32].y;
                temp_charInfo.width    = m_characterDictionary[32].width * tabSize + (m_characterDictionary[32].xAdvance - m_characterDictionary[32].width) * (tabSize - 1);
                temp_charInfo.height   = m_characterDictionary[32].height;
                temp_charInfo.xOffset  = m_characterDictionary[32].xOffset;
                temp_charInfo.yOffset  = m_characterDictionary[32].yOffset;
                temp_charInfo.xAdvance = m_characterDictionary[32].xAdvance * tabSize;
                temp_charInfo.scale    = 1;
                m_characterDictionary.Add(9, temp_charInfo);
            }

            // Centerline is located at the center of character like { or in the middle of the lowercase o.
            //m_fontInfo.CenterLine = m_characterDictionary[111].yOffset - m_characterDictionary[111].height * 0.5f;

            // Tab Width is using the same xAdvance as space (32).
            m_fontInfo.TabWidth = m_characterDictionary[9].xAdvance;

            // Set Cap Height
            if (m_fontInfo.CapHeight == 0 && m_characterDictionary.ContainsKey(72))
            {
                m_fontInfo.CapHeight = m_characterDictionary[72].yOffset;
            }

            // Adjust Font Scale for compatibility reasons
            if (m_fontInfo.Scale == 0)
            {
                m_fontInfo.Scale = 1.0f;
            }

            // Set Strikethrough Offset (if needed)
            if (m_fontInfo.strikethrough == 0)
            {
                m_fontInfo.strikethrough = m_fontInfo.CapHeight / 2.5f;
            }

            // Set Padding value for legacy font assets.
            if (m_fontInfo.Padding == 0)
            {
                if (material.HasProperty(ShaderUtilities.ID_GradientScale))
                {
                    m_fontInfo.Padding = material.GetFloat(ShaderUtilities.ID_GradientScale) - 1;
                }
            }

            // Populate Dictionary with Kerning Information
            m_kerningDictionary = new Dictionary <int, KerningPair>();
            List <KerningPair> pairs = m_kerningInfo.kerningPairs;

            //Debug.Log(m_fontInfo.Name + " has " + pairs.Count +  " Kerning Pairs.");
            for (int i = 0; i < pairs.Count; i++)
            {
                KerningPair pair = pairs[i];

                // Convert legacy kerning data
                if (pair.xOffset != 0)
                {
                    pairs[i].ConvertLegacyKerningData();
                }

                KerningPairKey uniqueKey = new KerningPairKey(pair.firstGlyph, pair.secondGlyph);

                if (m_kerningDictionary.ContainsKey((int)uniqueKey.key) == false)
                {
                    m_kerningDictionary.Add((int)uniqueKey.key, pair);
                }
                else
                {
                    if (!TMP_Settings.warningsDisabled)
                    {
                        Debug.LogWarning("Kerning Key for [" + uniqueKey.ascii_Left + "] and [" + uniqueKey.ascii_Right + "] already exists.");
                    }
                }
            }


            // Compute Hashcode for the font asset name
            hashCode = TMP_TextUtilities.GetSimpleHashCode(this.name);

            // Compute Hashcode for the material name
            materialHashCode = TMP_TextUtilities.GetSimpleHashCode(material.name);

            // Unload font atlas texture
            //ShaderUtilities.GetShaderPropertyIDs();
            //Resources.UnloadAsset(material.GetTexture(ShaderUtilities.ID_MainTex));

            // Initialize Font Weights if needed
            //InitializeFontWeights();
        }
示例#14
0
        public static void CreateTextMeshProObjectPerform()
        {
            Object target = Selection.activeObject;

            // Make sure the selection is a texture.
            if (target == null || target.GetType() != typeof(Texture2D))
            {
                Debug.LogWarning("A texture which contains sprites must first be selected in order to create a TextMesh Pro Sprite Asset.");
                return;
            }

            Texture2D sourceTex = target as Texture2D;

            // Get the path to the selected texture.
            string filePathWithName         = AssetDatabase.GetAssetPath(sourceTex);
            string fileNameWithExtension    = Path.GetFileName(filePathWithName);
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePathWithName);
            string filePath = filePathWithName.Replace(fileNameWithExtension, "");

            // Check if Sprite Asset already exists
            TMP_SpriteAsset spriteAsset = AssetDatabase.LoadAssetAtPath(filePath + fileNameWithoutExtension + ".asset", typeof(TMP_SpriteAsset)) as TMP_SpriteAsset;
            bool            isNewAsset  = spriteAsset == null ? true : false;

            if (isNewAsset)
            {
                // Create new Sprite Asset using this texture
                spriteAsset = ScriptableObject.CreateInstance <TMP_SpriteAsset>();
                AssetDatabase.CreateAsset(spriteAsset, filePath + fileNameWithoutExtension + ".asset");

                // Compute the hash code for the sprite asset.
                spriteAsset.hashCode = TMP_TextUtilities.GetSimpleHashCode(spriteAsset.name);

                // Assign new Sprite Sheet texture to the Sprite Asset.
                spriteAsset.spriteSheet    = sourceTex;
                spriteAsset.spriteInfoList = GetSpriteInfo(sourceTex);

                // Add new default material for sprite asset.
                AddDefaultMaterial(spriteAsset);
            }
            else
            {
                spriteAsset.spriteInfoList = UpdateSpriteInfo(spriteAsset);

                // Make sure the sprite asset already contains a default material
                if (spriteAsset.material == null)
                {
                    // Add new default material for sprite asset.
                    AddDefaultMaterial(spriteAsset);
                }
            }

            // Get the Sprites contained in the Sprite Sheet
            EditorUtility.SetDirty(spriteAsset);

            //spriteAsset.sprites = sprites;

            // Set source texture back to Not Readable.
            //texImporter.isReadable = false;


            AssetDatabase.SaveAssets();

            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(spriteAsset));  // Re-import font asset to get the new updated version.

            //AssetDatabase.Refresh();
        }
示例#15
0
        // Update existing SpriteInfo
        private static List <TMP_Sprite> UpdateSpriteInfo(TMP_SpriteAsset spriteAsset)
        {
            //Debug.Log("Updating Sprite Asset.");

            string filePath = AssetDatabase.GetAssetPath(spriteAsset.spriteSheet);

            // Get all the Sprites sorted Left to Right / Top to Bottom
            Sprite[] sprites = AssetDatabase.LoadAllAssetsAtPath(filePath).Select(x => x as Sprite).Where(x => x != null).OrderByDescending(x => x.rect.y).ThenBy(x => x.rect.x).ToArray();

            for (int i = 0; i < sprites.Length; i++)
            {
                Sprite sprite = sprites[i];

                // Check if the sprite is already contained in the SpriteInfoList
                int index = -1;
                if (spriteAsset.spriteInfoList.Count > i && spriteAsset.spriteInfoList[i].sprite != null)
                {
                    index = spriteAsset.spriteInfoList.FindIndex(item => item.sprite.GetInstanceID() == sprite.GetInstanceID());
                }

                // Use existing SpriteInfo if it already exists
                TMP_Sprite spriteInfo = index == -1 ? new TMP_Sprite() : spriteAsset.spriteInfoList[index];

                Rect spriteRect = sprite.rect;
                spriteInfo.x      = spriteRect.x;
                spriteInfo.y      = spriteRect.y;
                spriteInfo.width  = spriteRect.width;
                spriteInfo.height = spriteRect.height;

                // Get Sprite Pivot
                Vector2 pivot = new Vector2(0 - (sprite.bounds.min.x) / (sprite.bounds.extents.x * 2), 0 - (sprite.bounds.min.y) / (sprite.bounds.extents.y * 2));

                // The position of the pivot influences the Offset position.
                spriteInfo.pivot = new Vector2(0 - pivot.x * spriteRect.width, spriteRect.height - pivot.y * spriteRect.height);

                if (index == -1)
                {
                    // Find the next available index for this Sprite
                    int[] ids = spriteAsset.spriteInfoList.Select(item => item.id).ToArray();

                    int id = 0;
                    for (int j = 0; j < ids.Length; j++)
                    {
                        if (ids[0] != 0)
                        {
                            break;
                        }

                        if (j > 0 && (ids[j] - ids[j - 1]) > 1)
                        {
                            id = ids[j - 1] + 1;
                            break;
                        }

                        id = j + 1;
                    }

                    spriteInfo.sprite   = sprite;
                    spriteInfo.name     = sprite.name;
                    spriteInfo.hashCode = TMP_TextUtilities.GetSimpleHashCode(spriteInfo.name);
                    spriteInfo.id       = id;
                    spriteInfo.xAdvance = spriteRect.width;
                    spriteInfo.scale    = 1.0f;

                    spriteInfo.xOffset = spriteInfo.pivot.x;
                    spriteInfo.yOffset = spriteInfo.pivot.y;

                    spriteAsset.spriteInfoList.Add(spriteInfo);

                    // Sort the Sprites by ID
                    spriteAsset.spriteInfoList = spriteAsset.spriteInfoList.OrderBy(s => s.id).ToList();
                }
                else
                {
                    spriteAsset.spriteInfoList[index] = spriteInfo;
                }
            }

            return(spriteAsset.spriteInfoList);
        }
        List <TMP_Sprite> CreateSpriteInfoList(TexturePacker.SpriteDataObject spriteDataObject)
#endif
        {
#if TMP_2_1_0_PREVIEW_1_OR_NEWER
            List <TexturePacker_JsonArray.Frame> importedSprites = spriteDataObject.frames;
#else
            List <TexturePacker.SpriteData> importedSprites = spriteDataObject.frames;
#endif

            List <TMP_Sprite> spriteInfoList = new List <TMP_Sprite>();

            for (int i = 0; i < importedSprites.Count; i++)
            {
                TMP_Sprite sprite = new TMP_Sprite();

                sprite.id       = i;
                sprite.name     = Path.GetFileNameWithoutExtension(importedSprites[i].filename) ?? "";
                sprite.hashCode = TMP_TextUtilities.GetSimpleHashCode(sprite.name);

                // Attempt to extract Unicode value from name
                int unicode;
                int indexOfSeparator = sprite.name.IndexOf('-');
                if (indexOfSeparator != -1)
                {
                    string substring = sprite.name.Substring(0, indexOfSeparator);
#if TMP_1_4_0_OR_NEWER
                    unicode = TMP_TextUtilities.StringHexToInt(substring);
#else
                    unicode = TMP_TextUtilities.StringToInt(substring);
#endif
                }
                else
                {
#if TMP_1_4_0_OR_NEWER
                    unicode = TMP_TextUtilities.StringHexToInt(sprite.name);
#else
                    unicode = TMP_TextUtilities.StringToInt(sprite.name);
#endif
                }

                sprite.unicode = unicode;

                sprite.x      = importedSprites[i].frame.x;
                sprite.y      = m_SpriteAtlas.height - (importedSprites[i].frame.y + importedSprites[i].frame.h);
                sprite.width  = importedSprites[i].frame.w;
                sprite.height = importedSprites[i].frame.h;

                //Calculate sprite pivot position
                sprite.pivot = importedSprites[i].pivot;

                //Extra Properties
                //var scaledOffset = (sprite.height * ((m_globalGlyphScale - 1) * 0.5f)) * sprite.pivot.y;
                sprite.xAdvance = sprite.width;
#if TMP_1_4_0_OR_NEWER
                sprite.scale = 1.0f;
#else
                sprite.scale = m_globalGlyphScale;
#endif
                sprite.xOffset = 0 - (sprite.width * sprite.pivot.x);
                sprite.yOffset = sprite.height - (sprite.height * sprite.pivot.y);
                spriteInfoList.Add(sprite);
            }

            return(spriteInfoList);
        }
示例#17
0
        //TODO: Currently this doesn't work on a folder that has no textures in it.
        public void LoadCustomFolderSprite(ICustomFolderInfo folder, string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            var folderIconPath = Path.Combine(path, "folder.png");

            if (!File.Exists(folderIconPath))
            {
                folderIconPath = Path.Combine(path, "folder.jpg");
            }

            if (!File.Exists(folderIconPath))
            {
                folderIconPath = Path.Combine(path, "folder.jpeg");
            }

            if (!File.Exists(folderIconPath))
            {
                return;
            }

            // Assign new Sprite Sheet texture to the Sprite Asset.
            var texture = LoadTexture(folderIconPath);

            List <TMP_Sprite> spriteInfoList = new List <TMP_Sprite>();

            TMP_Sprite sprite = new TMP_Sprite();

            sprite.id       = 0;
            sprite.name     = Path.GetFileNameWithoutExtension(folderIconPath) ?? "";
            sprite.hashCode = TMP_TextUtilities.GetSimpleHashCode(sprite.name);

            //// Attempt to extract Unicode value from name
            int unicode;
            int indexOfSeperator = sprite.name.IndexOf('-');

            if (indexOfSeperator != -1)
            {
                unicode = TMP_TextUtilities.StringHexToInt(sprite.name.Substring(indexOfSeperator + 1));
            }
            else
            {
                unicode = TMP_TextUtilities.StringHexToInt(sprite.name);
            }

            sprite.unicode = unicode;

            sprite.x      = 0;
            sprite.y      = 0;
            sprite.width  = texture.width;
            sprite.height = texture.height;
            sprite.pivot  = new Vector2(0.5f, 0.5f);

            sprite.xAdvance = sprite.width;
            sprite.scale    = 1.0f;
            sprite.xOffset  = 0 - (sprite.width * sprite.pivot.x);
            sprite.yOffset  = sprite.height;

            spriteInfoList.Add(sprite);

            // Create new Sprite Asset using this texture
            TMP_SpriteAsset spriteAsset = ScriptableObject.CreateInstance <TMP_SpriteAsset>();

            // Compute the hash code for the sprite asset.
            spriteAsset.hashCode = TMP_TextUtilities.GetSimpleHashCode(spriteAsset.name);

            spriteAsset.spriteSheet    = texture;
            spriteAsset.spriteInfoList = spriteInfoList;

            // Add new default material for sprite asset.
            AddDefaultMaterial(spriteAsset);

            folder.CustomSprite = spriteAsset;
        }
示例#18
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            SerializedProperty nameProperty              = property.FindPropertyRelative("m_Name");
            SerializedProperty hashCodeProperty          = property.FindPropertyRelative("m_HashCode");
            SerializedProperty openingDefinitionProperty = property.FindPropertyRelative("m_OpeningDefinition");
            SerializedProperty closingDefinitionProperty = property.FindPropertyRelative("m_ClosingDefinition");
            SerializedProperty openingDefinitionArray    = property.FindPropertyRelative("m_OpeningTagArray");
            SerializedProperty closingDefinitionArray    = property.FindPropertyRelative("m_ClosingTagArray");


            EditorGUIUtility.labelWidth = 90;
            position.height             = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
            float labelHeight = position.height + 2f;

            EditorGUI.BeginChangeCheck();
            Rect rect0 = new Rect(position.x, position.y, (position.width) / 2 + 5, position.height);

            EditorGUI.PropertyField(rect0, nameProperty);
            if (EditorGUI.EndChangeCheck())
            {
                // Recompute HashCode if name has changed.
                hashCodeProperty.intValue = TMP_TextUtilities.GetSimpleHashCode(nameProperty.stringValue);

                property.serializedObject.ApplyModifiedProperties();
                // Dictionary needs to be updated since HashCode has changed.
                TMP_StyleSheet.RefreshStyles();
            }

            // HashCode
            Rect rect1 = new Rect(rect0.x + rect0.width + 5, position.y, 65, position.height);

            GUI.Label(rect1, "HashCode");
            GUI.enabled = false;
            rect1.x    += 65;
            rect1.width = position.width / 2 - 75;
            EditorGUI.PropertyField(rect1, hashCodeProperty, GUIContent.none);

            GUI.enabled = true;

            // Text Tags
            EditorGUI.BeginChangeCheck();

            // Opening Tags
            position.y += labelHeight;
            GUI.Label(position, "Opening Tags");
            Rect textRect1 = new Rect(108, position.y, position.width - 86, 35);

            openingDefinitionProperty.stringValue = EditorGUI.TextArea(textRect1, openingDefinitionProperty.stringValue);
            if (EditorGUI.EndChangeCheck())
            {
                // If any properties have changed, we need to update the Opening and Closing Arrays.
                int size = openingDefinitionProperty.stringValue.Length;

                // Adjust array size to match new string length.
                if (openingDefinitionArray.arraySize != size)
                {
                    openingDefinitionArray.arraySize = size;
                }

                for (int i = 0; i < size; i++)
                {
                    SerializedProperty element = openingDefinitionArray.GetArrayElementAtIndex(i);
                    element.intValue = openingDefinitionProperty.stringValue[i];
                }
            }

            EditorGUI.BeginChangeCheck();

            // Closing Tags
            position.y += 38;
            GUI.Label(position, "Closing Tags");
            Rect textRect2 = new Rect(108, position.y, position.width - 86, 35);

            closingDefinitionProperty.stringValue = EditorGUI.TextArea(textRect2, closingDefinitionProperty.stringValue);

            if (EditorGUI.EndChangeCheck())
            {
                // If any properties have changed, we need to update the Opening and Closing Arrays.
                int size = closingDefinitionProperty.stringValue.Length;

                // Adjust array size to match new string length.
                if (closingDefinitionArray.arraySize != size)
                {
                    closingDefinitionArray.arraySize = size;
                }

                for (int i = 0; i < size; i++)
                {
                    SerializedProperty element = closingDefinitionArray.GetArrayElementAtIndex(i);
                    element.intValue = closingDefinitionProperty.stringValue[i];
                }
            }
        }
示例#19
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            SerializedProperty serializedProperty  = property.FindPropertyRelative("m_Name");
            SerializedProperty serializedProperty2 = property.FindPropertyRelative("m_HashCode");
            SerializedProperty serializedProperty3 = property.FindPropertyRelative("m_OpeningDefinition");
            SerializedProperty serializedProperty4 = property.FindPropertyRelative("m_ClosingDefinition");
            SerializedProperty serializedProperty5 = property.FindPropertyRelative("m_OpeningTagArray");
            SerializedProperty serializedProperty6 = property.FindPropertyRelative("m_ClosingTagArray");

            EditorGUIUtility.labelWidth = 90f;
            position.height             = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
            float num = position.height + 2f;

            EditorGUI.BeginChangeCheck();
            Rect position2 = new Rect(position.x, position.y, position.width / 2f + 5f, position.height);

            EditorGUI.PropertyField(position2, serializedProperty);
            if (EditorGUI.EndChangeCheck())
            {
                serializedProperty2.intValue = TMP_TextUtilities.GetSimpleHashCode(serializedProperty.stringValue);
                property.serializedObject.ApplyModifiedProperties();
                TMP_StyleSheet.RefreshStyles();
            }
            Rect position3 = new Rect(position2.x + position2.width + 5f, position.y, 65f, position.height);

            GUI.Label(position3, "HashCode");
            GUI.enabled     = false;
            position3.x    += 65f;
            position3.width = position.width / 2f - 75f;
            EditorGUI.PropertyField(position3, serializedProperty2, GUIContent.none);
            GUI.enabled = true;
            EditorGUI.BeginChangeCheck();
            position.y += num;
            GUI.Label(position, "Opening Tags");
            Rect position4 = new Rect(108f, position.y, position.width - 86f, 35f);

            serializedProperty3.stringValue = EditorGUI.TextArea(position4, serializedProperty3.stringValue);
            if (EditorGUI.EndChangeCheck())
            {
                int length = serializedProperty3.stringValue.Length;
                if (serializedProperty5.arraySize != length)
                {
                    serializedProperty5.arraySize = length;
                }
                for (int i = 0; i < length; i++)
                {
                    SerializedProperty arrayElementAtIndex = serializedProperty5.GetArrayElementAtIndex(i);
                    arrayElementAtIndex.intValue = serializedProperty3.stringValue[i];
                }
            }
            EditorGUI.BeginChangeCheck();
            position.y += 38f;
            GUI.Label(position, "Closing Tags");
            Rect position5 = new Rect(108f, position.y, position.width - 86f, 35f);

            serializedProperty4.stringValue = EditorGUI.TextArea(position5, serializedProperty4.stringValue);
            if (EditorGUI.EndChangeCheck())
            {
                int length2 = serializedProperty4.stringValue.Length;
                if (serializedProperty6.arraySize != length2)
                {
                    serializedProperty6.arraySize = length2;
                }
                for (int j = 0; j < length2; j++)
                {
                    SerializedProperty arrayElementAtIndex2 = serializedProperty6.GetArrayElementAtIndex(j);
                    arrayElementAtIndex2.intValue = serializedProperty4.stringValue[j];
                }
            }
        }
示例#20
0
 /// <summary>
 /// Sets the <c>name</c> of the font, recalculating its hash code as necessary.
 /// </summary>
 /// <param name="font">the font to modify</param>
 /// <param name="name">the name to assign</param>
 /// <returns>the <paramref name="name"/> provided</returns>
 public static string SetName(this TMP_FontAsset font, string name)
 {
     font.name     = name;
     font.hashCode = TMP_TextUtilities.GetSimpleHashCode(font.name);
     return(name);
 }
示例#21
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            SerializedProperty property2           = property.FindPropertyRelative("id");
            SerializedProperty serializedProperty  = property.FindPropertyRelative("name");
            SerializedProperty serializedProperty2 = property.FindPropertyRelative("hashCode");
            SerializedProperty serializedProperty3 = property.FindPropertyRelative("unicode");
            SerializedProperty serializedProperty4 = property.FindPropertyRelative("x");
            SerializedProperty serializedProperty5 = property.FindPropertyRelative("y");
            SerializedProperty serializedProperty6 = property.FindPropertyRelative("width");
            SerializedProperty serializedProperty7 = property.FindPropertyRelative("height");
            SerializedProperty property3           = property.FindPropertyRelative("xOffset");
            SerializedProperty property4           = property.FindPropertyRelative("yOffset");
            SerializedProperty property5           = property.FindPropertyRelative("xAdvance");
            SerializedProperty property6           = property.FindPropertyRelative("scale");
            SerializedProperty serializedProperty8 = property.FindPropertyRelative("sprite");
            Texture            spriteSheet         = (property.serializedObject.targetObject as TMP_SpriteAsset).spriteSheet;

            if (spriteSheet == null)
            {
                Debug.LogWarning("Please assign a valid Sprite Atlas texture to the [" + property.serializedObject.targetObject.name + "] Sprite Asset.", property.serializedObject.targetObject);
                return;
            }
            Vector2 vector = new Vector2(65f, 65f);

            if (serializedProperty6.floatValue >= serializedProperty7.floatValue)
            {
                vector.y    = serializedProperty7.floatValue * vector.x / serializedProperty6.floatValue;
                position.y += (vector.x - vector.y) / 2f;
            }
            else
            {
                vector.x    = serializedProperty6.floatValue * vector.y / serializedProperty7.floatValue;
                position.x += (vector.y - vector.x) / 2f;
            }
            GUI.DrawTextureWithTexCoords(texCoords: new Rect(serializedProperty4.floatValue / (float)spriteSheet.width, serializedProperty5.floatValue / (float)spriteSheet.height, serializedProperty6.floatValue / (float)spriteSheet.width, serializedProperty7.floatValue / (float)spriteSheet.height), position: new Rect(position.x + 5f, position.y, vector.x, vector.y), image: spriteSheet, alphaBlend: true);
            Rect rect = new Rect(position.x, position.y, position.width, 49f);

            rect.x += 70f;
            bool enabled = GUI.enabled;

            GUI.enabled = false;
            EditorGUIUtility.labelWidth = 30f;
            EditorGUI.PropertyField(new Rect(rect.x + 5f, rect.y, 65f, 18f), property2, new GUIContent("ID:"));
            GUI.enabled = enabled;
            EditorGUI.BeginChangeCheck();
            EditorGUIUtility.labelWidth = 55f;
            GUI.SetNextControlName("Unicode Input");
            string s = EditorGUI.TextField(new Rect(rect.x + 75f, rect.y, 105f, 18f), "Unicode:", serializedProperty3.intValue.ToString("X"));

            if (GUI.GetNameOfFocusedControl() == "Unicode Input")
            {
                char character = Event.current.character;
                if ((character < '0' || character > '9') && (character < 'a' || character > 'f') && (character < 'A' || character > 'F'))
                {
                    Event.current.character = '\0';
                }
                if (EditorGUI.EndChangeCheck())
                {
                    serializedProperty3.intValue = TMP_TextUtilities.StringToInt(s);
                    property.serializedObject.ApplyModifiedProperties();
                    TMP_SpriteAsset tMP_SpriteAsset = property.serializedObject.targetObject as TMP_SpriteAsset;
                    tMP_SpriteAsset.UpdateLookupTables();
                }
            }
            EditorGUIUtility.labelWidth = 45f;
            EditorGUI.BeginChangeCheck();
            EditorGUI.PropertyField(new Rect(rect.x + 185f, rect.y, rect.width - 260f, 18f), serializedProperty, new GUIContent("Name: " + serializedProperty.stringValue));
            if (EditorGUI.EndChangeCheck())
            {
                Sprite sprite = serializedProperty8.objectReferenceValue as Sprite;
                if (sprite != null)
                {
                    sprite.name = serializedProperty.stringValue;
                }
                serializedProperty2.intValue = TMP_TextUtilities.GetSimpleHashCode(serializedProperty.stringValue);
                property.serializedObject.ApplyModifiedProperties();
            }
            EditorGUIUtility.labelWidth = 30f;
            EditorGUIUtility.fieldWidth = 10f;
            float num = (rect.width - 75f) / 4f;

            EditorGUI.PropertyField(new Rect(rect.x + 5f + num * 0f, rect.y + 22f, num - 5f, 18f), serializedProperty4, new GUIContent("X:"));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + num * 1f, rect.y + 22f, num - 5f, 18f), serializedProperty5, new GUIContent("Y:"));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + num * 2f, rect.y + 22f, num - 5f, 18f), serializedProperty6, new GUIContent("W:"));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + num * 3f, rect.y + 22f, num - 5f, 18f), serializedProperty7, new GUIContent("H:"));
            EditorGUI.BeginChangeCheck();
            EditorGUI.PropertyField(new Rect(rect.x + 5f + num * 0f, rect.y + 44f, num - 5f, 18f), property3, new GUIContent("OX:"));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + num * 1f, rect.y + 44f, num - 5f, 18f), property4, new GUIContent("OY:"));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + num * 2f, rect.y + 44f, num - 5f, 18f), property5, new GUIContent("Adv."));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + num * 3f, rect.y + 44f, num - 5f, 18f), property6, new GUIContent("SF."));
            if (!EditorGUI.EndChangeCheck())
            {
            }
        }
        public static void CreateSpriteAsset()
        {
            Object target = Selection.activeObject;

            if (target == null || target.GetType() != typeof(Texture2D)) // && target.GetType() != typeof(SpriteAtlas)))
            {
                Debug.LogWarning("A texture must first be selected in order to create a TextMesh Pro Sprite Asset.");
                return;
            }

            // Get the path to the selected asset.
            string filePathWithName         = AssetDatabase.GetAssetPath(target);
            string fileNameWithExtension    = Path.GetFileName(filePathWithName);
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePathWithName);
            string filePath = filePathWithName.Replace(fileNameWithExtension, "");


            // Create new Sprite Asset
            TMP_SpriteAsset spriteAsset = ScriptableObject.CreateInstance <TMP_SpriteAsset>();

            AssetDatabase.CreateAsset(spriteAsset, filePath + fileNameWithoutExtension + ".asset");

            spriteAsset.version = "1.1.0";

            // Compute the hash code for the sprite asset.
            spriteAsset.hashCode = TMP_TextUtilities.GetSimpleHashCode(spriteAsset.name);

            List <TMP_SpriteGlyph>     spriteGlyphTable     = new List <TMP_SpriteGlyph>();
            List <TMP_SpriteCharacter> spriteCharacterTable = new List <TMP_SpriteCharacter>();

            if (target.GetType() == typeof(Texture2D))
            {
                Texture2D sourceTex = target as Texture2D;

                // Assign new Sprite Sheet texture to the Sprite Asset.
                spriteAsset.spriteSheet = sourceTex;

                PopulateSpriteTables(sourceTex, ref spriteCharacterTable, ref spriteGlyphTable);

                spriteAsset.spriteCharacterTable = spriteCharacterTable;
                spriteAsset.spriteGlyphTable     = spriteGlyphTable;

                // Add new default material for sprite asset.
                AddDefaultMaterial(spriteAsset);
            }
            else if (target.GetType() == typeof(SpriteAtlas))
            {
                //SpriteAtlas spriteAtlas = target as SpriteAtlas;

                //PopulateSpriteTables(spriteAtlas, ref spriteCharacterTable, ref spriteGlyphTable);

                //spriteAsset.spriteCharacterTable = spriteCharacterTable;
                //spriteAsset.spriteGlyphTable = spriteGlyphTable;

                //spriteAsset.spriteSheet = spriteGlyphTable[0].sprite.texture;

                //// Add new default material for sprite asset.
                //AddDefaultMaterial(spriteAsset);
            }

            // Update Lookup tables.
            spriteAsset.UpdateLookupTables();

            // Get the Sprites contained in the Sprite Sheet
            EditorUtility.SetDirty(spriteAsset);

            //spriteAsset.sprites = sprites;

            // Set source texture back to Not Readable.
            //texImporter.isReadable = false;

            AssetDatabase.SaveAssets();

            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(spriteAsset));  // Re-import font asset to get the new updated version.

            //AssetDatabase.Refresh();
        }
示例#23
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            //SerializedProperty prop_fileID = property.FindPropertyRelative("fileID");
            SerializedProperty prop_id       = property.FindPropertyRelative("id");
            SerializedProperty prop_name     = property.FindPropertyRelative("name");
            SerializedProperty prop_hashCode = property.FindPropertyRelative("hashCode");
            SerializedProperty prop_x        = property.FindPropertyRelative("x");
            SerializedProperty prop_y        = property.FindPropertyRelative("y");
            SerializedProperty prop_width    = property.FindPropertyRelative("width");
            SerializedProperty prop_height   = property.FindPropertyRelative("height");
            SerializedProperty prop_xOffset  = property.FindPropertyRelative("xOffset");
            SerializedProperty prop_yOffset  = property.FindPropertyRelative("yOffset");
            SerializedProperty prop_xAdvance = property.FindPropertyRelative("xAdvance");
            SerializedProperty prop_scale    = property.FindPropertyRelative("scale");
            //SerializedProperty prop_sprite = property.FindPropertyRelative("sprite");

            // Get a reference to the sprite texture
            Texture tex = (property.serializedObject.targetObject as TMP_SpriteAsset).spriteSheet;

            Vector2 spriteSize = new Vector2(65, 65);

            if (prop_width.floatValue >= prop_height.floatValue)
            {
                spriteSize.y = prop_height.floatValue * spriteSize.x / prop_width.floatValue;
                position.y  += (spriteSize.x - spriteSize.y) / 2;
            }
            else
            {
                spriteSize.x = prop_width.floatValue * spriteSize.y / prop_height.floatValue;
                position.x  += (spriteSize.y - spriteSize.x) / 2;
            }

            // Compute the normalized texture coordinates
            Rect texCoords = new Rect(prop_x.floatValue / tex.width, prop_y.floatValue / tex.height, prop_width.floatValue / tex.width, prop_height.floatValue / tex.height);

            GUI.DrawTextureWithTexCoords(new Rect(position.x + 5, position.y, spriteSize.x, spriteSize.y), tex, texCoords, true);

            // We get Rect since a valid position may not be provided by the caller.
            Rect rect = GUILayoutUtility.GetRect(position.width, 49);

            rect.x += 70;
            rect.y -= 15;

            EditorGUIUtility.labelWidth = 40f;
            EditorGUIUtility.fieldWidth = 45f;

            EditorGUI.BeginChangeCheck();
            EditorGUI.LabelField(new Rect(rect.x + 5f, rect.y, 50f, 18), new GUIContent("ID: " + prop_id.intValue));
            EditorGUI.PropertyField(new Rect(rect.x + 50f, rect.y, rect.width - 125, 18), prop_name, new GUIContent("Name: " + prop_name.stringValue));
            if (EditorGUI.EndChangeCheck())
            {
                // Recompute hashCode for new name
                prop_hashCode.intValue = TMP_TextUtilities.GetSimpleHashCode(prop_name.stringValue);
                // Check to make sure for duplicates
                property.serializedObject.ApplyModifiedProperties();
                // Dictionary needs to be updated since HashCode has changed.
                //TMP_StyleSheet.Instance.LoadStyleDictionary();
            }

            EditorGUIUtility.labelWidth = 30f;
            EditorGUIUtility.fieldWidth = 10f;

            GUI.enabled = false;
            float width = (rect.width - 75f) / 4;

            EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 0, rect.y + 22, width - 5f, 18), prop_x, new GUIContent("X:"));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 1, rect.y + 22, width - 5f, 18), prop_y, new GUIContent("Y:"));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 2, rect.y + 22, width - 5f, 18), prop_width, new GUIContent("W:"));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 3, rect.y + 22, width - 5f, 18), prop_height, new GUIContent("H:"));

            GUI.enabled = true;

            EditorGUI.BeginChangeCheck();
            EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 0, rect.y + 44, width - 5f, 18), prop_xOffset, new GUIContent("OX:"));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 1, rect.y + 44, width - 5f, 18), prop_yOffset, new GUIContent("OY:"));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 2, rect.y + 44, width - 5f, 18), prop_xAdvance, new GUIContent("Adv."));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 3, rect.y + 44, width - 5f, 18), prop_scale, new GUIContent("SF."));
            if (EditorGUI.EndChangeCheck())
            {
                //Sprite sprite = prop_sprite.objectReferenceValue as Sprite;
                //sprite = Sprite.Create(sprite.texture, sprite.rect, new Vector2(0.1f, 0.8f));
                //prop_sprite.objectReferenceValue = sprite;
                //Debug.Log(sprite.bounds);
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            SerializedProperty prop_SpriteName         = property.FindPropertyRelative("m_Name");
            SerializedProperty prop_SpriteNameHashCode = property.FindPropertyRelative("m_HashCode");
            SerializedProperty prop_SpriteUnicode      = property.FindPropertyRelative("m_Unicode");
            SerializedProperty prop_SpriteGlyphIndex   = property.FindPropertyRelative("m_GlyphIndex");
            SerializedProperty prop_SpriteScale        = property.FindPropertyRelative("m_Scale");


            GUIStyle style = new GUIStyle(EditorStyles.label);

            style.richText = true;

            EditorGUIUtility.labelWidth = 40f;
            EditorGUIUtility.fieldWidth = 50;

            Rect rect = new Rect(position.x + 60, position.y, position.width, 49);

            // Display non-editable fields
            if (GUI.enabled == false)
            {
                // Sprite Character Index
                int spriteCharacterIndex;
                int.TryParse(property.displayName.Split(' ')[1], out spriteCharacterIndex);
                EditorGUI.LabelField(new Rect(rect.x, rect.y, 75f, 18), new GUIContent("Index: <color=#FFFF80>" + spriteCharacterIndex + "</color>"), style);

                EditorGUI.LabelField(new Rect(rect.x + 75f, rect.y, 120f, 18), new GUIContent("Unicode: <color=#FFFF80>0x" + prop_SpriteUnicode.intValue.ToString("X") + "</color>"), style);
                EditorGUI.LabelField(new Rect(rect.x + 195f, rect.y, rect.width - 255, 18), new GUIContent("Name: <color=#FFFF80>" + prop_SpriteName.stringValue + "</color>"), style);

                EditorGUI.LabelField(new Rect(rect.x, rect.y + 18, 120, 18), new GUIContent("Glyph ID: <color=#FFFF80>" + prop_SpriteGlyphIndex.intValue + "</color>"), style);

                // Draw Sprite Glyph (if exists)
                DrawSpriteGlyph(position, property);

                EditorGUI.LabelField(new Rect(rect.x, rect.y + 36, 80, 18), new GUIContent("Scale: <color=#FFFF80>" + prop_SpriteScale.floatValue + "</color>"), style);
            }
            else // Display editable fields
            {
                // Get a reference to the underlying Sprite Asset
                TMP_SpriteAsset spriteAsset = property.serializedObject.targetObject as TMP_SpriteAsset;

                // Sprite Character Index
                int spriteCharacterIndex;
                int.TryParse(property.displayName.Split(' ')[1], out spriteCharacterIndex);

                EditorGUI.LabelField(new Rect(rect.x, rect.y, 75f, 18), new GUIContent("Index: <color=#FFFF80>" + spriteCharacterIndex + "</color>"), style);

                EditorGUIUtility.labelWidth = 55f;
                GUI.SetNextControlName("Unicode Input");
                EditorGUI.BeginChangeCheck();
                string unicode = EditorGUI.DelayedTextField(new Rect(rect.x + 75f, rect.y, 120, 18), "Unicode:", prop_SpriteUnicode.intValue.ToString("X"));

                if (GUI.GetNameOfFocusedControl() == "Unicode Input")
                {
                    //Filter out unwanted characters.
                    char chr = Event.current.character;
                    if ((chr < '0' || chr > '9') && (chr < 'a' || chr > 'f') && (chr < 'A' || chr > 'F'))
                    {
                        Event.current.character = '\0';
                    }
                }

                if (EditorGUI.EndChangeCheck())
                {
                    // Update Unicode value
                    prop_SpriteUnicode.intValue = TMP_TextUtilities.StringHexToInt(unicode);
                    spriteAsset.m_IsSpriteAssetLookupTablesDirty = true;
                }

                EditorGUIUtility.labelWidth = 41f;
                EditorGUI.BeginChangeCheck();
                EditorGUI.DelayedTextField(new Rect(rect.x + 195f, rect.y, rect.width - 255, 18), prop_SpriteName, new GUIContent("Name:"));
                if (EditorGUI.EndChangeCheck())
                {
                    // Recompute hashCode for new name
                    prop_SpriteNameHashCode.intValue             = TMP_TextUtilities.GetSimpleHashCode(prop_SpriteName.stringValue);
                    spriteAsset.m_IsSpriteAssetLookupTablesDirty = true;
                }

                EditorGUIUtility.labelWidth = 59f;
                EditorGUI.BeginChangeCheck();
                EditorGUI.DelayedIntField(new Rect(rect.x, rect.y + 18, 100, 18), prop_SpriteGlyphIndex, new GUIContent("Glyph ID:"));
                if (EditorGUI.EndChangeCheck())
                {
                    spriteAsset.m_IsSpriteAssetLookupTablesDirty = true;
                }

                // Draw Sprite Glyph (if exists)
                DrawSpriteGlyph(position, property);

                int glyphIndex = prop_SpriteGlyphIndex.intValue;

                // Reset glyph selection if new character has been selected.
                if (GUI.enabled && m_GlyphSelectedForEditing != glyphIndex)
                {
                    m_GlyphSelectedForEditing = -1;
                }

                // Display button to edit the glyph data.
                if (GUI.Button(new Rect(rect.x + 120, rect.y + 18, 75, 18), new GUIContent("Edit Glyph")))
                {
                    if (m_GlyphSelectedForEditing == -1)
                    {
                        m_GlyphSelectedForEditing = glyphIndex;
                    }
                    else
                    {
                        m_GlyphSelectedForEditing = -1;
                    }

                    // Button clicks should not result in potential change.
                    GUI.changed = false;
                }

                // Show the glyph property drawer if selected
                if (glyphIndex == m_GlyphSelectedForEditing && GUI.enabled)
                {
                    if (spriteAsset != null)
                    {
                        // Lookup glyph and draw glyph (if available)
                        int elementIndex = spriteAsset.spriteGlyphTable.FindIndex(item => item.index == glyphIndex);

                        if (elementIndex != -1)
                        {
                            // Get a reference to the Sprite Glyph Table
                            SerializedProperty prop_SpriteGlyphTable = property.serializedObject.FindProperty("m_SpriteGlyphTable");

                            SerializedProperty prop_SpriteGlyph  = prop_SpriteGlyphTable.GetArrayElementAtIndex(elementIndex);
                            SerializedProperty prop_GlyphMetrics = prop_SpriteGlyph.FindPropertyRelative("m_Metrics");
                            SerializedProperty prop_GlyphRect    = prop_SpriteGlyph.FindPropertyRelative("m_GlyphRect");

                            Rect newRect = EditorGUILayout.GetControlRect(false, 115);
                            EditorGUI.DrawRect(new Rect(newRect.x + 62, newRect.y - 20, newRect.width - 62, newRect.height - 5), new Color(0.1f, 0.1f, 0.1f, 0.45f));
                            EditorGUI.DrawRect(new Rect(newRect.x + 63, newRect.y - 19, newRect.width - 64, newRect.height - 7), new Color(0.3f, 0.3f, 0.3f, 0.8f));

                            // Display GlyphRect
                            newRect.x     += 65;
                            newRect.y     -= 18;
                            newRect.width += 5;
                            EditorGUI.PropertyField(newRect, prop_GlyphRect);

                            // Display GlyphMetrics
                            newRect.y += 45;
                            EditorGUI.PropertyField(newRect, prop_GlyphMetrics);

                            rect.y += 120;
                        }
                    }
                }

                EditorGUIUtility.labelWidth = 39f;
                EditorGUI.PropertyField(new Rect(rect.x, rect.y + 36, 80, 18), prop_SpriteScale, new GUIContent("Scale:"));
            }
        }
示例#25
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            //SerializedProperty prop_fileID = property.FindPropertyRelative("fileID");
            SerializedProperty prop_id       = property.FindPropertyRelative("id");
            SerializedProperty prop_name     = property.FindPropertyRelative("name");
            SerializedProperty prop_hashCode = property.FindPropertyRelative("hashCode");
            SerializedProperty prop_unicode  = property.FindPropertyRelative("unicode");
            SerializedProperty prop_x        = property.FindPropertyRelative("x");
            SerializedProperty prop_y        = property.FindPropertyRelative("y");
            SerializedProperty prop_width    = property.FindPropertyRelative("width");
            SerializedProperty prop_height   = property.FindPropertyRelative("height");
            SerializedProperty prop_xOffset  = property.FindPropertyRelative("xOffset");
            SerializedProperty prop_yOffset  = property.FindPropertyRelative("yOffset");
            SerializedProperty prop_xAdvance = property.FindPropertyRelative("xAdvance");
            SerializedProperty prop_scale    = property.FindPropertyRelative("scale");
            SerializedProperty prop_sprite   = property.FindPropertyRelative("sprite");

            // Get a reference to the sprite texture
            Texture tex = (property.serializedObject.targetObject as TMP_SpriteAsset).spriteSheet;

            // Return if we don't have a texture assigned to the sprite asset.
            if (tex == null)
            {
                Debug.LogWarning("Please assign a valid Sprite Atlas texture to the [" + property.serializedObject.targetObject.name + "] Sprite Asset.", property.serializedObject.targetObject);
                return;
            }

            Vector2 spriteTexPosition = new Vector2(position.x, position.y);
            Vector2 spriteSize        = new Vector2(65, 65);

            if (prop_width.floatValue >= prop_height.floatValue)
            {
                spriteSize.y         = prop_height.floatValue * spriteSize.x / prop_width.floatValue;
                spriteTexPosition.y += (spriteSize.x - spriteSize.y) / 2;
            }
            else
            {
                spriteSize.x         = prop_width.floatValue * spriteSize.y / prop_height.floatValue;
                spriteTexPosition.x += (spriteSize.y - spriteSize.x) / 2;
            }

            // Compute the normalized texture coordinates
            Rect texCoords = new Rect(prop_x.floatValue / tex.width, prop_y.floatValue / tex.height, prop_width.floatValue / tex.width, prop_height.floatValue / tex.height);

            GUI.DrawTextureWithTexCoords(new Rect(spriteTexPosition.x + 5, spriteTexPosition.y + 2.5f, spriteSize.x, spriteSize.y), tex, texCoords, true);

            // We get Rect since a valid position may not be provided by the caller.
            Rect rect = new Rect(position.x, position.y, position.width, 49);

            rect.x += 70;

            bool isEnabled = GUI.enabled;

            GUI.enabled = false;
            EditorGUIUtility.labelWidth = 30f;
            EditorGUI.PropertyField(new Rect(rect.x + 5f, rect.y, 65f, 18), prop_id, new GUIContent("ID:"));

            GUI.enabled = isEnabled;
            EditorGUI.BeginChangeCheck();
            EditorGUIUtility.labelWidth = 55f;
            GUI.SetNextControlName("Unicode Input");
            string unicode = EditorGUI.TextField(new Rect(rect.x + 75f, rect.y, 105, 18), "Unicode:", prop_unicode.intValue.ToString("X"));

            if (GUI.GetNameOfFocusedControl() == "Unicode Input")
            {
                //Filter out unwanted characters.
                char chr = Event.current.character;
                if ((chr < '0' || chr > '9') && (chr < 'a' || chr > 'f') && (chr < 'A' || chr > 'F'))
                {
                    Event.current.character = '\0';
                }

                if (EditorGUI.EndChangeCheck())
                {
                    prop_unicode.intValue = TMP_TextUtilities.StringToInt(unicode);

                    property.serializedObject.ApplyModifiedProperties();

                    TMP_SpriteAsset spriteAsset = property.serializedObject.targetObject as TMP_SpriteAsset;
                    spriteAsset.UpdateLookupTables();
                }
            }


            EditorGUIUtility.labelWidth = 45f;
            EditorGUI.BeginChangeCheck();
            EditorGUI.PropertyField(new Rect(rect.x + 185f, rect.y, rect.width - 260, 18), prop_name, new GUIContent("Name: " + prop_name.stringValue));
            if (EditorGUI.EndChangeCheck())
            {
                Sprite sprite = prop_sprite.objectReferenceValue as Sprite;
                if (sprite != null)
                {
                    sprite.name = prop_name.stringValue;
                }

                // Recompute hashCode for new name
                prop_hashCode.intValue = TMP_TextUtilities.GetSimpleHashCode(prop_name.stringValue);
                // Check to make sure for duplicates
                property.serializedObject.ApplyModifiedProperties();
                // Dictionary needs to be updated since HashCode has changed.
                //TMP_StyleSheet.Instance.LoadStyleDictionary();
            }

            EditorGUIUtility.labelWidth = 30f;
            EditorGUIUtility.fieldWidth = 10f;

            //GUI.enabled = false;
            float width = (rect.width - 75f) / 4;

            EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 0, rect.y + 22, width - 5f, 18), prop_x, new GUIContent("X:"));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 1, rect.y + 22, width - 5f, 18), prop_y, new GUIContent("Y:"));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 2, rect.y + 22, width - 5f, 18), prop_width, new GUIContent("W:"));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 3, rect.y + 22, width - 5f, 18), prop_height, new GUIContent("H:"));

            //GUI.enabled = true;

            EditorGUI.BeginChangeCheck();
            EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 0, rect.y + 44, width - 5f, 18), prop_xOffset, new GUIContent("OX:"));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 1, rect.y + 44, width - 5f, 18), prop_yOffset, new GUIContent("OY:"));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 2, rect.y + 44, width - 5f, 18), prop_xAdvance, new GUIContent("Adv."));
            EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 3, rect.y + 44, width - 5f, 18), prop_scale, new GUIContent("SF."));
            if (EditorGUI.EndChangeCheck())
            {
                //Sprite sprite = prop_sprite.objectReferenceValue as Sprite;
                //sprite = Sprite.Create(sprite.texture, sprite.rect, new Vector2(0.1f, 0.8f));
                //prop_sprite.objectReferenceValue = sprite;
                //Debug.Log(sprite.bounds);
            }
        }