public void SetValue <T>(string key, object value) where T : NTVariable
        {
            if (string.IsNullOrEmpty(key))
            {
                return;
            }

            Type newVariableType = typeof(T);
            NTVariableDictionary variableTypeDictionary;

            if (dictionary.ContainsKey(newVariableType.ToString()))
            {
                variableTypeDictionary = dictionary[newVariableType.ToString()];
                if (variableTypeDictionary.ContainsKey(key))
                {
                    NTVariable ntvar = variableTypeDictionary[key];
                    ntvar.SetValue(value);

                    variableTypeDictionary[key]            = ntvar;
                    dictionary[newVariableType.ToString()] = variableTypeDictionary;
                }
            }

            return;
        }
        public bool AddVariable(NTVariable value, Type t)
        {
            if (string.IsNullOrEmpty(value.GetKey()))
            {
                return(false);
            }

            Type newVariableType = t;

            NTVariableDictionary variableTypeDictionary = new NTVariableDictionary(t);

            if (dictionary.ContainsKey(newVariableType.ToString()))
            {
                variableTypeDictionary = dictionary[newVariableType.ToString()];
                if (variableTypeDictionary.ContainsKey(value.GetKey()))
                {
                    return(false);
                }
                else
                {
                    variableTypeDictionary.Add(value.GetKey(), value);
                    dictionary[newVariableType.ToString()] = variableTypeDictionary;
                    onModified?.Invoke();
                    return(true);
                }
            }
            else
            {
                variableTypeDictionary.Add(value.GetKey(), value);
                dictionary.Add(newVariableType.ToString(), variableTypeDictionary);
                onModified?.Invoke();
                return(true);
            }
        }
        public void SetDefaultValue(Type ntVariableType, string key, object value)
        {
            if (string.IsNullOrEmpty(key))
            {
                return;
            }

            Type newVariableType = ntVariableType;
            NTVariableDictionary variableTypeDictionary;

            if (dictionary.ContainsKey(newVariableType.ToString()))
            {
                variableTypeDictionary = dictionary[newVariableType.ToString()];
                if (variableTypeDictionary.ContainsKey(key))
                {
                    NTVariable ntvar = variableTypeDictionary[key];
                    ntvar.SetDefaultValue(value);

                    variableTypeDictionary[key]            = ntvar;
                    dictionary[newVariableType.ToString()] = variableTypeDictionary;
                }
            }

            return;
        }
        public object GetValue <T>(string key) where T : NTVariable
        {
            if (string.IsNullOrEmpty(key))
            {
                return(default(object));
            }

            Type newVariableType = typeof(T);
            NTVariableDictionary variableTypeDictionary;

            if (dictionary.ContainsKey(newVariableType.ToString()))
            {
                variableTypeDictionary = dictionary[newVariableType.ToString()];
                if (variableTypeDictionary.ContainsKey(key))
                {
                    NTVariable ntvar = variableTypeDictionary[key];
                    return(ntvar.GetValue());
                }

                Debug.Log("No value???" + key + "   " + variableTypeDictionary.DictType);
            }


            return(default(object));
        }
Exemple #5
0
        public override bool Evaluate(Operator op, NTVariable value)
        {
            Type rightVariableType = value.GetDataType();

            if (rightVariableType == typeof(float) || rightVariableType == typeof(int) || rightVariableType == typeof(double))
            {
                float rightValue = (float)value.GetValue();
                return(InternalEvaluate(op, rightValue, true));
            }
            else
            {
                return(this.value > 0);
            }
        }
        public override bool Evaluate(Operator op, NTVariable value)
        {
            Type rightVariableType = value.GetDataType();

            if (rightVariableType == typeof(bool))
            {
                bool rightValue = (bool)value.GetValue();
                return(InternalEvaluate(op, rightValue, true));
            }
            else
            {
                return(this.value);
            }
        }
        public override bool Evaluate(Operator op, NTVariable value)
        {
            Type rightVariableType = value.GetDataType();

            if (rightVariableType == typeof(string))
            {
                string rightValue = (string)value.GetValue();
                return(Evaluate(op, rightValue, true));
            }
            else
            {
                return(!string.IsNullOrEmpty(this.value));
            }
        }
        public bool AddVariable(Type varType, object value)
        {
            NTVariable ntVar = (NTVariable)value;

            if (ntVar == null)
            {
                return(false);
            }
            if (string.IsNullOrEmpty(ntVar.GetKey()))
            {
                return(false);
            }

            Type newVariableType = varType;
            NTVariableDictionary variableTypeDictionary = new NTVariableDictionary(newVariableType);

            if (dictionary.ContainsKey(newVariableType.ToString()))
            {
                variableTypeDictionary = dictionary[newVariableType.ToString()];
                if (variableTypeDictionary.ContainsKey(ntVar.GetKey()))
                {
                    return(false);
                }
                else
                {
                    variableTypeDictionary.Add(ntVar.GetKey(), ntVar);
                    dictionary[newVariableType.ToString()] = variableTypeDictionary;
                    onModified?.Invoke();
                    return(true);
                }
            }
            else
            {
                variableTypeDictionary.Add(ntVar.GetKey(), ntVar);
                dictionary.Add(newVariableType.ToString(), variableTypeDictionary);
                onModified?.Invoke();
                return(true);
            }
        }
        public object GetNTValue(string key, Type t)
        {
            if (string.IsNullOrEmpty(key))
            {
                return(default(object));
            }

            Type newVariableType = t;
            NTVariableDictionary variableTypeDictionary;

            if (dictionary.ContainsKey(newVariableType.ToString()))
            {
                variableTypeDictionary = dictionary[newVariableType.ToString()];
                if (variableTypeDictionary.ContainsKey(key))
                {
                    NTVariable ntvar = variableTypeDictionary[key];
                    return(ntvar);
                }
            }

            return(default(object));
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var        obj         = fieldInfo.GetValue(property.serializedObject.targetObject);
            NTVariable myDataClass = obj as NTVariable;

            EditorGUI.BeginProperty(position, label, property);

            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            // Calculate rects
            var amountRect = new Rect(position.x, position.y, 30, position.height);
            var unitRect   = new Rect(position.x + 35, position.y, 50, position.height);
            var nameRect   = new Rect(position.x + 90, position.y, position.width - 90, position.height);

            // Draw fields - passs GUIContent.none to each so they are drawn without labels
            EditorGUI.LabelField(amountRect, "ss");
            EditorGUI.LabelField(unitRect, "ss");
            EditorGUI.LabelField(nameRect, "ss");



            EditorGUI.EndProperty();
        }