Example #1
0
        private ConditionGroup DrawConditionGroup(NodeValue nodeValue)
        {
            ConditionGroup conditionGroup = null;

            if (nodeValue.NodeType != (int)NODE_TYPE.CONDITION)
            {
                return(conditionGroup);
            }

            EditorGUILayout.BeginVertical("box");
            {
                conditionGroup = BehaviorConditionGroup.DrawTransitionGroup(nodeValue);

                if (GUILayout.Button("添加组"))
                {
                    if (null != BehaviorManager.behaviorAddDelConditionGroup)
                    {
                        BehaviorManager.behaviorAddDelConditionGroup(nodeValue.id, -1, true);
                    }
                }
            }
            EditorGUILayout.EndVertical();

            return(conditionGroup);
        }
        public void NodeAddConditionGroup(int nodeId)
        {
            NodeValue nodeValue = BehaviorDataController.Instance.GetNode(nodeId);

            if (null == nodeValue)
            {
                return;
            }

            for (int i = 0; i < nodeValue.conditionGroupList.Count + 1; ++i)
            {
                ConditionGroup conditionGroup = nodeValue.conditionGroupList.Find(a => a.index == i);
                if (null == conditionGroup)
                {
                    conditionGroup       = new ConditionGroup();
                    conditionGroup.index = i;
                    nodeValue.conditionGroupList.Add(conditionGroup);
                    break;
                }
            }

            if (nodeValue.conditionGroupList.Count <= 0)
            {
                ConditionGroup conditionGroup = new ConditionGroup();
                conditionGroup.index = 0;
                nodeValue.conditionGroupList.Add(conditionGroup);
            }
        }
Example #3
0
        private ConditionGroup DrawConditionGroup(NodeValue nodeValue)
        {
            ConditionGroup conditionGroup = null;

            if (nodeValue.NodeType != (int)NODE_TYPE.CONDITION)
            {
                return(conditionGroup);
            }

            EditorGUILayout.BeginVertical("box");
            {
                conditionGroup = BehaviorConditionGroup.DrawTransitionGroup(nodeValue);

                GUI.enabled = !BehaviorDataController.Instance.CurrentOpenConfigSubTree();
                if (GUILayout.Button("添加组"))
                {
                    DataNodeHandler dataNodeHandler = new DataNodeHandler();
                    dataNodeHandler.NodeAddConditionGroup(nodeValue.id);
                }

                GUI.enabled = true;
            }
            EditorGUILayout.EndVertical();

            return(conditionGroup);
        }
Example #4
0
        public ConditionGroup Clone()
        {
            ConditionGroup group = new ConditionGroup();

            group.index = this.index;
            group.parameterList.AddRange(parameterList);
            return(group);
        }
 public void SetGroup(List <ConditionGroup> conditionGroupList, List <BehaviorParameter> parameterList)
 {
     for (int i = 0; i < conditionGroupList.Count; ++i)
     {
         ConditionGroup          conditionGroup = conditionGroupList[i];
         ConditionGroupParameter group          = GetParameter(conditionGroup, parameterList);
         groupList.Add(group);
     }
 }
Example #6
0
        public void Init(List <ConditionGroup> conditionGroupList, List <BehaviorParameter> parameterList)
        {
            if (init)
            {
                return;
            }
            init = true;

            for (int i = 0; i < conditionGroupList.Count; ++i)
            {
                ConditionGroup          conditionGroup = conditionGroupList[i];
                ConditionGroupParameter group          = GetParameter(conditionGroup, parameterList);
                groupList.Add(group);
            }
        }
Example #7
0
        private ConditionGroupParameter GetParameter(ConditionGroup conditionGroup, List <BehaviorParameter> parameterList)
        {
            ConditionGroupParameter group = new ConditionGroupParameter();

            for (int i = 0; i < conditionGroup.parameterList.Count; ++i)
            {
                string parameter = conditionGroup.parameterList[i];
                for (int j = 0; j < parameterList.Count; ++j)
                {
                    if (parameter.CompareTo(parameterList[j].parameterName) == 0)
                    {
                        group.parameterList.Add(parameterList[j]);
                    }
                }
            }

            return(group);
        }
Example #8
0
        private List <ConditionGroup> GetConditionGroupList(JsonData jsonData)
        {
            List <ConditionGroup> conditionGroupList = new List <ConditionGroup>();

            foreach (JsonData item in jsonData)
            {
                JsonData       croupData      = item["parameterList"];
                ConditionGroup conditionGroup = new ConditionGroup();
                for (int i = 0; i < croupData.Count; ++i)
                {
                    string parameterName = croupData[i].ToString();
                    conditionGroup.parameterList.Add(parameterName);
                }

                conditionGroupList.Add(conditionGroup);
            }

            return(conditionGroupList);
        }
