net.dreditor.minigames.rs 0.0.0-stage → 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 (182) hide show
  1. package/.attestation.p7m +0 -0
  2. package/CrossSwordsMechanic.cs +330 -0
  3. package/CrossSwordsMechanic.cs.meta +11 -0
  4. package/CutHandler.cs +287 -0
  5. package/CutHandler.cs.meta +11 -0
  6. package/CutLimitMechanic.cs +59 -0
  7. package/CutLimitMechanic.cs.meta +11 -0
  8. package/DREditor.Minigames.RS.asmdef +38 -0
  9. package/DREditor.Minigames.RS.asmdef.meta +7 -0
  10. package/DamagePhraseOnSwordHit.cs +150 -0
  11. package/DamagePhraseOnSwordHit.cs.meta +11 -0
  12. package/Editor/DREditor.Minigames.RS.Editor.asmdef +24 -0
  13. package/Editor/DREditor.Minigames.RS.Editor.asmdef.meta +7 -0
  14. package/Editor/RSBuilderEditor.cs +396 -0
  15. package/Editor/RSBuilderEditor.cs.meta +11 -0
  16. package/Editor/RSDebugToolEditor.cs +99 -0
  17. package/Editor/RSDebugToolEditor.cs.meta +11 -0
  18. package/Editor/RSEditorBase.cs +190 -0
  19. package/Editor/RSEditorBase.cs.meta +11 -0
  20. package/Editor/RSPhraseEditor.cs +44 -0
  21. package/Editor/RSPhraseEditor.cs.meta +11 -0
  22. package/Editor.meta +8 -0
  23. package/FollowRectSizeDelta.cs +82 -0
  24. package/FollowRectSizeDelta.cs.meta +11 -0
  25. package/FollowableRect.cs +29 -0
  26. package/FollowableRect.cs.meta +11 -0
  27. package/IPhraseHealth.cs +36 -0
  28. package/IPhraseHealth.cs.meta +11 -0
  29. package/ISplitScreen.cs +49 -0
  30. package/ISplitScreen.cs.meta +11 -0
  31. package/ISwipeListener.cs +18 -0
  32. package/ISwipeListener.cs.meta +11 -0
  33. package/ISword.cs +45 -0
  34. package/ISword.cs.meta +11 -0
  35. package/ISwordHitListener.cs +18 -0
  36. package/ISwordHitListener.cs.meta +11 -0
  37. package/ITieBreaker.cs +18 -0
  38. package/ITieBreaker.cs.meta +11 -0
  39. package/Managers/FireSliceAnimation.cs +293 -0
  40. package/Managers/FireSliceAnimation.cs.meta +11 -0
  41. package/Managers/FiredSliceHandler.cs +93 -0
  42. package/Managers/FiredSliceHandler.cs.meta +11 -0
  43. package/Managers/InterjectHandler.cs +140 -0
  44. package/Managers/InterjectHandler.cs.meta +11 -0
  45. package/Managers/InterjectHandlerBase.cs +19 -0
  46. package/Managers/InterjectHandlerBase.cs.meta +11 -0
  47. package/Managers/RSBuilder.cs +308 -0
  48. package/Managers/RSBuilder.cs.meta +11 -0
  49. package/Managers/RSEnemyWinMechanic.cs +178 -0
  50. package/Managers/RSEnemyWinMechanic.cs.meta +11 -0
  51. package/Managers/RSGroup.cs +179 -0
  52. package/Managers/RSGroup.cs.meta +11 -0
  53. package/Managers/RSGroupManager.cs +379 -0
  54. package/Managers/RSGroupManager.cs.meta +11 -0
  55. package/Managers/RSManager.cs +320 -0
  56. package/Managers/RSManager.cs.meta +11 -0
  57. package/Managers/RSPanel.cs +39 -0
  58. package/Managers/RSPanel.cs.meta +11 -0
  59. package/Managers/RSPhrase.cs +57 -0
  60. package/Managers/RSPhrase.cs.meta +11 -0
  61. package/Managers.meta +8 -0
  62. package/MultiPanelManager.cs +179 -0
  63. package/MultiPanelManager.cs.meta +11 -0
  64. package/Samples~/CUT_Canvas.prefab +484 -0
  65. package/Samples~/CUT_Canvas.prefab.meta +7 -0
  66. package/Samples~/Cross_Swords_Mechanic_Shell.prefab +64 -0
  67. package/Samples~/Cross_Swords_Mechanic_Shell.prefab.meta +7 -0
  68. package/Samples~/Cross_Swords_Mechanic_Template.prefab +485 -0
  69. package/Samples~/Cross_Swords_Mechanic_Template.prefab.meta +7 -0
  70. package/Samples~/CutCount.asset +21 -0
  71. package/Samples~/CutCount.asset.meta +8 -0
  72. package/Samples~/Cut_Handler.prefab +253 -0
  73. package/Samples~/Cut_Handler.prefab.meta +7 -0
  74. package/Samples~/Cut_Limit_Mechanic_UI.prefab +233 -0
  75. package/Samples~/Cut_Limit_Mechanic_UI.prefab.meta +7 -0
  76. package/Samples~/Debate_Text_Texture.prefab +75 -0
  77. package/Samples~/Debate_Text_Texture.prefab.meta +7 -0
  78. package/Samples~/Fire_Slice_Animation.prefab +308 -0
  79. package/Samples~/Fire_Slice_Animation.prefab.meta +7 -0
  80. package/Samples~/Fired_Slice_Handler_Shell.prefab +49 -0
  81. package/Samples~/Fired_Slice_Handler_Shell.prefab.meta +7 -0
  82. package/Samples~/Fired_Slice_Handler_Template.prefab +163 -0
  83. package/Samples~/Fired_Slice_Handler_Template.prefab.meta +7 -0
  84. package/Samples~/Multi_Line_Processes.prefab +306 -0
  85. package/Samples~/Multi_Line_Processes.prefab.meta +7 -0
  86. package/Samples~/Multi_Panel_Canvas_Shell.prefab +140 -0
  87. package/Samples~/Multi_Panel_Canvas_Shell.prefab.meta +7 -0
  88. package/Samples~/Multi_Panel_Canvas_Template.prefab +426 -0
  89. package/Samples~/Multi_Panel_Canvas_Template.prefab.meta +7 -0
  90. package/Samples~/Multi_Panel_Manager_Shell.prefab +57 -0
  91. package/Samples~/Multi_Panel_Manager_Shell.prefab.meta +7 -0
  92. package/Samples~/Multi_Panel_Manager_Template.prefab +316 -0
  93. package/Samples~/Multi_Panel_Manager_Template.prefab.meta +7 -0
  94. package/Samples~/OnAdvance.asset +15 -0
  95. package/Samples~/OnAdvance.asset.meta +8 -0
  96. package/Samples~/OnDuelEnded.asset +15 -0
  97. package/Samples~/OnDuelEnded.asset.meta +8 -0
  98. package/Samples~/OnDuelStarted.asset +15 -0
  99. package/Samples~/OnDuelStarted.asset.meta +8 -0
  100. package/Samples~/OnRetreat.asset +15 -0
  101. package/Samples~/OnRetreat.asset.meta +8 -0
  102. package/Samples~/OutOfCuts.asset +21 -0
  103. package/Samples~/OutOfCuts.asset.meta +8 -0
  104. package/Samples~/Panel_Mask_1.prefab +182 -0
  105. package/Samples~/Panel_Mask_1.prefab.meta +7 -0
  106. package/Samples~/Panel_Mask_2.prefab +127 -0
  107. package/Samples~/Panel_Mask_2.prefab.meta +7 -0
  108. package/Samples~/RS Mesh Generator.asset +21 -0
  109. package/Samples~/RS Mesh Generator.asset.meta +8 -0
  110. package/Samples~/RS Triangle Shatter.asset +31 -0
  111. package/Samples~/RS Triangle Shatter.asset.meta +8 -0
  112. package/Samples~/RSCameraRightEnabled.asset +21 -0
  113. package/Samples~/RSCameraRightEnabled.asset.meta +8 -0
  114. package/Samples~/RS_Bullet_Canvas_ETemplate.prefab +290 -0
  115. package/Samples~/RS_Bullet_Canvas_ETemplate.prefab.meta +7 -0
  116. package/Samples~/RS_Bullet_Canvas_Shell.prefab +156 -0
  117. package/Samples~/RS_Bullet_Canvas_Shell.prefab.meta +7 -0
  118. package/Samples~/RS_Bullet_ETemplate.prefab +127 -0
  119. package/Samples~/RS_Bullet_ETemplate.prefab.meta +7 -0
  120. package/Samples~/RS_Bullet_Evaluator_Manager_Template.prefab +299 -0
  121. package/Samples~/RS_Bullet_Evaluator_Manager_Template.prefab.meta +7 -0
  122. package/Samples~/RS_Bullet_UI_Parent_ETemplate.prefab +164 -0
  123. package/Samples~/RS_Bullet_UI_Parent_ETemplate.prefab.meta +7 -0
  124. package/Samples~/RS_Canvas_Shell.prefab +98 -0
  125. package/Samples~/RS_Canvas_Shell.prefab.meta +7 -0
  126. package/Samples~/RS_Canvas_Template.prefab +841 -0
  127. package/Samples~/RS_Canvas_Template.prefab.meta +7 -0
  128. package/Samples~/RS_Click_Group.prefab +255 -0
  129. package/Samples~/RS_Click_Group.prefab.meta +7 -0
  130. package/Samples~/RS_Controls_UI_Handler.prefab +168 -0
  131. package/Samples~/RS_Controls_UI_Handler.prefab.meta +7 -0
  132. package/Samples~/RS_Cycle_Bullet_ETemplate.prefab +242 -0
  133. package/Samples~/RS_Cycle_Bullet_ETemplate.prefab.meta +7 -0
  134. package/Samples~/RS_Cycle_UI_Canvas_Shell.prefab +232 -0
  135. package/Samples~/RS_Cycle_UI_Canvas_Shell.prefab.meta +7 -0
  136. package/Samples~/RS_Cycle_UI_Canvas_Template.prefab +443 -0
  137. package/Samples~/RS_Cycle_UI_Canvas_Template.prefab.meta +7 -0
  138. package/Samples~/RS_Enemy_Win_Mechanic_Shell.prefab +106 -0
  139. package/Samples~/RS_Enemy_Win_Mechanic_Shell.prefab.meta +7 -0
  140. package/Samples~/RS_Enemy_Win_Mechanic_Template.prefab +230 -0
  141. package/Samples~/RS_Enemy_Win_Mechanic_Template.prefab.meta +7 -0
  142. package/Samples~/RS_Fire_Bullet_UI_Handler_Template.prefab +1234 -0
  143. package/Samples~/RS_Fire_Bullet_UI_Handler_Template.prefab.meta +7 -0
  144. package/Samples~/RS_Firing_Sword_UI_ETemplate.prefab +405 -0
  145. package/Samples~/RS_Firing_Sword_UI_ETemplate.prefab.meta +7 -0
  146. package/Samples~/RS_Group_Manager_Shell.prefab +145 -0
  147. package/Samples~/RS_Group_Manager_Shell.prefab.meta +7 -0
  148. package/Samples~/RS_Group_Manager_Template.prefab +537 -0
  149. package/Samples~/RS_Group_Manager_Template.prefab.meta +7 -0
  150. package/Samples~/RS_Line_Manager_Template.prefab +191 -0
  151. package/Samples~/RS_Line_Manager_Template.prefab.meta +7 -0
  152. package/Samples~/RS_Loading_Bullet_Canvas_Shell.prefab +204 -0
  153. package/Samples~/RS_Loading_Bullet_Canvas_Shell.prefab.meta +7 -0
  154. package/Samples~/RS_Loading_Bullet_Canvas_Template.prefab +411 -0
  155. package/Samples~/RS_Loading_Bullet_Canvas_Template.prefab.meta +7 -0
  156. package/Samples~/RS_Manager_Shell.prefab +514 -0
  157. package/Samples~/RS_Manager_Shell.prefab.meta +7 -0
  158. package/Samples~/RS_Manager_Template.prefab +1526 -0
  159. package/Samples~/RS_Manager_Template.prefab.meta +7 -0
  160. package/Samples~/RS_Text_Camera.prefab +125 -0
  161. package/Samples~/RS_Text_Camera.prefab.meta +7 -0
  162. package/Samples~/RS_UI_Shatter_Canvas_Template.prefab +150 -0
  163. package/Samples~/RS_UI_Shatter_Canvas_Template.prefab.meta +7 -0
  164. package/Samples~/ShowRSUI.asset +15 -0
  165. package/Samples~/ShowRSUI.asset.meta +8 -0
  166. package/Samples~/Split_Seam_UI.prefab +120 -0
  167. package/Samples~/Split_Seam_UI.prefab.meta +7 -0
  168. package/Samples~/Swipe_Sword.prefab +81 -0
  169. package/Samples~/Swipe_Sword.prefab.meta +7 -0
  170. package/Samples~/Swipe_Visualizer_Image.prefab +102 -0
  171. package/Samples~/Swipe_Visualizer_Image.prefab.meta +7 -0
  172. package/Samples~/Sword_Hit_Listeners.prefab +49 -0
  173. package/Samples~/Sword_Hit_Listeners.prefab.meta +7 -0
  174. package/SplitScreenHandler.cs +264 -0
  175. package/SplitScreenHandler.cs.meta +11 -0
  176. package/SwipeSword.cs +236 -0
  177. package/SwipeSword.cs.meta +11 -0
  178. package/SwipeVisualizer.cs +242 -0
  179. package/SwipeVisualizer.cs.meta +11 -0
  180. package/package.json +55 -4
  181. package/package.json.meta +7 -0
  182. package/README.md +0 -3
