net.dreditor.actors 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.
Files changed (143) hide show
  1. package/.attestation.p7m +0 -0
  2. package/Actor.cs +74 -74
  3. package/Actor.cs.meta +11 -11
  4. package/ActorBodyDebugger.cs +117 -117
  5. package/ActorBodyDebugger.cs.meta +13 -13
  6. package/ActorManager.cs +149 -149
  7. package/ActorManager.cs.meta +11 -11
  8. package/ActorOrganizer.cs +93 -93
  9. package/ActorOrganizer.cs.meta +11 -11
  10. package/BasicExpressionChanger.cs +157 -157
  11. package/BasicExpressionChanger.cs.meta +11 -11
  12. package/BasicLayerHandler.cs +108 -108
  13. package/BasicLayerHandler.cs.meta +11 -11
  14. package/DREditor.Actors.asmdef +20 -20
  15. package/DREditor.Actors.asmdef.meta +7 -7
  16. package/Editor/AssignmentStyleGUIEditor.cs +171 -171
  17. package/Editor/AssignmentStyleGUIEditor.cs.meta +1 -1
  18. package/Editor/AutoCreateCharacterWizard.cs +475 -475
  19. package/Editor/AutoCreateCharacterWizard.cs.meta +11 -11
  20. package/Editor/AutoCreateTrialCharacterWizard.cs +426 -426
  21. package/Editor/AutoCreateTrialCharacterWizard.cs.meta +1 -1
  22. package/Editor/CharacterUtility.cs +119 -119
  23. package/Editor/CharacterUtility.cs.meta +11 -11
  24. package/Editor/CircleDrawer.cs +206 -206
  25. package/Editor/CircleDrawer.cs.meta +1 -1
  26. package/Editor/CircleUtility.cs +54 -54
  27. package/Editor/CircleUtility.cs.meta +1 -1
  28. package/Editor/DREditor.Actors.Editor.asmdef +21 -21
  29. package/Editor/DREditor.Actors.Editor.asmdef.meta +7 -7
  30. package/Editor/GenerateCharacterIntroDialogues.cs +234 -234
  31. package/Editor/GenerateCharacterIntroDialogues.cs.meta +11 -11
  32. package/Editor/IItemImporter.cs +19 -19
  33. package/Editor/IItemImporter.cs.meta +1 -1
  34. package/Editor/ItemImporter.cs +170 -170
  35. package/Editor/ItemImporter.cs.meta +1 -1
  36. package/Editor/ItemUtility.cs +85 -85
  37. package/Editor/ItemUtility.cs.meta +11 -11
  38. package/Editor/ItemWizard.cs +41 -41
  39. package/Editor/ItemWizard.cs.meta +11 -11
  40. package/Editor.meta +8 -8
  41. package/Events/ActorCheckFocusEvent.cs +49 -49
  42. package/Events/ActorCheckFocusEvent.cs.meta +11 -11
  43. package/Events/ActorFadeEvent.cs +19 -19
  44. package/Events/ActorFadeEvent.cs.meta +11 -11
  45. package/Events/ActorFadeHandler.cs +53 -53
  46. package/Events/ActorFadeHandler.cs.meta +11 -11
  47. package/Events/ActorFaintEvent.cs +282 -282
  48. package/Events/ActorFaintEvent.cs.meta +11 -11
  49. package/Events/ActorFaintEventRenderQ.cs +65 -65
  50. package/Events/ActorFaintEventRenderQ.cs.meta +11 -11
  51. package/Events/ActorLeaveHandler.cs +238 -238
  52. package/Events/ActorLeaveHandler.cs.meta +11 -11
  53. package/Events/ActorSpriteFader.cs +190 -190
  54. package/Events/ActorSpriteFader.cs.meta +11 -11
  55. package/Events/ActorSpriteFaderRenderQ.cs +49 -49
  56. package/Events/ActorSpriteFaderRenderQ.cs.meta +11 -11
  57. package/Events/BSTrialActorFlash.cs +259 -259
  58. package/Events/BSTrialActorFlash.cs.meta +11 -11
  59. package/Events/ChangeLastFocusEvent.cs +62 -62
  60. package/Events/ChangeLastFocusEvent.cs.meta +11 -11
  61. package/Events/MoveCharacterEvent.cs +141 -141
  62. package/Events/MoveCharacterEvent.cs.meta +11 -11
  63. package/Events.meta +8 -8
  64. package/ExpressionChanger.cs +25 -25
  65. package/ExpressionChanger.cs.meta +11 -11
  66. package/FocusHandler.cs +96 -96
  67. package/FocusHandler.cs.meta +11 -11
  68. package/Implementation/ActorFocusHandler.cs +195 -195
  69. package/Implementation/ActorFocusHandler.cs.meta +11 -11
  70. package/Implementation/ActorFocusLoadEnd.cs +108 -108
  71. package/Implementation/ActorFocusLoadEnd.cs.meta +11 -11
  72. package/Implementation/ActorFocusPrepare.cs +102 -102
  73. package/Implementation/ActorFocusPrepare.cs.meta +11 -11
  74. package/Implementation/ActorFocusResolve.cs +67 -67
  75. package/Implementation/ActorFocusResolve.cs.meta +11 -11
  76. package/Implementation/ActorSpriteChanger.cs +129 -129
  77. package/Implementation/ActorSpriteChanger.cs.meta +11 -11
  78. package/Implementation/ActorTrialSpriteChanger.cs +46 -46
  79. package/Implementation/ActorTrialSpriteChanger.cs.meta +11 -11
  80. package/Implementation/ChangeLastSpriteEvent.cs +92 -92
  81. package/Implementation/ChangeLastSpriteEvent.cs.meta +11 -11
  82. package/Implementation/WorldSpriteChanger.cs +207 -207
  83. package/Implementation/WorldSpriteChanger.cs.meta +11 -11
  84. package/Implementation.meta +8 -8
  85. package/LayerHandler.cs +30 -30
  86. package/LayerHandler.cs.meta +11 -11
  87. package/{Samples → Samples~}/Actor.prefab +581 -581
  88. package/{Samples → Samples~}/Actor.prefab.meta +7 -7
  89. package/{Samples → Samples~}/Actor_Body_Debugger.prefab +68 -68
  90. package/{Samples → Samples~}/Actor_Body_Debugger.prefab.meta +7 -7
  91. package/{Samples → Samples~}/Actor_Check_Focus_Event.prefab +47 -47
  92. package/{Samples → Samples~}/Actor_Check_Focus_Event.prefab.meta +7 -7
  93. package/{Samples → Samples~}/Actor_Event_Handlers.prefab +668 -668
  94. package/{Samples → Samples~}/Actor_Event_Handlers.prefab.meta +7 -7
  95. package/{Samples → Samples~}/Actor_Fade_Handler.prefab +137 -137
  96. package/{Samples → Samples~}/Actor_Fade_Handler.prefab.meta +7 -7
  97. package/{Samples → Samples~}/Actor_Fade_Handler_Render_Q.prefab +137 -137
  98. package/{Samples → Samples~}/Actor_Fade_Handler_Render_Q.prefab.meta +7 -7
  99. package/{Samples → Samples~}/Actor_Faint_Event.prefab +71 -71
  100. package/{Samples → Samples~}/Actor_Faint_Event.prefab.meta +7 -7
  101. package/{Samples → Samples~}/Actor_Faint_Event_Render_Q.prefab +73 -73
  102. package/{Samples → Samples~}/Actor_Faint_Event_Render_Q.prefab.meta +7 -7
  103. package/{Samples → Samples~}/Actor_Focus_Handler.prefab +168 -168
  104. package/{Samples → Samples~}/Actor_Focus_Handler.prefab.meta +7 -7
  105. package/{Samples → Samples~}/Actor_Focus_Handler_Shell.prefab +56 -56
  106. package/{Samples → Samples~}/Actor_Focus_Handler_Shell.prefab.meta +7 -7
  107. package/{Samples → Samples~}/Actor_Focus_Load_End.prefab +66 -66
  108. package/{Samples → Samples~}/Actor_Focus_Load_End.prefab.meta +7 -7
  109. package/{Samples → Samples~}/Actor_Focus_Prepare.prefab +49 -49
  110. package/{Samples → Samples~}/Actor_Focus_Prepare.prefab.meta +7 -7
  111. package/{Samples → Samples~}/Actor_Focus_Resolve.prefab +48 -48
  112. package/{Samples → Samples~}/Actor_Focus_Resolve.prefab.meta +7 -7
  113. package/{Samples → Samples~}/Actor_Leave_Handler.prefab +141 -141
  114. package/{Samples → Samples~}/Actor_Leave_Handler.prefab.meta +7 -7
  115. package/{Samples → Samples~}/Actor_Leave_Handler_Render_Q.prefab +141 -141
  116. package/{Samples → Samples~}/Actor_Leave_Handler_Render_Q.prefab.meta +7 -7
  117. package/{Samples → Samples~}/Actor_Organizer.prefab +49 -49
  118. package/{Samples → Samples~}/Actor_Organizer.prefab.meta +7 -7
  119. package/{Samples → Samples~}/Actor_Sprite_Changer.prefab +163 -163
  120. package/{Samples → Samples~}/Actor_Sprite_Changer.prefab.meta +7 -7
  121. package/{Samples → Samples~}/Actor_Sprite_Changer_Shell.prefab +51 -51
  122. package/{Samples → Samples~}/Actor_Sprite_Changer_Shell.prefab.meta +7 -7
  123. package/{Samples → Samples~}/Actor_Sprite_Fader.prefab +52 -52
  124. package/{Samples → Samples~}/Actor_Sprite_Fader.prefab.meta +7 -7
  125. package/{Samples → Samples~}/Actor_Sprite_Fader_Render_Q.prefab +54 -54
  126. package/{Samples → Samples~}/Actor_Sprite_Fader_Render_Q.prefab.meta +7 -7
  127. package/{Samples → Samples~}/Actor_Trial_Sprite_Changer.prefab +47 -47
  128. package/{Samples → Samples~}/Actor_Trial_Sprite_Changer.prefab.meta +7 -7
  129. package/{Samples → Samples~}/Change_Last_Focus_Event.prefab +66 -66
  130. package/{Samples → Samples~}/Change_Last_Focus_Event.prefab.meta +7 -7
  131. package/{Samples → Samples~}/Change_Last_Sprite_Event.prefab +49 -49
  132. package/{Samples → Samples~}/Change_Last_Sprite_Event.prefab.meta +7 -7
  133. package/{Samples → Samples~}/Change_Last_World_Sprite_Event.prefab +186 -186
  134. package/{Samples → Samples~}/Change_Last_World_Sprite_Event.prefab.meta +7 -7
  135. package/{Samples → Samples~}/Focus_Handler.prefab +49 -49
  136. package/{Samples → Samples~}/Focus_Handler.prefab.meta +7 -7
  137. package/{Samples → Samples~}/Move_Character_Event.prefab +51 -51
  138. package/{Samples → Samples~}/Move_Character_Event.prefab.meta +7 -7
  139. package/{Samples → Samples~}/World_Sprite_Changer.prefab +51 -51
  140. package/{Samples → Samples~}/World_Sprite_Changer.prefab.meta +7 -7
  141. package/package.json +43 -38
  142. package/package.json.meta +7 -7
  143. package/Samples.meta +0 -8
