protected override void Draw() { base.Draw(); if (ValueType != null) { Value = EditorDataFields.EditorDataField(Tips, Value, ValueType); } }
public void OnGUI() { _oldType = EditorDataFields.EditorDataField("旧的类型", _oldType); _newType = EditorDataFields.EditorDataField("新的类型", _newType); if (string.IsNullOrEmpty(_oldType) || string.IsNullOrEmpty(_newType)) { return; } using (new EditorHorizontalLayout("Box")) { if (GUILayout.Button("替换客户端")) { EditorUtility.DisplayDialog("错误", "功能未实现", "关闭"); } if (GUILayout.Button("替换服务器")) { if (!EditorUtility.DisplayDialog("警告", "修改后不能够回退,是否确认修改", "OK", "CANCEL")) { return; } string path = EditorTreeConfigHelper.Instance.Config.ServersPath; string[] files = Directory.GetFiles(path, "*.txt"); foreach (string file in files) { try { StreamReader reader = new StreamReader(file); string data = reader.ReadToEnd(); NodeProto p = MongoHelper.FromJson <NodeProto>(data); p = TypeReplace(_oldType, _newType, p); reader.Close(); StreamWriter writer = new StreamWriter(file); writer.Write(MongoHelper.ToJson(p)); writer.Close(); } catch (Exception err) { BehaviourTreeDebugPanel.Error($"文件({file})无法解析成行为树"); Log.Error(err); } } EditorUtility.DisplayDialog("信息", "替换完成", "OK"); } } }
public void OnGUI() { _v = EditorGUILayout.BeginScrollView(_v); foreach (var pair in _info2Name) { object oldValue = pair.Key.GetValue(_config); object value = EditorDataFields.EditorDataField(pair.Value, oldValue, pair.Key.FieldType); if (!oldValue.Equals(value)) { _isFix = true; } pair.Key.SetValue(_config, value); } EditorGUILayout.EndScrollView(); }
public void OnGUI() { _name = EditorDataFields.EditorDataField("名字", _name); using (new EditorHorizontalLayout()) { if (GUILayout.Button("搜索客户端")) { bool get = false; _goes.Clear(); _files.Clear(); foreach (NodeParam param in _nodes) { if (param.NodeType.Name == _name) { get = true; _selected = param; break; } } if (get) { List <string> paths = EditorResHelper.GetAllPath("Assets", true); foreach (string path in paths) { GameObject go = AssetDatabase.LoadAssetAtPath <GameObject>(path); BehaviorTreeConfig config = go.GetComponent <BehaviorTreeConfig>(); if (!config) { continue; } NodeProto p = config.RootNodeProto; Stack <NodeProto> stack = new Stack <NodeProto>(); stack.Push(p); while (stack.Count > 0) { NodeProto node = stack.Pop(); if (node.Name == _name) { _goes.Add(go); break; } foreach (NodeProto child in node.Children) { stack.Push(child); } } } } else { _selected = null; } } if (GUILayout.Button("搜索服务器")) { string path = EditorTreeConfigHelper.Instance.Config.ServersPath; bool get = false; _goes.Clear(); _files.Clear(); foreach (NodeParam param in _nodes) { if (param.NodeType.Name == _name) { get = true; _selected = param; break; } } if (get) { string[] files = Directory.GetFiles(path, "*.txt"); foreach (string file in files) { try { StreamReader reader = new StreamReader(file); string data = reader.ReadToEnd(); NodeProto p = MongoHelper.FromJson <NodeProto>(data); Queue <NodeProto> queue = new Queue <NodeProto>(); queue.Enqueue(p); while (queue.Count > 0) { NodeProto node = queue.Dequeue(); if (node.Name == _name) { _files.Add(file); break; } foreach (NodeProto child in node.Children) { queue.Enqueue(child); } } } catch (Exception err) { BehaviourTreeDebugPanel.Error($"文件({file})无法解析成行为树"); Log.Error(err); } } } } } if (_selected == null) { EditorGUILayout.LabelField("请输入节点名称,不需要命名空间"); return; } if (_goes.Count > 0) { EditorDataFields.EditorListDataField(_goes, 20); } else if (_files.Count > 0) { EditorDataFields.EditorListDataField(_files, 20); } }
protected override void Draw() { if (_node == null) { return; } using (new EditorVerticalLayout("Button")) { string nodeDesc = EditorGUILayout.TextField("Description", _node.NodeDesc, GUILayout.Height(50)); if (nodeDesc != _node.NodeDesc) { _node.NodeDesc = nodeDesc; OnDataChange?.Invoke(); } using (new EditorVerticalLayout("Button")) { GUI.SetNextControlName("强制测试用名"); foreach (ParamInfo param in _node.Fields) { GUI.SetNextControlName(param.Desc); param.DefaultValue = EditorDataFields.EditorDataField($"{param.Desc}({param.ParamType})", param.DefaultValue, param.ParamType); } } using (new EditorVerticalLayout("Button")) { EditorGUILayout.LabelField("Input"); foreach (ParamInfoInput param in _node.Inputs) { string[] datas; try { if (_typeIndexShow.TryGetValue(param, out datas)) { string[] shows = _typeIndexShow[param]; int index = EditorGUILayout.Popup($"{param.Desc}({param.InputType.Name})", _typeIndexSelection[param], shows); _typeIndexSelection[param] = index; if (shows[index] == NONE_SELECTED) { continue; } if (shows[0] == NONE_SELECTED) { --index; } var outp = _outputs[param.InputType][index]; if (param.Input != outp) { param.Input = outp; param.SrcInputStr = outp.OutputName; OnDataChange?.Invoke(); } } else { EditorGUILayout.LabelField($"Param required is not found.:{param.InputType}"); } } catch (NullReferenceException err) { Log.Error(err); } } } using (new EditorVerticalLayout("Button")) { EditorGUILayout.LabelField("Output"); foreach (ParamInfoOutput param in _node.Outputs) { string name = EditorDataFields.EditorDataField($"{param.Desc}({param.OutputType})", param.OutputName); if (name != param.OutputName) { param.OutputName = name; OnOutputNameChange?.Invoke(); } } } } }