Example #9
0
        private static BehaviorTreeData RemoveInvalidParameter(BehaviorTreeData behaviorData)
        {
            HashSet <string> _usedParameterHash = new HashSet <string>();

            for (int i = 0; i < behaviorData.nodeList.Count; ++i)
            {
                NodeValue nodeValue = behaviorData.nodeList[i];

                for (int j = 0; j < nodeValue.parameterList.Count; ++j)
                {
                    BehaviorParameter parameter = nodeValue.parameterList[j];
                    if (!_usedParameterHash.Contains(parameter.parameterName))
                    {
                        _usedParameterHash.Add(parameter.parameterName);
                    }
                }

                for (int j = 0; j < nodeValue.conditionGroupList.Count; ++j)
                {
                    ConditionGroup group = nodeValue.conditionGroupList[j];
                    for (int k = 0; k < group.parameterList.Count; ++k)
                    {
                        string name = group.parameterList[k];
                        if (!_usedParameterHash.Contains(name))
                        {
                            _usedParameterHash.Add(name);
                        }
                    }
                }
            }

            for (int i = behaviorData.parameterList.Count - 1; i >= 0; --i)
            {
                BehaviorParameter parameter = behaviorData.parameterList[i];
                if (!_usedParameterHash.Contains(parameter.parameterName))
                {
                    behaviorData.parameterList.RemoveAt(i);
                }
            }

            return(behaviorData);
        }
Example #10
0
        public static ConditionGroup DrawTransitionGroup(NodeValue nodeValue)
        {
            if (null == nodeValue)
            {
                return(null);
            }

            ConditionGroup group = null;

            for (int i = 0; i < nodeValue.conditionGroupList.Count; ++i)
            {
                ConditionGroup tempGroup = nodeValue.conditionGroupList[i];
                ConditionGroup temp      = DrawGroup(nodeValue, tempGroup);
                if (null != temp)
                {
                    group = temp;
                }
            }

            return(group);
        }
