Esempio n. 1
0
    private void RemoveEntry()
    {
        //MessageBox.show();

        GameObject.DestroyImmediate(_toBeRemovedEntry, true);
        _toBeRemovedEntry = null;
        this.Repaint();
    }
Esempio n. 2
0
        private void drawSpriteFont(SpriteFontComponent spriteFont)
        {
            if (spriteFont == null || !spriteFont.IsVisible)
            {
                return;
            }

            _spriteBatch.DrawString(spriteFont.SpriteFont, spriteFont.Text, spriteFont.Position, spriteFont.Color, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, spriteFont.Depth);
        }
Esempio n. 3
0
    // Use this for initialization
    void OnGUI()
    {
        GetPrefab();

        // Draw the scroll bar
        _scrollView = GUILayout.BeginScrollView(_scrollView, false, false);

        this.BeginWindows();

        this.EndWindows();

        // Get the minus button size
        foreach (SpriteFontComponent font in _setup.GetComponents <SpriteFontComponent>())
        {
            // Draw the font component header
            //GUILayout.BeginVertical( "AS TextArea", GUILayout.Height( 5 ) );

            GUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.Height(5));


            GUILayout.Space(2);
            GUILayout.BeginHorizontal();

            // Draw the foldout button with the font name
            font.enabled = EditorGUILayout.Foldout(font.enabled, font.name);

            // Draw the minus button
            if (GUILayout.Button(_iconMinus, GUIStyle.none, GUILayout.Width(20)))
            {
                //Debug.Log( "destroy" );
                _toBeRemovedEntry = font;
            }
            GUILayout.EndHorizontal();

            // Draw the font component properties
            if (font.enabled)
            {
                // Font name
                font.name = EditorGUILayout.TextField("Font Name", font.name);

                // Load the new Custom Font asset
                //font.font = EditorGUILayout.ObjectField( "Custom Font", font.font, typeof( Font ), false ) as Font;

                // Load the Sprite asset
                font.sprite = EditorGUILayout.ObjectField("Sprite Font", font.sprite, typeof(Texture2D), false) as Texture2D;

                // Set the character order inside spritesheet
                EditorStyles.textField.wordWrap = true;
                GUILayout.Label("Character Font Order");
                font.characters = EditorGUILayout.TextArea(font.characters, GUILayout.Height(60.0f));

                // Just show this button when the CSV file exist in the same sprite path
                if (font.sprite != null)
                {
                    string path = GetPath(font.sprite, '.');
                    //Debug.Log( path );
                    if (AssetDatabase.LoadAssetAtPath <TextAsset>(path + "txt") ||
                        AssetDatabase.LoadAssetAtPath <TextAsset>(path + "fnt"))
                    {
                        EditorGUILayout.HelpBox("ShoeBox Created Sprite Sheet Found.", MessageType.Info);
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("Using User Created Sprite Sheet.", MessageType.Warning);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("No Sprite Selected.", MessageType.Error);
                }
            }

            // Draw the font component footer
            GUILayout.Space(2);
            GUILayout.EndVertical();
            GUILayout.Space(2);
        }

        // Add new font
        if (GUILayout.Button("Add New Sprite Font"))
        {
            AddEntry();
        }

        // Build the font button
        GUI.backgroundColor = Color.green;
        if (GUILayout.Button("Build the Sprite Font...", GUILayout.Height(50)))
        {
            BuildFont();
        }

        GUI.backgroundColor = Color.white;

        GUILayout.Label("Sprite Font Builder v.1.1.1", EditorStyles.miniBoldLabel);

        GUILayout.EndScrollView();

        if (_toBeRemovedEntry != null)
        {
            RemoveEntry();
        }
    }
