Documentation for the Unity C# Library
Loading...
Searching...
No Matches
ScenarioConverterWindow.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.IO;
3using System.Linq;
4using PixoVR.Audio;
5using UnityEngine;
6#if UNITY_EDITOR
7using UnityEditor;
8#endif
9
10
12{
13#if UNITY_EDITOR
14 public class ScenarioConverterWindow : EditorWindow
15 {
16 private StepsData _stepsData;
17 private ScenariosDataSO _module;
18
19 public VoiceOverData _voiceOverData;
20 public QuizData _quizData;
21
22 [MenuItem("Window/PIXO/Scenario Converter")]
23 public static void Open()
24 {
25 GetWindow(typeof(ScenarioConverterWindow), false, "Scenario Converter");
26 }
27
28 private void OnGUI()
29 {
30 _module = EditorGUILayout.ObjectField("Target Module", _module, typeof(ScenariosDataSO)) as ScenariosDataSO;
31
32 _stepsData = EditorGUILayout.ObjectField("Source Step Data", _stepsData, typeof(StepsData)) as StepsData;
33
34 _voiceOverData = EditorGUILayout.ObjectField("Source VO Data", _voiceOverData, typeof(VoiceOverData)) as VoiceOverData;
35
36 _quizData = EditorGUILayout.ObjectField("Source Quiz Data", _quizData, typeof(QuizData)) as QuizData;
37
38 if (GUILayout.Button("Convert"))
39 {
40 AddScenario(_stepsData.name, _stepsData, _voiceOverData, _quizData);
41 }
42 }
43
44 private void AddScenario(string name, StepsData stepsData, VoiceOverData voData, QuizData quizData)
45 {
46 if (!string.IsNullOrEmpty(name))
47 {
48 var scenarioPath = $"{ScenarioEditorWindow.ScenariosRootPath}/{_module.name}/{name}";
49
50 if (!Directory.Exists(scenarioPath))
51 {
52 if (_module != null)
53 {
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);
59
60 var stepsDataSO = ScriptableObject.CreateInstance<StepsDataSO>();
61 stepsDataSO.listOfSteps = new List<StepItemSO>();
62
63
64 for (int i = 0; i < stepsData.listOfSteps.Count; i++)
65 {
66 var stepId = stepsData.listOfSteps[i].stepID;
67
68 if (!string.IsNullOrEmpty(stepId))
69 {
70 if (!stepsDataSO.listOfSteps.Any(d => d.stepID.Equals(stepId)))
71 {
72 var stepPath = $"{scenarioStepsPath}/{stepId}.asset";
73
74 if (_module != null)
75 {
76 var stepItem = ScriptableObject.CreateInstance<StepItemSO>();
77 stepItem.stepID = stepId;
78
79 stepItem.functionsStep =
80 new List<StepFunction>(stepsData.listOfSteps[i].functionsStep);
81
82 stepItem.waitForUserAction = stepsData.listOfSteps[i].waitForUserAction;
83
84 stepItem.voiceOverIDWrongAction =
85 stepsData.listOfSteps[i].voiceOverIDWrongAction;
86
87 stepItem.nextSteps = new List<string>(stepsData.listOfSteps[i].nextSteps);
88
89 AssetDatabase.CreateAsset(stepItem, stepPath);
90
91 stepsDataSO.listOfSteps.Add(stepItem);
92 }
93 }
94 else
95 {
96 EditorUtility.DisplayDialog("Add Step Error", "Step id exist!", "ok");
97 }
98 }
99 else
100 {
101 EditorUtility.DisplayDialog("Add Step Error", "Step id empty!", "ok");
102 }
103 }
104
105 AssetDatabase.CreateAsset(stepsDataSO, scenarioStepDataPath);
106
107 var info = ScriptableObject.CreateInstance<ScenarioInfoSO>();
108 info.StepsDataLink = stepsDataSO;
109 info.VoiceOverData = voData;
110 info.QuizData = quizData;
111 AssetDatabase.CreateAsset(info, scenarioInfoPath);
112
113 _module.listOfScenariosInfo.Add(info);
114 EditorUtility.SetDirty(_module);
115 ScenarioEditorWindow.Reinit();
116 }
117 }
118 else
119 {
120 EditorUtility.DisplayDialog("Add Scenario Error", "Scenario already exist!", "ok");
121 }
122 }
123 else
124 {
125 EditorUtility.DisplayDialog("Add Scenario Error", "Scenario name is empty", "ok");
126 }
127 }
128 }
129#endif
130}
Data that stores all information about voice overs.
List< ScenarioInfoSO > listOfScenariosInfo
List< StepItem > listOfSteps
Definition StepsData.cs:13