Arabic input fields in unity

半世苍凉 提交于 2019-12-03 22:28:56

问题


Is there is a way to change the language of input fields in unity to Arabic?. I tried ArabicSupport and it displayed Arabic correctly but using it with input fields didn't work because

GameObject.Find("input_field")
    .GetComponent<InputField>().text = Fix3dTextCS.fix(   
        GameObject.Find("input_field").GetComponent<InputField>().text
    );

caused an error so, if I printed the input text elsewhere, it will appear correctly but how can I do it with the same input field?


回答1:


input field is a little bit tricky to let it work with Arabic Support

please try this opensource asset it has an prefab for Arabic Input Field and some other UIs.

  • OpenSource for ArabicSupport Solution Link

  • OpenSource for unity asset UI Arabic Support: Link




回答2:


Have you tried adding arabic font in that input.

If so, post the error message it may help to find the bug




回答3:


Using Font won't help because it will only change the theme of your current Input usage but not how you use to input in the Device.

You will need to use Input.Location <- Input is static so you can access it anywhere. The only problem is, I am not sure what is the exact variable for arabic is. My best guess is Input.Location = "Arabic" or "arabic".

If you want to automatically detect their location, the GPS which will unity3d turn on by calling Input.Location.Start, and turn off by Input.Location.Stop()

Here is a sample code for you.

using UnityEngine;
using System.Collections;

public class TestLocationService : MonoBehaviour
{
    IEnumerator Start()
    {
        // First, check if user has location service enabled
        if (!Input.location.isEnabledByUser) yield break;

        // Start service before querying location
        Input.location.Start();

        // Wait until service initializes
        int maxWait = 20;
        while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
        {
            yield return new WaitForSeconds(1);
            maxWait--;
        }

        // Service didn't initialize in 20 seconds
        if (maxWait < 1)
        {
            print("Timed out");
            yield break;
        }

        // Connection has failed
        if (Input.location.status == LocationServiceStatus.Failed)
        {
            print("Unable to determine device location");
            yield break;
        }
        else
        {
            // Access granted and location value could be retrieved
            print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
        }

        // Stop service if there is no need to query location updates continuously
        Input.location.Stop();
    }
}


来源:https://stackoverflow.com/questions/29637032/arabic-input-fields-in-unity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!