예제 #1
0
        private object OutPutEnumFieldValue(NodeFieldDesc desc)
        {
            string oldValue = mCurBehaviorNode.Args.Get(desc.name)?.ToString();

            if (string.IsNullOrEmpty(oldValue))
            {
                oldValue = BTEnvKey.None;
            }
            string[] enumValueArr;
            if (mCurBehaviorNode.IsRoot() && desc.value.ToString() != BTEnvKey.None)
            {
                enumValueArr = new string[] { desc.value.ToString() };
            }
            else
            {
                enumValueArr = BehaviorTreeInOutConstrain.GetEnvKeyEnum(typeof(BTEnvKey));
                if (enumValueArr.Length == 0)
                {
                    enumValueArr = new string[] { BTEnvKey.None };
                }
                if (oldValue == BTEnvKey.None)
                {
                    oldValue = desc.value.ToString();
                }
            }

            int    oldSelect = IndexInStringArr(enumValueArr, oldValue);
            string label     = desc.name + (desc.desc == ""? "" : $"({desc.desc})") + $"({desc.envKeyType})";

            EditorGUILayout.LabelField(label);
            int    selection = EditorGUILayout.Popup("", oldSelect, enumValueArr);
            string newValue  = enumValueArr[selection];

            return(newValue);
        }
예제 #2
0
        private object ConstTextFieldValue(NodeFieldDesc desc)
        {
            string oldValue = desc.value.ToString();

            EditorGUILayout.LabelField(GetPropDesc(desc));
            EditorGUILayout.LabelField("", oldValue);
            return(oldValue);
        }
예제 #3
0
        private object FloatFieldValue(NodeFieldDesc desc)
        {
            float oldValue = (float)mCurBehaviorNode.Args.Get(desc.name);

            EditorGUILayout.LabelField(GetPropDesc(desc));
            object newValue = EditorGUILayout.FloatField("", oldValue);

            return(newValue);
        }
예제 #4
0
        private object LongFieldValue(NodeFieldDesc desc)
        {
            long oldValue = (long)mCurBehaviorNode.Args.Get(desc.name);

            EditorGUILayout.LabelField(GetPropDesc(desc));
            object newValue = EditorGUILayout.LongField("", oldValue);

            return(newValue);
        }
예제 #5
0
        private object BoolFieldValue(NodeFieldDesc desc)
        {
            bool oldValue = (bool)mCurBehaviorNode.Args.Get(desc.name);

            EditorGUILayout.LabelField(GetPropDesc(desc));
            object newValue = EditorGUILayout.Toggle("", oldValue);

            return(newValue);
        }
예제 #6
0
        private object DoubletFieldValue(NodeFieldDesc desc)
        {
            double oldValue = (double)mCurBehaviorNode.Args.Get(desc.name);

            EditorGUILayout.LabelField(GetPropDesc(desc));
            object newValue = EditorGUILayout.DoubleField("", oldValue);

            return(newValue);
        }
예제 #7
0
        public List <string> GetNodeOutPutEnvKeyList(BehaviorNodeData nodeData, NodeFieldDesc desc = null)
        {
            NodeProto            rootNode  = this.BehaviorNodeDataToNodeProto(CurTree.Root);
            NodeProto            inputNode = this.BehaviorNodeDataToNodeProto(nodeData);
            List <NodeFieldDesc> descList  = _GetNodeOutPutEnvKeyList(rootNode, inputNode, desc);
            List <string>        list      = new List <string>();

            foreach (NodeFieldDesc item in descList)
            {
                string str = item.value?.ToString() ?? "";
                list.Add(str);
            }
            return(list);
        }
예제 #8
0
        private object EnumFieldValue(NodeFieldDesc desc)
        {
            string oldValue = mCurBehaviorNode.Args.Get(desc.name)?.ToString();

            if (string.IsNullOrEmpty(oldValue))
            {
                oldValue = GetDefaultEnumValue(desc.type);
            }
            Enum oldValueEnum = (Enum)Enum.Parse(desc.type, oldValue);

            EditorGUILayout.LabelField(desc.type.ToString());
            Enum newValueEnum = EditorGUILayout.EnumPopup(oldValueEnum);

            return(newValueEnum.ToString());
        }
