コード例 #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            Rect r = new Rect(position.x, position.y, position.width, position.height);

            EditorGUI.DrawRect(r, new Color(0.87f, 0.87f, 0.87f, 1.0f));


            float line = EditorGUIUtility.singleLineHeight;

            var pathProp = property.FindPropertyRelative("path");

            EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, line), pathProp, new GUIContent(property.displayName));

            var path = pathProp.stringValue;

            string[] splitted = path?.Split('/');

            if (splitted == null || splitted.Length != 3)
            {
                return;
            }

            var unitPath = splitted[0] + '/' + splitted[1];
            var key      = splitted[2];

            if (element == null)
            {
                element = new LocalizedTextField(unitPath, key, true);
            }
            else
            {
                if (element.UnitPath != unitPath || element.Key != key)
                {
                    Debug.Log(unitPath + " " + key);
                    element.Init(unitPath, key);
                }
                element.OnGUI(new Rect(position.x + line, position.y + line, position.width - line, position.height - line));
            }

            //GUILayout.BeginArea(new Rect(position.x, position.y, position.width, position.height - line));            element.OnGUI(new Rect(position.x, position.y, position.width, position.height - line));

            //GUILayout.EndArea();
        }
コード例 #2
0
        private void UpdateKeys()
        {
            var keysContainer = rootVisualElement.Q <Box>("keys");

            keysContainer.Clear();

            KeyNames.Clear();

            foreach (var pack in Localizer.Instance.Packs)
            {
                var group = pack.Groups.FirstOrDefault(g => g.Name == SelectedGroupName);

                if (group != null)
                {
                    var h = group.RequestUnitHandle(SelectedUnitName);

                    if (!h.IsEmpty())
                    {
                        var keysInUnit = h.GetKeys();
                        if (keysInUnit != null)
                        {
                            foreach (var key in keysInUnit)
                            {
                                if (!KeyNames.Contains(key))
                                {
                                    keysContainer.Add(new Label(key));

                                    KeyNames.Add(key);
                                    var element = new LocalizedTextField(SelectedGroupName + "/" + SelectedUnitName,
                                                                         key);
                                    keysContainer.Add(element);
                                }
                            }
                        }
                    }

                    h.Dispose();
                }
            }
        }
コード例 #3
0
        private void InitializeUI()
        {
            if (Localizer.Instance == null)
            {
                Localizer.Initialize(Application.streamingAssetsPath.TrimEnd('/', '\\') + "/Localization", "");
            }

            // Each editor window contains a root VisualElement object
            VisualElement root = rootVisualElement;

            root.Clear();

            // Import UXML
            var visualTree =
                AssetDatabase.LoadAssetAtPath(
                    "Assets/Ruccho/ORLL/Unity/Scripts/Editor/LocalizationEditor/LocalizationEditor.uxml",
                    typeof(VisualTreeAsset)) as VisualTreeAsset;
            VisualElement uxml;

#if UNITY_2018
            uxml = visualTree.CloneTree(null);
#else
            uxml = visualTree.CloneTree();
#endif

            string styleSheetPath =
                "Assets/Ruccho/ORLL/Unity/Scripts/Editor/LocalizationEditor/LocalizationEditor_style.uss";
#if UNITY_2018
            uxml.AddStyleSheetPath(styleSheetPath);
#else
            var ss = AssetDatabase.LoadAssetAtPath <StyleSheet>(styleSheetPath);
            uxml.styleSheets.Add(ss);
#endif
            root.Add(uxml);

            root.Q <Button>("group_add_button").clickable.clicked += () =>
            {
                var newName = root.Q <TextField>("group_add_name").value;
                if (!GroupNames.Contains(newName))
                {
                    GroupNames.Add(newName);
                }

                root.Q <ListView>("groupList").Refresh();
            };

            root.Q <Button>("unit_add_button").clickable.clicked += () =>
            {
                var newName = root.Q <TextField>("unit_add_name").value;
                if (!UnitNames.Contains(newName))
                {
                    UnitNames.Add(newName);
                }

                root.Q <ListView>("unitList").Refresh();
            };

            root.Q <Button>("key_add_button").clickable.clicked += () =>
            {
                var newName       = root.Q <TextField>("key_add_name").value;
                var keysContainer = rootVisualElement.Q <Box>("keys");

                keysContainer.Add(new Label(newName));
                var element = new LocalizedTextField(SelectedGroupName + "/" + SelectedUnitName, newName);
                keysContainer.Add(element);
            };

#if UNITY_2018
            root.Q <ScrollView>("keys-scroll").stretchContentWidth = true;
#endif


            UpdateGroupList();

            var groupList       = root.Q <ListView>("groupList");
            var groupListParent = groupList.parent;
            groupListParent.Remove(groupList);

            Func <VisualElement>        makeItem = () => new Label();
            Action <VisualElement, int> bindItem = (e, i) => (e as Label).text = GroupNames[i];

            const int itemHeight = 16;

            groupList = new ListView(GroupNames, itemHeight, makeItem, bindItem);

            groupList.selectionType = SelectionType.Single;

            groupList.onSelectionChanged += (o) =>
            {
                SelectedGroupName = groupList.selectedItem as string;
                UpdateUnitList();
            };

            groupList.style.flexGrow = 1.0f;
            groupList.name           = "groupList";

            groupListParent.Add(groupList);


            var refreshButton = new Button(() => { InitializeUI(); });

            refreshButton.text = "Refresh";
            refreshButton.name = "refresh-button";

            styleSheetPath =
                "Assets/Ruccho/ORLL/Unity/Scripts/Editor/LocalizationManager/LocalizationManager_style.uss";
#if UNITY_2018
            refreshButton.AddStyleSheetPath(styleSheetPath);
#else
            var ss = AssetDatabase.LoadAssetAtPath <StyleSheet>(styleSheetPath);
            refreshButton.styleSheets.Add(ss);
#endif

            root.Add(refreshButton);

            root.Q <Button>("group_export_csv").clickable.clicked += () => { ExportToCsv(); };
            root.Q <Button>("group_import_csv").clickable.clicked += () => { ImportFromCsv(); };
        }