Example #11
0
        private static ConditionGroup DrawGroup(NodeValue nodeValue, ConditionGroup group)
        {
            Rect area   = GUILayoutUtility.GetRect(0f, 1, GUILayout.ExpandWidth(true));
            bool select = (selectIndex == group.index);

            GUI.enabled = true;
            EditorGUILayout.BeginHorizontal("box", GUILayout.ExpandWidth(true));
            {
                if (selectIndex < 0 || nodeId < 0 || nodeId != nodeValue.id)
                {
                    nodeId      = nodeValue.id;
                    selectIndex = group.index;
                }

                Rect rect = new Rect(area.x, area.y, area.width, 30);
                GUI.backgroundColor = select ? new Color(0, 1, 0, 1) : Color.white;//
                GUI.Box(rect, string.Empty);
                GUI.backgroundColor = Color.white;

                if (GUILayout.Button("选择", GUILayout.Width(50)))
                {
                    selectIndex = group.index;
                }

                for (int i = group.parameterList.Count - 1; i >= 0; --i)
                {
                    string            parameter         = group.parameterList[i];
                    BehaviorParameter behaviorParameter = nodeValue.parameterList.Find(a => (a.parameterName.CompareTo(parameter) == 0));
                    if (null == behaviorParameter)
                    {
                        group.parameterList.RemoveAt(i);
                    }
                }

                GUI.enabled = select && !BehaviorManager.Instance.CurrentOpenConfigSubTree();

                for (int i = 0; i < nodeValue.parameterList.Count; ++i)
                {
                    BehaviorParameter parameter = nodeValue.parameterList[i];
                    string            name      = group.parameterList.Find(a => (a.CompareTo(parameter.parameterName) == 0));

                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField(i.ToString(), GUILayout.Width(10));
                        bool value    = !string.IsNullOrEmpty(name);
                        bool oldValue = value;
                        value = EditorGUILayout.Toggle(value, GUILayout.Width(10));
                        if (value)
                        {
                            if (!oldValue)
                            {
                                group.parameterList.Add(parameter.parameterName);
                                break;
                            }
                        }
                        else
                        {
                            if (oldValue)
                            {
                                group.parameterList.Remove(parameter.parameterName);
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                    GUILayout.Space(10);
                }
                GUI.enabled = true;

                GUI.enabled = !BehaviorManager.Instance.CurrentOpenConfigSubTree();
                if (GUILayout.Button("删除"))
                {
                    if (null != BehaviorManager.behaviorAddDelConditionGroup)
                    {
                        BehaviorManager.behaviorAddDelConditionGroup(nodeValue.id, group.index, false);
                    }
                }
                GUI.enabled = true;
            }
            EditorGUILayout.EndHorizontal();

            if (select)
            {
                return(group);
            }
            return(null);
        }
Example #12
0
        private void DrawNode(NodeValue nodeValue, string title)
        {
            ConditionGroup conditionGroup = DrawConditionGroup(nodeValue);

            for (int i = 0; i < nodeValue.parameterList.Count; ++i)
            {
                nodeValue.parameterList[i].index = i;
            }

            GUI.enabled = !BehaviorDataController.Instance.CurrentOpenConfigSubTree();
            EditorGUILayout.BeginVertical("box", GUILayout.ExpandWidth(true));
            {
                EditorGUILayout.LabelField(title);

                int height = (nodeValue.parameterList.Count * 58);
                height    = height <= 300 ? height : 300;
                scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Height(height));
                {
                    GUI.backgroundColor = new Color(0.85f, 0.85f, 0.85f, 1f);
                    for (int i = 0; i < nodeValue.parameterList.Count; ++i)
                    {
                        NodeParameter behaviorParameter = nodeValue.parameterList[i];

                        Action DelCallBack = () =>
                        {
                            DataNodeHandler dataNodeHandler = new DataNodeHandler();
                            dataNodeHandler.NodeDelParameter(nodeValue.id, behaviorParameter);
                        };

                        Color color = Color.white;
                        if (null != conditionGroup)
                        {
                            string name = conditionGroup.parameterList.Find(a => (a.CompareTo(behaviorParameter.parameterName) == 0));
                            if (!string.IsNullOrEmpty(name))
                            {
                                color = colorArr[0];
                            }
                        }

                        GUI.backgroundColor = color; // new Color(0.85f, 0.85f, 0.85f, 1f);

                        EditorGUILayout.BeginVertical("box");
                        {
                            string parameterName = behaviorParameter.parameterName;

                            NodeParameter tempParameter = behaviorParameter.Clone();
                            tempParameter = DrawParameter.Draw(behaviorParameter, DrawParameterType.NODE_PARAMETER, DelCallBack);
                            if (parameterName.CompareTo(behaviorParameter.parameterName) != 0)
                            {
                                DataNodeHandler dataNodeHandler = new DataNodeHandler();
                                dataNodeHandler.NodeParameterChange(nodeValue.id, parameterName, behaviorParameter.parameterName);
                            }
                            else
                            {
                                behaviorParameter.CloneFrom(tempParameter);
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }
                    GUI.backgroundColor = Color.white;
                }
                EditorGUILayout.EndScrollView();
            }
            EditorGUILayout.EndVertical();
            GUI.enabled = true;

            GUILayout.Space(10);
            EditorGUILayout.BeginVertical("box");
            {
                DrawAddParameter(nodeValue);
            }
            EditorGUILayout.EndVertical();
        }
Example #13
0
        private void DrawNode(NodeValue nodeValue, string title)
        {
            if (nodeValue.NodeType != (int)NODE_TYPE.CONDITION &&
                nodeValue.NodeType != (int)NODE_TYPE.ACTION)
            {
                return;
            }

            ConditionGroup conditionGroup = DrawConditionGroup(nodeValue);

            for (int i = 0; i < nodeValue.parameterList.Count; ++i)
            {
                nodeValue.parameterList[i].index = i;
            }

            EditorGUILayout.BeginVertical("box", GUILayout.ExpandWidth(true));
            {
                EditorGUILayout.LabelField(title);

                int height = (nodeValue.parameterList.Count * 50);
                height    = height <= 300 ? height : 300;
                scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Height(height));
                {
                    GUI.backgroundColor = new Color(0.85f, 0.85f, 0.85f, 1f);
                    for (int i = 0; i < nodeValue.parameterList.Count; ++i)
                    {
                        BehaviorParameter behaviorParameter = nodeValue.parameterList[i];

                        Action DelCallBack = () =>
                        {
                            if (null != BehaviorManager.behaviorNodeParameter)
                            {
                                BehaviorManager.behaviorNodeParameter(nodeValue.id, behaviorParameter, false);
                            }
                        };

                        Color color = Color.white;
                        if (null != conditionGroup)
                        {
                            string name = conditionGroup.parameterList.Find(a => (a.CompareTo(behaviorParameter.parameterName) == 0));
                            if (!string.IsNullOrEmpty(name))
                            {
                                color = colorArr[0];
                            }
                        }

                        GUI.backgroundColor = color; // new Color(0.85f, 0.85f, 0.85f, 1f);

                        EditorGUILayout.BeginVertical("box");
                        {
                            string parameterName = behaviorParameter.parameterName;

                            BehaviorParameter tempParameter = behaviorParameter.Clone();
                            tempParameter = DrawParameter.Draw(behaviorParameter, DrawParameterType.NODE_PARAMETER, DelCallBack);
                            if (parameterName.CompareTo(behaviorParameter.parameterName) != 0)
                            {
                                if (null != BehaviorManager.behaviorNodeChangeParameter)
                                {
                                    BehaviorManager.behaviorNodeChangeParameter(nodeValue.id, parameterName, behaviorParameter.parameterName);
                                }
                            }
                            else
                            {
                                behaviorParameter.CloneFrom(tempParameter);
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }
                    GUI.backgroundColor = Color.white;
                }
                EditorGUILayout.EndScrollView();
            }
            EditorGUILayout.EndVertical();

            GUILayout.Space(10);
            EditorGUILayout.BeginVertical("box");
            {
                DrawAddParameter(nodeValue);
            }
            EditorGUILayout.EndVertical();
        }