예제 #9
0
        private object ObjectFieldValue(NodeFieldDesc desc)
        {
            Object oldValue = (Object)mCurBehaviorNode.Args.Get(desc.name);

            EditorGUILayout.LabelField(GetPropDesc(desc));
            Object newValue = EditorGUILayout.ObjectField("", oldValue, desc.type, false);

            if (newValue == null)
            {
                return(null);
            }
            if (TypeHelper.IsGameObjectType(desc.type) && !BehaviorTreeArgsDict.SatisfyCondition((GameObject)newValue, desc.constraintTypes))
            {
                return(null);
            }
            return(newValue);
        }
예제 #10
0
        public List <string> GetCanInPutEnvKeyList(BehaviorNodeData nodeData, NodeFieldDesc desc)
        {
            List <string>    list1   = Instance.GetNodeOutPutEnvKeyList(nodeData, desc);
            HashSet <string> hashSet = new HashSet <string>();

            foreach (string item in list1)
            {
                hashSet.Add(item);
            }
            List <string> resultList = new List <string>();

            foreach (string item in hashSet)
            {
                resultList.Add(item);
            }
            return(resultList);
        }
예제 #11
0
        public string[] GetCanInPutEnvKeyArray(BehaviorNodeData nodeData, NodeFieldDesc desc)
        {
            List <string> list1 = new List <string>();

            list1.AddRange(Instance.GetNodeOutPutEnvKeyList(nodeData, desc));
            list1.Add(BTEnvKey.None);
            HashSet <string> hashSet = new HashSet <string>();

            foreach (string item in list1)
            {
                hashSet.Add(item);
            }

            string[] strArr = new string[hashSet.Count];
            int      i      = 0;

            foreach (string str in hashSet)
            {
                strArr[i++] = str;
            }
            return(strArr);
        }
예제 #12
0
        public static List <NodeFieldDesc> GetNodeFieldDesc(Type type, Type fieldAttributeType)
        {
            List <NodeFieldDesc> list = new List <NodeFieldDesc>();
            BindingFlags         flag = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;

            FieldInfo[] fields = type.GetFields(flag);
            foreach (FieldInfo field in fields)
            {
                object[] field_attrs = field.GetCustomAttributes(fieldAttributeType, false);
                if (field_attrs.Length > 0)
                {
                    NodeFieldBaseAttribute attri = field_attrs[0] as NodeFieldBaseAttribute;
                    NodeFieldDesc          desc  = new NodeFieldDesc();
                    desc.name          = field.Name;
                    desc.desc          = attri.Desc;
                    desc.type          = field.FieldType;
                    desc.value         = GetDefaultValue(field.FieldType, attri);
                    desc.attributeType = fieldAttributeType;
                    desc.envKeyType    = attri.envKeyType;
                    if ((typeof(NodeInputAttribute) == fieldAttributeType || typeof(NodeInputAttribute) == fieldAttributeType) && desc.envKeyType == null)
                    {
                        Log.Error($"Node:{type.Name} Field:{desc.name}  _envKeyType can not be null");
                        return(null);
                    }
                    object[] constraints = field.GetCustomAttributes(typeof(NodeFieldConstraintAttribute), false);
                    if (constraints.Length > 0)
                    {
                        NodeFieldConstraintAttribute constraint = constraints[0] as NodeFieldConstraintAttribute;
                        desc.constraintTypes = constraint.Types;
                    }

                    list.Add(desc);
                }
            }
            return(list);
        }
예제 #13
0
        private object InputEnumFieldValue(NodeFieldDesc desc)
        {
            string oldValue = mCurBehaviorNode.Args.Get(desc.name)?.ToString();

            string[] enumValueArr = BTEditor.Instance.GetCanInPutEnvKeyArray(mCurBehaviorNode, desc);
            if (enumValueArr.Length == 0)
            {
                enumValueArr = new string[1] {
                    BTEnvKey.None
                };
            }
            else if (string.IsNullOrEmpty(oldValue))
            {
                oldValue = enumValueArr[0];
            }
            int    oldSelect = IndexInStringArr(enumValueArr, oldValue);
            string label     = desc.name + (desc.desc == ""? "" : $"({desc.desc})") + $"({desc.envKeyType})";

            EditorGUILayout.LabelField(label);
            int    selection = EditorGUILayout.Popup("", oldSelect, enumValueArr);
            string newValue  = enumValueArr[selection];

            return(newValue);
        }
