public bool AddValue(string key, VarType type, string v)
 {
     if (HaveKey(key)) return false;
     Value val = new Value(v, type);
     val.ConverToRealType();
     _valueContainer[key] = val;
     return true;
 }
 private void LoadValue(BinaryReader r)
 {
     int count = r.ReadInt32();
     for (int i = 0; i < count; i++)
     {
         string key = r.ReadString();
         Value v = new Value(0);
         v.Deserialize(r);
         _valueContainer[key] = v;
         //AddValue(key, v);
     }
 }
Exemple #3
0
        void OnGUI()
        {
            GUILayout.Space(10);
            _name = EditorGUILayout.TextField("Name:", _name);
            GUILayout.Space(10);
            _varType = (VarType)EditorGUILayout.EnumPopup(_varType);
            GUILayout.Space(10);

            switch (_varType)
            {
                case VarType.INT:
                case VarType.FLOAT:
                case VarType.STRING:
                    _var = EditorGUILayout.TextField("Value:", _var);
                    break;
                case VarType.BOOL:
                    if (string.IsNullOrEmpty(_var)) _var = bool.TrueString;
                    try
                    {
                        _var = EditorGUILayout.Toggle(bool.Parse(_var)).ToString();
                    }
                    catch (System.Exception)
                    {
                        _var = bool.TrueString;
                    }
                    break;
            }

            GUILayout.Space(10);
            if (GUILayout.Button("Add", ResourcesManager.GetInstance.skin.button, GUILayout.Height(25)))
            {
                if (_container.HaveKey(_name))
                {
                    EditorUtility.DisplayDialog("Error!", "The name already exist! ", "OK");
                    return;
                }

                Value value = null;
                switch (_varType)
                {
                    case VarType.INT:
                        int result;
                        if (int.TryParse(_var, out result))
                            value = new Value(result);
                        break;
                    case VarType.FLOAT:
                        float resultF;
                        if (float.TryParse(_var, out resultF))
                            value = new Value(resultF);
                        break;
                    case VarType.BOOL:
                        value = new Value(bool.Parse(_var));
                        break;
                    case VarType.STRING:
                        value = new Value(_var);
                        break;
                }

                if (value == null)
                {
                    EditorUtility.DisplayDialog("Error!", "Value Type Was Wrong! ", "OK");
                    return;
                }

                _container.AddValue(_name, value);
                Close();
            }
        }
 public bool AddValue(string key, Value v)
 {
     if (HaveKey(key)) return false;
     _valueContainer[key] = v;
     return true;
 }
        private bool ShowValue(string name, Value val)
        {
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("<color=#00FFFF>" + name + "</color>[<color=yellow>" + val.ValueType + "</color>]", ResourcesManager.GetInstance.GetFontStyle(12));
            switch (val.ValueType)
            {
                case VarType.INT:
                    val.IntValue = EditorGUILayout.IntField(val.IntValue);
                    break;
                case VarType.FLOAT:
                    val.FloatValue = EditorGUILayout.FloatField(val.FloatValue);
                    break;
                case VarType.BOOL:
                    val.BoolValue = EditorGUILayout.Toggle(val.BoolValue);
                    break;
                case VarType.STRING:
                    val.StringValue = EditorGUILayout.TextField(val.StringValue);
                    break;
            }

            if (GUILayout.Button("<color=red>X</color>", ResourcesManager.GetInstance.skin.button, GUILayout.Height(18), GUILayout.Width(18)))
            {
                if (EditorUtility.DisplayDialog("Caution!", "You will delete value [" + name + "] !", "Confirm", "Cancel"))
                    return true;
            }

            EditorGUILayout.EndHorizontal();
            return false;
        }