14 public class ScenarioConverterWindow : EditorWindow
22 [MenuItem(
"Window/PIXO/Scenario Converter")]
23 public static void Open()
25 GetWindow(typeof(ScenarioConverterWindow),
false,
"Scenario Converter");
32 _stepsData = EditorGUILayout.ObjectField(
"Source Step Data", _stepsData, typeof(
StepsData)) as
StepsData;
36 _quizData = EditorGUILayout.ObjectField(
"Source Quiz Data", _quizData, typeof(
QuizData)) as
QuizData;
38 if (GUILayout.Button(
"Convert"))
40 AddScenario(_stepsData.name, _stepsData, _voiceOverData, _quizData);
46 if (!
string.IsNullOrEmpty(name))
48 var scenarioPath = $
"{ScenarioEditorWindow.ScenariosRootPath}/{_module.name}/{name}";
50 if (!Directory.Exists(scenarioPath))
54 var scenarioInfoPath = $
"{scenarioPath}/{name}ScenarioInfo.asset";
55 var scenarioStepDataPath = $
"{scenarioPath}/{name}StepData.asset";
56 var scenarioStepsPath = $
"{scenarioPath}/Steps";
57 Directory.CreateDirectory(scenarioPath);
58 Directory.CreateDirectory(scenarioStepsPath);
61 stepsDataSO.listOfSteps =
new List<StepItemSO>();
64 for (
int i = 0; i < stepsData.
listOfSteps.Count; i++)
68 if (!
string.IsNullOrEmpty(stepId))
70 if (!stepsDataSO.listOfSteps.Any(d => d.stepID.Equals(stepId)))
72 var stepPath = $
"{scenarioStepsPath}/{stepId}.asset";
77 stepItem.stepID = stepId;
79 stepItem.functionsStep =
80 new List<StepFunction>(stepsData.
listOfSteps[i].functionsStep);
82 stepItem.waitForUserAction = stepsData.
listOfSteps[i].waitForUserAction;
84 stepItem.voiceOverIDWrongAction =
87 stepItem.nextSteps =
new List<string>(stepsData.
listOfSteps[i].nextSteps);
89 AssetDatabase.CreateAsset(stepItem, stepPath);
91 stepsDataSO.listOfSteps.Add(stepItem);
96 EditorUtility.DisplayDialog(
"Add Step Error",
"Step id exist!",
"ok");
101 EditorUtility.DisplayDialog(
"Add Step Error",
"Step id empty!",
"ok");
105 AssetDatabase.CreateAsset(stepsDataSO, scenarioStepDataPath);
108 info.StepsDataLink = stepsDataSO;
109 info.VoiceOverData = voData;
110 info.QuizData = quizData;
111 AssetDatabase.CreateAsset(info, scenarioInfoPath);
114 EditorUtility.SetDirty(_module);
115 ScenarioEditorWindow.Reinit();
120 EditorUtility.DisplayDialog(
"Add Scenario Error",
"Scenario already exist!",
"ok");
125 EditorUtility.DisplayDialog(
"Add Scenario Error",
"Scenario name is empty",
"ok");