完成题库工具
parent
5037898610
commit
bb427c1bd2
|
@ -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<QuestionEditor>().Show();
|
||||
}
|
||||
|
||||
[FolderPath] public string savePath = "Assets/DemoGame/GameRes/Config";
|
||||
public string saveName;
|
||||
private string path => $"{savePath}/{saveName}.asset";
|
||||
|
||||
public List<AnswerData> AnswerDatas = new List<AnswerData>();
|
||||
|
||||
[Button("加载")]
|
||||
void LoadData(string fileName)
|
||||
{
|
||||
string filePath = $"{savePath}/{fileName}.asset";
|
||||
var loadAssetAtPath = AssetDatabase.LoadAssetAtPath<QuestionBankData>(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>();
|
||||
questionBankData.AnswerDatas = new List<AnswerData>(AnswerDatas);
|
||||
AssetDatabase.CreateAsset(questionBankData, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
var data = AssetDatabase.LoadAssetAtPath<QuestionBankData>(path);
|
||||
data.AnswerDatas = AnswerDatas;
|
||||
}
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
saveName = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 290ea4dab1c646dcbb9375d178a85f3f
|
||||
timeCreated: 1730038626
|
Loading…
Reference in New Issue