Пример #1
0
        public void SetValue <T>(string key, T value)
        {
            Type   type     = typeof(T);
            object newValue = value;

            if (type == typeof(Enum) || type.IsSubclassOf(typeof(Enum)))
            {
                type     = typeof(string);
                newValue = value.ToString();
            }
            int  index  = args_list.FindIndex(item => { return(item.key == key); });
            bool hasKey = index != -1;

            if (hasKey)
            {
                args_list[index].value.SetValueByType(typeof(T), newValue);
            }
            else
            {
                StrValueBasePair pair = new StrValueBasePair();
                pair.key   = key;
                pair.value = new ValueBase();
                pair.value.SetValueByType(typeof(T), newValue);
                args_list.Add(pair);
            }
            if (!args_dict.ContainsKey(key))
            {
                args_dict.Add(key, new ValueBase());
            }
            args_dict[key].SetValueByType(typeof(T), newValue);
        }
        public BehaviorTreeArgsDict Clone()
        {
            BehaviorTreeArgsDict behaviorTreeArgsDict = new BehaviorTreeArgsDict();

            foreach (KeyValuePair <string, object> keyValuePair in this.dict)
            {
                behaviorTreeArgsDict.Add(keyValuePair.Key, Clone(keyValuePair.Value));
            }
            return(behaviorTreeArgsDict);
        }
Пример #3
0
        public BehaviorTreeArgsDict GetArgsDict()
        {
            BehaviorTreeArgsDict dict = new BehaviorTreeArgsDict();

            foreach (BTTypeBaseComponent item in gameObject.GetComponents <BTTypeBaseComponent>())
            {
                FieldInfo info = item.GetType().GetField("fieldValue");
                dict.Add(item.fieldName, info.GetValue(item));
            }
            return(dict);
        }
Пример #4
0
        public BehaviorTreeArgsDict GetArgsDict()
        {
            BehaviorTreeArgsDict dict = new BehaviorTreeArgsDict();

            foreach (var item in gameObject.GetComponents <BTTypeBaseComponent>())
            {
                FieldInfo info      = item.GetType().GetField("fieldValue");
                ValueBase valueBase = new ValueBase();
                if (item.GetType() == typeof(BTEnumComponent))
                {
                    valueBase.SetValueByType(typeof(Enum), info.GetValue(item));
                }
                else
                {
                    valueBase.SetValueByType(info.FieldType, info.GetValue(item));
                }

                dict.Add(item.fieldName, valueBase);
            }
            return(dict);
        }