コード例 #1
0
ファイル: TexFontSigned.cs プロジェクト: step4/rac-quiz
        public override void ImportDictionary()
        {
            base.ImportDictionary();

            if (!asset)
            {
                return;
            }

            // sanitize input

            assetmetrices.Clear();

            var info = asset.fontInfo;

            var padding = asset.fontInfo.Padding;

            for (int i = 0; i < catalog.Length; i++)
            {
                if (!asset.characterDictionary.ContainsKey(catalog[i]))
                {
                    assetmetrices[catalog[i]] = new SpriteMetrics();
                    continue;
                }

                TMP_Glyph c = asset.characterDictionary[catalog[i]];

                var factor = c.scale / info.PointSize;

                assetmetrices[catalog[i]] = new SpriteMetrics()
                {
                    size = new Vector4()
                    {
                        x = (-c.xOffset + padding) * factor,
                        y = (c.height - c.yOffset + padding) * factor,
                        z = (c.width + c.xOffset + padding) * factor,
                        w = (c.yOffset + padding) * factor,
                    },
                    advance = c.xAdvance * factor,
                    uv      = new Rect()
                    {
                        x      = (c.x - padding) / info.AtlasWidth,
                        y      = 1 - (c.y + c.height + padding) / info.AtlasHeight,
                        width  = (c.width + 2 * padding) / info.AtlasWidth,
                        height = (c.height + 2 * padding) / info.AtlasHeight
                    }
                };
            }
        }
コード例 #2
0
ファイル: TexSprite.cs プロジェクト: Synedh/the_m_wand
        public override void ImportDictionary()
        {
            // sanitize input
            if (catalog.Length > assets.Length)
            {
                Array.Resize(ref catalog, assets.Length);
                Array.Resize(ref chars, assets.Length);
            }

            base.ImportDictionary();

            assetindexes.Clear();
            assetmetrices.Clear();

            for (int i = 0; i < assets.Length; i++)
            {
                var a = assets[i]; var sz = new Vector2(1f / a.texture.width, 1f / a.texture.height);
                var aspect = a.rect.width / a.rect.height; var pivot = Vector2.Scale(a.pivot, sz);
                assetindexes[catalog[i]]  = a;
                assetmetrices[catalog[i]] = new SpriteMetrics()
                {
                    size = new Vector4()
                    {
                        x = aspect * lineHeight * pivot.x,
                        y = -lineOffset + lineHeight * pivot.y,
                        z = aspect * lineHeight * (1 - pivot.x),
                        w = lineOffset + lineHeight * (1 - pivot.y),
                    },
                    advance = aspect * lineHeight,
                    uv      = new Rect()
                    {
                        min = Vector2.Scale(a.rect.min, sz),
                        max = Vector2.Scale(a.rect.max, sz),
                    }
                };
            }
        }