-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMasterDataWindow.cs
More file actions
213 lines (185 loc) · 8.57 KB
/
MasterDataWindow.cs
File metadata and controls
213 lines (185 loc) · 8.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
using System;
using System.Linq;
using System.Reflection;
using System.Text;
using Game.Library.Shared.MasterData;
using UnityEditor;
using UnityEngine;
namespace Game.Editor
{
public class MasterDataWindow : EditorWindow
{
// 1.MemoryTable手動作成
// 2.MemoryTableからTsv新規作成(仮データ)または更新
// 3.Tsvからマスターデータバイナリ作成
// 4.Addressableに登録
// 5.Addressable経由でバイナリをロードしてデータベース構築(⇒MasterDataServiceでアプリ起動時に読み込む)
// EX.MySql定義情報からMemoryTableクラスを自動生成できるツールを検討(やりすぎ感)
[MenuItem("Project/MasterMemory/MasterDataWindow")]
public static void Open()
{
var w = GetWindow<MasterDataWindow>(nameof(MasterDataWindow));
w.UpdateMemoryTables();
}
[MenuItem("Project/MasterMemory/GenerateMasterDataBinary")]
public static void GenerateBinary()
{
MasterDataHelper.GenerateMasterDataBinary();
Debug.Log("[MasterDataWindow] MasterDataBinary generated.");
}
private void UpdateMemoryTables()
{
_memoryTables = MasterDataHelper.GetMemoryTableTypes();
Repaint();
}
private Type[] _memoryTables = Array.Empty<Type>();
private Type _memoryTable;
private int _selectedIndex;
private bool _replaceToggle = true;
private bool _backupToggle;
private Vector2 _tableScrollPosition = Vector2.zero;
private Vector2 _logScrollPosition = Vector2.zero;
private StringBuilder _logBuilder = new();
private char _logSeparator = '\n';
private void OnGUI()
{
GUILayout.Space(10);
using (new EditorGUILayout.HorizontalScope())
{
using (new EditorGUILayout.VerticalScope())
{
GUILayout.Label("MemoryTables");
using (new EditorGUI.DisabledScope(!_memoryTables.Any()))
{
using (var scroller = new EditorGUILayout.ScrollViewScope(_tableScrollPosition, "box"))
{
_tableScrollPosition = scroller.scrollPosition;
var tableNames = _memoryTables.Select(x => x.Name).ToArray();
foreach (var tableName in tableNames)
{
EditorGUILayout.SelectableLabel($"{tableName}");
}
}
}
}
using (new EditorGUILayout.VerticalScope(GUILayout.Width(360)))
{
GUILayout.Label("マスタデータ作成メニュー");
using (new EditorGUI.DisabledScope(!_memoryTables.Any()))
{
var options = new[] { "作成&更新するマスタを選択してください" }
.Concat(_memoryTables.Select(x => x.Name))
.ToArray();
_selectedIndex = EditorGUILayout.Popup(_selectedIndex, options);
if (_selectedIndex > 0 && _memoryTables.Any())
{
_memoryTable = _memoryTables[_selectedIndex - 1];
}
_replaceToggle = EditorGUILayout.ToggleLeft("既に存在するTsvデータを引継ぎ、最新のテーブル定義情報で更新する", _replaceToggle);
_backupToggle = EditorGUILayout.ToggleLeft("更新前にバックアップを作成", _backupToggle);
using (new EditorGUI.DisabledScope(_selectedIndex <= 0))
{
// GUILayout.FlexibleSpace();
if (GUILayout.Button("Tsv作成&更新"))
{
AppendLog($"Tsv作成: {_memoryTable.Name}");
MasterDataHelper.GenerateTsv(_memoryTable, _replaceToggle, _backupToggle);
}
}
if (GUILayout.Button("Tsv一括作成&更新"))
{
AppendLog($"Tsv一括作成: {_memoryTables.Length}件");
MasterDataHelper.GenerateTsvAll(_replaceToggle, _replaceToggle);
}
if (GUILayout.Button("マスタデータバイナリ作成"))
{
AppendLog($"マスタデータバイナリ作成: {_memoryTables.Length}件");
MasterDataHelper.GenerateMasterDataBinary();
}
}
if (GUILayout.Button("マスタデータバイナリ読込テスト"))
{
AppendLog($"マスタデータバイナリ読込: {_memoryTables.Length}件");
MasterDataBinaryWindow.Open();
}
if (GUILayout.Button("最新状態を取得"))
{
UpdateMemoryTables();
AppendLog($"最新状態を取得 Tsv件数: {_memoryTables.Length}");
}
using (new EditorGUI.DisabledScope(_logBuilder.Length <= 0))
{
using (var scroller = new EditorGUILayout.ScrollViewScope(_logScrollPosition, "box"))
{
_logScrollPosition = scroller.scrollPosition;
var logs = _logBuilder.ToString().Split('\r', '\n');
foreach (var log in logs)
{
EditorGUILayout.LabelField($"{log}");
}
}
}
}
}
GUILayout.Space(10);
}
private void AppendLog(string log)
{
_logBuilder.Append(DateTime.Now + " " + log + _logSeparator);
}
}
public class MasterDataBinaryWindow : EditorWindow
{
[MenuItem("Project/MasterMemory/MasterDataBinaryEditorWindow")]
public static void Open()
{
var w = GetWindow<MasterDataBinaryWindow>(nameof(MasterDataBinaryWindow));
w.UpdateMemoryDatabase();
}
private void UpdateMemoryDatabase()
{
_memoryDatabase = MasterDataHelper.LoadMasterDataBinary();
Repaint();
}
private MemoryDatabase _memoryDatabase;
private Vector2 _tableScrollPosition;
private void OnGUI()
{
GUILayout.Space(10);
using (new EditorGUILayout.HorizontalScope())
{
using (new EditorGUILayout.VerticalScope())
{
GUILayout.Label("MemoryDatabase");
using (new EditorGUI.DisabledScope(_memoryDatabase is null))
{
using (var scroller = new EditorGUILayout.ScrollViewScope(_tableScrollPosition, "box"))
{
_tableScrollPosition = scroller.scrollPosition;
if (_memoryDatabase != null)
{
var tables = _memoryDatabase
.GetType()
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.ToDictionary(x => x.PropertyType, x => x.GetValue(_memoryDatabase));
foreach (var (type, instance) in tables)
{
var count = type.GetProperty("Count")?.GetValue(instance);
EditorGUILayout.SelectableLabel($"テーブル名: {type.Name} データ件数: {count}");
}
}
}
}
if (GUILayout.Button("マスタデータバイナリ読込テスト"))
{
UpdateMemoryDatabase();
}
}
using (new EditorGUILayout.VerticalScope(GUILayout.Width(320)))
{
}
}
GUILayout.Space(10);
}
}
}