From bb427c1bd2ea78082994eafda54c8f39e8da03b1 Mon Sep 17 00:00:00 2001 From: zc <1062808664@qq.com> Date: Sun, 27 Oct 2024 23:12:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E9=A2=98=E5=BA=93=E5=B7=A5?= =?UTF-8?q?=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GameScript/Editor/QuestionEditor.cs | 64 +++++++++++++++++++ .../GameScript/Editor/QuestionEditor.cs.meta | 3 + 2 files changed, 67 insertions(+) create mode 100644 Assets/DemoGame/GameScript/Editor/QuestionEditor.cs create mode 100644 Assets/DemoGame/GameScript/Editor/QuestionEditor.cs.meta diff --git a/Assets/DemoGame/GameScript/Editor/QuestionEditor.cs b/Assets/DemoGame/GameScript/Editor/QuestionEditor.cs new file mode 100644 index 0000000..d5d0352 --- /dev/null +++ b/Assets/DemoGame/GameScript/Editor/QuestionEditor.cs @@ -0,0 +1,64 @@ +using System.Collections.Generic; +using System.IO; +using Sirenix.OdinInspector; +using Sirenix.OdinInspector.Editor; +using UnityEditor; +using UnityEngine; +using ZC; + +namespace ZEditor +{ + public class QuestionEditor : OdinEditorWindow + { + [MenuItem("ZTools/QuestionEditor")] + private static void OpenWindow() + { + GetWindow().Show(); + } + + [FolderPath] public string savePath = "Assets/DemoGame/GameRes/Config"; + public string saveName; + private string path => $"{savePath}/{saveName}.asset"; + + public List AnswerDatas = new List(); + + [Button("加载")] + void LoadData(string fileName) + { + string filePath = $"{savePath}/{fileName}.asset"; + var loadAssetAtPath = AssetDatabase.LoadAssetAtPath(filePath); + AnswerDatas = loadAssetAtPath.AnswerDatas; + } + + [Button("保存")] + void SaveData() + { + if (string.IsNullOrEmpty(savePath)) + { + Debug.LogError("请填入正确路径!"); + return; + } + + if (string.IsNullOrEmpty(saveName)) + { + Debug.LogError("请填入正确文件名!"); + return; + } + + if (!File.Exists(path)) + { + var questionBankData = ScriptableObject.CreateInstance(); + questionBankData.AnswerDatas = new List(AnswerDatas); + AssetDatabase.CreateAsset(questionBankData, path); + } + else + { + var data = AssetDatabase.LoadAssetAtPath(path); + data.AnswerDatas = AnswerDatas; + } + + AssetDatabase.SaveAssets(); + saveName = string.Empty; + } + } +} \ No newline at end of file diff --git a/Assets/DemoGame/GameScript/Editor/QuestionEditor.cs.meta b/Assets/DemoGame/GameScript/Editor/QuestionEditor.cs.meta new file mode 100644 index 0000000..0cb1442 --- /dev/null +++ b/Assets/DemoGame/GameScript/Editor/QuestionEditor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 290ea4dab1c646dcbb9375d178a85f3f +timeCreated: 1730038626 \ No newline at end of file