@@ -1,427 +1,427 @@
1
- //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
- using DREditor.Cameras;
3
- using DREditor.Characters;
4
- using DREditor.Editor.Utility;
5
- using DREditor.Talkables;
6
- using System;
7
- using System.Collections.Generic;
8
- using System.Linq;
9
- using UnityEditor;
10
- using UnityEngine;
11
-
12
- namespace DREditor.Actors.Editor
13
- {
14
- /// <summary>
15
- ///
16
- /// </summary>
17
- public class AutoCreateTrialCharacterWizard : ScriptableWizard
18
- {
19
- /// <summary>
20
- ///
21
- /// </summary>
22
- [Tooltip("")]
23
- [SerializeField] protected CharacterDatabase characterDatabase = null;
24
-
25
-
26
- /// <summary>
27
- ///
28
- /// </summary>
29
- [Header("Trial Actor Settings")]
30
- [Divider]
31
- [Tooltip("")]
32
- [SerializeField] protected string trialActorPrefabPath = "Assets/Prefabs/Actors/Trial";
33
-
34
- /// <summary>
35
- ///
36
- /// </summary>
37
- [Tooltip("")]
38
- [SerializeField] protected Vector3 prefabScale = new(3, 3, 3);
39
-
40
-
41
- /// <summary>
42
- ///
43
- /// </summary>
44
- [Header("Trial Shader Settings")]
45
- [Divider]
46
- [Tooltip("")]
47
- [SerializeField] protected Shader trialShader;
48
-
49
- /// <summary>
50
- ///
51
- /// </summary>
52
- [Tooltip("")]
53
- [ShowIf(nameof(UsingTrialShader))]
54
- [SerializeField] protected Vector2 extrudeSize = new(-1.01f, -1.01f);
55
-
56
- /// <summary>
57
- ///
58
- /// </summary>
59
- [Tooltip("")]
60
- [ShowIf(nameof(UsingTrialShader))]
61
- [SerializeField] protected float outlineInfluence = 390f;
62
-
63
- /// <summary>
64
- ///
65
- /// </summary>
66
- [Tooltip("")]
67
- [ShowIf(nameof(UsingTrialShader))]
68
- [SerializeField] protected float lightAngle = -0.4f;
69
-
70
- /// <summary>
71
- ///
72
- /// </summary>
73
- [Tooltip("")]
74
- [ShowIf(nameof(UsingTrialShader))]
75
- [SerializeField] protected Color outlineColor = new(1, 1, 1, 0.02745098f);
76
-
77
-
78
- /// <summary>
79
- ///
80
- /// </summary>
81
- [Header("Spawn Settings")]
82
- [Divider]
83
- [Tooltip("")]
84
- [SerializeField] protected Transform trialCameraTransform;
85
-
86
- /// <summary>
87
- ///
88
- /// </summary>
89
- [Tooltip("")]
90
- [SerializeField] protected Transform spawnParent;
91
-
92
- /// <summary>
93
- ///
94
- /// </summary>
95
- [Tooltip("")]
96
- [Range(0, 50)]
97
- [SerializeField] protected int numberOfObjects = 16;
98
-
99
- /// <summary>
100
- ///
101
- /// </summary>
102
- [Tooltip("")]
103
- [SerializeField] protected float spawnRadius = 8.11f;
104
-
105
- /// <summary>
106
- ///
107
- /// </summary>
108
- [Range(-360f, 360f)]
109
- [Tooltip("")]
110
- [SerializeField] protected float startingDegreeOffset = 90f;
111
-
112
- /// <summary>
113
- ///
114
- /// </summary>
115
- [Tooltip("")]
116
- [SerializeField] protected List<Character> ignoredCharacters = new();
117
-
118
-
119
- /// <summary>
120
- ///
121
- /// </summary>
122
- [Header("Editor Settings")]
123
- [Divider]
124
- [Tooltip("")]
125
- [SerializeField] protected AssignmentStyleGUIEditor<Character> assignmentEditor;
126
-
127
- /// <summary>
128
- ///
129
- /// </summary>
130
- [Tooltip("")]
131
- [SerializeField] protected CircleDrawer circleDrawer = new();
132
-
133
-
134
- /// <summary>
135
- ///
136
- /// </summary>
137
- protected bool changed;
138
-
139
- /// <summary>
140
- ///
141
- /// </summary>
142
- protected int slot;
143
-
144
- /// <summary>
145
- ///
146
- /// </summary>
147
- protected int newIndex;
148
-
149
-
150
- /// <summary>
151
- ///
152
- /// </summary>
153
- protected readonly string spawnParentName = "Characters";
154
-
155
-
156
- /// <summary>
157
- ///
158
- /// </summary>
159
- /// <returns></returns>
160
- [MenuItem("DREditor/Characters/Auto Setup Trial Character", true)]
161
- public static bool VerifyWizard() =>
162
- DatabaseUtility.LoadDatabase<CharacterDatabase>() is CharacterDatabase database &&
163
- database.Characters.Count > 0;
164
-
165
-
166
- [MenuItem("DREditor/Characters/Auto Setup Trial Character")]
167
- public static void ShowWizard() => DisplayWizard<AutoCreateTrialCharacterWizard>("Auto Setup Trial Character", "Create");
168
-
169
-
170
- protected virtual void OnEnable()
171
- {
172
- minSize = new Vector2(1100, 800);
173
-
174
- characterDatabase = DatabaseUtility.LoadDatabase<CharacterDatabase>();
175
-
176
- trialShader = Shader.Find("Shader Graphs/CharacterTrial");
177
-
178
- if (FindAnyObjectByType<DRTrialCamera>() is DRTrialCamera camera)
179
- trialCameraTransform = camera.transform;
180
-
181
- if (GameObject.Find(spawnParentName) is GameObject spawnParent)
182
- this.spawnParent = spawnParent.transform;
183
-
184
- ResetAssignmentEditor();
185
- }
186
-
187
- protected virtual void OnWizardCreate()
188
- {
189
- DestroyAllChildren();
190
-
191
- SpawnTrialCharacters();
192
-
193
- EditorUtility.SetDirty(spawnParent);
194
- }
195
-
196
- /// <summary>
197
- ///
198
- /// </summary>
199
- protected virtual void DestroyAllChildren()
200
- {
201
- foreach (Transform child in spawnParent.transform)
202
- GameObject.DestroyImmediate(child.gameObject);
203
- }
204
-
205
- /// <summary>
206
- ///
207
- /// </summary>
208
- protected virtual void SpawnTrialCharacters()
209
- {
210
- for (int i = 0; i < assignmentEditor.Assignments.Length; i++)
211
- if (CharacterCanBeSpawnedAtAssignment(i))
212
- SpawnTrialCharacter(assignmentEditor.Objects[assignmentEditor.Assignments[i]], i);
213
- }
214
-
215
- /// <summary>
216
- ///
217
- /// </summary>
218
- /// <param name="i"></param>
219
- /// <returns></returns>
220
- protected virtual bool CharacterCanBeSpawnedAtAssignment(int i) =>
221
- assignmentEditor.Assignments[i] is int assignIndex &&
222
- assignIndex >= 0 &&
223
- assignIndex < assignmentEditor.Objects.Count &&
224
- assignmentEditor.Objects[assignIndex].ActorPrefab != null;
225
-
226
- /// <summary>
227
- ///
228
- /// </summary>
229
- /// <param name="character"></param>
230
- /// <param name="i"></param>
231
- protected virtual void SpawnTrialCharacter(Character character, int i)
232
- {
233
- float currentAngle = (startingDegreeOffset + CircleUtility.DegreesInCircle * -i / numberOfObjects) * Mathf.Deg2Rad;
234
-
235
- Vector3 spawnPosition = trialCameraTransform.position +
236
- new Vector3(Mathf.Cos(currentAngle) * spawnRadius, 0f, Mathf.Sin(currentAngle) * spawnRadius);
237
-
238
- Vector3 directionFromCenter = (spawnPosition - trialCameraTransform.position).normalized;
239
-
240
- Quaternion spawnRotation = Quaternion.LookRotation(directionFromCenter);
241
-
242
- string path = AssetDatabase.GetAssetPath(character.ActorPrefab);
243
-
244
- GameObject actorPrefab = AssetDatabase.LoadAssetAtPath<GameObject>(path);
245
-
246
- GameObject trialPrefab = SpawnObjectAt(actorPrefab, spawnPosition, spawnRotation);
247
-
248
- CustomEditorUtility.EnsureFolders(trialActorPrefabPath);
249
-
250
- PrefabUtility.SaveAsPrefabAsset(trialPrefab, trialActorPrefabPath + "/" + actorPrefab.name + ".prefab");
251
-
252
- character.TrialPosition = i;
253
-
254
- EditorUtility.SetDirty(character);
255
- }
256
-
257
- /// <summary>
258
- ///
259
- /// </summary>
260
- /// <param name="prefabToSpawn"></param>
261
- /// <param name="spawnPosition"></param>
262
- /// <param name="spawnRotation"></param>
263
- /// <returns></returns>
264
- protected virtual GameObject SpawnObjectAt(GameObject prefabToSpawn, Vector3 spawnPosition, Quaternion spawnRotation)
265
- {
266
- GameObject spawned = (GameObject)PrefabUtility.InstantiatePrefab(prefabToSpawn, spawnParent);
267
-
268
- spawned.transform.SetPositionAndRotation(spawnPosition, spawnRotation);
269
-
270
- float xPos = spawned.transform.localPosition.x;
271
-
272
- float zPos = spawned.transform.localPosition.z;
273
-
274
- spawned.transform.localPosition = new(xPos, -1, zPos);
275
-
276
- float yRot = spawned.transform.eulerAngles.y;
277
-
278
- spawned.transform.localEulerAngles = new(0, yRot + 180, 0);
279
-
280
- spawned.transform.localScale = prefabScale;
281
-
282
- ApplyTrialShader(spawned);
283
-
284
- if (spawned.TryGetComponent(out SpriteLookAtTarget billboard))
285
- billboard.enabled = false;
286
-
287
- return spawned;
288
- }
289
-
290
- /// <summary>
291
- ///
292
- /// </summary>
293
- /// <param name="objectToDuplicateName"></param>
294
- /// <param name="objectToDuplicatePath"></param>
295
- /// <returns></returns>
296
- protected virtual string BuildDuplicatedMaterialPath(string objectToDuplicateName, string objectToDuplicatePath) =>
297
- objectToDuplicatePath.Replace(objectToDuplicateName, objectToDuplicateName + "_Trial");
298
-
299
- /// <summary>
300
- ///
301
- /// </summary>
302
- /// <param name="spawnedObj"></param>
303
- protected virtual void ApplyTrialShader(GameObject spawnedObj)
304
- {
305
- if (spawnedObj.transform.GetChild(0) is not Transform rendererChild || !rendererChild.TryGetComponent<MeshRenderer>(out var actorRenderer))
306
- return;
307
-
308
- Material baseMaterial = actorRenderer.sharedMaterial;
309
-
310
- if (CustomEditorUtility.TryDuplicateAsset(baseMaterial, BuildDuplicatedMaterialPath, out Material trialMaterial))
311
- {
312
- trialMaterial.shader = trialShader;
313
-
314
- actorRenderer.material = trialMaterial;
315
-
316
- if (UsingTrialShader())
317
- {
318
- trialMaterial.SetVector(nameof(extrudeSize), extrudeSize);
319
-
320
- trialMaterial.SetColor(nameof(outlineColor), outlineColor);
321
-
322
- trialMaterial.SetFloat(nameof(outlineInfluence), outlineInfluence);
323
-
324
- trialMaterial.SetFloat(nameof(lightAngle), lightAngle);
325
- }
326
- }
327
- }
328
-
329
- /// <summary>
330
- ///
331
- /// </summary>
332
- /// <returns></returns>
333
- protected virtual bool UsingTrialShader() => trialShader == Shader.Find("Shader Graphs/CharacterTrial");
334
-
335
- #region Editor GUI
336
-
337
- protected override bool DrawWizardGUI()
338
- {
339
- changed = base.DrawWizardGUI();
340
-
341
- HandySplitters.UISplitter();
342
-
343
- if (changed)
344
- ResetAssignmentEditor();
345
- else
346
- DrawCircleGUI();
347
-
348
- return changed;
349
- }
350
-
351
- /// <summary>
352
- ///
353
- /// </summary>
354
- protected virtual void ResetAssignmentEditor() => assignmentEditor = CreateNewAssignmentEditor();
355
-
356
- /// <summary>
357
- ///
358
- /// </summary>
359
- /// <returns></returns>
360
- protected virtual AssignmentStyleGUIEditor<Character> CreateNewAssignmentEditor() =>
361
- new(GetTrialCharacters(), GetCharacterName, numberOfObjects, assignmentEditor?.Assignments);
362
-
363
- /// <summary>
364
- ///
365
- /// </summary>
366
- /// <returns></returns>
367
- protected virtual List<Character> GetTrialCharacters()
368
- {
369
- if (ignoredCharacters.Count == 0)
370
- return characterDatabase.Characters;
371
-
372
- List<Character> characters = new();
373
-
374
- foreach (Character character in characterDatabase.Characters)
375
- if (ignoredCharacters.Contains(character))
376
- continue;
377
- else
378
- characters.Add(character);
379
-
380
- return characters;
381
- }
382
-
383
- /// <summary>
384
- ///
385
- /// </summary>
386
- /// <param name="character"></param>
387
- /// <returns></returns>
388
- protected virtual string GetCharacterName(Character character) => character.FirstName + " " + character.LastName;
389
-
390
- /// <summary>
391
- ///
392
- /// </summary>
393
- protected virtual void DrawCircleGUI()
394
- {
395
- assignmentEditor?.ValidateAssignments();
396
-
397
- circleDrawer?.Draw();
398
-
399
- if (numberOfObjects == assignmentEditor.Assignments.Length)
400
- circleDrawer?.DrawObjectsAround(numberOfObjects, DrawDropdown, OnDropdownChanged);
401
- }
402
-
403
- /// <summary>
404
- ///
405
- /// </summary>
406
- /// <param name="aroundCircleRect"></param>
407
- /// <param name="slot"></param>
408
- protected virtual void DrawDropdown(Rect aroundCircleRect, int slot)
409
- {
410
- this.slot = slot;
411
-
412
- newIndex = EditorGUI.Popup(aroundCircleRect, assignmentEditor.Assignments[slot], assignmentEditor.GetAssignedNames());
413
- }
414
-
415
- /// <summary>
416
- ///
417
- /// </summary>
418
- protected virtual void OnDropdownChanged()
419
- {
420
- assignmentEditor.SwapAssignment(slot, newIndex);
421
-
422
- changed = true;
423
- }
424
-
425
- #endregion
426
- }
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ using DREditor.Cameras;
3
+ using DREditor.Characters;
4
+ using DREditor.Editor.Utility;
5
+ using DREditor.Talkables;
6
+ using System;
7
+ using System.Collections.Generic;
8
+ using System.Linq;
9
+ using UnityEditor;
10
+ using UnityEngine;
11
+
12
+ namespace DREditor.Actors.Editor
13
+ {
14
+ /// <summary>
15
+ ///
16
+ /// </summary>
17
+ public class AutoCreateTrialCharacterWizard : ScriptableWizard
18
+ {
19
+ /// <summary>
20
+ ///
21
+ /// </summary>
22
+ [Tooltip("")]
23
+ [SerializeField] protected CharacterDatabase characterDatabase = null;
24
+
25
+
26
+ /// <summary>
27
+ ///
28
+ /// </summary>
29
+ [Header("Trial Actor Settings")]
30
+ [Divider]
31
+ [Tooltip("")]
32
+ [SerializeField] protected string trialActorPrefabPath = "Assets/Prefabs/Actors/Trial";
33
+
34
+ /// <summary>
35
+ ///
36
+ /// </summary>
37
+ [Tooltip("")]
38
+ [SerializeField] protected Vector3 prefabScale = new(3, 3, 3);
39
+
40
+
41
+ /// <summary>
42
+ ///
43
+ /// </summary>
44
+ [Header("Trial Shader Settings")]
45
+ [Divider]
46
+ [Tooltip("")]
47
+ [SerializeField] protected Shader trialShader;
48
+
49
+ /// <summary>
50
+ ///
51
+ /// </summary>
52
+ [Tooltip("")]
53
+ [ShowIf(nameof(UsingTrialShader))]
54
+ [SerializeField] protected Vector2 extrudeSize = new(-1.01f, -1.01f);
55
+
56
+ /// <summary>
57
+ ///
58
+ /// </summary>
59
+ [Tooltip("")]
60
+ [ShowIf(nameof(UsingTrialShader))]
61
+ [SerializeField] protected float outlineInfluence = 390f;
62
+
63
+ /// <summary>
64
+ ///
65
+ /// </summary>
66
+ [Tooltip("")]
67
+ [ShowIf(nameof(UsingTrialShader))]
68
+ [SerializeField] protected float lightAngle = -0.4f;
69
+
70
+ /// <summary>
71
+ ///
72
+ /// </summary>
73
+ [Tooltip("")]
74
+ [ShowIf(nameof(UsingTrialShader))]
75
+ [SerializeField] protected Color outlineColor = new(1, 1, 1, 0.02745098f);
76
+
77
+
78
+ /// <summary>
79
+ ///
80
+ /// </summary>
81
+ [Header("Spawn Settings")]
82
+ [Divider]
83
+ [Tooltip("")]
84
+ [SerializeField] protected Transform trialCameraTransform;
85
+
86
+ /// <summary>
87
+ ///
88
+ /// </summary>
89
+ [Tooltip("")]
90
+ [SerializeField] protected Transform spawnParent;
91
+
92
+ /// <summary>
93
+ ///
94
+ /// </summary>
95
+ [Tooltip("")]
96
+ [Range(0, 50)]
97
+ [SerializeField] protected int numberOfObjects = 16;
98
+
99
+ /// <summary>
100
+ ///
101
+ /// </summary>
102
+ [Tooltip("")]
103
+ [SerializeField] protected float spawnRadius = 8.11f;
104
+
105
+ /// <summary>
106
+ ///
107
+ /// </summary>
108
+ [Range(-360f, 360f)]
109
+ [Tooltip("")]
110
+ [SerializeField] protected float startingDegreeOffset = 90f;
111
+
112
+ /// <summary>
113
+ ///
114
+ /// </summary>
115
+ [Tooltip("")]
116
+ [SerializeField] protected List<Character> ignoredCharacters = new();
117
+
118
+
119
+ /// <summary>
120
+ ///
121
+ /// </summary>
122
+ [Header("Editor Settings")]
123
+ [Divider]
124
+ [Tooltip("")]
125
+ [SerializeField] protected AssignmentStyleGUIEditor<Character> assignmentEditor;
126
+
127
+ /// <summary>
128
+ ///
129
+ /// </summary>
130
+ [Tooltip("")]
131
+ [SerializeField] protected CircleDrawer circleDrawer = new();
132
+
133
+
134
+ /// <summary>
135
+ ///
136
+ /// </summary>
137
+ protected bool changed;
138
+
139
+ /// <summary>
140
+ ///
141
+ /// </summary>
142
+ protected int slot;
143
+
144
+ /// <summary>
145
+ ///
146
+ /// </summary>
147
+ protected int newIndex;
148
+
149
+
150
+ /// <summary>
151
+ ///
152
+ /// </summary>
153
+ protected readonly string spawnParentName = "Characters";
154
+
155
+
156
+ /// <summary>
157
+ ///
158
+ /// </summary>
159
+ /// <returns></returns>
160
+ [MenuItem("DREditor/Characters/Auto Setup Trial Character", true)]
161
+ public static bool VerifyWizard() =>
162
+ DatabaseUtility.LoadDatabase<CharacterDatabase>() is CharacterDatabase database &&
163
+ database.Characters.Count > 0;
164
+
165
+
166
+ [MenuItem("DREditor/Characters/Auto Setup Trial Character")]
167
+ public static void ShowWizard() => DisplayWizard<AutoCreateTrialCharacterWizard>("Auto Setup Trial Character", "Create");
168
+
169
+
170
+ protected virtual void OnEnable()
171
+ {
172
+ minSize = new Vector2(1100, 800);
173
+
174
+ characterDatabase = DatabaseUtility.LoadDatabase<CharacterDatabase>();
175
+
176
+ trialShader = Shader.Find("Shader Graphs/CharacterTrial");
177
+
178
+ if (FindAnyObjectByType<DRTrialCamera>() is DRTrialCamera camera)
179
+ trialCameraTransform = camera.transform;
180
+
181
+ if (GameObject.Find(spawnParentName) is GameObject spawnParent)
182
+ this.spawnParent = spawnParent.transform;
183
+
184
+ ResetAssignmentEditor();
185
+ }
186
+
187
+ protected virtual void OnWizardCreate()
188
+ {
189
+ DestroyAllChildren();
190
+
191
+ SpawnTrialCharacters();
192
+
193
+ EditorUtility.SetDirty(spawnParent);
194
+ }
195
+
196
+ /// <summary>
197
+ ///
198
+ /// </summary>
199
+ protected virtual void DestroyAllChildren()
200
+ {
201
+ foreach (Transform child in spawnParent.transform)
202
+ GameObject.DestroyImmediate(child.gameObject);
203
+ }
204
+
205
+ /// <summary>
206
+ ///
207
+ /// </summary>
208
+ protected virtual void SpawnTrialCharacters()
209
+ {
210
+ for (int i = 0; i < assignmentEditor.Assignments.Length; i++)
211
+ if (CharacterCanBeSpawnedAtAssignment(i))
212
+ SpawnTrialCharacter(assignmentEditor.Objects[assignmentEditor.Assignments[i]], i);
213
+ }
214
+
215
+ /// <summary>
216
+ ///
217
+ /// </summary>
218
+ /// <param name="i"></param>
219
+ /// <returns></returns>
220
+ protected virtual bool CharacterCanBeSpawnedAtAssignment(int i) =>
221
+ assignmentEditor.Assignments[i] is int assignIndex &&
222
+ assignIndex >= 0 &&
223
+ assignIndex < assignmentEditor.Objects.Count &&
224
+ assignmentEditor.Objects[assignIndex].ActorPrefab != null;
225
+
226
+ /// <summary>
227
+ ///
228
+ /// </summary>
229
+ /// <param name="character"></param>
230
+ /// <param name="i"></param>
231
+ protected virtual void SpawnTrialCharacter(Character character, int i)
232
+ {
233
+ float currentAngle = (startingDegreeOffset + CircleUtility.DegreesInCircle * -i / numberOfObjects) * Mathf.Deg2Rad;
234
+
235
+ Vector3 spawnPosition = trialCameraTransform.position +
236
+ new Vector3(Mathf.Cos(currentAngle) * spawnRadius, 0f, Mathf.Sin(currentAngle) * spawnRadius);
237
+
238
+ Vector3 directionFromCenter = (spawnPosition - trialCameraTransform.position).normalized;
239
+
240
+ Quaternion spawnRotation = Quaternion.LookRotation(directionFromCenter);
241
+
242
+ string path = AssetDatabase.GetAssetPath(character.ActorPrefab);
243
+
244
+ GameObject actorPrefab = AssetDatabase.LoadAssetAtPath<GameObject>(path);
245
+
246
+ GameObject trialPrefab = SpawnObjectAt(actorPrefab, spawnPosition, spawnRotation);
247
+
248
+ CustomEditorUtility.EnsureFolders(trialActorPrefabPath);
249
+
250
+ PrefabUtility.SaveAsPrefabAsset(trialPrefab, trialActorPrefabPath + "/" + actorPrefab.name + ".prefab");
251
+
252
+ character.TrialPosition = i;
253
+
254
+ EditorUtility.SetDirty(character);
255
+ }
256
+
257
+ /// <summary>
258
+ ///
259
+ /// </summary>
260
+ /// <param name="prefabToSpawn"></param>
261
+ /// <param name="spawnPosition"></param>
262
+ /// <param name="spawnRotation"></param>
263
+ /// <returns></returns>
264
+ protected virtual GameObject SpawnObjectAt(GameObject prefabToSpawn, Vector3 spawnPosition, Quaternion spawnRotation)
265
+ {
266
+ GameObject spawned = (GameObject)PrefabUtility.InstantiatePrefab(prefabToSpawn, spawnParent);
267
+
268
+ spawned.transform.SetPositionAndRotation(spawnPosition, spawnRotation);
269
+
270
+ float xPos = spawned.transform.localPosition.x;
271
+
272
+ float zPos = spawned.transform.localPosition.z;
273
+
274
+ spawned.transform.localPosition = new(xPos, -1, zPos);
275
+
276
+ float yRot = spawned.transform.eulerAngles.y;
277
+
278
+ spawned.transform.localEulerAngles = new(0, yRot + 180, 0);
279
+
280
+ spawned.transform.localScale = prefabScale;
281
+
282
+ ApplyTrialShader(spawned);
283
+
284
+ if (spawned.TryGetComponent(out SpriteLookAtTarget billboard))
285
+ billboard.enabled = false;
286
+
287
+ return spawned;
288
+ }
289
+
290
+ /// <summary>
291
+ ///
292
+ /// </summary>
293
+ /// <param name="objectToDuplicateName"></param>
294
+ /// <param name="objectToDuplicatePath"></param>
295
+ /// <returns></returns>
296
+ protected virtual string BuildDuplicatedMaterialPath(string objectToDuplicateName, string objectToDuplicatePath) =>
297
+ objectToDuplicatePath.Replace(objectToDuplicateName, objectToDuplicateName + "_Trial");
298
+
299
+ /// <summary>
300
+ ///
301
+ /// </summary>
302
+ /// <param name="spawnedObj"></param>
303
+ protected virtual void ApplyTrialShader(GameObject spawnedObj)
304
+ {
305
+ if (spawnedObj.transform.GetChild(0) is not Transform rendererChild || !rendererChild.TryGetComponent<MeshRenderer>(out var actorRenderer))
306
+ return;
307
+
308
+ Material baseMaterial = actorRenderer.sharedMaterial;
309
+
310
+ if (CustomEditorUtility.TryDuplicateAsset(baseMaterial, BuildDuplicatedMaterialPath, out Material trialMaterial))
311
+ {
312
+ trialMaterial.shader = trialShader;
313
+
314
+ actorRenderer.material = trialMaterial;
315
+
316
+ if (UsingTrialShader())
317
+ {
318
+ trialMaterial.SetVector(nameof(extrudeSize), extrudeSize);
319
+
320
+ trialMaterial.SetColor(nameof(outlineColor), outlineColor);
321
+
322
+ trialMaterial.SetFloat(nameof(outlineInfluence), outlineInfluence);
323
+
324
+ trialMaterial.SetFloat(nameof(lightAngle), lightAngle);
325
+ }
326
+ }
327
+ }
328
+
329
+ /// <summary>
330
+ ///
331
+ /// </summary>
332
+ /// <returns></returns>
333
+ protected virtual bool UsingTrialShader() => trialShader == Shader.Find("Shader Graphs/CharacterTrial");
334
+
335
+ #region Editor GUI
336
+
337
+ protected override bool DrawWizardGUI()
338
+ {
339
+ changed = base.DrawWizardGUI();
340
+
341
+ HandySplitters.UISplitter();
342
+
343
+ if (changed)
344
+ ResetAssignmentEditor();
345
+ else
346
+ DrawCircleGUI();
347
+
348
+ return changed;
349
+ }
350
+
351
+ /// <summary>
352
+ ///
353
+ /// </summary>
354
+ protected virtual void ResetAssignmentEditor() => assignmentEditor = CreateNewAssignmentEditor();
355
+
356
+ /// <summary>
357
+ ///
358
+ /// </summary>
359
+ /// <returns></returns>
360
+ protected virtual AssignmentStyleGUIEditor<Character> CreateNewAssignmentEditor() =>
361
+ new(GetTrialCharacters(), GetCharacterName, numberOfObjects, assignmentEditor?.Assignments);
362
+
363
+ /// <summary>
364
+ ///
365
+ /// </summary>
366
+ /// <returns></returns>
367
+ protected virtual List<Character> GetTrialCharacters()
368
+ {
369
+ if (ignoredCharacters.Count == 0)
370
+ return characterDatabase.Characters;
371
+
372
+ List<Character> characters = new();
373
+
374
+ foreach (Character character in characterDatabase.Characters)
375
+ if (ignoredCharacters.Contains(character))
376
+ continue;
377
+ else
378
+ characters.Add(character);
379
+
380
+ return characters;
381
+ }
382
+
383
+ /// <summary>
384
+ ///
385
+ /// </summary>
386
+ /// <param name="character"></param>
387
+ /// <returns></returns>
388
+ protected virtual string GetCharacterName(Character character) => character.FirstName + " " + character.LastName;
389
+
390
+ /// <summary>
391
+ ///
392
+ /// </summary>
393
+ protected virtual void DrawCircleGUI()
394
+ {
395
+ assignmentEditor?.ValidateAssignments();
396
+
397
+ circleDrawer?.Draw();
398
+
399
+ if (numberOfObjects == assignmentEditor.Assignments.Length)
400
+ circleDrawer?.DrawObjectsAround(numberOfObjects, DrawDropdown, OnDropdownChanged);
401
+ }
402
+
403
+ /// <summary>
404
+ ///
405
+ /// </summary>
406
+ /// <param name="aroundCircleRect"></param>
407
+ /// <param name="slot"></param>
408
+ protected virtual void DrawDropdown(Rect aroundCircleRect, int slot)
409
+ {
410
+ this.slot = slot;
411
+
412
+ newIndex = EditorGUI.Popup(aroundCircleRect, assignmentEditor.Assignments[slot], assignmentEditor.GetAssignedNames());
413
+ }
414
+
415
+ /// <summary>
416
+ ///
417
+ /// </summary>
418
+ protected virtual void OnDropdownChanged()
419
+ {
420
+ assignmentEditor.SwapAssignment(slot, newIndex);
421
+
422
+ changed = true;
423
+ }
424
+
425
+ #endregion
426
+ }
427
427
  }