예제 #14
0
        public static Object[] ObjectArrFieldValue(ref bool fold, string fieldDesc, Object[] oldValue, NodeFieldDesc desc)
        {
            if (oldValue == null)
            {
                oldValue = new Object[0];
            }
            Object[] newValue = oldValue;

            fold = EditorGUILayout.Foldout(fold, fieldDesc);
            if (fold)
            {
                int size = EditorGUILayout.IntField("Size", oldValue.Length);

                newValue = new Object[size];
                if (size >= oldValue.Length)
                {
                    for (int i = 0; i < oldValue.Length; i++)
                    {
                        newValue[i] = EditorGUILayout.ObjectField(i.ToString(), oldValue[i], desc.type.GetElementType(), false);
                        if (TypeHelper.IsGameObjectArrayType(desc.type) &&
                            !BehaviorTreeArgsDict.SatisfyCondition((GameObject)newValue[i], desc.constraintTypes))
                        {
                            newValue[i] = null;
                        }
                    }
                    for (int i = oldValue.Length; i < size; i++)
                    {
                        newValue[i] = EditorGUILayout.ObjectField(i.ToString(), newValue[i], desc.type.GetElementType(), false);
                        if (TypeHelper.IsGameObjectArrayType(desc.type) &&
                            !BehaviorTreeArgsDict.SatisfyCondition((GameObject)newValue[i], desc.constraintTypes))
                        {
                            newValue[i] = null;
                        }
                    }
                }
                else if (size < oldValue.Length)
                {
                    for (int i = 0; i < size; i++)
                    {
                        newValue[i] = EditorGUILayout.ObjectField(i.ToString(), oldValue[i], desc.type.GetElementType(), false);
                        if (TypeHelper.IsGameObjectArrayType(desc.type) &&
                            !BehaviorTreeArgsDict.SatisfyCondition((GameObject)newValue[i], desc.constraintTypes))
                        {
                            newValue[i] = null;
                        }
                    }
                }
            }

            return(newValue);
        }
예제 #15
0
        public string GetPropDesc(NodeFieldDesc desc)
        {
            string typeDesc = desc.type.ToString().Split('.')[1].ToLower();

            return(desc.name + desc.desc + "(" + typeDesc + ")");
        }
예제 #16
0
        private static List <NodeFieldDesc> _GetNodeOutPutEnvKeyList(NodeProto nodeProto, NodeProto inputNode, NodeFieldDesc desc = null)
        {
            if (nodeProto.Id >= inputNode.Id)
            {
                return(new List <NodeFieldDesc>());
            }
            List <NodeFieldDesc> list = new List <NodeFieldDesc>();

            if (desc == null)
            {
                list = NodeMetaHelper.GetNodeFieldInOutPutDescList(nodeProto.Name, typeof(NodeOutputAttribute));
            }
            else
            {
                list = NodeMetaHelper.GetNodeFieldInOutPutFilterDescList(nodeProto.Name, typeof(NodeOutputAttribute), desc.envKeyType);
            }
            for (int i = 0; i < list.Count; i++)
            {
                object value = nodeProto.Args.Get(list[i].name);
                list[i].value = value;
            }

            foreach (NodeProto childProto in nodeProto.children)
            {
                list.AddRange(_GetNodeOutPutEnvKeyList(childProto, inputNode, desc));
            }
            return(list);
        }
예제 #17
0
 private object ObjectArrFieldValue(NodeFieldDesc desc)
 {
     Object[] oldValue = (Object[])mCurBehaviorNode.Args.Get(desc.name);
     Object[] newValue = CustomArrayField.ObjectArrFieldValue(ref foldObjectArr, GetPropDesc(desc), oldValue, desc);
     return(newValue);
 }
