private void NodeAddDelParameter(int stateId, int transitionId, SkillHsmConfigHSMParameter parameter, bool isAdd) { SkillHsmConfigNodeData nodeValue = GetNode(stateId); if (null == nodeValue) { return; } List <SkillHsmConfigHSMParameter> parameterList = new List <SkillHsmConfigHSMParameter>(); if (transitionId >= 0) { SkillHsmConfigTransition transition = null; for (int i = 0; i < nodeValue.TransitionList.Count; ++i) { if (nodeValue.TransitionList[i].TransitionId == transitionId) { transition = nodeValue.TransitionList[i]; break; } } if (null == transition) { return; } parameterList = transition.ParameterList; } else { parameterList = nodeValue.ParameterList; } if (isAdd) { AddParameter(parameterList, parameter, true); } else { DelParameter(parameterList, parameter); } for (int i = 0; i < parameterList.Count; ++i) { SkillHsmConfigHSMParameter p = parameterList[i]; p.Index = i; } }
public void SetParameter(string parameterName, int intValue) { SkillHsmConfigHSMParameter parameter = null; if (!_environmentParameterDic.TryGetValue(parameterName, out parameter)) // 当前行为树不需要的参数值就不保存了 { return; } if (parameter.ParameterType == (int)HSMParameterType.Int) { parameter.IntValue = intValue; _environmentParameterDic[parameterName] = parameter; } }
public static SkillHsmConfigHSMTreeData UpdateData(SkillHsmConfigHSMTreeData skillHsmData) { HashSet <string> useParameter = new HashSet <string>(); for (int i = 0; i < skillHsmData.NodeList.Count; ++i) { SkillHsmConfigNodeData nodeData = skillHsmData.NodeList[i]; for (int j = 0; j < nodeData.TransitionList.Count; ++j) { SkillHsmConfigTransition transition = nodeData.TransitionList[j]; for (int k = 0; k < transition.GroupList.Count; ++k) { SkillHsmConfigTransitionGroup transitionGroup = transition.GroupList[k]; for (int n = 0; n < transitionGroup.ParameterList.Count; ++n) { string parameter = transitionGroup.ParameterList[n]; if (!useParameter.Contains(parameter)) { useParameter.Add(parameter); } if (parameter.CompareTo("ForcedAbortSkill") == 0) { Debug.LogError(skillHsmData.FileName + " ForcedAbortSkill:" + nodeData.Id + " " + transition.ToStateId); } if (parameter.CompareTo("ForcedAbortSkillToFish") == 0) { Debug.LogError(skillHsmData.FileName + " ForcedAbortSkillToFish:" + nodeData.Id + " " + transition.ToStateId); } } } } } for (int k = skillHsmData.ParameterList.Count - 1; k >= 0; --k) { SkillHsmConfigHSMParameter parameter = skillHsmData.ParameterList[k]; if (!useParameter.Contains(parameter.ParameterName)) { Debug.LogError(skillHsmData.FileName + " " + parameter.ParameterName + " " + parameter.CNName); skillHsmData.ParameterList.RemoveAt(k); } } return(skillHsmData); }
public static HSMCompare CompareFloat(this SkillHsmConfigHSMParameter self, SkillHsmConfigHSMParameter parameter) { HSMCompare hSMCompare = HSMCompare.INVALID; if (self.FloatValue > parameter.FloatValue) { hSMCompare |= HSMCompare.GREATER; } if (self.FloatValue < parameter.FloatValue) { hSMCompare |= HSMCompare.LESS; } return(hSMCompare); }
public bool ConditionAllAnd(List <SkillHsmConfigHSMParameter> parameterList) { bool result = true; for (int i = 0; i < parameterList.Count; ++i) { SkillHsmConfigHSMParameter temp = parameterList[i]; bool value = Condition(temp); if (!value) { result = false; break; } } return(result); }
public void SetParameter(SkillHsmConfigHSMParameter parameter) { SkillHsmConfigHSMParameter cacheParameter = null; if (!_environmentParameterDic.TryGetValue(parameter.ParameterName, out cacheParameter)) // 当前行为树不需要的参数值就不保存了 { return; } if (parameter.ParameterType != cacheParameter.ParameterType) { Debug.LogError("parameter type invalid:" + parameter.ParameterName); return; } cacheParameter.CloneFrom(parameter); _environmentParameterDic[parameter.ParameterName] = cacheParameter; }
//将配置好的Parameter存到环境dic中 public void InitParmeter() { for (int i = 0; i < _parameterList.Count; ++i) { SkillHsmConfigHSMParameter parameter = _parameterList[i]; SkillHsmConfigHSMParameter cacheParaemter = null; if (!_environmentParameterDic.TryGetValue(parameter.ParameterName, out cacheParaemter)) { cacheParaemter = parameter.Clone(); _environmentParameterDic[parameter.ParameterName] = cacheParaemter; } cacheParaemter.IntValue = parameter.IntValue; cacheParaemter.FloatValue = parameter.FloatValue; cacheParaemter.BoolValue = parameter.BoolValue; } }
public bool Condition(SkillHsmConfigHSMParameter parameter) { SkillHsmConfigHSMParameter environmentParameter = null; if (!_environmentParameterDic.TryGetValue(parameter.ParameterName, out environmentParameter)) { return(false); } if (environmentParameter.ParameterType != parameter.ParameterType) { Debug.LogError("parameter Type not Equal:" + environmentParameter.ParameterName + " " + environmentParameter.ParameterType + " " + parameter.ParameterType); return(false); } HSMCompare hsmCompare = environmentParameter.Compare(parameter); return((parameter.Compare & (int)hsmCompare) > 0); }
private void DrawAddParameter() { if (null == newAddParameter) { newAddParameter = new SkillHsmConfigHSMParameter(); } EditorGUILayout.BeginVertical("box"); { newAddParameter = HSMDrawParameter.Draw(newAddParameter, HSMDrawParameterType.HSM_PARAMETER_ADD, null); } EditorGUILayout.EndVertical(); GUILayout.Space(5); if (GUILayout.Button("添加条件")) { if (null != HSMManager.hSMNodeAddDelParameter) { HSMManager.parameterChange(newAddParameter, true); } } }
public static HSMCompare CompareInt(this SkillHsmConfigHSMParameter self, SkillHsmConfigHSMParameter parameter) { HSMCompare hSMCompare = HSMCompare.INVALID; hSMCompare = self.CompareFloat(parameter); if (self.IntValue > parameter.IntValue) { hSMCompare |= HSMCompare.GREATER; } if (self.IntValue < parameter.IntValue) { hSMCompare |= HSMCompare.LESS; } if (self.IntValue == parameter.IntValue) { hSMCompare |= HSMCompare.EQUALS; } if (self.IntValue != parameter.IntValue) { hSMCompare |= HSMCompare.NOT_EQUAL; } if (self.IntValue >= parameter.IntValue) { hSMCompare |= HSMCompare.GREATER_EQUALS; } if (self.IntValue <= parameter.IntValue) { hSMCompare |= HSMCompare.LESS_EQUAL; } return(hSMCompare); }
private void DrawNodeAddParameter(SkillHsmConfigNodeData nodeValue) { if (GUILayout.Button("添加条件")) { if (HSMManager.Instance.HSMTreeData.ParameterList.Count <= 0) { string msg = "没有参数可添加,请先添加参数"; if (HSMNodeWindow.window != null) { HSMNodeWindow.window.ShowNotification(msg); } } else { if (null != HSMManager.hSMNodeAddDelParameter) { SkillHsmConfigHSMParameter hSMParameter = HSMManager.Instance.HSMTreeData.ParameterList[0]; HSMManager.hSMNodeAddDelParameter(nodeValue.Id, -1, hSMParameter, true); } } } }
private void DrawParameter(SkillHsmConfigNodeData nodeData, List <SkillHsmConfigHSMParameter> parametersList, Action <SkillHsmConfigHSMParameter> delCallBack, Action <string> ChangeParameter, SkillHsmConfigTransitionGroup group) { EditorGUILayout.BeginVertical("box", GUILayout.ExpandWidth(true)); { int height = 0; for (int i = 0; i < parametersList.Count; ++i) { SkillHsmConfigHSMParameter parameter = parametersList[i]; height += 50; } height = height <= 300 ? height : 300; scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Height(height)); { for (int i = 0; i < parametersList.Count; ++i) { SkillHsmConfigHSMParameter hSMParameter = parametersList[i]; Action DelCallBack = () => { if (null != delCallBack) { delCallBack(hSMParameter); } }; Color color = Color.white; if (null != group) { string name = group.ParameterList.Find(a => (a.CompareTo(hSMParameter.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 = hSMParameter.ParameterName; SkillHsmConfigHSMParameter tempParameter = hSMParameter.Clone(); tempParameter = HSMDrawParameter.Draw(hSMParameter, HSMDrawParameterType.NODE_PARAMETER, DelCallBack); if (parameterName.CompareTo(hSMParameter.ParameterName) != 0) { if (null != ChangeParameter) { ChangeParameter(hSMParameter.ParameterName); } } else { hSMParameter.CloneFrom(tempParameter); } } EditorGUILayout.EndVertical(); GUILayout.Space(5); GUI.backgroundColor = Color.white; } } EditorGUILayout.EndScrollView(); } EditorGUILayout.EndVertical(); }
private void NodeChangeParameter(int stateId, int transitionId, string newParameter) { SkillHsmConfigNodeData nodeValue = GetNode(stateId); if (null == nodeValue) { return; } SkillHsmConfigHSMParameter parameter = null; for (int i = 0; i < _HSMTreeData.ParameterList.Count; ++i) { SkillHsmConfigHSMParameter temp = _HSMTreeData.ParameterList[i]; if (temp.ParameterName.CompareTo(newParameter) == 0) { parameter = temp; } } if (null == parameter) { return; } List <SkillHsmConfigHSMParameter> parameterList = new List <SkillHsmConfigHSMParameter>(); if (transitionId >= 0) { SkillHsmConfigTransition transition = null; for (int i = 0; i < nodeValue.TransitionList.Count; ++i) { if (nodeValue.TransitionList[i].TransitionId == transitionId) { transition = nodeValue.TransitionList[i]; break; } } if (null == transition) { return; } parameterList = transition.ParameterList; } else { parameterList = nodeValue.ParameterList; } for (int i = 0; i < parameterList.Count; ++i) { SkillHsmConfigHSMParameter temp = parameterList[i]; if (temp.ParameterName.CompareTo(parameter.ParameterName) == 0) { parameterList[i] = parameter.Clone(); break; } } for (int i = 0; i < parameterList.Count; ++i) { parameterList[i].Index = i; } }
private static SkillHsmConfigHSMTreeData ImportParameter(SkillHsmConfigHSMTreeData hsmData, string fileName) { Debug.LogError(hsmData.FileName); TableRead.Instance.Init(); string csvPath = Extend.GameUtils.CombinePath(Application.dataPath, "StreamingAssets", "CSV"); //string.Format("{0}/StreamingAssets/CSV/", Application.dataPath); TableRead.Instance.ReadCustomPath(csvPath); // Debug.LogError(filePath + " " + fileName); List <int> keyList = TableRead.Instance.GetKeyList(fileName); Dictionary <string, SkillHsmConfigHSMParameter> parameterDic = new Dictionary <string, SkillHsmConfigHSMParameter>(); for (int i = 0; i < hsmData.ParameterList.Count; ++i) { SkillHsmConfigHSMParameter parameter = hsmData.ParameterList[i]; parameterDic[parameter.ParameterName] = parameter; } for (int i = 0; i < keyList.Count; ++i) { int key = keyList[i]; string EnName = TableRead.Instance.GetData(fileName, key, "EnName"); string cnName = TableRead.Instance.GetData(fileName, key, "CnName"); string typeName = TableRead.Instance.GetData(fileName, key, "Type"); int type = int.Parse(typeName); string floatContent = TableRead.Instance.GetData(fileName, key, "FloatValue"); float floatValue = float.Parse(floatContent); string intContent = TableRead.Instance.GetData(fileName, key, "IntValue"); int intValue = int.Parse(intContent); string boolContent = TableRead.Instance.GetData(fileName, key, "BoolValue"); bool boolValue = (int.Parse(boolContent) == 1); if (parameterDic.ContainsKey(EnName)) { if (parameterDic[EnName].ParameterType != type) { Debug.LogError("已经存在参数:" + EnName + " type:" + (HSMParameterType)parameterDic[EnName].ParameterType + " newType:" + (HSMParameterType)type); } else { Debug.LogError("已经存在参数:" + EnName); } parameterDic.Remove(EnName); for (int j = 0; j < hsmData.ParameterList.Count; ++j) { SkillHsmConfigHSMParameter cacheParameter = hsmData.ParameterList[j]; if (cacheParameter.ParameterName == EnName) { hsmData.ParameterList.RemoveAt(j); break; } } //continue; } //Debug.LogError(EnName + " " +cnName + " " + typeName); SkillHsmConfigHSMParameter parameter = new SkillHsmConfigHSMParameter(); parameter.ParameterName = EnName; parameter.CNName = cnName; parameter.Compare = (int)HSMCompare.EQUALS; parameter.ParameterType = type; parameter.BoolValue = false; if (type == (int)HSMParameterType.Float) { parameter.FloatValue = floatValue; } if (type == (int)HSMParameterType.Int) { parameter.IntValue = intValue; } if (type == (int)HSMParameterType.Float) { parameter.BoolValue = boolValue; } hsmData.ParameterList.Add(parameter); } foreach (var kv in parameterDic) { Debug.LogError("==========缺失的参数:" + kv.Key); } return(hsmData); }
public static SkillHsmConfigHSMParameter Draw(SkillHsmConfigHSMParameter hSMParameter, HSMDrawParameterType drawParameterType, Action DelCallBack) { if (null == hSMParameter) { return(hSMParameter); } EditorGUILayout.BeginHorizontal(); { string[] parameterNameArr = EnumNames.GetEnumNames <HSMParameterType>(); int index = EnumNames.GetEnumIndex <HSMParameterType>((HSMParameterType)(hSMParameter.ParameterType)); HSMParameterType HSMParameterType = EnumNames.GetEnum <HSMParameterType>(index); bool enableChangeType = (drawParameterType == HSMDrawParameterType.HSM_PARAMETER_ADD); GUI.enabled = enableChangeType; { GUI.enabled = false; if (drawParameterType == HSMDrawParameterType.NODE_PARAMETER) { EditorGUILayout.BeginHorizontal(); { hSMParameter.Index = EditorGUILayout.IntField(hSMParameter.Index, GUILayout.Width(30)); } EditorGUILayout.EndHorizontal(); } GUI.enabled = enableChangeType; index = EditorGUILayout.Popup(index, parameterNameArr, GUILayout.ExpandWidth(true)); hSMParameter.ParameterType = (int)EnumNames.GetEnum <HSMParameterType>(index); GUILayout.Space(5); } GUI.enabled = true; if (drawParameterType == HSMDrawParameterType.NODE_PARAMETER || drawParameterType == HSMDrawParameterType.HSM_PARAMETER) { if (GUILayout.Button("删除", GUILayout.Width(45))) { if (null != DelCallBack) { DelCallBack(); } } } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { if (drawParameterType == HSMDrawParameterType.NODE_PARAMETER) { List <SkillHsmConfigHSMParameter> parameterList = HSMManager.Instance.HSMTreeData.ParameterList; string[] parameterArr = new string[parameterList.Count]; int index = -1; for (int i = 0; i < parameterList.Count; ++i) { SkillHsmConfigHSMParameter p = parameterList[i]; parameterArr[i] = p.CNName; //p.ParameterName; if (hSMParameter.ParameterName.CompareTo(p.ParameterName) == 0) { index = i; } } int result = EditorGUILayout.Popup(index, parameterArr, GUILayout.ExpandWidth(true)); if (result != index) { hSMParameter.ParameterName = parameterList[result].ParameterName; //parameterArr[result]; } } else if (drawParameterType == HSMDrawParameterType.HSM_PARAMETER || drawParameterType == HSMDrawParameterType.RUNTIME_PARAMETER) { GUI.enabled = (drawParameterType == HSMDrawParameterType.HSM_PARAMETER_ADD); hSMParameter.ParameterName = EditorGUILayout.TextField(hSMParameter.ParameterName); hSMParameter.CNName = EditorGUILayout.TextField(hSMParameter.CNName); GUI.enabled = true; } else if (drawParameterType == HSMDrawParameterType.HSM_PARAMETER_ADD) { EditorGUILayout.BeginVertical(); { string oldName = hSMParameter.ParameterName; hSMParameter.ParameterName = EditorGUILayout.TextField("英文:", hSMParameter.ParameterName); if (oldName.CompareTo(hSMParameter.ParameterName) != 0) { bool isNumOrAlp = IsNumOrAlp(hSMParameter.ParameterName); if (!isNumOrAlp) { string msg = string.Format("参数名只能包含:数字、字母、下划线,且数字不能放在第一个字符位置"); HSMNodeWindow.window.ShowNotification(msg); hSMParameter.ParameterName = oldName; } } hSMParameter.CNName = EditorGUILayout.TextField("中文", hSMParameter.CNName); } EditorGUILayout.EndVertical(); } HSMCompare[] compareEnumArr = new HSMCompare[] { }; if (hSMParameter.ParameterType == (int)HSMParameterType.Int) { compareEnumArr = new HSMCompare[] { HSMCompare.GREATER, HSMCompare.GREATER_EQUALS, HSMCompare.LESS_EQUAL, HSMCompare.LESS, HSMCompare.EQUALS, HSMCompare.NOT_EQUAL }; } if (hSMParameter.ParameterType == (int)HSMParameterType.Float) { compareEnumArr = new HSMCompare[] { HSMCompare.GREATER, HSMCompare.LESS }; } if (hSMParameter.ParameterType == (int)HSMParameterType.Bool) { compareEnumArr = new HSMCompare[] { HSMCompare.EQUALS, HSMCompare.NOT_EQUAL }; } string[] compareArr = new string[compareEnumArr.Length]; int compare = hSMParameter.Compare; bool found = false; for (int i = 0; i < compareEnumArr.Length; ++i) { int index = EnumNames.GetEnumIndex <HSMCompare>(compareEnumArr[i]); string typeName = EnumNames.GetEnumName <HSMCompare>(index); compareArr[i] = typeName; if ((HSMCompare)hSMParameter.Compare == compareEnumArr[i]) { compare = i; found = true; } } if (!found) { compare = 0; } bool value = (drawParameterType != HSMDrawParameterType.HSM_PARAMETER) && (drawParameterType != HSMDrawParameterType.RUNTIME_PARAMETER) && (drawParameterType != HSMDrawParameterType.HSM_PARAMETER_ADD); bool boolType = (hSMParameter.ParameterType == (int)HSMParameterType.Bool); if (boolType) { hSMParameter.Compare = (int)HSMCompare.EQUALS; } else if (value) { compare = EditorGUILayout.Popup(compare, compareArr, GUILayout.Width(65)); hSMParameter.Compare = (int)(compareEnumArr[compare]); } { if (hSMParameter.ParameterType == (int)HSMParameterType.Int) { hSMParameter.IntValue = EditorGUILayout.IntField(hSMParameter.IntValue, GUILayout.Width(50)); } if (hSMParameter.ParameterType == (int)HSMParameterType.Float) { hSMParameter.FloatValue = EditorGUILayout.FloatField(hSMParameter.FloatValue, GUILayout.Width(50)); } if (hSMParameter.ParameterType == (int)HSMParameterType.Bool) { hSMParameter.BoolValue = EditorGUILayout.Toggle(hSMParameter.BoolValue, GUILayout.Width(50)); } } } EditorGUILayout.EndHorizontal(); return(hSMParameter); }
public virtual void AddParameter(SkillHsmConfigHSMParameter parameter) { _parameterList.Add(parameter); }
public static HSMCompare CompareBool(this SkillHsmConfigHSMParameter self, SkillHsmConfigHSMParameter parameter) { HSMCompare hSMCompare = (self.BoolValue == parameter.BoolValue) ? HSMCompare.EQUALS : HSMCompare.NOT_EQUAL; return(hSMCompare); }