|
5 | 5 | using System.Collections.Generic; |
6 | 6 | using Ecsact.Editor; |
7 | 7 |
|
| 8 | +[System.Serializable] |
| 9 | +struct MessageBase { |
| 10 | + public string type; |
| 11 | +} |
| 12 | + |
| 13 | +[System.Serializable] |
| 14 | +struct AlertMessage { |
| 15 | + public const string type = "alert"; |
| 16 | + public string content; |
| 17 | +} |
| 18 | + |
| 19 | +[System.Serializable] |
| 20 | +struct InfoMessage { |
| 21 | + public const string type = "info"; |
| 22 | + public string content; |
| 23 | +} |
| 24 | + |
| 25 | +[System.Serializable] |
| 26 | +struct ErrorMessage { |
| 27 | + public const string type = "error"; |
| 28 | + public string content; |
| 29 | +} |
| 30 | + |
| 31 | +[System.Serializable] |
| 32 | +struct WarningMessage { |
| 33 | + public const string type = "warning"; |
| 34 | + public string content; |
| 35 | +} |
| 36 | + |
| 37 | +[System.Serializable] |
| 38 | +struct SuccessMessage { |
| 39 | + public const string type = "success"; |
| 40 | + public string content; |
| 41 | +} |
| 42 | + |
| 43 | +[System.Serializable] |
| 44 | +struct ModuleMethodsMessage { |
| 45 | + [System.Serializable] |
| 46 | + public struct MethodInfo { |
| 47 | + public bool available; |
| 48 | + } |
| 49 | + |
| 50 | + public const string type = "module_methods"; |
| 51 | + public string module_name; |
| 52 | + public Dictionary<string, MethodInfo> methods; |
| 53 | +} |
| 54 | + |
8 | 55 | public static class EcsactRuntimeBuilder { |
9 | 56 |
|
10 | 57 | public struct Options { |
@@ -56,16 +103,50 @@ public static void Build |
56 | 103 | proc.OutputDataReceived += (_, ev) => { |
57 | 104 | var line = ev.Data; |
58 | 105 | if(!string.IsNullOrWhiteSpace(line)) { |
59 | | - Progress.SetDescription(progressId, line); |
60 | | - UnityEngine.Debug.Log(line); |
| 106 | + var baseMessage = JsonUtility.FromJson<MessageBase>(line); |
| 107 | + switch(baseMessage.type) { |
| 108 | + case AlertMessage.type: |
| 109 | + ReceiveMessage( |
| 110 | + progressId, |
| 111 | + JsonUtility.FromJson<AlertMessage>(line) |
| 112 | + ); |
| 113 | + break; |
| 114 | + case InfoMessage.type: |
| 115 | + ReceiveMessage( |
| 116 | + progressId, |
| 117 | + JsonUtility.FromJson<InfoMessage>(line) |
| 118 | + ); |
| 119 | + break; |
| 120 | + case ErrorMessage.type: |
| 121 | + ReceiveMessage( |
| 122 | + progressId, |
| 123 | + JsonUtility.FromJson<ErrorMessage>(line) |
| 124 | + ); |
| 125 | + break; |
| 126 | + case WarningMessage.type: |
| 127 | + ReceiveMessage( |
| 128 | + progressId, |
| 129 | + JsonUtility.FromJson<WarningMessage>(line) |
| 130 | + ); |
| 131 | + break; |
| 132 | + case SuccessMessage.type: |
| 133 | + ReceiveMessage( |
| 134 | + progressId, |
| 135 | + JsonUtility.FromJson<SuccessMessage>(line) |
| 136 | + ); |
| 137 | + break; |
| 138 | + case ModuleMethodsMessage.type: |
| 139 | + ReceiveMessage( |
| 140 | + progressId, |
| 141 | + JsonUtility.FromJson<ModuleMethodsMessage>(line) |
| 142 | + ); |
| 143 | + break; |
| 144 | + } |
61 | 145 | } |
62 | 146 | }; |
63 | 147 |
|
64 | 148 | proc.Exited += (_, _) => { |
65 | 149 | if(proc.ExitCode != 0) { |
66 | | - UnityEngine.Debug.LogError( |
67 | | - $"ecsact_rtb exited with code {proc.ExitCode}" |
68 | | - ); |
69 | 150 | Progress.Finish(progressId, Progress.Status.Failed); |
70 | 151 | } else { |
71 | 152 | Progress.Finish(progressId, Progress.Status.Succeeded); |
@@ -104,13 +185,65 @@ public static void Build |
104 | 185 | FileUtil.GetUniqueTempPathInProject() |
105 | 186 | ); |
106 | 187 |
|
107 | | - UnityEngine.Debug.Log(proc.StartInfo.FileName); |
108 | | - UnityEngine.Debug.Log(proc.StartInfo.Arguments); |
109 | | - UnityEngine.Debug.Log($"CWD: {System.IO.Directory.GetCurrentDirectory()}"); |
110 | | - |
111 | 188 | Progress.Report(progressId, 0.1f); |
112 | 189 | proc.Start(); |
113 | 190 | proc.BeginOutputReadLine(); |
114 | 191 | proc.BeginErrorReadLine(); |
115 | 192 | } |
| 193 | + |
| 194 | + private static void ReceiveMessage |
| 195 | + ( int progressId |
| 196 | + , AlertMessage message |
| 197 | + ) |
| 198 | + { |
| 199 | + EditorUtility.DisplayDialog( |
| 200 | + title: "Ecsact Runtime Builder", |
| 201 | + message: message.content, |
| 202 | + ok: "ok" |
| 203 | + ); |
| 204 | + } |
| 205 | + |
| 206 | + private static void ReceiveMessage |
| 207 | + ( int progressId |
| 208 | + , InfoMessage message |
| 209 | + ) |
| 210 | + { |
| 211 | + Progress.SetDescription(progressId, message.content); |
| 212 | + UnityEngine.Debug.Log(message.content); |
| 213 | + } |
| 214 | + |
| 215 | + private static void ReceiveMessage |
| 216 | + ( int progressId |
| 217 | + , ErrorMessage message |
| 218 | + ) |
| 219 | + { |
| 220 | + Progress.SetDescription(progressId, message.content); |
| 221 | + UnityEngine.Debug.LogError(message.content); |
| 222 | + } |
| 223 | + |
| 224 | + private static void ReceiveMessage |
| 225 | + ( int progressId |
| 226 | + , WarningMessage message |
| 227 | + ) |
| 228 | + { |
| 229 | + Progress.SetDescription(progressId, message.content); |
| 230 | + UnityEngine.Debug.LogWarning(message.content); |
| 231 | + } |
| 232 | + |
| 233 | + private static void ReceiveMessage |
| 234 | + ( int progressId |
| 235 | + , SuccessMessage message |
| 236 | + ) |
| 237 | + { |
| 238 | + Progress.SetDescription(progressId, message.content); |
| 239 | + UnityEngine.Debug.Log(message.content); |
| 240 | + } |
| 241 | + |
| 242 | + private static void ReceiveMessage |
| 243 | + ( int progressId |
| 244 | + , ModuleMethodsMessage message |
| 245 | + ) |
| 246 | + { |
| 247 | + |
| 248 | + } |
116 | 249 | } |
0 commit comments