コード例 #1
0
        void GUINewItem()
        {
            if (string.IsNullOrEmpty(baseData.path))
            {
                return;
            }

            string error = null;

            using (new GUILayout.HorizontalScope())
            {
                searchKey = EditorGUILayoutx.SearchTextField(searchKey, GUIContent.none, GUILayout.Width(EditorGUIUtility.labelWidth));

                int      typeNameIndex = 0;
                string[] typeNames     = EditorLocalization.GetValueTypeNames().ToArray();
                for (int i = 0; i < typeNames.Length; i++)
                {
                    if (typeNames[i] == newValueTypeName)
                    {
                        typeNameIndex = i;
                        break;
                    }
                }
                float width = (Screen.width - EditorGUIUtility.labelWidth) * 0.3f;
                width            = Mathf.Min(width, 150);
                typeNameIndex    = EditorGUILayout.Popup(typeNameIndex, typeNames.Select(o => ("type_" + o).Localization()).ToArray(), GUILayout.Width(width));
                newValueTypeName = typeNames[typeNameIndex];

                string newKeyCurrent;
                newKey = EditorGUILayoutx.DelayedPlaceholderField(newKey ?? string.Empty, out newKeyCurrent, new GUIContent("New Key".Localization()) /*, GUILayout.Width(EditorGUIUtility.labelWidth)*/);



                if (!string.IsNullOrEmpty(newKeyCurrent))
                {
                    if (baseData.values.ContainsKey(newKeyCurrent))
                    {
                        error = string.Format("key <{0}> base exists", newKeyCurrent);
                    }
                }

                if (!string.IsNullOrEmpty(newKey) && error == null)
                {
                    var value = new LocalizationValue(newValueTypeName, Localization.GetValueProvider(newValueTypeName).DefaultValue);

                    if (newValueTypeName == "string")
                    {
                        value.Value = newKey;
                    }

                    baseData.values[newKey] = value;
                    newKey = string.Empty;
                    GUIUtility.keyboardControl = -1;
                    DiryBaseData();
                }
            }

            if (error != null)
            {
                EditorGUILayout.HelpBox(error, MessageType.Error);
            }
        }