net.dreditor.editor.utility.converting 0.0.0-stage → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,105 @@
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ using DREditor.Characters;
3
+ using DREditor.EventObjects;
4
+ using DREditor.Processables;
5
+ using UnityEditor;
6
+ using UnityEngine;
7
+
8
+ namespace DREditor.Editor.Utility.Converting
9
+ {
10
+ /// <summary>
11
+ ///
12
+ /// </summary>
13
+ public static class ActorConversion
14
+ {
15
+ /// <summary>
16
+ ///
17
+ /// </summary>
18
+ [MenuItem("DREditor/Convert/Actors/Update Selected Actor Display Names.")]
19
+ public static void UpdateName()
20
+ {
21
+ CharacterDatabase database = DatabaseUtility.LoadDatabase<CharacterDatabase>();
22
+
23
+ foreach (Character character in database.Characters)
24
+ foreach (var obj in Selection.objects)
25
+ if (obj is GameObject gameObject && gameObject.name == character.FirstName)
26
+ UpdateObject(character, gameObject);
27
+ }
28
+
29
+ /// <summary>
30
+ ///
31
+ /// </summary>
32
+ /// <param name="character"></param>
33
+ /// <param name="go"></param>
34
+ static void UpdateObject(Character character, GameObject go)
35
+ {
36
+ if (go.TryGetComponent<INameDisplayable>(out var component))
37
+ component.DisplayName = character.FirstName + " " + character.LastName;
38
+
39
+ EditorUtility.SetDirty(go);
40
+
41
+ AssetDatabase.SaveAssets();
42
+ }
43
+
44
+
45
+ /// <summary>
46
+ ///
47
+ /// </summary>
48
+ [MenuItem("DREditor/Convert/Actors/Update Selected Actor Colliders.")]
49
+ public static void UpdateColliders()
50
+ {
51
+ foreach (var obj in Selection.objects)
52
+ if (obj is GameObject go)
53
+ UpdateCollider(go);
54
+ }
55
+
56
+ /// <summary>
57
+ ///
58
+ /// </summary>
59
+ /// <param name="gameObject"></param>
60
+ static void UpdateCollider(GameObject gameObject)
61
+ {
62
+ BoxCollider parentCollider = gameObject.GetComponent<BoxCollider>();
63
+
64
+ BoxCollider childCollider = gameObject.transform.GetChild(0).GetComponent<BoxCollider>();
65
+
66
+ if (!parentCollider || !childCollider || parentCollider == childCollider)
67
+ {
68
+ UnityEngine.Debug.LogWarning("ALERT: Invalid collider setup. Either your missing a parent or child collider, or " +
69
+ "the child and parent colliders are the same, which is not allowed.");
70
+
71
+ return;
72
+ }
73
+
74
+ Undo.RecordObject(parentCollider, "Copy Collider From Child (Apply Scale)");
75
+
76
+ Transform parentTransform = parentCollider.transform;
77
+
78
+ Transform childTransform = childCollider.transform;
79
+
80
+ var bounds = new Bounds(
81
+ childTransform.TransformPoint(childCollider.center),
82
+ Vector3.Scale(childCollider.size, childTransform.lossyScale)
83
+ );
84
+
85
+ Vector3 localCenter = parentTransform.InverseTransformPoint(bounds.center);
86
+
87
+ Vector3 localSize = Vector3.Scale(bounds.size, InverseScale(parentTransform.lossyScale));
88
+
89
+ parentCollider.center = localCenter;
90
+
91
+ parentCollider.size = localSize;
92
+
93
+ EditorUtility.SetDirty(parentCollider);
94
+
95
+ UnityEngine.Debug.Log($"Copied scaled collider from '{childCollider.name}' to '{parentCollider.name}'.");
96
+ }
97
+
98
+ /// <summary>
99
+ ///
100
+ /// </summary>
101
+ /// <param name="vector"></param>
102
+ /// <returns></returns>
103
+ static Vector3 InverseScale(Vector3 vector) => new(1f / vector.x, 1f / vector.y, 1f / vector.z);
104
+ }
105
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 1a1644d210669e74190d5f2d359f28ea
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,438 @@
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ using DREditor.Doors;
3
+ using DREditor.Editor;
4
+ using DREditor.Progressing;
5
+ using DREditor.RoomBuilding;
6
+ using DREditor.RoomBuilding.Implementation;
7
+ using DREditor.RoomBuilding.Implementation.Actors;
8
+ using DREditor.RoomBuilding.Old;
9
+ using DREditor.SubAreas;
10
+ using DREditor.Talkables;
11
+ using DREditor.Triggers;
12
+ using System.Collections.Generic;
13
+ using System.IO;
14
+ using UnityEditor;
15
+ using UnityEngine;
16
+
17
+ namespace DREditor.Editor.Utility.Converting
18
+ {
19
+ /// <summary>
20
+ ///
21
+ /// </summary>
22
+ public class ConvertRoomDataRegion
23
+ {
24
+ /// <summary>
25
+ ///
26
+ /// </summary>
27
+ protected ProgressionDatabase pDB;
28
+
29
+ /// <summary>
30
+ ///
31
+ /// </summary>
32
+ protected RoomBuilder currentRoomBuilder;
33
+
34
+ /// <summary>
35
+ ///
36
+ /// </summary>
37
+ protected RoomSection currentRoomSection;
38
+
39
+ /// <summary>
40
+ ///
41
+ /// </summary>
42
+ protected RoomData currentRoomData;
43
+
44
+ /// <summary>
45
+ ///
46
+ /// </summary>
47
+ protected RoomStateBuilder currentRoomStateBuilder;
48
+
49
+ /// <summary>
50
+ ///
51
+ /// </summary>
52
+ protected RoomStateSection currentRoomStateSection;
53
+
54
+
55
+ [MenuItem("DREditor/Convert/Convert First Room Data Builder")]
56
+ public static void ConvertFirstRoomDataBuilders() => new ConvertRoomDataRegion().ConvertFirst();
57
+
58
+ /// <summary>
59
+ ///
60
+ /// </summary>
61
+ public virtual void ConvertFirst()
62
+ {
63
+ var roomBuilders = BuilderUtility.FindAssetsByType<RoomBuilder>();
64
+
65
+ currentRoomBuilder = roomBuilders[0];
66
+
67
+ CreateRoomStateBuilder(roomBuilders[0]);
68
+ }
69
+
70
+
71
+ [MenuItem("DREditor/Convert/Convert All Room Data Builders")]
72
+ public static void ConvertAllRoomDataBuilders() => new ConvertRoomDataRegion().ConvertAll();
73
+
74
+ /// <summary>
75
+ ///
76
+ /// </summary>
77
+ public virtual void ConvertAll()
78
+ {
79
+ if (!DatabaseUtility.InitializeDatabase(pDB, out pDB))
80
+ return;
81
+
82
+ var roomBuilders = BuilderUtility.FindAssetsByType<RoomBuilder>();
83
+
84
+ foreach (var roomBuilder in roomBuilders)
85
+ CreateRoomStateBuilder(roomBuilder);
86
+ }
87
+
88
+ /// <summary>
89
+ ///
90
+ /// </summary>
91
+ /// <param name="roomBuilder"></param>
92
+ public virtual void CreateRoomStateBuilder(RoomBuilder roomBuilder)
93
+ {
94
+ currentRoomBuilder = roomBuilder;
95
+
96
+ InitializeBuilder(roomBuilder.name.Replace(".asset", ""));
97
+ }
98
+
99
+ /// <summary>
100
+ ///
101
+ /// </summary>
102
+ /// <param name="builderName"></param>
103
+ protected virtual void InitializeBuilder(string builderName)
104
+ {
105
+ var builderAsset = ScriptableObject.CreateInstance<RoomStateBuilder>();
106
+
107
+ string buildFolderPath = "Assets/RoomBuilding";
108
+
109
+ if (!ConvertUtility.ProjectFolderExists(buildFolderPath))
110
+ AssetDatabase.CreateFolder("Assets", "RoomBuilding");
111
+
112
+ string buildFolder = AssetDatabase.CreateFolder(buildFolderPath, builderName);
113
+
114
+ if (buildFolder == "")
115
+ {
116
+ UnityEngine.Debug.LogWarning("Could not create folder. Canceling Initialization.");
117
+
118
+ UnityEngine.Debug.Log("Builder Path: " + buildFolderPath);
119
+
120
+ return;
121
+ }
122
+
123
+ string newFolderPath = AssetDatabase.GUIDToAssetPath(buildFolder);
124
+
125
+ AssetDatabase.CreateAsset(builderAsset, newFolderPath + "/" + builderName + ".asset");
126
+
127
+ AssetDatabase.SaveAssets();
128
+
129
+ EditorUtility.SetDirty(builderAsset);
130
+
131
+ InitializeSections(builderAsset);
132
+ }
133
+
134
+ /// <summary>
135
+ ///
136
+ /// </summary>
137
+ /// <param name="builder"></param>
138
+ protected virtual void InitializeSections(RoomStateBuilder builder)
139
+ {
140
+ foreach (Chapter chapter in pDB.Chapters)
141
+ {
142
+ var sectionAsset = ScriptableObject.CreateInstance<RoomStateSection>();
143
+
144
+ sectionAsset.SetChapter(chapter);
145
+
146
+
147
+ string newAssetPath = CreateSectionAssetPath(chapter, builder);
148
+
149
+ if (newAssetPath == "")
150
+ return;
151
+
152
+
153
+ AssetDatabase.CreateAsset(sectionAsset, newAssetPath);
154
+
155
+ AssetDatabase.SaveAssets();
156
+
157
+ EditorUtility.SetDirty(sectionAsset);
158
+
159
+ builder.Sections.Add(sectionAsset);
160
+
161
+ EditorUtility.SetDirty(builder);
162
+ }
163
+
164
+ currentRoomStateBuilder = builder;
165
+
166
+ CreateDataAssets();
167
+ }
168
+
169
+ /// <summary>
170
+ ///
171
+ /// </summary>
172
+ /// <param name="chapter"></param>
173
+ /// <param name="builder"></param>
174
+ /// <returns></returns>
175
+ protected virtual string CreateSectionAssetPath(Chapter chapter, RoomStateBuilder builder)
176
+ {
177
+ string builderPath = AssetDatabase.GetAssetPath(builder);
178
+
179
+ string builderPrefix = builder.name.Replace(".asset", "");
180
+
181
+ string sectionPath = builderPath.Replace("/" + builder.name + ".asset", "");
182
+
183
+ string sectionFolderName = builderPrefix + $"_{pDB.GetChapterIndex(chapter)}";
184
+
185
+ string sectionFolder = AssetDatabase.CreateFolder(sectionPath, sectionFolderName);
186
+
187
+ if (sectionFolder == "")
188
+ {
189
+ UnityEngine.Debug.LogWarning("Could not create folder. Canceling Initialization.");
190
+
191
+ UnityEngine.Debug.Log("Builder Path: " + sectionPath);
192
+
193
+ return "";
194
+ }
195
+
196
+ string newFolderPath = AssetDatabase.GUIDToAssetPath(sectionFolder);
197
+
198
+ return newFolderPath + "/" + builderPrefix + $"_{pDB.GetChapterIndex(chapter)}.asset";
199
+ }
200
+
201
+ /// <summary>
202
+ ///
203
+ /// </summary>
204
+ protected virtual void CreateDataAssets()
205
+ {
206
+ foreach (var section in currentRoomBuilder.Sections)
207
+ {
208
+ currentRoomSection = section;
209
+
210
+ currentRoomStateSection = currentRoomStateBuilder.Sections[currentRoomBuilder.Sections.IndexOf(section)];
211
+
212
+ ConvertRoom();
213
+ }
214
+
215
+ for (int i = 0; i < currentRoomBuilder.Shells.Count; i++)
216
+ CreateShellSave(i);
217
+ }
218
+
219
+ /// <summary>
220
+ ///
221
+ /// </summary>
222
+ protected virtual void ConvertRoom()
223
+ {
224
+ for (int i = 0; i < currentRoomSection.Rooms.Count; i++)
225
+ {
226
+ currentRoomData = currentRoomSection.Rooms[i];
227
+
228
+ SaveRoom(currentRoomData.progressionValue);
229
+ }
230
+ }
231
+
232
+ /// <summary>
233
+ ///
234
+ /// </summary>
235
+ /// <param name="pValue"></param>
236
+ protected virtual void SaveRoom(Objective pValue)
237
+ {
238
+ int index = pDB.Chapters.IndexOf(currentRoomStateSection.Chapter);
239
+
240
+ string sectionPath = currentRoomStateBuilder.Sections[index].GetFolderPath();
241
+
242
+ string sectionPrefix = currentRoomStateBuilder.Sections[index].name.Replace(".asset", "");
243
+
244
+ string roomStateName = sectionPrefix + "_" + pValue.Description;
245
+
246
+ if (!ConvertUtility.TryCreateFolder(ref sectionPath, roomStateName))
247
+ return;
248
+
249
+ string newAssetPath = sectionPath + "/" + roomStateName + ".asset";
250
+
251
+ RoomStateData room = CreateRoomState(pValue, newAssetPath);
252
+
253
+ room.SetPersistent(currentRoomData.isPersistent);
254
+
255
+ currentRoomStateBuilder.Sections[index].Rooms.Add(room);
256
+
257
+ string path = AssetDatabase.GetAssetPath(room);
258
+
259
+ if (path.Length >= 252)
260
+ UnityEngine.Debug.LogWarning("path too long for: " + path);
261
+
262
+ EditorUtility.SetDirty(currentRoomStateBuilder);
263
+
264
+ EditorUtility.SetDirty(currentRoomStateBuilder.Sections[index]);
265
+
266
+ EditorUtility.SetDirty(room);
267
+ }
268
+
269
+ /// <summary>
270
+ ///
271
+ /// </summary>
272
+ /// <param name="pValue"></param>
273
+ /// <param name="path"></param>
274
+ /// <param name="data"></param>
275
+ /// <returns></returns>
276
+ protected virtual RoomStateData CreateRoomState(Objective pValue, string path, RoomStateData data = null)
277
+ {
278
+ bool createAsset = false;
279
+
280
+ if (data == null)
281
+ {
282
+ data = ScriptableObject.CreateInstance<RoomStateData>();
283
+
284
+ data.SetProgressionValue(pValue);
285
+
286
+
287
+ createAsset = true;
288
+ }
289
+
290
+ string dataAssetPath = path.Replace(".asset", "");
291
+
292
+ data = ConvertRoomData(data, dataAssetPath);
293
+
294
+ if (createAsset)
295
+ ConvertUtility.CreateAssetAt(data, path);
296
+
297
+ return data;
298
+ }
299
+
300
+ /// <summary>
301
+ ///
302
+ /// </summary>
303
+ /// <param name="data"></param>
304
+ /// <param name="path"></param>
305
+ /// <returns></returns>
306
+ protected virtual RoomStateData ConvertRoomData(RoomStateData data, string path)
307
+ {
308
+ data.dataStates.Add(SaveDataAsset<SpawnableStateData, GameObject>(path, "Spawnables", currentRoomData.spawnDatas));
309
+
310
+ data.dataStates.Add(SaveDataAsset<ActorStateData, ActorData>(path, "Actors", currentRoomData.actorDatas));
311
+
312
+ data.dataStates.Add(SaveDataAsset<ItemStateData, ItemData>(path, "Items", currentRoomData.itemDatas));
313
+
314
+ data.dataStates.Add(SaveDataAsset<TriggerStateData, EventTrigger>(path, "Triggers", currentRoomData.triggers));
315
+
316
+ data.dataStates.Add(SaveDataAsset<SubAreaStateData, SubAreaData>(path, "SubAreas", currentRoomData.subAreas));
317
+
318
+ data.dataStates.Add(SaveDataAsset<DoorStateData, DoorData>(path, "Doors", currentRoomData.doorDatas));
319
+
320
+ data.dataStates.Add(SaveDataAsset<MoveStateData, MoveData>(path, "Moveables", currentRoomData.moveDatas));
321
+
322
+ data.dataStates
323
+ .Add(SaveDataAsset<SaveableStateData, SaveableDataSet>(path, "Saveables", currentRoomData.saveables.dataSets));
324
+
325
+ data.dataStates.RemoveAll(item => item == null);
326
+
327
+ return data;
328
+ }
329
+
330
+ /// <summary>
331
+ ///
332
+ /// </summary>
333
+ /// <typeparam name="T"></typeparam>
334
+ /// <typeparam name="T2"></typeparam>
335
+ /// <param name="path"></param>
336
+ /// <param name="dataAssetName"></param>
337
+ /// <param name="list"></param>
338
+ /// <returns></returns>
339
+ protected virtual ScriptableObject SaveDataAsset<T, T2>(string path, string dataAssetName, List<T2> list)
340
+ where T : StateDataAsset<T2>
341
+ {
342
+ if (list.Count == 0)
343
+ return null;
344
+
345
+ string[] guids = AssetDatabase.FindAssets($"t:{typeof(T).Name}",
346
+ new[] { Path.GetDirectoryName(path.TrimEnd(Path.DirectorySeparatorChar)) });
347
+
348
+ T dataAsset;
349
+
350
+ if (guids.Length > 0)
351
+ dataAsset = ConvertUtility.GetAssetFromGUID<T>(guids[0]);
352
+ else
353
+ dataAsset = ScriptableObject.CreateInstance<T>();
354
+
355
+ dataAsset.SetDatas(list);
356
+
357
+ if (!(guids.Length > 0) && dataAsset.datas != null && dataAsset.datas.Count != 0)
358
+ AssetDatabase.CreateAsset(dataAsset, path + "_" + dataAssetName + ".asset");
359
+
360
+ EditorUtility.SetDirty(dataAsset);
361
+
362
+ AssetDatabase.SaveAssets();
363
+
364
+ if (guids.Length > 0)
365
+ return null;
366
+
367
+ return dataAsset;
368
+ }
369
+
370
+ /// <summary>
371
+ ///
372
+ /// </summary>
373
+ /// <param name="i"></param>
374
+ protected virtual void CreateShellSave(int i)
375
+ {
376
+ if (!CreateShellPath($"_{i}_Shell", out string newAssetPath))
377
+ {
378
+ UnityEngine.Debug.LogWarning("ALERT: Had trouble creating shell path, aborting for index: " + i);
379
+
380
+ return;
381
+ }
382
+
383
+ currentRoomData = currentRoomBuilder.Shells[i];
384
+
385
+ RoomStateData shellAsset = CreateRoomState(null, newAssetPath);
386
+
387
+ CheckFillShells(i);
388
+
389
+ if (currentRoomStateBuilder.Shells.HasValidIndexFor(i))
390
+ currentRoomStateBuilder.Shells[i] = shellAsset;
391
+ else
392
+ currentRoomStateBuilder.Shells.Add(shellAsset);
393
+
394
+ EditorUtility.SetDirty(currentRoomStateBuilder);
395
+ }
396
+
397
+ /// <summary>
398
+ ///
399
+ /// </summary>
400
+ /// <param name="builderSuffix"></param>
401
+ /// <param name="newAssetPath"></param>
402
+ /// <returns></returns>
403
+ protected virtual bool CreateShellPath(string builderSuffix, out string newAssetPath)
404
+ {
405
+ newAssetPath = "";
406
+
407
+ string shellPath = currentRoomStateBuilder.GetFolderPath();
408
+
409
+ if (!ConvertUtility.TryCreateFolder(ref shellPath, currentRoomStateBuilder.name + "_Shell"))
410
+ return false;
411
+
412
+ string builderPrefix = currentRoomStateBuilder.name.Replace(".asset", "");
413
+
414
+ string shellAssetName = builderPrefix + builderSuffix;
415
+
416
+ if (!ConvertUtility.TryCreateFolder(ref shellPath, shellAssetName))
417
+ return false;
418
+
419
+ newAssetPath = shellPath + "/" + shellAssetName + ".asset";
420
+
421
+ return true;
422
+ }
423
+
424
+ /// <summary>
425
+ ///
426
+ /// </summary>
427
+ /// <param name="i"></param>
428
+ protected virtual void CheckFillShells(int i)
429
+ {
430
+ if (currentRoomStateBuilder.Shells.Count < i)
431
+ {
432
+ currentRoomStateBuilder.Shells.Add(null);
433
+
434
+ CheckFillShells(i);
435
+ }
436
+ }
437
+ }
438
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 6ff79ff0f10accd458d6413e7c465bc5
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,169 @@
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ using DREditor.RoomBuilding;
3
+ using DREditor.RoomBuilding.Old;
4
+ using System.Collections.Generic;
5
+ using UnityEditor;
6
+ using UnityEditor.SceneManagement;
7
+ using UnityEngine;
8
+
9
+ namespace DREditor.Editor.Utility.Converting
10
+ {
11
+ /// <summary>
12
+ ///
13
+ /// </summary>
14
+ public class ConvertRoomDataScenes : ScriptableWizard
15
+ {
16
+ // Get the asset of the RoomStateManager Prefab
17
+
18
+ // Get all valid scenes guids
19
+ // Get all valid scene assets
20
+ // Get the paths to each valid scene
21
+ // Open each scene
22
+
23
+ // If that scene contains a RoomManager,
24
+ // Then
25
+ // Instantiate the prefab in the scene
26
+ // Select Prefab
27
+ // Delete the RoomManager GameObject
28
+ // Set the scene dirty and save
29
+ // ELSE
30
+ // Move to the next scene
31
+
32
+ /// <summary>
33
+ ///
34
+ /// </summary>
35
+ static readonly List<RoomStateBuilder> Builders = new();
36
+
37
+ /// <summary>
38
+ ///
39
+ /// </summary>
40
+ [Header("")]
41
+ [Tooltip("")]
42
+ [SerializeField] protected GameObject roomStateManagerPrefab = null;
43
+
44
+
45
+ [MenuItem("DREditor/Convert/Convert Scene Room Managers")]
46
+ public static void CreateWizard() => DisplayWizard<ConvertRoomDataScenes>("Convert Room Data", "Convert");
47
+
48
+ protected virtual void OnWizardCreate()
49
+ {
50
+ if (EditorUtility.DisplayDialog("Confirm", "You MUST convert the Room Data Assets FIRST." +
51
+ "\nYou can do this by calling: DREditor/Convert/Convert All Room Data Builders." +
52
+ "\nHave you done this?", "Yes", "No"))
53
+ ConvertSceneRoomManagers();
54
+ }
55
+
56
+
57
+ /// <summary>
58
+ ///
59
+ /// </summary>
60
+ protected virtual void ConvertSceneRoomManagers()
61
+ {
62
+ InitializeBuilders();
63
+
64
+ ConvertAllValidScenes();
65
+ }
66
+
67
+ /// <summary>
68
+ ///
69
+ /// </summary>
70
+ protected virtual void InitializeBuilders()
71
+ {
72
+ Builders.Clear();
73
+
74
+ var found = AssetDatabase.FindAssets("t:RoomStateBuilder");
75
+
76
+ if (found.Length != 0)
77
+ foreach (var asset in found)
78
+ {
79
+ string path = AssetDatabase.GUIDToAssetPath(asset);
80
+
81
+ var roomStateBuilder = AssetDatabase.LoadAssetAtPath<RoomStateBuilder>(path);
82
+
83
+ Builders.Add(roomStateBuilder);
84
+ }
85
+ }
86
+
87
+
88
+ /// <summary>
89
+ ///
90
+ /// </summary>
91
+ protected virtual void ConvertAllValidScenes()
92
+ {
93
+ var scenes = CustomEditorUtility.GetAllValidSceneAssets();
94
+
95
+ foreach (var scene in scenes)
96
+ ConvertScene(scene);
97
+ }
98
+
99
+ /// <summary>
100
+ ///
101
+ /// </summary>
102
+ /// <param name="scene"></param>
103
+ protected virtual void ConvertScene(SceneAsset scene)
104
+ {
105
+ try
106
+ {
107
+ CustomEditorUtility.LoadScene(scene);
108
+ }
109
+ catch
110
+ {
111
+ UnityEngine.Debug.LogWarning("Had trouble opening scene: " + scene.name + " , Skipping conversion.");
112
+
113
+ return;
114
+ }
115
+
116
+ ExecuteRoomConvert();
117
+ }
118
+
119
+ /// <summary>
120
+ ///
121
+ /// </summary>
122
+ protected virtual void ExecuteRoomConvert()
123
+ {
124
+ var roomManagers = MonoBehaviour.FindObjectsByType<RoomManager>();
125
+
126
+ if (roomManagers.Length > 0 && HasExistingBuilder(out RoomStateBuilder builder))
127
+ {
128
+ var managerObject = (GameObject)PrefabUtility.InstantiatePrefab(roomStateManagerPrefab);
129
+
130
+ var manager = managerObject.GetComponent<RoomStateManager>();
131
+
132
+ manager.SetBuilder(builder);
133
+
134
+ EditorUtility.SetDirty(manager);
135
+
136
+ MonoBehaviour.DestroyImmediate(roomManagers[0].gameObject);
137
+
138
+ EditorUtility.SetDirty(managerObject);
139
+
140
+ EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
141
+ }
142
+ }
143
+
144
+ /// <summary>
145
+ ///
146
+ /// </summary>
147
+ /// <param name="builder"></param>
148
+ /// <returns></returns>
149
+ protected virtual bool HasExistingBuilder(out RoomStateBuilder builder)
150
+ {
151
+ builder = null;
152
+
153
+ if (Builders.Count != 0)
154
+ {
155
+ foreach (var roomStateBuilder in Builders)
156
+ {
157
+ if (roomStateBuilder != null && roomStateBuilder.name == EditorSceneManager.GetActiveScene().name)
158
+ {
159
+ builder = roomStateBuilder;
160
+
161
+ return true;
162
+ }
163
+ }
164
+ }
165
+
166
+ return false;
167
+ }
168
+ }
169
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: f031a83469ae6d34db2692c0db899dfa
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,108 @@
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ using System.Collections.Generic;
3
+ using System.IO;
4
+ using UnityEditor;
5
+ using UnityEngine;
6
+
7
+ namespace DREditor.Editor.Utility.Converting
8
+ {
9
+ /// <summary>
10
+ ///
11
+ /// </summary>
12
+ public static class ConvertUtility
13
+ {
14
+ /// <summary>
15
+ ///
16
+ /// </summary>
17
+ /// <typeparam name="T"></typeparam>
18
+ /// <param name="list"></param>
19
+ /// <param name="index"></param>
20
+ /// <returns></returns>
21
+ public static bool HasValidIndexFor<T>(this List<T> list, int index) => index >= 0 && index < list.Count;
22
+
23
+ /// <summary>
24
+ ///
25
+ /// </summary>
26
+ /// <param name="asset"></param>
27
+ /// <returns></returns>
28
+ public static string GetFolderPath(this Object asset)
29
+ {
30
+ string assetPath = AssetDatabase.GetAssetPath(asset);
31
+
32
+ assetPath = assetPath.Replace("/" + asset.name + ".asset", "");
33
+
34
+ return assetPath;
35
+ }
36
+
37
+ /// <summary>
38
+ ///
39
+ /// </summary>
40
+ /// <typeparam name="T"></typeparam>
41
+ /// <param name="guid"></param>
42
+ /// <returns></returns>
43
+ public static T GetAssetFromGUID<T>(string guid) where T : UnityEngine.Object
44
+ {
45
+ string path = AssetDatabase.GUIDToAssetPath(guid);
46
+
47
+ return AssetDatabase.LoadAssetAtPath<T>(path);
48
+ }
49
+
50
+ /// <summary>
51
+ ///
52
+ /// </summary>
53
+ /// <param name="obj"></param>
54
+ /// <param name="path"></param>
55
+ public static void CreateAssetAt(UnityEngine.Object obj, string path)
56
+ {
57
+ if (!path.EndsWith(".asset"))
58
+ path += ".asset";
59
+
60
+ AssetDatabase.CreateAsset(obj, path);
61
+
62
+ AssetDatabase.SaveAssets();
63
+
64
+ EditorUtility.SetDirty(obj);
65
+ }
66
+
67
+ /// <summary>
68
+ ///
69
+ /// </summary>
70
+ /// <param name="assetPath"></param>
71
+ /// <param name="assetName"></param>
72
+ /// <returns></returns>
73
+ public static bool TryCreateFolder(ref string assetPath, string assetName)
74
+ {
75
+ assetPath = assetPath.Replace(".asset", "");
76
+
77
+ if (!ProjectFolderExists(assetPath + "/" + assetName))
78
+ {
79
+ string shellFolder = AssetDatabase.CreateFolder(assetPath, assetName);
80
+
81
+ if (shellFolder == "")
82
+ {
83
+ UnityEngine.Debug.LogWarning("Could not create folder. Canceling Initialization.");
84
+
85
+ UnityEngine.Debug.Log("Builder Path: " + assetPath);
86
+
87
+ return false;
88
+ }
89
+ }
90
+
91
+ assetPath = assetPath + "/" + assetName;
92
+
93
+ return true;
94
+ }
95
+
96
+ /// <summary>
97
+ ///
98
+ /// </summary>
99
+ /// <param name="relativePath"></param>
100
+ /// <returns></returns>
101
+ public static bool ProjectFolderExists(string relativePath)
102
+ {
103
+ string fullPath = Path.Combine(Application.dataPath, "..", relativePath);
104
+
105
+ return Directory.Exists(fullPath);
106
+ }
107
+ }
108
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 861473e519cac9f459804906f93810a4
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "DREditor.Editor.Utility.Converting",
3
+ "rootNamespace": "",
4
+ "references": [
5
+ "Unity.RenderPipelines.Universal.Runtime",
6
+ "Unity.InputSystem",
7
+ "DREditor.Editor",
8
+ "DREditor",
9
+ "DREditor.Controls",
10
+ "DREditor.States",
11
+ "DREditor.Progressing.Handling",
12
+ "DREditor.DialogueMechanics.Investigation",
13
+ "DREditor.RoomStateBuilding",
14
+ "DREditor.RoomBuilding",
15
+ "DREditor.Actors",
16
+ "DREditor.Doors",
17
+ "DREditor.Talkables",
18
+ "DREditor.SubAreas",
19
+ "DREditor.Triggers",
20
+ "DREditor.DebugTesting",
21
+ "DREditor.UI"
22
+ ],
23
+ "includePlatforms": [
24
+ "Editor"
25
+ ],
26
+ "excludePlatforms": [],
27
+ "allowUnsafeCode": false,
28
+ "overrideReferences": false,
29
+ "precompiledReferences": [],
30
+ "autoReferenced": true,
31
+ "defineConstraints": [],
32
+ "versionDefines": [],
33
+ "noEngineReferences": false
34
+ }
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: 2135f79bd7a042d4bab6d1690fc7fba9
3
+ AssemblyDefinitionImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
@@ -0,0 +1,129 @@
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ #if UNITY_EDITOR
3
+ using DREditor.UI.Buttons;
4
+ using System.Collections.Generic;
5
+ using System.Linq;
6
+ using UnityEditor;
7
+ using UnityEngine;
8
+ using UnityEngine.UI;
9
+
10
+ namespace DREditor.Editor.Utility.Converting
11
+ {
12
+ /// <summary>
13
+ ///
14
+ /// </summary>
15
+ public static class MigrationUtility
16
+ {
17
+ /// <summary>
18
+ ///
19
+ /// </summary>
20
+ static readonly string MonoscriptSearch = "t:MonoScript ";
21
+
22
+ /// <summary>
23
+ ///
24
+ /// </summary>
25
+ static readonly string PrefabSearch = "t:Prefab";
26
+
27
+ /// <summary>
28
+ ///
29
+ /// </summary>
30
+ static readonly string ScriptPropertyName = "m_Script";
31
+
32
+
33
+ /// <summary>
34
+ ///
35
+ /// </summary>
36
+ [MenuItem("DREditor/Convert/Buttons/Migrate Buttons to DREButton")]
37
+ public static void MigrateButtons() => MigrateType<Button, DREButton>();
38
+
39
+ /// <summary>
40
+ ///
41
+ /// </summary>
42
+ /// <typeparam name="T"></typeparam>
43
+ /// <typeparam name="T2"></typeparam>
44
+ public static void MigrateType<T, T2>() where T : Object
45
+ {
46
+ if (FindTypeScript<T2>(out var childScript))
47
+ {
48
+ MigrateSceneObjects<T>(childScript);
49
+
50
+ MigratePrefabs<T>(childScript);
51
+
52
+ AssetDatabase.SaveAssets();
53
+ }
54
+ else
55
+ UnityEngine.Debug.LogError($"ALERT: {typeof(T2).Name} script not found in project.");
56
+ }
57
+
58
+ /// <summary>
59
+ ///
60
+ /// </summary>
61
+ /// <typeparam name="T"></typeparam>
62
+ /// <param name="childScript"></param>
63
+ /// <returns></returns>
64
+ private static bool FindTypeScript<T>(out MonoScript childScript)
65
+ {
66
+ childScript = AssetDatabase.FindAssets(MonoscriptSearch + typeof(T).Name)
67
+ .Select(guid => AssetDatabase.LoadAssetAtPath<MonoScript>(AssetDatabase.GUIDToAssetPath(guid)))
68
+ .FirstOrDefault(s => s != null && s.GetClass() == typeof(T));
69
+
70
+ return childScript != null;
71
+ }
72
+
73
+ /// <summary>
74
+ ///
75
+ /// </summary>
76
+ /// <typeparam name="T"></typeparam>
77
+ /// <param name="childScript"></param>
78
+ private static void MigrateSceneObjects<T>(MonoScript childScript) where T : Object
79
+ => SwappedReferences(UnityEngine.Object.FindObjectsByType<T>(), childScript);
80
+
81
+ /// <summary>
82
+ ///
83
+ /// </summary>
84
+ /// <typeparam name="T"></typeparam>
85
+ /// <param name="childScript"></param>
86
+ private static void MigratePrefabs<T>(MonoScript childScript) where T : Object
87
+ {
88
+ foreach (string guid in AssetDatabase.FindAssets(PrefabSearch))
89
+ {
90
+ string path = AssetDatabase.GUIDToAssetPath(guid);
91
+
92
+ GameObject prefab = PrefabUtility.LoadPrefabContents(path);
93
+
94
+ bool modified = SwappedReferences(prefab.GetComponentsInChildren<Button>(true), childScript);
95
+
96
+ if (modified)
97
+ PrefabUtility.SaveAsPrefabAsset(prefab, path);
98
+
99
+ PrefabUtility.UnloadPrefabContents(prefab);
100
+ }
101
+ }
102
+
103
+ /// <summary>
104
+ ///
105
+ /// </summary>
106
+ /// <param name="references"></param>
107
+ /// <param name="childScript"></param>
108
+ /// <returns></returns>
109
+ /// <remarks></remarks>
110
+ private static bool SwappedReferences<T>(IEnumerable<T> references, MonoScript childScript) where T : Object
111
+ {
112
+ bool modified = false;
113
+
114
+ foreach (T reference in references.Where(b => b.GetType() == typeof(T)))
115
+ {
116
+ SerializedObject serializedButton = new(reference);
117
+
118
+ serializedButton.FindProperty(ScriptPropertyName).objectReferenceValue = childScript;
119
+
120
+ serializedButton.ApplyModifiedPropertiesWithoutUndo();
121
+
122
+ modified = true;
123
+ }
124
+
125
+ return modified;
126
+ }
127
+ }
128
+ }
129
+ #endif
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 1c9d4197915d6524697ab09b1e2671e0
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
- {
2
- "name": "net.dreditor.editor.utility.converting",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "net.dreditor.editor.utility.converting",
3
+ "version": "0.1.6",
4
+ "displayName": "DREditor Editor Utility Converting",
5
+ "description": "The beta for DREditor. A tool to create death game style projects without having to code.",
6
+ "unity": "6000.4",
7
+ "dependencies": {
8
+ "com.unity.render-pipelines.universal": "17.4.0",
9
+ "com.unity.inputsystem": "1.19.0",
10
+ "net.dreditor.core": "0.1.6",
11
+ "net.dreditor.states": "0.1.6",
12
+ "net.dreditor.progressing.handling": "0.1.6",
13
+ "net.dreditor.dialoguemechanics.investigation": "0.1.6",
14
+ "net.dreditor.roomstatebuilding": "0.1.6",
15
+ "net.dreditor.roombuilding": "0.1.6",
16
+ "net.dreditor.actors": "0.1.6",
17
+ "net.dreditor.doors": "0.1.6",
18
+ "net.dreditor.talkables": "0.1.6",
19
+ "net.dreditor.subareas": "0.1.6",
20
+ "net.dreditor.triggers": "0.1.6",
21
+ "net.dreditor.debugtesting": "0.1.6",
22
+ "net.dreditor.ui": "0.1.6"
23
+ },
24
+ "keywords": [
25
+ "editor",
26
+ "tool",
27
+ "dreditor"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "author": {
33
+ "name": "Benjamin \"Sweden\" Jillson",
34
+ "email": "dreditortool@gmail.com",
35
+ "url": "https://dreditor.net"
36
+ },
37
+ "samples": [
38
+ {
39
+ "displayName": "Samples",
40
+ "description": "",
41
+ "path": "Samples~"
42
+ }
43
+ ],
44
+ "documentationUrl": "https://dreditor.net",
45
+ "license": "Apache-2.0",
46
+ "licensesUrl": "https://dreditor.net/docs/LICENSE.html",
47
+ "changelogUrl": "https://dreditor.net/docs/CHANGELOG.html"
48
+ }
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: 2c1cfb89d0cc0de418d66bffb850ce03
3
+ TextScriptImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.