Exemplo n.º 1
0
        private void OnEnable()
        {
            if (!isLoaded)
            {
                isLoaded = true;
            }

            using (EditorLocalization.EditorLocalizationValues.BeginScope())
            {
                titleContent = new GUIContent("Localization".Localization());

                if (itemDatas == null)
                {
                    itemDatas = new ItemData[0];
                }
                if (baseData == null)
                {
                    baseData = new ItemData();
                }

                baseData.Load();

                foreach (var item in itemDatas)
                {
                    item.Load();
                }
                if (allLangNames == null)
                {
                    allLangNames = new string[0];
                    allLangPaths = new string[0];
                }
                EditorLocalization.GetValueDrawer("string");
            }
        }
Exemplo n.º 2
0
        void GUIItemNode(ItemData item, string key, LocalizationValue value, int itemIndex)
        {
            ILocalizationValueDrawer drawer;

            drawer = EditorLocalization.GetValueDrawer(value.TypeName);
            if (drawer == null)
            {
                drawer = EditorLocalization.GetValueDrawer("string");
            }

            bool ineritValue = !item.values.ContainsKey(key);

            if (!ineritValue)
            {
                value.Value      = drawer.OnGUI(value.Value);
                item.values[key] = value;

                if (baseData.lang != item.lang)
                {
                    if (GUILayout.Button("T", TranslateButtonStyle, GUILayout.ExpandWidth(false)))
                    {
                        Translate(baseData, new List <TranslateItem>()
                        {
                            new TranslateItem()
                            {
                                itemData = item, key = key
                            }
                        });
                        //EditorUtility.DisplayProgressBar("Translate", "", 0f);

                        //GoogleTranslator.Process(itemDatas[0].lang, item.lang, (string)baseData.values[key].Value, (b, result) =>
                        //{
                        //    EditorUtility.ClearProgressBar();
                        //    if (b)
                        //    {
                        //        value.Value = result;
                        //        item.values[key] = value;
                        //        DirtyData(item);
                        //    }
                        //});
                    }
                }
            }
            else
            {
                var baseValue = baseData.values[key];
                using (new GUIx.Scopes.ColorScope(GUI.color * new Color(1, 1, 1, 0.5f)))
                    using (var checker = new EditorGUI.ChangeCheckScope())
                    {
                        object newValue = drawer.OnGUI(baseValue.Value);
                        if (checker.changed)
                        {
                            var clone = baseValue.Clone();
                            clone.Value      = newValue;
                            item.values[key] = clone;
                            GUI.changed      = true;
                        }
                    }
            }
        }