コード例 #1
0
        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();
                }
            }
        }
コード例 #2
0
        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;
            }
        }