public override void OnInspectorGUI()
    {
        serializedObject.Update();

        GUILayout.Space(6f);
        PGUIEditorTools.SetLabelWidth(80f);
        var sp = PGUIEditorTools.DrawProperty("Localize", serializedObject, "m_localize");

        if (sp.boolValue)
        {
            // Key not found in the localization file -- draw it as a text field
            DrawLocalization();
        }
        else
        {
            PGUIEditorTools.DrawProperty("Message", serializedObject, "m_toolTips");
        }

        PGUIEditorTools.DrawProperty("GapY", serializedObject, "m_gap_y");
        PGUIEditorTools.DrawProperty("ShowDelta", serializedObject, "m_showDelta");

        serializedObject.ApplyModifiedProperties();
    }
Exemple #2
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        GUILayout.Space(6f);
        PGUIEditorTools.SetLabelWidth(80f);

        GUILayout.BeginHorizontal();
        // Key not found in the localization file -- draw it as a text field
        SerializedProperty sp = PGUIEditorTools.DrawProperty("Key", serializedObject, "key");

        string myKey     = sp.stringValue;
        bool   isPresent = (mKeys != null) && mKeys.Contains(myKey);

        GUI.color = isPresent ? Color.green : Color.red;
        GUILayout.BeginVertical(GUILayout.Width(22f));
        GUILayout.Space(2f);
#if UNITY_3_5
        GUILayout.Label(isPresent? "ok" : "!!", GUILayout.Height(20f));
#else
        GUILayout.Label(isPresent? "\u2714" : "\u2718", "TL SelectionButtonNew", GUILayout.Height(20f));
#endif
        GUILayout.EndVertical();
        GUI.color = Color.white;
        GUILayout.EndHorizontal();

        if (isPresent)
        {
            if (PGUIEditorTools.DrawHeader("Preview"))
            {
                PGUIEditorTools.BeginContents();

                string[] keys;
                string[] values;

                if (Localization.dictionary.TryGetValue("KEY", out keys) && Localization.dictionary.TryGetValue(myKey, out values))
                {
                    for (int i = 0; i < keys.Length; ++i)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label(keys[i], GUILayout.Width(70f));

                        if (GUILayout.Button(values[i], "TextArea" /*"AS TextArea"*/, GUILayout.MinWidth(80f), GUILayout.MaxWidth(Screen.width - 110f)))
                        {
                            (target as UILocalize).value = values[i];
                            GUIUtility.hotControl        = 0;
                            GUIUtility.keyboardControl   = 0;
                        }
                        GUILayout.EndHorizontal();
                    }
                }
                else
                {
                    GUILayout.Label("No preview available");
                }

                PGUIEditorTools.EndContents();
            }
        }
        else if (mKeys != null && !string.IsNullOrEmpty(myKey))
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            GUILayout.BeginVertical();
            GUI.backgroundColor = new Color(1f, 1f, 1f, 0.35f);

            int matches = 0;

            for (int i = 0, imax = mKeys.Count; i < imax; ++i)
            {
                if (mKeys[i].StartsWith(myKey, System.StringComparison.OrdinalIgnoreCase) || mKeys[i].Contains(myKey))
                {
#if UNITY_3_5
                    if (GUILayout.Button(mKeys[i] + " \u25B2"))
#else
                    if (GUILayout.Button(mKeys[i] + " \u25B2", "CN CountBadge"))
#endif
                    {
                        sp.stringValue             = mKeys[i];
                        GUIUtility.hotControl      = 0;
                        GUIUtility.keyboardControl = 0;
                    }

                    if (++matches == 8)
                    {
                        GUILayout.Label("...and more");
                        break;
                    }
                }
            }
            GUI.backgroundColor = Color.white;
            GUILayout.EndVertical();
            GUILayout.Space(22f);
            GUILayout.EndHorizontal();
        }

        serializedObject.ApplyModifiedProperties();
    }