Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

c# - What Causes Monospaced Font Issue on iOS using Unicode Block Elements (Made in Unity)

I'm using the block elements in unity to create a progress bar. I am using the Roboto Mono font. This progress bar works fine in Unity but when running on my iOS device it seems to have an issue with some of the block unicode producing non-monospaced text.

iOS ui reference Image

Unity reference Image

Here is the code:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ProgressBar : MonoBehaviour
{

        // declaring variables
    private int maxExp;
    private int currentExp;
    static private double percentFull;
    public Text progressBarText;
    static private string progress;

        // Update is called once per frame
    void Update()
    {
            // intializing variables
        Text progressBar = progressBarText.GetComponent<Text>();
        int maxExp = grabExpForRank(PlayerPrefs.GetInt("ArithmeticLvl") + 1);
        int currentExp = PlayerPrefs.GetInt("ArithmeticExp");

            // generates the value of how much exp the user has compared the amount required to rank up
        percentFull = (double) currentExp / (double) maxExp;
        percentFull = Math.Round(percentFull, 2);
        
            // if user has 0 exp then give all space
        if (percentFull == 0) {
            progress = "          ";
        }
            // else if the user has any percent that doesn't end in 0
            // then get the represention of how full the exp bar is in blocks
        else if (percentFull % .1 != .1){
            progress = getTenthUnicode() + getHundredthUnicode();
                // for loops adds a space to make sure all progress bars are 10 characters
            for (int i=progress.Length; i < 10; i++){
                progress += "_";
            }
        }
            // finally if the user has a clean 10,20,30..,90 percent full progress bar just get the full blocks
        else {
            progress = getTenthUnicode();
                // for loops adds a space to make sure all progress bars are 10 characters
            for (int i=progress.Length; i < 10; i++){
                progress += "_";
            }
        }
        
            //formats the progress bar text object
        progressBar.text = "●----------●
" +
                           "|"+ progress +"|"+
                           "
●----------●";
        Debug.Log("Length of ""+ progress +"" is: " + progress.Length);
        
    }

        // Should probably replace this with a for loop
        // Every ten of a percent a new full bar is added 
    string getTenthUnicode(){
        
        if (percentFull >= (9.00/10.00)) { return "█████████";}
        else if (percentFull >= (8.00/10.00)) { return "████████";}
        else if (percentFull >= (7.00/10.00)) { return "███████";}
        else if (percentFull >= (6.00/10.00)) { return "██████";}
        else if (percentFull >= (5.00/10.00)) { return "█████";}
        else if (percentFull >= (4.00/10.00)) { return "████";}
        else if (percentFull >= (3.00/10.00)) { return "███";}
        else if (percentFull >= (2.00/10.00)) { return "██";}
        else if (percentFull >= (1.00/10.00)) { return "█";}
        else { return " ";}
    }

        // every eigth of a percent a new sliver is added
    char getHundredthUnicode(){

        double hundredthValue = percentFull % .1;
        if (hundredthValue >= (7.00/8.00)) { return '▉';}
        else if (hundredthValue >= (6.00/8.00)) { return '▊';}
        else if (hundredthValue >= (5.00/8.00)) { return '▋';}
        else if (hundredthValue >= (4.00/8.00)) { return '▌';}
        else if (hundredthValue >= (3.00/8.00)) { return '▍';}
        else if (hundredthValue >= (2.00/8.00)) { return '▎';}
        else if (hundredthValue >= (2.00/8.00)) { return '▏';}
        else { return ' ';}
    }

    // function for generation exp curve based on level
    int grabExpForRank(int i){
        int expPerRank = (int) (60f*Mathf.Pow(i, (.02f*i)));
        return expPerRank;
    }
}
question from:https://stackoverflow.com/questions/65646590/what-causes-monospaced-font-issue-on-ios-using-unicode-block-elements-made-in-u

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...