public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (LocalisationController.FindInstance())
            {
                if (!LocalisationController.instance.IsLoaded)
                {
                    LocalisationController.instance.Load();
                }

                Rect rect1 = new Rect(position.x, position.y, position.width - 80, position.height);
                Rect rect2 = new Rect(position.x + (position.width - 75), position.y, 75, position.height);

                SerializedProperty propertyKey = property.FindPropertyRelative("key");

                string[] keys     = LocalisationController.instance.GetKeys();
                int      keyIndex = System.Array.IndexOf <string>(keys, propertyKey.stringValue);

                keyIndex = EditorGUI.Popup(rect1, label.text, keyIndex, keys);
                propertyKey.stringValue = keys[Mathf.Clamp(keyIndex, 0, keys.Length)];

                if (GUI.Button(rect2, "Refresh", EditorStyles.miniButton))
                {
                    LocalisationController.instance.Load();
                }
            }
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            bool keyUpdated = false;

            if (LocalisationController.FindInstance())
            {
                if (!LocalisationController.instance.IsLoaded)
                {
                    Debug.Log("Load");
                    LocalisationController.instance.Load();
                }

                EditorGUI.BeginChangeCheck();

                string[] keys     = LocalisationController.instance.GetKeys();
                int      keyIndex = System.Array.IndexOf <string>(keys, _propertyKey.stringValue);
                keyIndex = EditorGUILayout.Popup("Key", keyIndex, keys);
                _propertyKey.stringValue = keyIndex >= 0 ? keys[keyIndex] : string.Empty;

                string[] languages = LocalisationController.instance.GetSupportedLanguages();
                int      index     = System.Array.IndexOf <string>(languages, _propertyLanugage.stringValue);
                index = EditorGUILayout.Popup("Preview Language", index, languages);
                _propertyLanugage.stringValue = index >= 0 ? languages[index] : LocalisationController.instance.currentLanguage;

                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Refresh", EditorStyles.miniButton, GUILayout.Width(100)))
                {
                    LocalisationController.instance.Load();
                    keyUpdated = true;
                }
                EditorGUILayout.EndHorizontal();

                keyUpdated = keyUpdated || EditorGUI.EndChangeCheck();
            }
            else
            {
                EditorGUILayout.PropertyField(_propertyKey);
                EditorGUILayout.HelpBox("Unable to locate LocalisationController, previewing disabled", MessageType.Warning);

                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Search", EditorStyles.miniButton, GUILayout.Width(100)))
                {
                    LocalisationController.FindInstance();
                }
                EditorGUILayout.EndHorizontal();
            }

            serializedObject.ApplyModifiedProperties();

            if (keyUpdated)
            {
                _text.GetComponent <Text>().text = LocalisationController.instance.GetString(_propertyKey.stringValue, _propertyLanugage.stringValue);
                GUI.changed = true;
            }
        }
示例#3
0
        private void OnEnable()
        {
            _controller = target as LocalisationController;

            _properyDefaultLanguage         = serializedObject.FindProperty("_defaultLanguage");
            _properyDocumentID              = serializedObject.FindProperty("_documentID");
            _properySheetID                 = serializedObject.FindProperty("_sheetID");
            _properyOutputCharacters        = serializedObject.FindProperty("_outputCharacters");
            _properyIgnoreRichText          = serializedObject.FindProperty("_ignoreRichTextTags");
            _properyOutputCharactersMap     = serializedObject.FindProperty("_outputCharactersMap");
            _properyOutputCharactersInclude = serializedObject.FindProperty("_autoIncludeCharacters");
        }
示例#4
0
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
            LoadAllFiles();
            isReady = true;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        DontDestroyOnLoad(gameObject);
    }
示例#5
0
        private void HandleLanguageChanged(LocalisationController sender, string currentLanguage)
        {
            int i = 0, l = fonts.Length;

            for (; i < l; ++i)
            {
                TMPFallbackMap map  = fonts[i];
                TMP_FontAsset  font = map.fontAsset;
                font.fallbackFontAssetTable.Clear();

                int j = 0, k = map.fallbacks.Length;
                for (; j < k; ++j)
                {
                    TMPFallbackMapLanguage fallback = map.fallbacks[j];
                    if (fallback.languageCode == currentLanguage)
                    {
                        font.fallbackFontAssetTable.Add(fallback.fontAsset);
                        //Debug.LogFormat("Set fallback {0} for {1}, language {2}", fallback.fontAsset, font, currentLanguage);
                        break;
                    }
                }
            }
        }
 private void HandleEventLanguageChanged(LocalisationController sender, string currentLanguage)
 {
     SetKey(_key);
 }
示例#7
0
 private void OnEnable()
 {
     myController = (LocalisationController)target;
 }