net.dreditor.roombuilding 0.1.6 → 0.1.7
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.
- package/.attestation.p7m +0 -0
- package/DREditor.RoomBuilding.asmdef +28 -28
- package/DREditor.RoomBuilding.asmdef.meta +7 -7
- package/Editor/DREditor.RoomBuilding.Editor.asmdef +19 -19
- package/Editor/DREditor.RoomBuilding.Editor.asmdef.meta +7 -7
- package/Editor/FindCharactersInRoomsWizard.cs +55 -55
- package/Editor/FindCharactersInRoomsWizard.cs.meta +11 -11
- package/Editor/RoomBuilderContainsObjective.cs +38 -38
- package/Editor/RoomBuilderContainsObjective.cs.meta +11 -11
- package/Editor/RoomBuilderScanWizard.cs +90 -90
- package/Editor/RoomBuilderScanWizard.cs.meta +11 -11
- package/Editor/ScanRoomBuilders.cs +74 -74
- package/Editor/ScanRoomBuilders.cs.meta +11 -11
- package/Editor.meta +8 -8
- package/Implementation/Actors/ActorData.cs +115 -115
- package/Implementation/Actors/ActorData.cs.meta +11 -11
- package/Implementation/Actors/ActorStateData.cs +10 -10
- package/Implementation/Actors/ActorStateData.cs.meta +11 -11
- package/Implementation/Actors/ActorStateLoader.cs +344 -344
- package/Implementation/Actors/ActorStateLoader.cs.meta +11 -11
- package/Implementation/Actors/TActorData.cs +35 -35
- package/Implementation/Actors/TActorData.cs.meta +11 -11
- package/Implementation/Actors/TrialActorManager.cs +157 -157
- package/Implementation/Actors/TrialActorManager.cs.meta +11 -11
- package/Implementation/Actors.meta +8 -8
- package/Implementation/DoorLoader.cs +117 -117
- package/Implementation/DoorLoader.cs.meta +11 -11
- package/Implementation/DoorLoaderUtility.cs +51 -51
- package/Implementation/DoorLoaderUtility.cs.meta +11 -11
- package/Implementation/DoorStateData.cs +11 -11
- package/Implementation/DoorStateData.cs.meta +11 -11
- package/Implementation/ItemActorLoader.cs +157 -157
- package/Implementation/ItemActorLoader.cs.meta +11 -11
- package/Implementation/ItemData.cs +67 -67
- package/Implementation/ItemData.cs.meta +11 -11
- package/Implementation/ItemStateData.cs +10 -10
- package/Implementation/ItemStateData.cs.meta +11 -11
- package/Implementation/MoveLoader.cs +67 -67
- package/Implementation/MoveLoader.cs.meta +11 -11
- package/Implementation/MoveStateData.cs +11 -11
- package/Implementation/MoveStateData.cs.meta +11 -11
- package/Implementation/RoomStateHandlerBase.cs +241 -241
- package/Implementation/RoomStateHandlerBase.cs.meta +11 -11
- package/Implementation/SaveableData.cs +56 -56
- package/Implementation/SaveableData.cs.meta +11 -11
- package/Implementation/SaveableDataSet.cs +66 -66
- package/Implementation/SaveableDataSet.cs.meta +11 -11
- package/Implementation/SaveableManager.cs +70 -70
- package/Implementation/SaveableManager.cs.meta +11 -11
- package/Implementation/SaveableStateData.cs +10 -10
- package/Implementation/SaveableStateData.cs.meta +11 -11
- package/Implementation/SpawnableLoader.cs +125 -125
- package/Implementation/SpawnableLoader.cs.meta +11 -11
- package/Implementation/SpawnableStateData.cs +11 -11
- package/Implementation/SpawnableStateData.cs.meta +11 -11
- package/Implementation/StateDataAsset.cs +28 -28
- package/Implementation/StateDataAsset.cs.meta +11 -11
- package/Implementation/SubAreaLoader.cs +108 -108
- package/Implementation/SubAreaLoader.cs.meta +11 -11
- package/Implementation/SubAreaStateData.cs +11 -11
- package/Implementation/SubAreaStateData.cs.meta +11 -11
- package/Implementation/TriggerConverter.cs +137 -137
- package/Implementation/TriggerConverter.cs.meta +11 -11
- package/Implementation/TriggerLoader.cs +295 -295
- package/Implementation/TriggerLoader.cs.meta +11 -11
- package/Implementation/TriggerStateData.cs +18 -18
- package/Implementation/TriggerStateData.cs.meta +11 -11
- package/Implementation.meta +8 -8
- package/InstanceListWrapper.cs +23 -23
- package/InstanceListWrapper.cs.meta +11 -11
- package/Instances/ConvertInstanceData.cs +89 -89
- package/Instances/ConvertInstanceData.cs.meta +11 -11
- package/Instances/InstanceData.cs +43 -43
- package/Instances/InstanceData.cs.meta +11 -11
- package/Instances/InstanceStateData.cs +51 -51
- package/Instances/InstanceStateData.cs.meta +11 -11
- package/Instances/RoomInstanceData.cs +68 -68
- package/Instances/RoomInstanceData.cs.meta +11 -11
- package/Instances/RoomInstanceManager.cs +452 -452
- package/Instances/RoomInstanceManager.cs.meta +11 -11
- package/Instances.meta +8 -8
- package/LoadInvestigationRoomState.cs +53 -53
- package/LoadInvestigationRoomState.cs.meta +11 -11
- package/Old/ActorLoader.cs +382 -382
- package/Old/ActorLoader.cs.meta +11 -11
- package/Old/Room.cs +24 -24
- package/Old/Room.cs.meta +11 -11
- package/Old/RoomBuilder.cs +59 -59
- package/Old/RoomBuilder.cs.meta +11 -11
- package/Old/RoomData.cs +90 -90
- package/Old/RoomData.cs.meta +11 -11
- package/Old/RoomManager.cs +256 -256
- package/Old/RoomManager.cs.meta +11 -11
- package/Old/RoomManagerDisplayEditor.cs +72 -72
- package/Old/RoomManagerDisplayEditor.cs.meta +11 -11
- package/Old/RoomManagerEditor.cs +211 -211
- package/Old/RoomManagerEditor.cs.meta +11 -11
- package/Old/RoomManagerShellDisplayEditor.cs +48 -48
- package/Old/RoomManagerShellDisplayEditor.cs.meta +11 -11
- package/Old/RoomSection.cs +35 -35
- package/Old/RoomSection.cs.meta +11 -11
- package/Old.meta +8 -8
- package/RoomManagerBase.cs +84 -84
- package/RoomManagerBase.cs.meta +11 -11
- package/RoomManagerEditorBase.cs +86 -86
- package/RoomManagerEditorBase.cs.meta +11 -11
- package/RoomManagerEditorCoreBase.cs +159 -159
- package/RoomManagerEditorCoreBase.cs.meta +11 -11
- package/RoomSaveDisplayEditorBase.cs +111 -111
- package/RoomSaveDisplayEditorBase.cs.meta +11 -11
- package/RoomShellDisplayEditorBase.cs +68 -68
- package/RoomShellDisplayEditorBase.cs.meta +11 -11
- package/RoomStateBuilder.cs +53 -53
- package/RoomStateBuilder.cs.meta +11 -11
- package/RoomStateData.cs +58 -58
- package/RoomStateData.cs.meta +11 -11
- package/RoomStateManager.cs +202 -202
- package/RoomStateManager.cs.meta +11 -11
- package/RoomStateManagerEditor.cs +392 -392
- package/RoomStateManagerEditor.cs.meta +11 -11
- package/RoomStateSaveDisplayEditor.cs +175 -175
- package/RoomStateSaveDisplayEditor.cs.meta +11 -11
- package/RoomStateSection.cs +69 -69
- package/RoomStateSection.cs.meta +11 -11
- package/RoomStateShellDisplayEditor.cs +108 -108
- package/RoomStateShellDisplayEditor.cs.meta +11 -11
- package/{Samples → Samples~}/Room_State_Manager.prefab +473 -473
- package/{Samples → Samples~}/Room_State_Manager.prefab.meta +7 -7
- package/{Samples → Samples~}/Trial_Actor_Manager.prefab +51 -51
- package/{Samples → Samples~}/Trial_Actor_Manager.prefab.meta +7 -7
- package/package.json +51 -46
- package/package.json.meta +7 -7
- package/Samples.meta +0 -8
package/Old/ActorLoader.cs
CHANGED
|
@@ -1,383 +1,383 @@
|
|
|
1
|
-
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
-
using DREditor.Actors;
|
|
3
|
-
using DREditor.Characters;
|
|
4
|
-
using DREditor.LocalDialogues;
|
|
5
|
-
using DREditor.RoomBuilding.Implementation.Actors;
|
|
6
|
-
using System.Collections.Generic;
|
|
7
|
-
using UnityEditor;
|
|
8
|
-
using UnityEngine;
|
|
9
|
-
|
|
10
|
-
namespace DREditor.RoomBuilding.Old
|
|
11
|
-
{
|
|
12
|
-
/// <summary>
|
|
13
|
-
///
|
|
14
|
-
/// </summary>
|
|
15
|
-
[ClassHeader("")]
|
|
16
|
-
public class ActorLoader : MonoBehaviour
|
|
17
|
-
{
|
|
18
|
-
public static List<ActorData> Save()
|
|
19
|
-
{
|
|
20
|
-
CharacterDatabase characterDatabase = GetDatabase();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
List<GameObject> ActorPrefabs = new();
|
|
24
|
-
if (ActorPrefabs.Count < characterDatabase.GetActorPrefabCount())
|
|
25
|
-
{
|
|
26
|
-
List<GameObject> p = new();
|
|
27
|
-
|
|
28
|
-
foreach (Character c in characterDatabase.Characters)
|
|
29
|
-
{
|
|
30
|
-
if (c.ActorPrefab != null)
|
|
31
|
-
{
|
|
32
|
-
UnityEngine.Debug.Log("Added " + c.ActorPrefab.name);
|
|
33
|
-
|
|
34
|
-
p.Add(c.ActorPrefab);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
ActorPrefabs = p;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
List<ActorData> ActorListIn = new();
|
|
43
|
-
|
|
44
|
-
Actor[] x = (Actor[])FindObjectsByType(typeof(Actor));
|
|
45
|
-
|
|
46
|
-
if (x.Length == 0)
|
|
47
|
-
{
|
|
48
|
-
UnityEngine.Debug.Log("There are no Actors in the scene!");
|
|
49
|
-
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
for (int i = 0; i < x.Length; i++)
|
|
54
|
-
{
|
|
55
|
-
GameObject actor = x[i].gameObject.transform.parent.gameObject;
|
|
56
|
-
|
|
57
|
-
for (int j = 0; j < ActorPrefabs.Count; j++) // Look through Actor references
|
|
58
|
-
{
|
|
59
|
-
if (ActorPrefabs[j] != null && ActorPrefabs[j].name == actor.name) // Actor Reference found Save actor data
|
|
60
|
-
{
|
|
61
|
-
ActorData a = new(ActorPrefabs[j].name, x[i]);
|
|
62
|
-
|
|
63
|
-
ActorListIn.Add((ActorData)a.Clone());
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return ActorListIn;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public static void Load(RoomData room, RoomData instanceRoom = null)
|
|
72
|
-
{
|
|
73
|
-
CharacterDatabase characterDatabase = GetDatabase();
|
|
74
|
-
|
|
75
|
-
List<GameObject> ActorPrefabs = SpawnActors(characterDatabase);
|
|
76
|
-
|
|
77
|
-
// when something is built itll take the object and convert it there
|
|
78
|
-
if (room != null && room.actorDatas != null && room.actorDatas.Count != 0)
|
|
79
|
-
{
|
|
80
|
-
List<ActorData> actors = room.actorDatas;
|
|
81
|
-
for (int i = 0; i < actors.Count; i++)
|
|
82
|
-
{
|
|
83
|
-
ActorData actor = (ActorData)actors[i].Clone();
|
|
84
|
-
//UnityEngine.Debug.Log("Actor prefab count: " + ActorPrefabs.Count);
|
|
85
|
-
for (int j = 0; j < ActorPrefabs.Count; j++) // Look through Actor references
|
|
86
|
-
{
|
|
87
|
-
// Actor prefab matches Base room name
|
|
88
|
-
if (ActorPrefabs[j] != null && ActorPrefabs[j].name == actor.aReference)
|
|
89
|
-
{
|
|
90
|
-
var x = instanceRoom != null ? GetCorrectInst(instanceRoom.actorDatas, ActorPrefabs[j].name) : null;
|
|
91
|
-
|
|
92
|
-
LoadActor(ActorPrefabs[j], actor, x, characterDatabase);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
UnityEngine.Debug.Log("Finished Loading Actors");
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
static List<GameObject> SpawnActors(CharacterDatabase characterDatabase)
|
|
103
|
-
{
|
|
104
|
-
List<GameObject> ActorPrefabs = new();
|
|
105
|
-
|
|
106
|
-
if (ActorPrefabs.Count < characterDatabase.GetActorPrefabCount())
|
|
107
|
-
{
|
|
108
|
-
List<GameObject> p = new();
|
|
109
|
-
|
|
110
|
-
foreach (Character c in characterDatabase.Characters)
|
|
111
|
-
{
|
|
112
|
-
if (c.ActorPrefab != null)
|
|
113
|
-
{
|
|
114
|
-
UnityEngine.Debug.Log("Added " + c.ActorPrefab.name);
|
|
115
|
-
|
|
116
|
-
p.Add(c.ActorPrefab);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
ActorPrefabs = p;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return ActorPrefabs;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
static CharacterDatabase GetDatabase()
|
|
127
|
-
{
|
|
128
|
-
#if UNITY_EDITOR
|
|
129
|
-
string[] _databaseguids = AssetDatabase.FindAssets("t:CharacterDatabase");
|
|
130
|
-
if (_databaseguids.Length >= 1)
|
|
131
|
-
{
|
|
132
|
-
string _databasepath = AssetDatabase.GUIDToAssetPath(_databaseguids[0]);
|
|
133
|
-
|
|
134
|
-
try
|
|
135
|
-
{
|
|
136
|
-
EditorGUILayout.LabelField($"Loading CharacterDatabase at {_databasepath}.");
|
|
137
|
-
}
|
|
138
|
-
catch
|
|
139
|
-
{
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
return AssetDatabase.LoadAssetAtPath<CharacterDatabase>(_databasepath);
|
|
143
|
-
}
|
|
144
|
-
#endif
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
static ActorData GetCorrectInst(List<ActorData> instList, string nameLook)
|
|
149
|
-
{
|
|
150
|
-
// This if statement has been added because when leaving damons dorm on FTE 1
|
|
151
|
-
// the game freezes going to the dorm hallway because it has dorm hallway instance data from the
|
|
152
|
-
// previous objective. why this happens hasn't been fixed but this code keeps this problem from making
|
|
153
|
-
// an error freezing the game in a exported build.
|
|
154
|
-
|
|
155
|
-
if (instList == null)
|
|
156
|
-
{
|
|
157
|
-
UnityEngine.Debug.LogWarning("CRITICAL WARNING! INSTANCE LIST WAS NULL." +
|
|
158
|
-
" Instance data might be leaking Through the game?");
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
for (int i = 0; i < instList.Count; i++)
|
|
163
|
-
{
|
|
164
|
-
if (instList[i].aReference == nameLook)
|
|
165
|
-
return instList[i];
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
UnityEngine.Debug.LogWarning("The instance actor data list couldn't find the character it was looking for? " + nameLook);
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
public static void LoadActor(GameObject shell, ActorData actorData, ActorData instanceData = null,
|
|
173
|
-
CharacterDatabase characterDatabase = null)
|
|
174
|
-
{
|
|
175
|
-
Actor a = SpawnActor(shell, actorData);
|
|
176
|
-
|
|
177
|
-
if (characterDatabase == null)
|
|
178
|
-
characterDatabase = GetDatabase();
|
|
179
|
-
|
|
180
|
-
// This is so the sprite is loaded correctly, but I need to add a way to reference
|
|
181
|
-
// the character database, I'm too lazy rn lmao
|
|
182
|
-
if (a.GetComponentInChildren<SpriteRenderer>().sprite.name != actorData.matName)
|
|
183
|
-
{
|
|
184
|
-
Character character = null;
|
|
185
|
-
|
|
186
|
-
if (characterDatabase != null)
|
|
187
|
-
{
|
|
188
|
-
character = characterDatabase.GetCharacter(actorData.aReference);
|
|
189
|
-
}
|
|
190
|
-
else
|
|
191
|
-
{
|
|
192
|
-
UnityEngine.Debug.LogError("Character Database Not Found?");
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (character != null && character.Expressions != null &&
|
|
196
|
-
!actorData.matName.Contains(character.Expressions[0].Sprite.name) &&
|
|
197
|
-
!a.GetComponentInChildren<SpriteRenderer>().sprite.name.Contains("stare") &&
|
|
198
|
-
!actorData.matName.Contains("Stare"))
|
|
199
|
-
{
|
|
200
|
-
|
|
201
|
-
//UnityEngine.Debug.Log("Materials and sprites were not loaded the same for: " + actorData.matName + " , "
|
|
202
|
-
//+ a.GetComponentInChildren<SpriteRenderer>().sprite.name);
|
|
203
|
-
|
|
204
|
-
//UnityEngine.Debug.Log("MAT NAME WAS: " + actorData.matName);
|
|
205
|
-
for (int i = 0; i < character.Expressions.Count; i++)
|
|
206
|
-
{
|
|
207
|
-
Expression exp = character.Expressions[i];
|
|
208
|
-
|
|
209
|
-
if (actorData.matName.Contains(exp.Sprite.name))
|
|
210
|
-
{
|
|
211
|
-
a.GetComponentInChildren<SpriteRenderer>().sprite = character.Sprites[i].Sprite;
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (Application.isPlaying)
|
|
220
|
-
{
|
|
221
|
-
// The spawned object registers itself.
|
|
222
|
-
//ServiceLocator.GetService<ActorManager>().RegisterObject(a);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
LoadActorInstance(a, actorData, instanceData, characterDatabase);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
protected static void LoadActorInstance(Actor a, ActorData actorData, ActorData instanceData = null,
|
|
231
|
-
CharacterDatabase characterDatabase = null)
|
|
232
|
-
{
|
|
233
|
-
if (instanceData != null)
|
|
234
|
-
{
|
|
235
|
-
Character character = characterDatabase.GetCharacter(actorData.aReference);
|
|
236
|
-
a.gameObject.transform.position = instanceData.position;
|
|
237
|
-
a.gameObject.transform.eulerAngles = instanceData.rotation;
|
|
238
|
-
a.SetIdentified(instanceData.identified);
|
|
239
|
-
if (instanceData.displayName != "")
|
|
240
|
-
{
|
|
241
|
-
a.DisplayName = instanceData.displayName;
|
|
242
|
-
}
|
|
243
|
-
for (int i = 0; i < instanceData.actorDialogues.Count && i < actorData.actorDialogues.Count; i++)
|
|
244
|
-
{
|
|
245
|
-
UnityEngine.Debug.Log(i);
|
|
246
|
-
a.conversations[i].SetTriggered(instanceData.actorDialogues[i].triggered);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
UnityEngine.Debug.Log("MAT NAME WAS: " + instanceData.matName);
|
|
250
|
-
for (int i = 0; i < character.Expressions.Count; i++)
|
|
251
|
-
{
|
|
252
|
-
Expression exp = character.Expressions[i];
|
|
253
|
-
|
|
254
|
-
if (instanceData.matName.Contains(exp.Sprite.name))
|
|
255
|
-
{
|
|
256
|
-
UnityEngine.Debug.Log(exp.Sprite.name);
|
|
257
|
-
var instanceMeshes = a.GetComponentsInChildren<MeshRenderer>();
|
|
258
|
-
|
|
259
|
-
instanceMeshes[0].material = exp.Sprite;
|
|
260
|
-
|
|
261
|
-
Material ma = new(instanceMeshes[1].sharedMaterial.shader);
|
|
262
|
-
ma.mainTexture = instanceMeshes[0].sharedMaterial.mainTexture;
|
|
263
|
-
instanceMeshes[1].sharedMaterial = ma;
|
|
264
|
-
instanceMeshes[1].sharedMaterial.color = Color.black;
|
|
265
|
-
instanceMeshes[1].sharedMaterial.renderQueue = 3000;
|
|
266
|
-
a.GetComponentInChildren<SpriteRenderer>().sprite = character.Sprites[i].Sprite;
|
|
267
|
-
break;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
protected static Actor SpawnActor(GameObject shell, ActorData actorData)
|
|
274
|
-
{
|
|
275
|
-
GameObject loaded = Instantiate(shell);
|
|
276
|
-
loaded.name = actorData.aReference;
|
|
277
|
-
loaded.transform.position = actorData.position;
|
|
278
|
-
loaded.transform.eulerAngles = actorData.rotation;
|
|
279
|
-
Actor a = loaded.GetComponent<Actor>();
|
|
280
|
-
|
|
281
|
-
a.conversations.Clear();
|
|
282
|
-
|
|
283
|
-
for (int i = 0; i < actorData.actorDialogues.Count; i++)
|
|
284
|
-
a.conversations.Add((LocalDialogue)actorData.actorDialogues[i].Clone());
|
|
285
|
-
|
|
286
|
-
var meshes = a.GetComponentsInChildren<MeshRenderer>();
|
|
287
|
-
|
|
288
|
-
meshes[0].material = actorData.mat;
|
|
289
|
-
Material m = new(meshes[1].sharedMaterial.shader);
|
|
290
|
-
m.mainTexture = meshes[0].sharedMaterial.mainTexture;
|
|
291
|
-
meshes[1].sharedMaterial = m;
|
|
292
|
-
meshes[1].sharedMaterial.color = Color.black;
|
|
293
|
-
meshes[1].sharedMaterial.renderQueue = 3000;
|
|
294
|
-
a.SetIdentified(actorData.identified);
|
|
295
|
-
if (actorData.displayName != "")
|
|
296
|
-
a.DisplayName = actorData.displayName;
|
|
297
|
-
return a;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
public static void UnloadActors(bool inEditor)
|
|
301
|
-
{
|
|
302
|
-
CharacterDatabase characterDatabase = GetDatabase();
|
|
303
|
-
|
|
304
|
-
List<GameObject> ActorPrefabs = new();
|
|
305
|
-
if (ActorPrefabs.Count < characterDatabase.GetActorPrefabCount())
|
|
306
|
-
{
|
|
307
|
-
List<GameObject> p = new();
|
|
308
|
-
|
|
309
|
-
foreach (Character c in characterDatabase.Characters)
|
|
310
|
-
{
|
|
311
|
-
if (c.ActorPrefab != null)
|
|
312
|
-
{
|
|
313
|
-
UnityEngine.Debug.Log("Added " + c.ActorPrefab.name);
|
|
314
|
-
|
|
315
|
-
p.Add(c.ActorPrefab);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
ActorPrefabs = p;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// Add pop up window that says "Are you sure you want to unload actors? this will remove ALL actors in the scene."
|
|
323
|
-
// Destroy current Actor Objects in the scene
|
|
324
|
-
|
|
325
|
-
Actor[] x = (Actor[])FindObjectsByType(typeof(Actor));
|
|
326
|
-
|
|
327
|
-
if (x.Length == 0)
|
|
328
|
-
{
|
|
329
|
-
UnityEngine.Debug.Log("There are no Referenced Actors to Unload in the scene!");
|
|
330
|
-
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
for (int i = 0; i < x.Length; i++)
|
|
335
|
-
{
|
|
336
|
-
GameObject actor = x[i].gameObject.transform.parent.gameObject;
|
|
337
|
-
for (int j = 0; j < ActorPrefabs.Count; j++) // Look through Actor references
|
|
338
|
-
{
|
|
339
|
-
if (ActorPrefabs[j] != null && ActorPrefabs[j].name == actor.name) // Found
|
|
340
|
-
{
|
|
341
|
-
if (inEditor)
|
|
342
|
-
DestroyImmediate(actor);
|
|
343
|
-
else
|
|
344
|
-
Destroy(actor);
|
|
345
|
-
|
|
346
|
-
break;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
#if UNITY_EDITOR
|
|
357
|
-
/// <summary>
|
|
358
|
-
///
|
|
359
|
-
/// </summary>
|
|
360
|
-
/// <typeparam name="T"></typeparam>
|
|
361
|
-
/// <returns></returns>
|
|
362
|
-
public static List<T> FindAssetsByType<T>() where T : UnityEngine.Object
|
|
363
|
-
{
|
|
364
|
-
List<T> assets = new();
|
|
365
|
-
|
|
366
|
-
string[] guids = AssetDatabase.FindAssets(string.Format("t:{0}", typeof(T)));
|
|
367
|
-
|
|
368
|
-
for (int i = 0; i < guids.Length; i++)
|
|
369
|
-
{
|
|
370
|
-
string assetPath = AssetDatabase.GUIDToAssetPath(guids[i]);
|
|
371
|
-
|
|
372
|
-
T asset = AssetDatabase.LoadAssetAtPath<T>(assetPath);
|
|
373
|
-
|
|
374
|
-
if (asset != null)
|
|
375
|
-
assets.Add(asset);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
return assets;
|
|
379
|
-
}
|
|
380
|
-
#endif
|
|
381
|
-
}
|
|
382
|
-
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using DREditor.Actors;
|
|
3
|
+
using DREditor.Characters;
|
|
4
|
+
using DREditor.LocalDialogues;
|
|
5
|
+
using DREditor.RoomBuilding.Implementation.Actors;
|
|
6
|
+
using System.Collections.Generic;
|
|
7
|
+
using UnityEditor;
|
|
8
|
+
using UnityEngine;
|
|
9
|
+
|
|
10
|
+
namespace DREditor.RoomBuilding.Old
|
|
11
|
+
{
|
|
12
|
+
/// <summary>
|
|
13
|
+
///
|
|
14
|
+
/// </summary>
|
|
15
|
+
[ClassHeader("")]
|
|
16
|
+
public class ActorLoader : MonoBehaviour
|
|
17
|
+
{
|
|
18
|
+
public static List<ActorData> Save()
|
|
19
|
+
{
|
|
20
|
+
CharacterDatabase characterDatabase = GetDatabase();
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
List<GameObject> ActorPrefabs = new();
|
|
24
|
+
if (ActorPrefabs.Count < characterDatabase.GetActorPrefabCount())
|
|
25
|
+
{
|
|
26
|
+
List<GameObject> p = new();
|
|
27
|
+
|
|
28
|
+
foreach (Character c in characterDatabase.Characters)
|
|
29
|
+
{
|
|
30
|
+
if (c.ActorPrefab != null)
|
|
31
|
+
{
|
|
32
|
+
UnityEngine.Debug.Log("Added " + c.ActorPrefab.name);
|
|
33
|
+
|
|
34
|
+
p.Add(c.ActorPrefab);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
ActorPrefabs = p;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
List<ActorData> ActorListIn = new();
|
|
43
|
+
|
|
44
|
+
Actor[] x = (Actor[])FindObjectsByType(typeof(Actor));
|
|
45
|
+
|
|
46
|
+
if (x.Length == 0)
|
|
47
|
+
{
|
|
48
|
+
UnityEngine.Debug.Log("There are no Actors in the scene!");
|
|
49
|
+
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for (int i = 0; i < x.Length; i++)
|
|
54
|
+
{
|
|
55
|
+
GameObject actor = x[i].gameObject.transform.parent.gameObject;
|
|
56
|
+
|
|
57
|
+
for (int j = 0; j < ActorPrefabs.Count; j++) // Look through Actor references
|
|
58
|
+
{
|
|
59
|
+
if (ActorPrefabs[j] != null && ActorPrefabs[j].name == actor.name) // Actor Reference found Save actor data
|
|
60
|
+
{
|
|
61
|
+
ActorData a = new(ActorPrefabs[j].name, x[i]);
|
|
62
|
+
|
|
63
|
+
ActorListIn.Add((ActorData)a.Clone());
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return ActorListIn;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public static void Load(RoomData room, RoomData instanceRoom = null)
|
|
72
|
+
{
|
|
73
|
+
CharacterDatabase characterDatabase = GetDatabase();
|
|
74
|
+
|
|
75
|
+
List<GameObject> ActorPrefabs = SpawnActors(characterDatabase);
|
|
76
|
+
|
|
77
|
+
// when something is built itll take the object and convert it there
|
|
78
|
+
if (room != null && room.actorDatas != null && room.actorDatas.Count != 0)
|
|
79
|
+
{
|
|
80
|
+
List<ActorData> actors = room.actorDatas;
|
|
81
|
+
for (int i = 0; i < actors.Count; i++)
|
|
82
|
+
{
|
|
83
|
+
ActorData actor = (ActorData)actors[i].Clone();
|
|
84
|
+
//UnityEngine.Debug.Log("Actor prefab count: " + ActorPrefabs.Count);
|
|
85
|
+
for (int j = 0; j < ActorPrefabs.Count; j++) // Look through Actor references
|
|
86
|
+
{
|
|
87
|
+
// Actor prefab matches Base room name
|
|
88
|
+
if (ActorPrefabs[j] != null && ActorPrefabs[j].name == actor.aReference)
|
|
89
|
+
{
|
|
90
|
+
var x = instanceRoom != null ? GetCorrectInst(instanceRoom.actorDatas, ActorPrefabs[j].name) : null;
|
|
91
|
+
|
|
92
|
+
LoadActor(ActorPrefabs[j], actor, x, characterDatabase);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
UnityEngine.Debug.Log("Finished Loading Actors");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static List<GameObject> SpawnActors(CharacterDatabase characterDatabase)
|
|
103
|
+
{
|
|
104
|
+
List<GameObject> ActorPrefabs = new();
|
|
105
|
+
|
|
106
|
+
if (ActorPrefabs.Count < characterDatabase.GetActorPrefabCount())
|
|
107
|
+
{
|
|
108
|
+
List<GameObject> p = new();
|
|
109
|
+
|
|
110
|
+
foreach (Character c in characterDatabase.Characters)
|
|
111
|
+
{
|
|
112
|
+
if (c.ActorPrefab != null)
|
|
113
|
+
{
|
|
114
|
+
UnityEngine.Debug.Log("Added " + c.ActorPrefab.name);
|
|
115
|
+
|
|
116
|
+
p.Add(c.ActorPrefab);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
ActorPrefabs = p;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return ActorPrefabs;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static CharacterDatabase GetDatabase()
|
|
127
|
+
{
|
|
128
|
+
#if UNITY_EDITOR
|
|
129
|
+
string[] _databaseguids = AssetDatabase.FindAssets("t:CharacterDatabase");
|
|
130
|
+
if (_databaseguids.Length >= 1)
|
|
131
|
+
{
|
|
132
|
+
string _databasepath = AssetDatabase.GUIDToAssetPath(_databaseguids[0]);
|
|
133
|
+
|
|
134
|
+
try
|
|
135
|
+
{
|
|
136
|
+
EditorGUILayout.LabelField($"Loading CharacterDatabase at {_databasepath}.");
|
|
137
|
+
}
|
|
138
|
+
catch
|
|
139
|
+
{
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
return AssetDatabase.LoadAssetAtPath<CharacterDatabase>(_databasepath);
|
|
143
|
+
}
|
|
144
|
+
#endif
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
static ActorData GetCorrectInst(List<ActorData> instList, string nameLook)
|
|
149
|
+
{
|
|
150
|
+
// This if statement has been added because when leaving damons dorm on FTE 1
|
|
151
|
+
// the game freezes going to the dorm hallway because it has dorm hallway instance data from the
|
|
152
|
+
// previous objective. why this happens hasn't been fixed but this code keeps this problem from making
|
|
153
|
+
// an error freezing the game in a exported build.
|
|
154
|
+
|
|
155
|
+
if (instList == null)
|
|
156
|
+
{
|
|
157
|
+
UnityEngine.Debug.LogWarning("CRITICAL WARNING! INSTANCE LIST WAS NULL." +
|
|
158
|
+
" Instance data might be leaking Through the game?");
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
for (int i = 0; i < instList.Count; i++)
|
|
163
|
+
{
|
|
164
|
+
if (instList[i].aReference == nameLook)
|
|
165
|
+
return instList[i];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
UnityEngine.Debug.LogWarning("The instance actor data list couldn't find the character it was looking for? " + nameLook);
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
public static void LoadActor(GameObject shell, ActorData actorData, ActorData instanceData = null,
|
|
173
|
+
CharacterDatabase characterDatabase = null)
|
|
174
|
+
{
|
|
175
|
+
Actor a = SpawnActor(shell, actorData);
|
|
176
|
+
|
|
177
|
+
if (characterDatabase == null)
|
|
178
|
+
characterDatabase = GetDatabase();
|
|
179
|
+
|
|
180
|
+
// This is so the sprite is loaded correctly, but I need to add a way to reference
|
|
181
|
+
// the character database, I'm too lazy rn lmao
|
|
182
|
+
if (a.GetComponentInChildren<SpriteRenderer>().sprite.name != actorData.matName)
|
|
183
|
+
{
|
|
184
|
+
Character character = null;
|
|
185
|
+
|
|
186
|
+
if (characterDatabase != null)
|
|
187
|
+
{
|
|
188
|
+
character = characterDatabase.GetCharacter(actorData.aReference);
|
|
189
|
+
}
|
|
190
|
+
else
|
|
191
|
+
{
|
|
192
|
+
UnityEngine.Debug.LogError("Character Database Not Found?");
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (character != null && character.Expressions != null &&
|
|
196
|
+
!actorData.matName.Contains(character.Expressions[0].Sprite.name) &&
|
|
197
|
+
!a.GetComponentInChildren<SpriteRenderer>().sprite.name.Contains("stare") &&
|
|
198
|
+
!actorData.matName.Contains("Stare"))
|
|
199
|
+
{
|
|
200
|
+
|
|
201
|
+
//UnityEngine.Debug.Log("Materials and sprites were not loaded the same for: " + actorData.matName + " , "
|
|
202
|
+
//+ a.GetComponentInChildren<SpriteRenderer>().sprite.name);
|
|
203
|
+
|
|
204
|
+
//UnityEngine.Debug.Log("MAT NAME WAS: " + actorData.matName);
|
|
205
|
+
for (int i = 0; i < character.Expressions.Count; i++)
|
|
206
|
+
{
|
|
207
|
+
Expression exp = character.Expressions[i];
|
|
208
|
+
|
|
209
|
+
if (actorData.matName.Contains(exp.Sprite.name))
|
|
210
|
+
{
|
|
211
|
+
a.GetComponentInChildren<SpriteRenderer>().sprite = character.Sprites[i].Sprite;
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
if (Application.isPlaying)
|
|
220
|
+
{
|
|
221
|
+
// The spawned object registers itself.
|
|
222
|
+
//ServiceLocator.GetService<ActorManager>().RegisterObject(a);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
LoadActorInstance(a, actorData, instanceData, characterDatabase);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
protected static void LoadActorInstance(Actor a, ActorData actorData, ActorData instanceData = null,
|
|
231
|
+
CharacterDatabase characterDatabase = null)
|
|
232
|
+
{
|
|
233
|
+
if (instanceData != null)
|
|
234
|
+
{
|
|
235
|
+
Character character = characterDatabase.GetCharacter(actorData.aReference);
|
|
236
|
+
a.gameObject.transform.position = instanceData.position;
|
|
237
|
+
a.gameObject.transform.eulerAngles = instanceData.rotation;
|
|
238
|
+
a.SetIdentified(instanceData.identified);
|
|
239
|
+
if (instanceData.displayName != "")
|
|
240
|
+
{
|
|
241
|
+
a.DisplayName = instanceData.displayName;
|
|
242
|
+
}
|
|
243
|
+
for (int i = 0; i < instanceData.actorDialogues.Count && i < actorData.actorDialogues.Count; i++)
|
|
244
|
+
{
|
|
245
|
+
UnityEngine.Debug.Log(i);
|
|
246
|
+
a.conversations[i].SetTriggered(instanceData.actorDialogues[i].triggered);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
UnityEngine.Debug.Log("MAT NAME WAS: " + instanceData.matName);
|
|
250
|
+
for (int i = 0; i < character.Expressions.Count; i++)
|
|
251
|
+
{
|
|
252
|
+
Expression exp = character.Expressions[i];
|
|
253
|
+
|
|
254
|
+
if (instanceData.matName.Contains(exp.Sprite.name))
|
|
255
|
+
{
|
|
256
|
+
UnityEngine.Debug.Log(exp.Sprite.name);
|
|
257
|
+
var instanceMeshes = a.GetComponentsInChildren<MeshRenderer>();
|
|
258
|
+
|
|
259
|
+
instanceMeshes[0].material = exp.Sprite;
|
|
260
|
+
|
|
261
|
+
Material ma = new(instanceMeshes[1].sharedMaterial.shader);
|
|
262
|
+
ma.mainTexture = instanceMeshes[0].sharedMaterial.mainTexture;
|
|
263
|
+
instanceMeshes[1].sharedMaterial = ma;
|
|
264
|
+
instanceMeshes[1].sharedMaterial.color = Color.black;
|
|
265
|
+
instanceMeshes[1].sharedMaterial.renderQueue = 3000;
|
|
266
|
+
a.GetComponentInChildren<SpriteRenderer>().sprite = character.Sprites[i].Sprite;
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
protected static Actor SpawnActor(GameObject shell, ActorData actorData)
|
|
274
|
+
{
|
|
275
|
+
GameObject loaded = Instantiate(shell);
|
|
276
|
+
loaded.name = actorData.aReference;
|
|
277
|
+
loaded.transform.position = actorData.position;
|
|
278
|
+
loaded.transform.eulerAngles = actorData.rotation;
|
|
279
|
+
Actor a = loaded.GetComponent<Actor>();
|
|
280
|
+
|
|
281
|
+
a.conversations.Clear();
|
|
282
|
+
|
|
283
|
+
for (int i = 0; i < actorData.actorDialogues.Count; i++)
|
|
284
|
+
a.conversations.Add((LocalDialogue)actorData.actorDialogues[i].Clone());
|
|
285
|
+
|
|
286
|
+
var meshes = a.GetComponentsInChildren<MeshRenderer>();
|
|
287
|
+
|
|
288
|
+
meshes[0].material = actorData.mat;
|
|
289
|
+
Material m = new(meshes[1].sharedMaterial.shader);
|
|
290
|
+
m.mainTexture = meshes[0].sharedMaterial.mainTexture;
|
|
291
|
+
meshes[1].sharedMaterial = m;
|
|
292
|
+
meshes[1].sharedMaterial.color = Color.black;
|
|
293
|
+
meshes[1].sharedMaterial.renderQueue = 3000;
|
|
294
|
+
a.SetIdentified(actorData.identified);
|
|
295
|
+
if (actorData.displayName != "")
|
|
296
|
+
a.DisplayName = actorData.displayName;
|
|
297
|
+
return a;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
public static void UnloadActors(bool inEditor)
|
|
301
|
+
{
|
|
302
|
+
CharacterDatabase characterDatabase = GetDatabase();
|
|
303
|
+
|
|
304
|
+
List<GameObject> ActorPrefabs = new();
|
|
305
|
+
if (ActorPrefabs.Count < characterDatabase.GetActorPrefabCount())
|
|
306
|
+
{
|
|
307
|
+
List<GameObject> p = new();
|
|
308
|
+
|
|
309
|
+
foreach (Character c in characterDatabase.Characters)
|
|
310
|
+
{
|
|
311
|
+
if (c.ActorPrefab != null)
|
|
312
|
+
{
|
|
313
|
+
UnityEngine.Debug.Log("Added " + c.ActorPrefab.name);
|
|
314
|
+
|
|
315
|
+
p.Add(c.ActorPrefab);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
ActorPrefabs = p;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// Add pop up window that says "Are you sure you want to unload actors? this will remove ALL actors in the scene."
|
|
323
|
+
// Destroy current Actor Objects in the scene
|
|
324
|
+
|
|
325
|
+
Actor[] x = (Actor[])FindObjectsByType(typeof(Actor));
|
|
326
|
+
|
|
327
|
+
if (x.Length == 0)
|
|
328
|
+
{
|
|
329
|
+
UnityEngine.Debug.Log("There are no Referenced Actors to Unload in the scene!");
|
|
330
|
+
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
for (int i = 0; i < x.Length; i++)
|
|
335
|
+
{
|
|
336
|
+
GameObject actor = x[i].gameObject.transform.parent.gameObject;
|
|
337
|
+
for (int j = 0; j < ActorPrefabs.Count; j++) // Look through Actor references
|
|
338
|
+
{
|
|
339
|
+
if (ActorPrefabs[j] != null && ActorPrefabs[j].name == actor.name) // Found
|
|
340
|
+
{
|
|
341
|
+
if (inEditor)
|
|
342
|
+
DestroyImmediate(actor);
|
|
343
|
+
else
|
|
344
|
+
Destroy(actor);
|
|
345
|
+
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
#if UNITY_EDITOR
|
|
357
|
+
/// <summary>
|
|
358
|
+
///
|
|
359
|
+
/// </summary>
|
|
360
|
+
/// <typeparam name="T"></typeparam>
|
|
361
|
+
/// <returns></returns>
|
|
362
|
+
public static List<T> FindAssetsByType<T>() where T : UnityEngine.Object
|
|
363
|
+
{
|
|
364
|
+
List<T> assets = new();
|
|
365
|
+
|
|
366
|
+
string[] guids = AssetDatabase.FindAssets(string.Format("t:{0}", typeof(T)));
|
|
367
|
+
|
|
368
|
+
for (int i = 0; i < guids.Length; i++)
|
|
369
|
+
{
|
|
370
|
+
string assetPath = AssetDatabase.GUIDToAssetPath(guids[i]);
|
|
371
|
+
|
|
372
|
+
T asset = AssetDatabase.LoadAssetAtPath<T>(assetPath);
|
|
373
|
+
|
|
374
|
+
if (asset != null)
|
|
375
|
+
assets.Add(asset);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return assets;
|
|
379
|
+
}
|
|
380
|
+
#endif
|
|
381
|
+
}
|
|
382
|
+
|
|
383
383
|
}
|