Esempio n. 4
0
    private void BuildSprite(SpriteFontComponent font)
    {
        string    path = GetPath(font.sprite, '.');
        string    fnt;
        TextAsset fntIn = null;

        if (AssetDatabase.LoadAssetAtPath <TextAsset>(path + "txt"))
        {
            fntIn = AssetDatabase.LoadAssetAtPath <TextAsset>(path + "txt");
        }
        else if (AssetDatabase.LoadAssetAtPath <TextAsset>(path + "fnt"))
        {
            fntIn = AssetDatabase.LoadAssetAtPath <TextAsset>(path + "fnt");
        }

        if (!fntIn)
        {
            Debug.LogWarning("Sprite Font Builder: " + font.name + " built using user created sprite sheet.");
            return;
        }

        fnt = fntIn.text;

        // Get the total of characters
        int totalChars = int.Parse(new Regex("((chars count=)([0-9]*))").Match(fnt).Value.Replace("chars count=", ""));

        font.fontBase        = int.Parse(new Regex("((base=)([0-9]*))").Match(fnt).Value.Replace("base=", ""));
        _spriteFonteImporter = TextureImporter.GetAtPath(AssetDatabase.GetAssetPath(font.sprite)) as TextureImporter;

        // Reset the current sprite suff
        _spriteFonteImporter.spriteImportMode = SpriteImportMode.Single;
        _spriteFonteImporter.spritesheet      = null;
        _spriteFonteImporter.SaveAndReimport();

        // And create a new one!
        _spriteFonteImporter.spriteImportMode = SpriteImportMode.Multiple;
        SpriteMetaData[] tSheet = new SpriteMetaData[totalChars];
        font.vector = new SpriteFontVector[totalChars];
        Match chars = new Regex("((char )(.*))").Match(fnt);

        font.characters = "";

        int x = 0;

        while (chars.Success)
        {
            string l = new Regex("((letter=\")(.*)(\"))").Match(chars.Value).Value.Replace("letter=\"", "");
            l = l.Substring(0, l.Length - 1);
            font.characters += l;

            font.vector[x] = new SpriteFontVector();
            Rect rect = new Rect();

            rect.x      = float.Parse(new Regex("((x=)([0-9]*))").Match(chars.Value).Value.Replace("x=", ""));
            rect.y      = float.Parse(new Regex("((y=)([0-9]*))").Match(chars.Value).Value.Replace("y=", ""));
            rect.width  = float.Parse(new Regex("((width=)([0-9]*))").Match(chars.Value).Value.Replace("width=", ""));
            rect.height = float.Parse(new Regex("((height=)([0-9]*))").Match(chars.Value).Value.Replace("height=", ""));

            rect.y = font.sprite.height - rect.y - rect.height;

            font.vector[x].x        = (int)(rect.x);
            font.vector[x].y        = (int)(rect.y);
            font.vector[x].width    = (int)(rect.width);
            font.vector[x].height   = (int)(rect.height);
            font.vector[x].xOffset  = int.Parse(new Regex("((xoffset=)([0-9]*))").Match(chars.Value).Value.Replace("xoffset=", ""));
            font.vector[x].yOffset  = int.Parse(new Regex("((yoffset=)([0-9]*))").Match(chars.Value).Value.Replace("yoffset=", ""));
            font.vector[x].xAdvance = int.Parse(new Regex("((xadvance=)([0-9]*))").Match(chars.Value).Value.Replace("xadvance=", ""));

            SpriteMetaData tSpriteData = new SpriteMetaData();
            tSpriteData.name  = font.name + "_" + x;
            tSpriteData.pivot = Vector2.zero;

            tSpriteData.rect = rect;

            tSheet[x] = tSpriteData;

            chars = chars.NextMatch();
            x++;
        }

        // Update and save the new sprite stuff
        _spriteFonteImporter.spritesheet = tSheet;
        _spriteFonteImporter.SaveAndReimport();
    }
Esempio n. 5
0
    private void AddEntry()
    {
        SpriteFontComponent newFont = _setup.AddComponent <SpriteFontComponent>();

        newFont.name = "New Sprite Font";
    }