Exemplo n.º 1
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);
        position        = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
        position.width -= 34;
        position.height = 18;

        Rect valueRect = new Rect(position);

        valueRect.x     += 15;
        valueRect.width -= 15;

        Rect foldButtonRect = new Rect(position);

        foldButtonRect.width = 15;

        dropdown = EditorGUI.Foldout(foldButtonRect, dropdown, "");

        position.x     += 15;
        position.width -= 15;

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

        key.stringValue = EditorGUI.TextField(position, key.stringValue);

        position.x     += position.width + 2;
        position.width  = 17;
        position.height = 17;

        Texture    searchIcon    = (Texture)Resources.Load("search");
        GUIContent searchContent = new GUIContent(searchIcon, "Search");

        if (GUI.Button(position, searchContent))
        {
            TextLocalizerSearchWindow.Open();
        }

        position.x += position.width + 2;

        Texture    storeIcon    = (Texture)Resources.Load("store");
        GUIContent storeContent = new GUIContent(storeIcon);

        if (GUI.Button(position, storeContent))
        {
            TextLocalizerEditWindow.Open(key.stringValue);
        }

        if (dropdown)
        {
            var      value = LocalizationSystem.GetLocalizedValue(key.stringValue);
            GUIStyle style = GUI.skin.box;
            height = style.CalcHeight(new GUIContent(value), valueRect.width);

            valueRect.height = height;
            valueRect.y     += 21;
            EditorGUI.LabelField(valueRect, value, EditorStyles.wordWrappedLabel);
        }

        EditorGUI.EndProperty();
    }
Exemplo n.º 2
0
    public static void Open(string key)
    {
        TextLocalizerEditWindow window = ScriptableObject.CreateInstance <TextLocalizerEditWindow>();

        window.titleContent = new GUIContent("Localizer Window");
        window.ShowUtility();
        window.key = key;
    }
    public static void Open(string key)
    {
        TextLocalizerEditWindow window = CreateInstance <TextLocalizerEditWindow>();

        window.titleContent = new GUIContent("Add new Localizer Key");
        window.ShowUtility();
        window.key = key;
    }
    public static void Open(string key) //Open the custom edit window for an entry
    {
        TextLocalizerEditWindow window = (TextLocalizerEditWindow)ScriptableObject.CreateInstance(typeof(TextLocalizerEditWindow));

        window.titleContent = new GUIContent("Localizer Window");
        window.ShowUtility();
        window.key = key;
    }
Exemplo n.º 5
0
    public static void Open(string key)
    {
        TextLocalizerEditWindow window = CreateInstance <TextLocalizerEditWindow>();

        window.titleContent = new GUIContent("Localizer Window");
        window.ShowUtility();
        IsOpen = true;
        Key    = key;

        for (int i = 0; i < Values.Length; i++)
        {
            Values[i] = LocalizationManager.GetLocalizedValue(key, (LocalizationManager.LocalizedLanguage)System.Enum.GetValues(typeof(LocalizationManager.LocalizedLanguage)).GetValue(i));
        }
    }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        //Draw label
        position        = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
        position.width -= 57;
        position.height = 18;

        //Adjust Rect
        Rect valueRect = new Rect(position);

        valueRect.x     += 15;
        valueRect.width -= 15;

        //Create rect for foldout
        position.x -= 35;
        Rect foldButtonRect = new Rect(position);

        foldButtonRect.width = 15;

        dropdown = EditorGUI.Foldout(foldButtonRect, dropdown, "");

        //Key Label
        position.x += 5;
        EditorGUI.LabelField(position, "Key", EditorStyles.boldLabel);
        position.x -= 5;

        position.x     += 35;
        position.width -= 15;
        //Text field for the key
        SerializedProperty key = property.FindPropertyRelative("key");

        key.stringValue = EditorGUI.TextField(position, key.stringValue);

        //Draw Search Button
        position.x     += position.width + 2;
        position.width  = 25;
        position.height = 25;

        GUIContent searchContent = EditorGUIUtility.IconContent("ViewToolZoom On");

        if (GUI.Button(position, searchContent))
        {
            TextLocalizerSearchWindow.Open();
        }

        //Draw Add/Edit Button
        position.x += position.width + 2;

        GUIContent storeContent = EditorGUIUtility.IconContent("d_Toolbar Plus");

        if (GUI.Button(position, storeContent))
        {
            TextLocalizerEditWindow.Open(key.stringValue);
        }

        //If the dropdown is enabled, draw the translations
        if (dropdown)
        {
            if (languages == null)
            {
                GetLanguages();
            }

            if (languages != null)
            {
                float startX = valueRect.x;
                for (int i = 0; i < languages.Length; i++)
                {
                    //Draw label with the specific language and its translation
                    valueRect.x = startX;
                    var      value = LocalizationSystem.GetLocalizedValue(key.stringValue, (LocalizationSystem.Language)i);
                    GUIStyle style = GUI.skin.box;
                    height = style.CalcHeight(new GUIContent(value), valueRect.width);

                    //Language Label
                    valueRect.height = height;
                    valueRect.y     += 21;
                    EditorGUI.LabelField(valueRect, languages[i] + ":");

                    //Translation Value Label
                    valueRect.x += position.width + 25;
                    EditorGUI.LabelField(valueRect, value, EditorStyles.wordWrappedLabel);
                }
            }
        }

        EditorGUI.EndProperty();
    }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);
        position        = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
        position.width -= 34;
        position.height = 18;

        Rect valueRect = new Rect(position);

        valueRect.x     += 15;
        valueRect.y     += 20;
        valueRect.width -= 15;

        Rect foldButtonRectRect = new Rect(position);

        foldButtonRectRect.width = 15;

        dropdown = EditorGUI.Foldout(foldButtonRectRect, dropdown, "");

        position.x     += 15;
        position.width -= 15;

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

        key.stringValue = EditorGUI.TextField(position, key.stringValue);

        position.x     += position.width + 2;
        position.width  = 17;
        position.height = 17;

        Texture    searchIcon    = (Texture)Resources.Load("Localization/search");
        GUIContent searchContent = new GUIContent(searchIcon);

        if (GUI.Button(position, searchContent))
        {
            if (!TextLocalizerSearchWindow.IsOpen)
            {
                TextLocalizerSearchWindow.Open();
            }
        }

        position.x += position.width + 2;

        Texture    addIcon    = (Texture)Resources.Load("Localization/add");
        GUIContent addContent = new GUIContent(addIcon);

        if (GUI.Button(position, addContent))
        {
            if (!TextLocalizerEditWindow.IsOpen)
            {
                TextLocalizerEditWindow.Open(key.stringValue);
            }
        }

        if (dropdown)
        {
            for (int i = 0; i < System.Enum.GetNames(typeof(LocalizationManager.LocalizedLanguage)).Length; i++)
            {
                var      value = LocalizationManager.GetLocalizedValue(key.stringValue, (LocalizationManager.LocalizedLanguage)System.Enum.GetValues(typeof(LocalizationManager.LocalizedLanguage)).GetValue(i));
                GUIStyle style = GUI.skin.box;
                height = style.CalcHeight(new GUIContent(value), valueRect.width);

                valueRect.height = height;
                valueRect.width += 21;
                valueRect.y      = 20 * (i + 2) + 5;
                EditorGUI.LabelField(valueRect, value, EditorStyles.wordWrappedLabel);
            }
        }

        EditorGUI.EndProperty();
    }