net.dreditor.minigames.rs 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 (182) hide show
  1. package/.attestation.p7m +0 -0
  2. package/CrossSwordsMechanic.cs +329 -329
  3. package/CrossSwordsMechanic.cs.meta +11 -11
  4. package/CutHandler.cs +286 -286
  5. package/CutHandler.cs.meta +11 -11
  6. package/CutLimitMechanic.cs +58 -58
  7. package/CutLimitMechanic.cs.meta +11 -11
  8. package/DREditor.Minigames.RS.asmdef +37 -37
  9. package/DREditor.Minigames.RS.asmdef.meta +7 -7
  10. package/DamagePhraseOnSwordHit.cs +149 -149
  11. package/DamagePhraseOnSwordHit.cs.meta +11 -11
  12. package/Editor/DREditor.Minigames.RS.Editor.asmdef +23 -23
  13. package/Editor/DREditor.Minigames.RS.Editor.asmdef.meta +7 -7
  14. package/Editor/RSBuilderEditor.cs +395 -395
  15. package/Editor/RSBuilderEditor.cs.meta +11 -11
  16. package/Editor/RSDebugToolEditor.cs +98 -98
  17. package/Editor/RSDebugToolEditor.cs.meta +11 -11
  18. package/Editor/RSEditorBase.cs +189 -189
  19. package/Editor/RSEditorBase.cs.meta +11 -11
  20. package/Editor/RSPhraseEditor.cs +43 -43
  21. package/Editor/RSPhraseEditor.cs.meta +11 -11
  22. package/Editor.meta +8 -8
  23. package/FollowRectSizeDelta.cs +81 -81
  24. package/FollowRectSizeDelta.cs.meta +11 -11
  25. package/FollowableRect.cs +28 -28
  26. package/FollowableRect.cs.meta +11 -11
  27. package/IPhraseHealth.cs +35 -35
  28. package/IPhraseHealth.cs.meta +11 -11
  29. package/ISplitScreen.cs +48 -48
  30. package/ISplitScreen.cs.meta +11 -11
  31. package/ISwipeListener.cs +17 -17
  32. package/ISwipeListener.cs.meta +11 -11
  33. package/ISword.cs +44 -44
  34. package/ISword.cs.meta +11 -11
  35. package/ISwordHitListener.cs +17 -17
  36. package/ISwordHitListener.cs.meta +11 -11
  37. package/ITieBreaker.cs +17 -17
  38. package/ITieBreaker.cs.meta +11 -11
  39. package/Managers/FireSliceAnimation.cs +292 -292
  40. package/Managers/FireSliceAnimation.cs.meta +11 -11
  41. package/Managers/FiredSliceHandler.cs +92 -92
  42. package/Managers/FiredSliceHandler.cs.meta +11 -11
  43. package/Managers/InterjectHandler.cs +139 -139
  44. package/Managers/InterjectHandler.cs.meta +11 -11
  45. package/Managers/InterjectHandlerBase.cs +18 -18
  46. package/Managers/InterjectHandlerBase.cs.meta +11 -11
  47. package/Managers/RSBuilder.cs +307 -307
  48. package/Managers/RSBuilder.cs.meta +11 -11
  49. package/Managers/RSEnemyWinMechanic.cs +177 -177
  50. package/Managers/RSEnemyWinMechanic.cs.meta +11 -11
  51. package/Managers/RSGroup.cs +178 -178
  52. package/Managers/RSGroup.cs.meta +11 -11
  53. package/Managers/RSGroupManager.cs +378 -378
  54. package/Managers/RSGroupManager.cs.meta +11 -11
  55. package/Managers/RSManager.cs +319 -319
  56. package/Managers/RSManager.cs.meta +11 -11
  57. package/Managers/RSPanel.cs +38 -38
  58. package/Managers/RSPanel.cs.meta +11 -11
  59. package/Managers/RSPhrase.cs +56 -56
  60. package/Managers/RSPhrase.cs.meta +11 -11
  61. package/Managers.meta +8 -8
  62. package/MultiPanelManager.cs +178 -178
  63. package/MultiPanelManager.cs.meta +11 -11
  64. package/{Samples → Samples~}/CUT_Canvas.prefab +484 -484
  65. package/{Samples → Samples~}/CUT_Canvas.prefab.meta +7 -7
  66. package/{Samples → Samples~}/Cross_Swords_Mechanic_Shell.prefab +64 -64
  67. package/{Samples → Samples~}/Cross_Swords_Mechanic_Shell.prefab.meta +7 -7
  68. package/{Samples → Samples~}/Cross_Swords_Mechanic_Template.prefab +485 -485
  69. package/{Samples → Samples~}/Cross_Swords_Mechanic_Template.prefab.meta +7 -7
  70. package/{Samples → Samples~}/CutCount.asset +21 -21
  71. package/{Samples → Samples~}/CutCount.asset.meta +8 -8
  72. package/{Samples → Samples~}/Cut_Handler.prefab +253 -253
  73. package/{Samples → Samples~}/Cut_Handler.prefab.meta +7 -7
  74. package/{Samples → Samples~}/Cut_Limit_Mechanic_UI.prefab +233 -233
  75. package/{Samples → Samples~}/Cut_Limit_Mechanic_UI.prefab.meta +7 -7
  76. package/{Samples → Samples~}/Debate_Text_Texture.prefab +75 -75
  77. package/{Samples → Samples~}/Debate_Text_Texture.prefab.meta +7 -7
  78. package/{Samples → Samples~}/Fire_Slice_Animation.prefab +308 -308
  79. package/{Samples → Samples~}/Fire_Slice_Animation.prefab.meta +7 -7
  80. package/{Samples → Samples~}/Fired_Slice_Handler_Shell.prefab +49 -49
  81. package/{Samples → Samples~}/Fired_Slice_Handler_Shell.prefab.meta +7 -7
  82. package/{Samples → Samples~}/Fired_Slice_Handler_Template.prefab +163 -163
  83. package/{Samples → Samples~}/Fired_Slice_Handler_Template.prefab.meta +7 -7
  84. package/{Samples → Samples~}/Multi_Line_Processes.prefab +306 -306
  85. package/{Samples → Samples~}/Multi_Line_Processes.prefab.meta +7 -7
  86. package/{Samples → Samples~}/Multi_Panel_Canvas_Shell.prefab +140 -140
  87. package/{Samples → Samples~}/Multi_Panel_Canvas_Shell.prefab.meta +7 -7
  88. package/{Samples → Samples~}/Multi_Panel_Canvas_Template.prefab +426 -426
  89. package/{Samples → Samples~}/Multi_Panel_Canvas_Template.prefab.meta +7 -7
  90. package/{Samples → Samples~}/Multi_Panel_Manager_Shell.prefab +57 -57
  91. package/{Samples → Samples~}/Multi_Panel_Manager_Shell.prefab.meta +7 -7
  92. package/{Samples → Samples~}/Multi_Panel_Manager_Template.prefab +316 -316
  93. package/{Samples → Samples~}/Multi_Panel_Manager_Template.prefab.meta +7 -7
  94. package/{Samples → Samples~}/OnAdvance.asset +15 -15
  95. package/{Samples → Samples~}/OnAdvance.asset.meta +8 -8
  96. package/{Samples → Samples~}/OnDuelEnded.asset +15 -15
  97. package/{Samples → Samples~}/OnDuelEnded.asset.meta +8 -8
  98. package/{Samples → Samples~}/OnDuelStarted.asset +15 -15
  99. package/{Samples → Samples~}/OnDuelStarted.asset.meta +8 -8
  100. package/{Samples → Samples~}/OnRetreat.asset +15 -15
  101. package/{Samples → Samples~}/OnRetreat.asset.meta +8 -8
  102. package/{Samples → Samples~}/OutOfCuts.asset +21 -21
  103. package/{Samples → Samples~}/OutOfCuts.asset.meta +8 -8
  104. package/{Samples → Samples~}/Panel_Mask_1.prefab +182 -182
  105. package/{Samples → Samples~}/Panel_Mask_1.prefab.meta +7 -7
  106. package/{Samples → Samples~}/Panel_Mask_2.prefab +127 -127
  107. package/{Samples → Samples~}/Panel_Mask_2.prefab.meta +7 -7
  108. package/{Samples → Samples~}/RS Mesh Generator.asset +21 -21
  109. package/{Samples → Samples~}/RS Mesh Generator.asset.meta +8 -8
  110. package/{Samples → Samples~}/RS Triangle Shatter.asset +31 -31
  111. package/{Samples → Samples~}/RS Triangle Shatter.asset.meta +8 -8
  112. package/{Samples → Samples~}/RSCameraRightEnabled.asset +21 -21
  113. package/{Samples → Samples~}/RSCameraRightEnabled.asset.meta +8 -8
  114. package/{Samples → Samples~}/RS_Bullet_Canvas_ETemplate.prefab +290 -290
  115. package/{Samples → Samples~}/RS_Bullet_Canvas_ETemplate.prefab.meta +7 -7
  116. package/{Samples → Samples~}/RS_Bullet_Canvas_Shell.prefab +156 -156
  117. package/{Samples → Samples~}/RS_Bullet_Canvas_Shell.prefab.meta +7 -7
  118. package/{Samples → Samples~}/RS_Bullet_ETemplate.prefab +127 -127
  119. package/{Samples → Samples~}/RS_Bullet_ETemplate.prefab.meta +7 -7
  120. package/{Samples → Samples~}/RS_Bullet_Evaluator_Manager_Template.prefab +299 -299
  121. package/{Samples → Samples~}/RS_Bullet_Evaluator_Manager_Template.prefab.meta +7 -7
  122. package/{Samples → Samples~}/RS_Bullet_UI_Parent_ETemplate.prefab +164 -164
  123. package/{Samples → Samples~}/RS_Bullet_UI_Parent_ETemplate.prefab.meta +7 -7
  124. package/{Samples → Samples~}/RS_Canvas_Shell.prefab +98 -98
  125. package/{Samples → Samples~}/RS_Canvas_Shell.prefab.meta +7 -7
  126. package/{Samples → Samples~}/RS_Canvas_Template.prefab +841 -841
  127. package/{Samples → Samples~}/RS_Canvas_Template.prefab.meta +7 -7
  128. package/{Samples → Samples~}/RS_Click_Group.prefab +255 -255
  129. package/{Samples → Samples~}/RS_Click_Group.prefab.meta +7 -7
  130. package/{Samples → Samples~}/RS_Controls_UI_Handler.prefab +168 -168
  131. package/{Samples → Samples~}/RS_Controls_UI_Handler.prefab.meta +7 -7
  132. package/{Samples → Samples~}/RS_Cycle_Bullet_ETemplate.prefab +242 -242
  133. package/{Samples → Samples~}/RS_Cycle_Bullet_ETemplate.prefab.meta +7 -7
  134. package/{Samples → Samples~}/RS_Cycle_UI_Canvas_Shell.prefab +232 -232
  135. package/{Samples → Samples~}/RS_Cycle_UI_Canvas_Shell.prefab.meta +7 -7
  136. package/{Samples → Samples~}/RS_Cycle_UI_Canvas_Template.prefab +443 -443
  137. package/{Samples → Samples~}/RS_Cycle_UI_Canvas_Template.prefab.meta +7 -7
  138. package/{Samples → Samples~}/RS_Enemy_Win_Mechanic_Shell.prefab +106 -106
  139. package/{Samples → Samples~}/RS_Enemy_Win_Mechanic_Shell.prefab.meta +7 -7
  140. package/{Samples → Samples~}/RS_Enemy_Win_Mechanic_Template.prefab +230 -230
  141. package/{Samples → Samples~}/RS_Enemy_Win_Mechanic_Template.prefab.meta +7 -7
  142. package/{Samples → Samples~}/RS_Fire_Bullet_UI_Handler_Template.prefab +1234 -1234
  143. package/{Samples → Samples~}/RS_Fire_Bullet_UI_Handler_Template.prefab.meta +7 -7
  144. package/{Samples → Samples~}/RS_Firing_Sword_UI_ETemplate.prefab +405 -405
  145. package/{Samples → Samples~}/RS_Firing_Sword_UI_ETemplate.prefab.meta +7 -7
  146. package/{Samples → Samples~}/RS_Group_Manager_Shell.prefab +145 -145
  147. package/{Samples → Samples~}/RS_Group_Manager_Shell.prefab.meta +7 -7
  148. package/{Samples → Samples~}/RS_Group_Manager_Template.prefab +537 -537
  149. package/{Samples → Samples~}/RS_Group_Manager_Template.prefab.meta +7 -7
  150. package/{Samples → Samples~}/RS_Line_Manager_Template.prefab +191 -191
  151. package/{Samples → Samples~}/RS_Line_Manager_Template.prefab.meta +7 -7
  152. package/{Samples → Samples~}/RS_Loading_Bullet_Canvas_Shell.prefab +204 -204
  153. package/{Samples → Samples~}/RS_Loading_Bullet_Canvas_Shell.prefab.meta +7 -7
  154. package/{Samples → Samples~}/RS_Loading_Bullet_Canvas_Template.prefab +411 -411
  155. package/{Samples → Samples~}/RS_Loading_Bullet_Canvas_Template.prefab.meta +7 -7
  156. package/{Samples → Samples~}/RS_Manager_Shell.prefab +514 -514
  157. package/{Samples → Samples~}/RS_Manager_Shell.prefab.meta +7 -7
  158. package/{Samples → Samples~}/RS_Manager_Template.prefab +1526 -1526
  159. package/{Samples → Samples~}/RS_Manager_Template.prefab.meta +7 -7
  160. package/{Samples → Samples~}/RS_Text_Camera.prefab +125 -125
  161. package/{Samples → Samples~}/RS_Text_Camera.prefab.meta +7 -7
  162. package/{Samples → Samples~}/RS_UI_Shatter_Canvas_Template.prefab +150 -150
  163. package/{Samples → Samples~}/RS_UI_Shatter_Canvas_Template.prefab.meta +7 -7
  164. package/{Samples → Samples~}/ShowRSUI.asset +15 -15
  165. package/{Samples → Samples~}/ShowRSUI.asset.meta +8 -8
  166. package/{Samples → Samples~}/Split_Seam_UI.prefab +120 -120
  167. package/{Samples → Samples~}/Split_Seam_UI.prefab.meta +7 -7
  168. package/{Samples → Samples~}/Swipe_Sword.prefab +81 -81
  169. package/{Samples → Samples~}/Swipe_Sword.prefab.meta +7 -7
  170. package/{Samples → Samples~}/Swipe_Visualizer_Image.prefab +102 -102
  171. package/{Samples → Samples~}/Swipe_Visualizer_Image.prefab.meta +7 -7
  172. package/{Samples → Samples~}/Sword_Hit_Listeners.prefab +49 -49
  173. package/{Samples → Samples~}/Sword_Hit_Listeners.prefab.meta +7 -7
  174. package/SplitScreenHandler.cs +263 -263
  175. package/SplitScreenHandler.cs.meta +11 -11
  176. package/SwipeSword.cs +235 -235
  177. package/SwipeSword.cs.meta +11 -11
  178. package/SwipeVisualizer.cs +241 -241
  179. package/SwipeVisualizer.cs.meta +11 -11
  180. package/package.json +57 -52
  181. package/package.json.meta +7 -7
  182. package/Samples.meta +0 -8
@@ -1,11 +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:
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 CHANGED
@@ -1,287 +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
- }
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
287
  }
@@ -1,11 +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:
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: