/// <summary> /// 渲染窗口 /// </summary> public static void OnGUI(DataDrivenEditor _editor) { Vector2 size = _editor.position.size; float h = size.y * 0.5f; float w = size.x * 0.5f; bool isPress = GUI.Button(new Rect(new Vector2(w - 50, h - 70), new Vector2(100, 60)), new GUIContent("打开")); if (isPress) { string path = EditorUtility.OpenFilePanel("选择您要打开的文件", _editor.ConfigPath, Fliter); if (path != null && path.Length > 0) { _editor.FilePath = path; string content = File.ReadAllText(path); _editor.ParseContent(content); } else { _editor.ShowNotification(new GUIContent("用户取消操作")); } } isPress = GUI.Button(new Rect(new Vector2(w - 50, h + 10), new Vector2(100, 60)), new GUIContent("创建")); if (isPress) { string defaultName = System.DateTime.Now.Ticks.ToString(); string path = EditorUtility.SaveFilePanelInProject("您要保存的文件", defaultName, Fliter, "message"); if (path != null && path.Length > 0) { string _p = Application.dataPath.Replace("Assets", "") + path; _editor.FilePath = _p; string _name = FileUtil.GetFileName(_p); string _content = GenerateDefaultContent(_name); FileUtil.CreateTextFile(_p, _content); _editor.ParseContent(_content); } else { _editor.ShowNotification(new GUIContent("用户取消操作")); } } }
/// <summary> /// 展示驱动数据 /// </summary> /// <param name="dataDrivenEditor">编辑器</param> /// <param name="ability">驱动</param> public static void OnGUI(DataDrivenEditor dataDrivenEditor, BaseDriven ability) { string _type = ability.GetType().ToString(); _type = _type.Replace("DataDriven.", ""); dtype = (DDConfig.DrivenType)System.Enum.Parse(typeof(DDConfig.DrivenType), _type); _editor = SwitchDrawDrivenEditor(); EditorGUILayout.BeginVertical(); if (EditorGUILayout.DropdownButton(new UnityEngine.GUIContent("保存"), UnityEngine.FocusType.Keyboard)) { SaveAbility(dataDrivenEditor, ability); } // 文件名 EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("文件名:"); EditorGUILayout.LabelField(ability.Name); EditorGUILayout.EndHorizontal(); // 驱动类型 EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("驱动类型:"); int iType = EditorGUILayout.Popup((int)dtype, DDConfig.DrivenTypeName); EditorGUILayout.EndHorizontal(); if (_editor != null) { _editor.OnGUI(ability, dataDrivenEditor); } EditorGUILayout.EndVertical(); if (iType != (int)dtype) { // 转换类型,可能会丢失数据 if (EditorUtility.DisplayDialog("转换类型", "转换类型可能会引起数据丢失!!确定需要转换?", "确定", "取消")) { // 关闭展示 if (_editor != null) { _editor.CloseDrawDriven(); } dataDrivenEditor.ChangeDrivenTypeTo((DDConfig.DrivenType)iType); } else { dataDrivenEditor.ShowNotification(new UnityEngine.GUIContent("取消转换")); } } }