Binary file
@@ -0,0 +1,330 @@
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ using DREditor.Audio;
3
+ using DREditor.EventObjects;
4
+ using DREditor.Minigames.Debates.Mechanics;
5
+ using DREditor.Services;
6
+ using DREditor.UIHandling;
7
+ using System;
8
+ using System.Collections;
9
+ using UnityEngine;
10
+ using UnityEngine.Events;
11
+ using UnityEngine.InputSystem;
12
+ using static UnityEngine.InputSystem.InputAction;
13
+
14
+ namespace DREditor.Minigames.RS
15
+ {
16
+ /// <summary>
17
+ ///
18
+ /// </summary>
19
+ [ClassHeader(nameof(ServiceHolder<ITieBreaker>) + ", " + nameof(ITieBreaker) +
20
+ "\n\n")]
21
+ public class CrossSwordsMechanic : ServiceHolder<ITieBreaker>, ITieBreaker
22
+ {
23
+ /// <summary>
24
+ ///
25
+ /// </summary>
26
+ [Tooltip("")]
27
+ [SerializeField] protected InputActionReference submit = null;
28
+
29
+
30
+ /// <summary>
31
+ ///
32
+ /// </summary>
33
+ [Header("")]
34
+ [Divider]
35
+ [Tooltip("")]
36
+ [SerializeField] protected SceneEvent duelStartedEvent;
37
+
38
+ /// <summary>
39
+ ///
40
+ /// </summary>
41
+ [Tooltip("")]
42
+ [SerializeField] protected SceneEvent duelEndedEvent;
43
+
44
+
45
+ /// <summary>
46
+ ///
47
+ /// </summary>
48
+ [Header("")]
49
+ [Divider]
50
+ [Tooltip("")]
51
+ [SerializeField] protected UIVisibilityComponent introAnimation = null;
52
+
53
+ /// <summary>
54
+ ///
55
+ /// </summary>
56
+ [Tooltip("")]
57
+ [SerializeField] protected UIVisibilityComponent successAnimation = null;
58
+
59
+ /// <summary>
60
+ ///
61
+ /// </summary>
62
+ [Tooltip("")]
63
+ [SerializeField] protected UIVisibilityComponent failureAnimation = null;
64
+
65
+
66
+ /// <summary>
67
+ ///
68
+ /// </summary>
69
+ [Header("")]
70
+ [Divider]
71
+ [Tooltip("")]
72
+ [SerializeField] protected int totalTaps = 8;
73
+
74
+ /// <summary>
75
+ ///
76
+ /// </summary>
77
+ [Tooltip("")]
78
+ [SerializeField] protected float duelDuration = 3;
79
+
80
+ /// <summary>
81
+ ///
82
+ /// </summary>
83
+ [Tooltip("")]
84
+ [SerializeField] protected int enemyIndex = 0;
85
+
86
+ /// <summary>
87
+ ///
88
+ /// </summary>
89
+ [Tooltip("")]
90
+ [SerializeField] protected float enemyAttackRate = 0.2f;
91
+
92
+ /// <summary>
93
+ ///
94
+ /// </summary>
95
+ [Tooltip("")]
96
+ [SerializeField] protected float damage = 5;
97
+
98
+
99
+ [Header("")]
100
+ [SerializeField] protected UnityEvent onDuelStarted = null;
101
+
102
+
103
+ /// <summary>
104
+ ///
105
+ /// </summary>
106
+ [Header("")]
107
+ [Divider]
108
+ [Tooltip("")]
109
+ [SerializeField] protected SoundPlayerDRE successSFX;
110
+
111
+ /// <summary>
112
+ ///
113
+ /// </summary>
114
+ [Tooltip("")]
115
+ [SerializeField] protected SoundPlayerDRE failureSFX;
116
+
117
+ /// <summary>
118
+ ///
119
+ /// </summary>
120
+ [Tooltip("")]
121
+ [SerializeField] protected SoundPlayerDRE clashingSFX;
122
+
123
+
124
+ /// <summary>
125
+ ///
126
+ /// </summary>
127
+ protected int currentTaps = 0;
128
+
129
+ /// <summary>
130
+ ///
131
+ /// </summary>
132
+ protected ISplitScreen splitService;
133
+
134
+
135
+ protected virtual void Start() => InitializeMechanic();
136
+
137
+ /// <summary>
138
+ ///
139
+ /// </summary>
140
+ protected virtual void InitializeMechanic()
141
+ {
142
+ if (!InitializationValid())
143
+ OnInitializationFailed();
144
+ }
145
+
146
+ /// <summary>
147
+ ///
148
+ /// </summary>
149
+ /// <returns></returns>
150
+ protected virtual bool InitializationValid() => ServiceLocator.HasService(out splitService);
151
+
152
+ /// <summary>
153
+ ///
154
+ /// </summary>
155
+ protected virtual void OnInitializationFailed()
156
+ {
157
+ UnityEngine.Debug.LogWarning($"ALERT: The {nameof(CrossSwordsMechanic)} requires " +
158
+ $"an active {nameof(ISplitScreen)} service to function.\n" +
159
+ $"PROPOSAL: Ensure that a service registering {nameof(ISplitScreen)} is available.");
160
+
161
+ UnityEngine.Debug.Log($"REPORT: Destroying {nameof(CrossSwordsMechanic)}.");
162
+
163
+ Destroy(gameObject);
164
+ }
165
+
166
+
167
+ /// <inheritdoc/>
168
+ public virtual IEnumerator TieBreakerProcess(Action<bool> result)
169
+ {
170
+ UnityEngine.Debug.Log("REPORT: Starting CrossSwords.");
171
+
172
+ InitializeDuel();
173
+
174
+ InvokeDuelStarted();
175
+
176
+ yield return DisplayStartingDuel();
177
+
178
+ RaiseEvent(duelStartedEvent);
179
+
180
+ EnablePlayerDueling();
181
+
182
+ yield return Duel();
183
+
184
+ DisablePlayerDueling();
185
+
186
+ RaiseEvent(duelEndedEvent);
187
+
188
+ yield return ResolveDuel();
189
+
190
+ result(splitService.WillAdvanceOnTie());
191
+
192
+ UnityEngine.Debug.Log("REPORT: Ending CrossSwords.");
193
+ }
194
+
195
+ /// <summary>
196
+ ///
197
+ /// </summary>
198
+ protected virtual void InitializeDuel()
199
+ {
200
+ splitService.AnimateToResetState();
201
+
202
+ currentTaps = totalTaps;
203
+
204
+ var speeds = transform.root.GetComponentsInChildren<SpeedHandlerBase>();
205
+
206
+ foreach (var speed in speeds)
207
+ {
208
+ speed.OnPanelsStopped();
209
+
210
+ speed.DeactivateControls();
211
+ }
212
+ }
213
+
214
+ /// <summary>
215
+ ///
216
+ /// </summary>
217
+ /// <returns></returns>
218
+ protected virtual IEnumerator DisplayStartingDuel()
219
+ {
220
+ if (introAnimation != null)
221
+ {
222
+ yield return introAnimation.ShowTillComplete();
223
+
224
+ introAnimation.Hide();
225
+ }
226
+ }
227
+
228
+ /// <summary>
229
+ ///
230
+ /// </summary>
231
+ /// <param name="sceneEvent"></param>
232
+ protected virtual void RaiseEvent(SceneEvent sceneEvent)
233
+ {
234
+ if (sceneEvent != null)
235
+ sceneEvent.Raise();
236
+ }
237
+
238
+ /// <summary>
239
+ ///
240
+ /// </summary>
241
+ protected virtual void InvokeDuelStarted() => onDuelStarted?.Invoke();
242
+
243
+ /// <summary>
244
+ ///
245
+ /// </summary>
246
+ protected virtual void EnablePlayerDueling() => submit.action.started += Tap;
247
+
248
+ /// <summary>
249
+ ///
250
+ /// </summary>
251
+ /// <param name="ctx"></param>
252
+ protected virtual void Tap(CallbackContext ctx)
253
+ {
254
+ currentTaps++;
255
+
256
+ splitService.PlayerAttack(damage);
257
+
258
+ if (clashingSFX != null)
259
+ clashingSFX.PlaySFX();
260
+ }
261
+
262
+ /// <summary>
263
+ ///
264
+ /// </summary>
265
+ /// <returns></returns>
266
+ protected virtual IEnumerator Duel()
267
+ {
268
+ float timeRemaining = duelDuration;
269
+
270
+ while (timeRemaining > 0 && currentTaps != 0 && currentTaps <= totalTaps)
271
+ {
272
+ yield return new WaitForSeconds(enemyAttackRate);
273
+
274
+ timeRemaining -= enemyAttackRate;
275
+
276
+ splitService.EnemyAttack(enemyIndex, damage);
277
+
278
+ currentTaps--;
279
+
280
+ if (clashingSFX != null)
281
+ clashingSFX.PlaySFX();
282
+
283
+ UnityEngine.Debug.Log("REPORT: Enemy Attacked.");
284
+
285
+ yield return null;
286
+ }
287
+ }
288
+
289
+ /// <summary>
290
+ ///
291
+ /// </summary>
292
+ protected virtual void DisablePlayerDueling() => submit.action.started -= Tap;
293
+
294
+ /// <summary>
295
+ ///
296
+ /// </summary>
297
+ protected virtual IEnumerator ResolveDuel()
298
+ {
299
+ bool playerWon = splitService.WillAdvanceOnTie();
300
+
301
+ var resultSound = playerWon ? successSFX : failureSFX;
302
+
303
+ var resultAnimation = playerWon ? successAnimation : failureAnimation;
304
+
305
+ if (playerWon)
306
+ splitService.PlayerAttack(damage);
307
+ else
308
+ splitService.EnemyAttack(enemyIndex, damage);
309
+
310
+ if (resultSound != null)
311
+ resultSound.PlaySFX();
312
+
313
+ if (resultAnimation != null)
314
+ {
315
+ yield return resultAnimation.ShowTillComplete();
316
+
317
+ resultAnimation.Hide();
318
+ }
319
+ }
320
+
321
+
322
+ /// <inheritdoc/>
323
+ protected override void OnDestroy()
324
+ {
325
+ base.OnDestroy();
326
+
327
+ DisablePlayerDueling();
328
+ }
329
+ }
330
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: a53406f39601c64448afb18b909d5e5f
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
package/CutHandler.cs ADDED
@@ -0,0 +1,287 @@
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ using DREditor.EventObjects;
3
+ using DREditor.UIHandling;
4
+ using System.Collections;
5
+ using System.Collections.Generic;
6
+ using System.Linq;
7
+ using UnityEngine;
8
+ using UnityEngine.Events;
9
+ using UnityEngine.InputSystem;
10
+ using static UnityEngine.InputSystem.InputAction;
11
+
12
+ namespace DREditor.Minigames.RS
13
+ {
14
+ /// <summary>
15
+ ///
16
+ /// </summary>
17
+ /// <remarks></remarks>
18
+ [ClassHeader(nameof(ControlledComponent) +
19
+ "\n\n")]
20
+ public class CutHandler : ControlledComponent
21
+ {
22
+ /// <summary>
23
+ ///
24
+ /// </summary>
25
+ [Tooltip("")]
26
+ [SerializeField] protected InputActionReference swipe = null;
27
+
28
+
29
+ /// <summary>
30
+ ///
31
+ /// </summary>
32
+ [Header("")]
33
+ [Divider]
34
+ [Tooltip("")]
35
+ [SerializeField] protected bool outputDebugSwipeLogs = false;
36
+
37
+
38
+ /// <summary>
39
+ ///
40
+ /// </summary>
41
+ [Header("")]
42
+ [Divider]
43
+ [Tooltip("")]
44
+ [SerializeField] protected EvaluateBoolCondition preventCutsCondition;
45
+
46
+ /// <summary>
47
+ ///
48
+ /// </summary>
49
+ [Tooltip("")]
50
+ [SerializeField] protected int frameWindowForInput = 5;
51
+
52
+ /// <summary>
53
+ ///
54
+ /// </summary>
55
+ [Tooltip("")]
56
+ [SerializeField] protected float timeForSwordToCut = 0.2f;
57
+
58
+ /// <summary>
59
+ ///
60
+ /// </summary>
61
+ [Tooltip("")]
62
+ [SerializeField] protected float cutCooldown = 0.1f;
63
+
64
+
65
+ [Header("")]
66
+ [SerializeField] protected UnityEvent<Vector3, Vector3> OnSwiped;
67
+
68
+ [Header("")]
69
+ [SerializeField] protected UnityEvent OnHit;
70
+
71
+ [Header("")]
72
+ [SerializeField] protected UnityEvent OnMissed;
73
+
74
+
75
+ /// <summary>
76
+ ///
77
+ /// </summary>
78
+ protected readonly List<Vector2> inputs = new();
79
+
80
+ /// <summary>
81
+ ///
82
+ /// </summary>
83
+ protected ISword cutSword;
84
+
85
+ /// <summary>
86
+ ///
87
+ /// </summary>
88
+ protected ISwipeListener[] swipeListeners;
89
+
90
+
91
+ /// <inheritdoc/>
92
+ protected override void Awake()
93
+ {
94
+ base.Awake();
95
+
96
+ swipeListeners = transform.root.GetComponentsInChildren<ISwipeListener>();
97
+
98
+ cutSword = GetComponentsInChildren<ISword>()?.First();
99
+
100
+ if (cutSword == null)
101
+ UnityEngine.Debug.LogError($"ALERT: No {nameof(ISword)} found in children of {name}");
102
+ }
103
+
104
+ /// <inheritdoc/>
105
+ protected override void OnEnable()
106
+ {
107
+ base.OnEnable();
108
+
109
+ cutSword?.StopDetectingCuts();
110
+
111
+ foreach (var listener in swipeListeners)
112
+ if (listener != null)
113
+ OnSwiped.AddListener(listener.OnSwiped);
114
+ }
115
+
116
+ /// <inheritdoc/>
117
+ protected override void OnDisable()
118
+ {
119
+ base.OnDisable();
120
+
121
+ DeactivateControls();
122
+
123
+ foreach (var listener in swipeListeners)
124
+ if (listener != null)
125
+ OnSwiped.RemoveListener(listener.OnSwiped);
126
+ }
127
+
128
+ /// <inheritdoc/>
129
+ public override void ActivateControls()
130
+ {
131
+ inputs.Clear();
132
+
133
+ if (outputDebugSwipeLogs)
134
+ UnityEngine.Debug.LogWarning($"REPORT: Enabling Controls");
135
+
136
+ swipe.action.performed += Swipe;
137
+ }
138
+
139
+ /// <inheritdoc/>
140
+ public override void DeactivateControls()
141
+ {
142
+ StopAllCoroutines();
143
+
144
+ cutSword?.StopDetectingCuts();
145
+
146
+ if (outputDebugSwipeLogs)
147
+ UnityEngine.Debug.LogWarning($"REPORT: Disabling Controls");
148
+
149
+ swipe.action.performed -= Swipe;
150
+ }
151
+
152
+ /// <summary>
153
+ ///
154
+ /// </summary>
155
+ /// <param name="context"></param>
156
+ protected virtual void Swipe(CallbackContext context)
157
+ {
158
+ if (preventCutsCondition != null && preventCutsCondition.Evaluate())
159
+ return;
160
+
161
+ Vector2 direction = context.ReadValue<Vector2>();
162
+
163
+ if (!InputDirectionValid(direction))
164
+ return;
165
+
166
+ if (inputs.Count == 0)
167
+ StartCoroutine(BufferSwipe());
168
+
169
+ inputs.Add(direction);
170
+ }
171
+
172
+ /// <summary>
173
+ ///
174
+ /// </summary>
175
+ /// <param name="direction"></param>
176
+ /// <returns></returns>
177
+ protected virtual bool InputDirectionValid(Vector2 direction)
178
+ {
179
+ bool directionEmpty = direction == Vector2.zero;
180
+
181
+ bool roundedDirectionEmpty = Mathf.Round(direction.x) == 0 && Mathf.Round(direction.y) == 0;
182
+
183
+ bool directionValid = !directionEmpty && !roundedDirectionEmpty;
184
+
185
+ if (directionEmpty && outputDebugSwipeLogs)
186
+ UnityEngine.Debug.Log($"REPORT: Attempted Cut Direction was Zero");
187
+
188
+ if (roundedDirectionEmpty && outputDebugSwipeLogs)
189
+ UnityEngine.Debug.Log($"REPORT: Swipe Input did not reach the threshold: " + direction);
190
+
191
+ if (!directionValid)
192
+ StartCoroutine(Cooldown());
193
+
194
+ return directionValid;
195
+ }
196
+
197
+ /// <summary>
198
+ ///
199
+ /// </summary>
200
+ protected virtual IEnumerator BufferSwipe()
201
+ {
202
+ yield return new WaitForEndOfFrame();
203
+
204
+ yield return new WaitForSecondsRealtime(Time.deltaTime * frameWindowForInput);
205
+
206
+ DeactivateControls();
207
+
208
+ SwipeAtDirection(CombineInputDirections());
209
+
210
+ StartCoroutine(SwipeProcess());
211
+ }
212
+
213
+ /// <summary>
214
+ ///
215
+ /// </summary>
216
+ /// <returns></returns>
217
+ protected virtual Vector2 CombineInputDirections()
218
+ {
219
+ Vector2 combine = Vector2.zero;
220
+
221
+ foreach (var i in inputs)
222
+ {
223
+ combine.x += Mathf.Round(i.x);
224
+
225
+ combine.y += Mathf.Round(i.y);
226
+
227
+ if (outputDebugSwipeLogs)
228
+ UnityEngine.Debug.Log($"REPORT: Input Filtered: " + i);
229
+ }
230
+
231
+ combine.x = Mathf.Clamp(combine.x, -1, 1);
232
+
233
+ combine.y = Mathf.Clamp(combine.y, -1, 1);
234
+
235
+ inputs.Clear();
236
+
237
+ return combine;
238
+ }
239
+
240
+ /// <summary>
241
+ ///
242
+ /// </summary>
243
+ /// <param name="direction"></param>
244
+ protected virtual void SwipeAtDirection(Vector2 direction)
245
+ {
246
+ if (outputDebugSwipeLogs)
247
+ UnityEngine.Debug.Log($"REPORT: Verified Swipe Direction is: " + direction);
248
+
249
+ OnSwiped?.Invoke(cutSword.AngleSword(direction), direction);
250
+ }
251
+
252
+ /// <summary>
253
+ ///
254
+ /// </summary>
255
+ protected virtual IEnumerator SwipeProcess()
256
+ {
257
+ cutSword?.StartDetectingCuts();
258
+
259
+ yield return new WaitForSeconds(timeForSwordToCut);
260
+
261
+ cutSword?.StopDetectingCuts();
262
+
263
+ if (cutSword.RecentlyLandedHit)
264
+ OnHit?.Invoke();
265
+ else
266
+ OnMissed?.Invoke();
267
+
268
+ yield return Cooldown();
269
+ }
270
+
271
+ /// <summary>
272
+ ///
273
+ /// </summary>
274
+ protected virtual IEnumerator Cooldown()
275
+ {
276
+ if (outputDebugSwipeLogs)
277
+ UnityEngine.Debug.Log($"REPORT: Started cooldown");
278
+
279
+ yield return new WaitForSeconds(cutCooldown);
280
+
281
+ if (outputDebugSwipeLogs)
282
+ UnityEngine.Debug.Log($"REPORT: Ended Cooldown");
283
+
284
+ ActivateControls();
285
+ }
286
+ }
287
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 8b6b53a1398817a4dbf208329069363a
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,59 @@
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ using DREditor.EventObjects;
3
+ using TMPro;
4
+ using UnityEngine;
5
+
6
+ namespace DREditor.Minigames.RS
7
+ {
8
+ /// <summary>
9
+ ///
10
+ /// </summary>
11
+ [ClassHeader(nameof(ISwipeListener) +
12
+ "\n\n")]
13
+ public class CutLimitMechanic : MonoBehaviour, ISwipeListener
14
+ {
15
+ /// <summary>
16
+ ///
17
+ /// </summary>
18
+ [Tooltip("")]
19
+ [SerializeField] protected IntWithEvent cutCount = null;
20
+
21
+ /// <summary>
22
+ ///
23
+ /// </summary>
24
+ [Tooltip("")]
25
+ [SerializeField] protected BoolWithEvent outOfCuts;
26
+
27
+ /// <summary>
28
+ ///
29
+ /// </summary>
30
+ [Tooltip("")]
31
+ [SerializeField] protected TextMeshProUGUI cutVisual = null;
32
+
33
+ /// <summary>
34
+ ///
35
+ /// </summary>
36
+ [Tooltip("")]
37
+ [SerializeField] protected int cutReduceAmount = 1;
38
+
39
+
40
+ /// <summary>
41
+ ///
42
+ /// </summary>
43
+ /// <param name="swipeStart"></param>
44
+ /// <param name="swipeEnd"></param>
45
+ public virtual void OnSwiped(Vector3 swipeStart, Vector3 swipeEnd)
46
+ {
47
+ if (cutCount == null)
48
+ return;
49
+
50
+ cutCount.SetValue(cutCount.Value - cutReduceAmount);
51
+
52
+ if (outOfCuts != null)
53
+ outOfCuts.SetValue(cutCount.Value == 0);
54
+
55
+ if (cutVisual != null)
56
+ cutVisual.text = cutCount.Value.ToString();
57
+ }
58
+ }
59
+ }