예제 #18
0
        private void DrawProp(string nodeName, List <NodeFieldDesc> fieldList, NodeParamType nodeParamType)
        {
            for (int i = 0; i < fieldList.Count; i++)
            {
                NodeFieldDesc desc      = fieldList[i];
                Type          fieldType = NodeMetaHelper.GetFieldType(nodeName, desc.name);
                NodeMeta      nodeMeta  = BTEditor.Instance.GetComponent <BTNodeInfoComponent>().GetNodeMeta(nodeName);

                // 如果不存在这个参数,给一个默认的
                if (!mCurBehaviorNode.Args.ContainsKey(desc.name))
                {
                    object obj = desc.value ?? BTTypeManager.GetDefaultValue(fieldType);
                    mCurBehaviorNode.Args.Add(desc.name, obj);
                }

                object newValue = null;
                if (TypeHelper.IsStringType(fieldType))
                {
                    if (nodeParamType == NodeParamType.Input)
                    {
                        newValue = InputEnumFieldValue(desc);
                    }
                    else if (nodeParamType == NodeParamType.Output && nodeMeta.classify == NodeClassifyType.Root.ToString())
                    {
                        newValue = ConstTextFieldValue(desc);
                    }
                    else
                    {
                        newValue = TextFieldValue(desc);
                    }
                }
                else if (TypeHelper.IsFloatType(fieldType))
                {
                    newValue = FloatFieldValue(desc);
                }
                else if (TypeHelper.IsDoubleType(fieldType))
                {
                    newValue = DoubletFieldValue(desc);
                }
                else if (TypeHelper.IsIntType(fieldType))
                {
                    newValue = IntFieldValue(desc);
                }
                else if (TypeHelper.IsLongType(fieldType))
                {
                    newValue = LongFieldValue(desc);
                }
                else if (TypeHelper.IsBoolType(fieldType))
                {
                    newValue = BoolFieldValue(desc);
                }
                else if (TypeHelper.IsObjectType(fieldType))
                {
                    newValue = ObjectFieldValue(desc);
                }
                else if (TypeHelper.IsIntArrType(fieldType))
                {
                    newValue = IntArrFieldValue(desc);
                }
                else if (TypeHelper.IsLongArrType(fieldType))
                {
                    newValue = LongArrFieldValue(desc);
                }
                else if (TypeHelper.IsStringArrType(fieldType))
                {
                    newValue = StrArrFieldValue(desc);
                }
                else if (TypeHelper.IsFloatArrType(fieldType))
                {
                    newValue = FloatArrFieldValue(desc);
                }
                else if (TypeHelper.IsDoubleArrType(fieldType))
                {
                    newValue = DoubleArrFieldValue(desc);
                }
                else if (TypeHelper.IsEnumType(fieldType))
                {
                    newValue = EnumFieldValue(desc);
                }
                else if (TypeHelper.IsObjectArrayType(fieldType))
                {
                    newValue = ObjectArrFieldValue(desc);
                }
                else
                {
                    Log.Error($"行为树节点暂时未支持此类型:{fieldType}!");
                    return;
                }
                mCurBehaviorNode.Args.SetKeyValueComp(desc.name, newValue);
            }
        }
예제 #19
0
 private object DoubleArrFieldValue(NodeFieldDesc desc)
 {
     double[] oldValue = (double[])mCurBehaviorNode.Args.Get(desc.name);
     double[] newValue = CustomArrayField.DoubleArrFieldValue(ref foldDoubleArr, GetPropDesc(desc), oldValue);
     return(newValue);
 }
예제 #20
0
 private object FloatArrFieldValue(NodeFieldDesc desc)
 {
     float[] oldValue = (float[])mCurBehaviorNode.Args.Get(desc.name);
     float[] newValue = CustomArrayField.FloatArrFieldValue(ref foldFloatArr, GetPropDesc(desc), oldValue);
     return(newValue);
 }
예제 #21
0
 private object LongArrFieldValue(NodeFieldDesc desc)
 {
     long[] oldValue = (long[])mCurBehaviorNode.Args.Get(desc.name);
     long[] newValue = CustomArrayField.LongArrFieldValue(ref foldLongArr, GetPropDesc(desc), oldValue);
     return(newValue);
 }
예제 #22
0
 private object IntArrFieldValue(NodeFieldDesc desc)
 {
     int[] oldValue = (int[])mCurBehaviorNode.Args.Get(desc.name);
     int[] newValue = CustomArrayField.IntArrFieldValue(ref foldIntArr, GetPropDesc(desc), oldValue);
     return(newValue);
 }
예제 #23
0
 private object StrArrFieldValue(NodeFieldDesc desc)
 {
     string[] oldValue = (string[])mCurBehaviorNode.Args.Get(desc.name);
     string[] newValue = CustomArrayField.StringArrFieldValue(ref foldStrArr, GetPropDesc(desc), oldValue);
     return(newValue);
 }