public static ClientNodeTypeProto GetNodeTypeProtoFromType(Type type) { object[] nodeAttrs = type.GetCustomAttributes(typeof(NodeAttribute), false); if (nodeAttrs.Length == 0) { return(null); } object[] nodeDeprecatedAttrs = type.GetCustomAttributes(typeof(NodeDeprecatedAttribute), false); NodeAttribute nodeAttribute = nodeAttrs[0] as NodeAttribute; NodeDeprecatedAttribute nodeDeprecatedAttribute = null; if (nodeDeprecatedAttrs.Length != 0) { nodeDeprecatedAttribute = nodeDeprecatedAttrs[0] as NodeDeprecatedAttribute; } ClientNodeTypeProto proto = new ClientNodeTypeProto(); proto.type = nodeAttribute.ClassifytType.ToString(); proto.name = type.Name; proto.describe = nodeAttribute.Desc; if (nodeDeprecatedAttribute != null) { proto.isDeprecated = true; proto.deprecatedDesc = nodeDeprecatedAttribute.Desc; } proto.new_args_desc.AddRange(GetNodeFieldDesc(type, typeof(NodeInputAttribute))); proto.new_args_desc.AddRange(GetNodeFieldDesc(type, typeof(NodeOutputAttribute))); proto.new_args_desc.AddRange(GetNodeFieldDesc(type, typeof(NodeFieldAttribute))); proto.child_limit = NodeTypeCountDict[nodeAttribute.ClassifytType]; proto.classify = nodeAttribute.ClassifytType.ToString(); return(proto); }
private static int CompareShowName(ClientNodeTypeProto clientNodeType1, ClientNodeTypeProto clientNodeType2) { if (string.IsNullOrEmpty(clientNodeType1.name) || string.IsNullOrEmpty(clientNodeType2.name)) { Log.Error("字符串输入参数有误"); } return(string.Compare(clientNodeType1.name, clientNodeType2.name)); }
public static Dictionary <string, ClientNodeTypeProto> ExportToDict() { Dictionary <string, ClientNodeTypeProto> name2NodeProtoDict = new Dictionary <string, ClientNodeTypeProto>(); Type[] types = DllHelper.GetMonoTypes(); foreach (Type type in types) { ClientNodeTypeProto proto = GetNodeTypeProtoFromType(type); if (proto == null) { continue; } name2NodeProtoDict.Add(proto.name, proto); } return(name2NodeProtoDict); }
public static Dictionary <string, ClientNodeTypeProto> ExportToDict() { Dictionary <string, ClientNodeTypeProto> name2NodeProtoDict = new Dictionary <string, ClientNodeTypeProto>(); Assembly assembly = GetControllerAssembly(); Type[] types = assembly.GetTypes(); foreach (Type type in types) { ClientNodeTypeProto proto = GetNodeTypeProtoFromType(type); if (proto == null) { continue; } name2NodeProtoDict.Add(proto.name, proto); } return(name2NodeProtoDict); }
public void RemoveUnusedArgs(NodeProto nodeProto) { ClientNodeTypeProto proto = ExportNodeTypeConfig.GetNodeTypeProtoFromDll(nodeProto.name); List <string> unUsedList = new List <string>(); foreach (var item in nodeProto.args_dict) { if (!proto.new_args_desc.Exists(a => (a.name == item.Key))) { unUsedList.Add(item.Key); } } foreach (var item in unUsedList) { nodeProto.args_dict.Remove(item); } for (int i = 0; i < nodeProto.children.Count; i++) { RemoveUnusedArgs(nodeProto.children[i]); } }
public List <string> Filter(List <string> list, string text) { List <string> result1 = new List <string>(); string selectType; if (mEnumNodeTypeSelection == 0) { selectType = "All"; result1 = list; } else { selectType = Enum.GetName(typeof(NodeClassifyType), mEnumNodeTypeSelection - 1); foreach (var name in list) { ClientNodeTypeProto proto = ExportNodeTypeConfig.GetNodeTypeProtoFromDll(name); if (selectType == proto.classify) { result1.Add(name); } } } if (string.IsNullOrEmpty(text)) { return(result1); } List <string> result2 = new List <string>(); foreach (var name in result1) { ClientNodeTypeProto proto = ExportNodeTypeConfig.GetNodeTypeProtoFromDll(name); if (name.ToUpper().Contains(text.ToUpper()) || proto.describe.ToUpper().Contains(text.ToUpper())) { result2.Add(name); } } return(result2); }
private void DrawAllValue(ClientNodeTypeProto proto) { List <NodeFieldDesc> paramFieldList = GetFieldDescList(proto.new_args_desc, typeof(NodeFieldAttribute)); List <NodeFieldDesc> inputFieldList = GetFieldDescList(proto.new_args_desc, typeof(NodeInputAttribute)); List <NodeFieldDesc> outputFieldList = GetFieldDescList(proto.new_args_desc, typeof(NodeOutputAttribute)); mFoldParam = EditorGUILayout.Foldout(mFoldParam, "参数"); if (mFoldParam) { DrawProp(proto.name, paramFieldList, NodeParamType.None); } mFoldInput = EditorGUILayout.Foldout(mFoldInput, "输入"); if (mFoldInput) { DrawProp(proto.name, inputFieldList, NodeParamType.Input); } mFoldOutput = EditorGUILayout.Foldout(mFoldOutput, "输出"); if (mFoldOutput) { DrawProp(proto.name, outputFieldList, NodeParamType.Output); } }
private void DrawValueView() { if (mCurBehaviorNode == null || mCurBehaviorNode.Proto == null) { return; } if (GUILayout.Button("保存行为树")) { BehaviorManager.GetInstance().SaveAll(); } ClientNodeTypeProto proto = mCurBehaviorNode.Proto; GUILayout.Space(10f); GUILayout.Label("节点ID:" + mCurBehaviorNode.nodeId); GUILayout.Label("节点名:" + mCurBehaviorNode.name); GUILayout.Label("说明:"); GUILayout.Label(proto.describe); GUILayout.Label("描述:"); mCurBehaviorNode.describe = EditorGUILayout.TextArea(mCurBehaviorNode.describe, GUILayout.Height(50f)); DrawAllValue(proto); }
//节点配置 get set public ClientNodeTypeProto GetNodeTypeProto(string name) { ClientNodeTypeProto proto = ExportNodeTypeConfig.GetNodeTypeProtoFromDll(name); return(proto); }
private void DrawProp(string nodeName, List <NodeFieldDesc> fieldList, NodeParamType nodeParamType) { for (int i = 0; i < fieldList.Count; i++) { NodeFieldDesc desc = fieldList[i]; Type fieldType = ExportNodeTypeConfig.GetFieldType(nodeName, desc.name); ClientNodeTypeProto clientNode = ExportNodeTypeConfig.GetNodeTypeProtoFromDll(nodeName); object newValue = null; if (!mCurBehaviorNode.args_dict.ContainsKey(desc.name)) { mCurBehaviorNode.args_dict.Add(desc.name, new ValueBase()); } if (BehaviorTreeArgsDict.IsStringType(fieldType)) { if (nodeParamType == NodeParamType.Input) { newValue = InputEnumFieldValue(desc); } else if (nodeParamType == NodeParamType.Output && clientNode.classify == NodeClassifyType.Root.ToString()) { newValue = ConstTextFieldValue(desc); } else { newValue = TextFieldValue(desc); } } else if (BehaviorTreeArgsDict.IsFloatType(fieldType)) { newValue = FloatFieldValue(desc); } else if (BehaviorTreeArgsDict.IsDoubleType(fieldType)) { newValue = DoubletFieldValue(desc); } else if (BehaviorTreeArgsDict.IsIntType(fieldType)) { newValue = IntFieldValue(desc); } else if (BehaviorTreeArgsDict.IsLongType(fieldType)) { newValue = LongFieldValue(desc); } else if (BehaviorTreeArgsDict.IsBoolType(fieldType)) { newValue = BoolFieldValue(desc); } else if (BehaviorTreeArgsDict.IsObjectType(fieldType)) { newValue = ObjectFieldValue(desc); } else if (BehaviorTreeArgsDict.IsIntArrType(fieldType)) { newValue = IntArrFieldValue(desc); } else if (BehaviorTreeArgsDict.IsLongArrType(fieldType)) { newValue = LongArrFieldValue(desc); } else if (BehaviorTreeArgsDict.IsStringArrType(fieldType)) { newValue = StrArrFieldValue(desc); } else if (BehaviorTreeArgsDict.IsFloatArrType(fieldType)) { newValue = FloatArrFieldValue(desc); } else if (BehaviorTreeArgsDict.IsDoubleArrType(fieldType)) { newValue = DoubleArrFieldValue(desc); } else if (BehaviorTreeArgsDict.IsEnumType(fieldType)) { if (nodeParamType == NodeParamType.Input) { newValue = InputEnumFieldValue(desc); } else if (nodeParamType == NodeParamType.Output) { newValue = OutPutEnumFieldValue(desc); } else { newValue = EnumFieldValue(desc); } } else if (BehaviorTreeArgsDict.IsObjectArrayType(fieldType)) { newValue = ObjectArrFieldValue(desc); } else { Log.Error($"行为树节点暂时未支持此类型:{fieldType}!"); return; } mCurBehaviorNode.args_dict.SetKeyValueComp(fieldType, desc.name, newValue); } }
public string DrawSearchList() { List <string> targetList = new List <string>(); if (mSubWinType == SubWinType.CreateNode) { targetList = GraphDesigner.GetCanCreateList(); } else if (mSubWinType == SubWinType.ReplaceNode) { targetList = GraphDesigner.GetCanRepalceList(); } List <string> nodeNameList = Filter(targetList, mSearchNode); GUILayout.BeginHorizontal(); GUI.SetNextControlName("Search"); this.mSearchNode = GUILayout.TextField(this.mSearchNode, GUI.skin.FindStyle("ToolbarSeachTextField")); GUI.FocusControl("Search"); GUILayout.EndHorizontal(); // toolbarRect = new Rect(0f, 15f + 20, mWidth, 25f); Rect boxRect = new Rect(0f, toolbarRect.height, this.mWidth, (Screen.height - toolbarRect.height) - 21f + 10); GUILayout.BeginArea(toolbarRect, EditorStyles.toolbar); GUILayout.BeginHorizontal(); GUILayout.Label("Filter"); Array strArr = Enum.GetValues(typeof(NodeClassifyType)); List <string> strList = new List <string>(); strList.Add("All"); foreach (var str in strArr) { strList.Add(str.ToString()); } mEnumNodeTypeArr = strList.ToArray(); mEnumNodeTypeSelection = EditorGUILayout.Popup(mEnumNodeTypeSelection, mEnumNodeTypeArr); if (GUILayout.Button("Clear")) { ClearNodes(); } GUILayout.EndHorizontal(); GUILayout.EndArea(); // GUILayout.BeginArea(new Rect(0, 0, windowRect.width, windowRect.height)); float topSpace = 60; this.mTreeScrollPos = GUI.BeginScrollView(new Rect(0f, topSpace, windowRect.width, windowRect.height - topSpace), this.mTreeScrollPos, new Rect(0f, 0f, windowRect.width - 20f, nodeNameList.Count * 19), false, true); foreach (var name in nodeNameList) { ClientNodeTypeProto proto = ExportNodeTypeConfig.GetNodeTypeProtoFromDll(name); if (GUILayout.Button(name + $"({proto.describe})", GetButtonStyle())) { if (SubWinType.CreateNode == mSubWinType) { GraphDesigner.onCreateNode(name, Vector2.zero); } else if (SubWinType.ReplaceNode == mSubWinType) { GraphDesigner.onChangeNodeType(name, Vector2.zero); } BehaviorDesignerWindow.Instance.CloseSubWin(); } } GUI.EndScrollView(); GUILayout.EndArea(); return(""); }