net.dreditor.subareas 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.
@@ -1,350 +1,350 @@
1
- //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
- using DREditor.Cameras;
3
- using DREditor.Choices;
4
- using DREditor.Dialogues;
5
- using DREditor.Dialogues.Events;
6
- using DREditor.Doors;
7
- using DREditor.EventObjects;
8
- using DREditor.Fading;
9
- using DREditor.Input;
10
- using DREditor.Services;
11
- using DREditor.TwoPointFiveD;
12
- using System;
13
- using System.Collections;
14
- using UnityEngine;
15
- using UnityEngine.EventSystems;
16
- using static UnityEngine.InputSystem.InputAction;
17
-
18
- namespace DREditor.SubAreas
19
- {
20
- /// <summary>
21
- ///
22
- /// </summary>
23
- [ClassHeader(nameof(SubAreaActivationHandler) +
24
- "\n\n")]
25
- public class SubAreaDeactivator : SubAreaActivationHandler
26
- {
27
- /// <summary>
28
- ///
29
- /// </summary>
30
- [Tooltip("")]
31
- [SerializeField] protected float panToBodyBufferTime = 0.1f;
32
-
33
- /// <summary>
34
- ///
35
- /// </summary>
36
- [Tooltip("")]
37
- [SerializeField] protected float fadeTime = 0.3f;
38
-
39
- /// <summary>
40
- ///
41
- /// </summary>
42
- [Tooltip("")]
43
- [SerializeField] protected float leaveAskAnimationDuration = 0.5f;
44
-
45
-
46
- /// <summary>
47
- ///
48
- /// </summary>
49
- [Header("")]
50
- [Divider]
51
- [Tooltip("")]
52
- [SerializeField] protected string onDidntLeaveEvent = "SubAreaOnDidntLeave";
53
-
54
- /// <summary>
55
- ///
56
- /// </summary>
57
- [Tooltip("")]
58
- [SerializeField] protected BoolWithEvent inMenu = null;
59
-
60
- /// <summary>
61
- ///
62
- /// </summary>
63
- [Tooltip("")]
64
- [SerializeField] protected BoolWithEvent inSubAreaActivation = null;
65
-
66
- /// <summary>
67
- ///
68
- /// </summary>
69
- [Tooltip("")]
70
- [SerializeField] protected SceneEvent OnSAMDeactivateVisuals = null;
71
-
72
-
73
- /// <summary>
74
- ///
75
- /// </summary>
76
- protected Action ResubscribeLeaveInput;
77
-
78
- /// <summary>
79
- ///
80
- /// </summary>
81
- protected SubAreaData Data;
82
-
83
-
84
- /// <inheritdoc/>
85
- protected override void Awake()
86
- {
87
- base.Awake();
88
-
89
- ResubscribeLeaveInput = () => ServiceLocator.GetService<IInputManager>().GetLeave().performed += Release;
90
- }
91
-
92
- protected virtual void OnDestroy() => ServiceLocator.GetService<IInputManager>().GetLeave().performed -= Release;
93
-
94
- /// <inheritdoc/>
95
- public override void Initialize(object subAreaData) => Data = (SubAreaData)subAreaData;
96
-
97
- /// <inheritdoc/>
98
- public override void BeginActivationState()
99
- {
100
- inSubAreaActivation.SetValue(false);
101
-
102
- ResubscribeLeaveInput?.Invoke();
103
- }
104
-
105
- #region Leave Input
106
-
107
- /// <summary>
108
- ///
109
- /// </summary>
110
- /// <param name="context"></param>
111
- protected virtual void Release(CallbackContext context)
112
- {
113
- ServiceLocator.GetService<IInputManager>().GetLeave().performed -= Release;
114
-
115
- if (!inLeaveProcess.Value && !inMenu.Value && !inDialogue.Value)
116
- CheckRelease();
117
- else
118
- ResubscribeLeaveInput?.Invoke();
119
- }
120
-
121
- /// <summary>
122
- ///
123
- /// </summary>
124
- protected virtual void CheckRelease()
125
- {
126
- SetAccessibility(false);
127
-
128
- if (!Data.leaveData.IsUnlocked())
129
- OnLeavingLocked();
130
- else
131
- PromptLeavingSubArea();
132
- }
133
-
134
- /// <summary>
135
- ///
136
- /// </summary>
137
- protected virtual void OnLeavingLocked()
138
- {
139
- if (TryPlayingDialogue(null, Data.leaveData.lockDialogues))
140
- SubscribeEndDialogueEvent(AfterLock);
141
- else
142
- PromptLeavingSubArea();
143
- }
144
-
145
- /// <summary>
146
- ///
147
- /// </summary>
148
- protected virtual void PromptLeavingSubArea()
149
- {
150
- SubscribeChoices();
151
-
152
- Dialogue dialogue = (Dialogue)ServiceLocator.GetService<LeaveAskManager>().GetLeaveAskDialogue();
153
-
154
- dialogueManager.StartDialogue(null, dialogue, true);
155
- }
156
-
157
- /// <summary>
158
- ///
159
- /// </summary>
160
- protected virtual void SubscribeChoices()
161
- {
162
- ServiceLocator.GetService<IChoiceManager>().SubscribeChoice(0, Deactivate);
163
-
164
- ServiceLocator.GetService<IChoiceManager>().SubscribeChoice(1, DummyNoOption);
165
- }
166
-
167
- /// <summary>
168
- ///
169
- /// </summary>
170
- protected virtual void DummyNoOption()
171
- {
172
- UnsubscribeChoices();
173
-
174
- EventSystem.current.SetSelectedGameObject(null);
175
-
176
- DialogueEventSystem.TriggerEvent(onDidntLeaveEvent);
177
-
178
- AfterLock();
179
-
180
- ResubscribeLeaveInput?.Invoke();
181
- }
182
-
183
- /// <summary>
184
- ///
185
- /// </summary>
186
- protected virtual void UnsubscribeChoices()
187
- {
188
- ServiceLocator.GetService<IChoiceManager>().UnsubscribeChoice(0, Deactivate);
189
-
190
- ServiceLocator.GetService<IChoiceManager>().UnsubscribeChoice(1, DummyNoOption);
191
- }
192
-
193
- /// <summary>
194
- ///
195
- /// </summary>
196
- /// <remarks>
197
- ///
198
- /// </remarks>
199
- protected virtual void AfterLock()
200
- {
201
- UnsubscribeEndDialogueEvent(AfterLock);
202
-
203
- SetAccessibility(true);
204
-
205
- ResubscribeLeaveInput?.Invoke();
206
- }
207
-
208
- /// <summary>
209
- ///
210
- /// </summary>
211
- protected virtual void SetAccessibility(bool to)
212
- {
213
- inLeaveProcess.SetValue(!to);
214
-
215
- playerSystem.TPFDScript.enabled = to;
216
-
217
- hasMenuAccess.SetValue(to);
218
- }
219
-
220
- #endregion
221
-
222
- #region Deactivation
223
-
224
- /// <summary>
225
- ///
226
- /// </summary>
227
- protected virtual void Deactivate()
228
- {
229
- UnsubscribeChoices();
230
-
231
- StartCoroutine(Deactivation());
232
- }
233
-
234
- /// <summary>
235
- ///
236
- /// </summary>
237
- protected virtual IEnumerator Deactivation()
238
- {
239
- if (AlreadyInTPFD())
240
- yield return DeactivateTPFD();
241
- else
242
- yield return DeactivateThreeD();
243
-
244
- OnSAMDeactivateVisuals.Raise();
245
-
246
- TurnOffDisplayedObjectName();
247
-
248
- objectGroup.EnableItems(false);
249
-
250
- if (AlreadyInTPFD())
251
- yield return PreDeactivateTPFD();
252
-
253
- EndOfActivationHandler();
254
- }
255
-
256
- /// <summary>
257
- ///
258
- /// </summary>
259
- protected virtual IEnumerator DeactivateTPFD()
260
- {
261
- if (!ServiceLocator.GetService<GlobalFade>().IsDark)
262
- {
263
- yield return new WaitForSeconds(leaveAskAnimationDuration);
264
-
265
- yield return ServiceLocator.GetService<GlobalFade>().FadeToRoutine(fadeTime);
266
- }
267
-
268
- tpfdManager.enabled = false;
269
-
270
- foreach (TPFDManager manager in managers)
271
- {
272
- manager.enabled = true;
273
-
274
- manager.SetPnCCamera();
275
- }
276
- }
277
-
278
- /// <summary>
279
- ///
280
- /// </summary>
281
- protected virtual IEnumerator DeactivateThreeD()
282
- {
283
- playerSystem.EnableBehaviours(false);
284
-
285
- playerSystem.enabled = false;
286
-
287
- inTPFD.Value = false;
288
-
289
- SmoothMouseLook mouse = mainCamera.GetComponent<SmoothMouseLook>();
290
-
291
- mouse.SetCorePos(Data.returnAbs); // was new Vector2(1.401298e-45f, 1.401298e-45f)
292
-
293
- yield return MoveCameraToPosition(Data.returnPosition, Data.returnRotation, panToBodyTime, panToBodyBufferTime);
294
-
295
- playerSystem.enabled = true;
296
-
297
- playerSystem.EnableBehaviours(true);
298
- }
299
-
300
- /// <summary>
301
- ///
302
- /// </summary>
303
- protected virtual IEnumerator PreDeactivateTPFD()
304
- {
305
- yield return new WaitUntil(() => ServiceLocator.GetService<GlobalFade>().IsDark);
306
-
307
- playerSystem.enabled = true;
308
-
309
- playerSystem.TPFDScript.enabled = true;
310
- }
311
-
312
- /// <inheritdoc/>
313
- public override void EndOfActivationHandler()
314
- {
315
- subAreaCollider.enabled = true;
316
-
317
- Data.SetActivated(false);
318
-
319
- inLeaveProcess.SetValue(false);
320
-
321
- if (!AlreadyInTPFD())
322
- inDialogue.Value = false;
323
-
324
- if (AlreadyInTPFD())
325
- StartCoroutine(PostDeactivateTPFD());
326
- else
327
- FinishHandler();
328
- }
329
-
330
- /// <summary>
331
- ///
332
- /// </summary>
333
- protected IEnumerator PostDeactivateTPFD()
334
- {
335
- yield return new WaitForSeconds(fadeTime);
336
-
337
- FinishHandler();
338
-
339
- yield return new WaitUntil(() => !inDialogue.Value);
340
-
341
- yield return ServiceLocator.GetService<GlobalFade>().FadeOutRoutine(fadeTime);
342
-
343
- UnityEngine.Debug.Log($"REPORT: {gameObject.name} Added Back TPFD Door Controls");
344
-
345
- GetTPFDDoors().ForEach(door => door.AddDoorControl());
346
- }
347
-
348
- #endregion
349
- }
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ using DREditor.Cameras;
3
+ using DREditor.Choices;
4
+ using DREditor.Dialogues;
5
+ using DREditor.Dialogues.Events;
6
+ using DREditor.Doors;
7
+ using DREditor.EventObjects;
8
+ using DREditor.Fading;
9
+ using DREditor.Input;
10
+ using DREditor.Services;
11
+ using DREditor.TwoPointFiveD;
12
+ using System;
13
+ using System.Collections;
14
+ using UnityEngine;
15
+ using UnityEngine.EventSystems;
16
+ using static UnityEngine.InputSystem.InputAction;
17
+
18
+ namespace DREditor.SubAreas
19
+ {
20
+ /// <summary>
21
+ ///
22
+ /// </summary>
23
+ [ClassHeader(nameof(SubAreaActivationHandler) +
24
+ "\n\n")]
25
+ public class SubAreaDeactivator : SubAreaActivationHandler
26
+ {
27
+ /// <summary>
28
+ ///
29
+ /// </summary>
30
+ [Tooltip("")]
31
+ [SerializeField] protected float panToBodyBufferTime = 0.1f;
32
+
33
+ /// <summary>
34
+ ///
35
+ /// </summary>
36
+ [Tooltip("")]
37
+ [SerializeField] protected float fadeTime = 0.3f;
38
+
39
+ /// <summary>
40
+ ///
41
+ /// </summary>
42
+ [Tooltip("")]
43
+ [SerializeField] protected float leaveAskAnimationDuration = 0.5f;
44
+
45
+
46
+ /// <summary>
47
+ ///
48
+ /// </summary>
49
+ [Header("")]
50
+ [Divider]
51
+ [Tooltip("")]
52
+ [SerializeField] protected string onDidntLeaveEvent = "SubAreaOnDidntLeave";
53
+
54
+ /// <summary>
55
+ ///
56
+ /// </summary>
57
+ [Tooltip("")]
58
+ [SerializeField] protected BoolWithEvent inMenu = null;
59
+
60
+ /// <summary>
61
+ ///
62
+ /// </summary>
63
+ [Tooltip("")]
64
+ [SerializeField] protected BoolWithEvent inSubAreaActivation = null;
65
+
66
+ /// <summary>
67
+ ///
68
+ /// </summary>
69
+ [Tooltip("")]
70
+ [SerializeField] protected SceneEvent OnSAMDeactivateVisuals = null;
71
+
72
+
73
+ /// <summary>
74
+ ///
75
+ /// </summary>
76
+ protected Action ResubscribeLeaveInput;
77
+
78
+ /// <summary>
79
+ ///
80
+ /// </summary>
81
+ protected SubAreaData Data;
82
+
83
+
84
+ /// <inheritdoc/>
85
+ protected override void Awake()
86
+ {
87
+ base.Awake();
88
+
89
+ ResubscribeLeaveInput = () => ServiceLocator.GetService<IInputManager>().GetLeave().performed += Release;
90
+ }
91
+
92
+ protected virtual void OnDestroy() => ServiceLocator.GetService<IInputManager>().GetLeave().performed -= Release;
93
+
94
+ /// <inheritdoc/>
95
+ public override void Initialize(object subAreaData) => Data = (SubAreaData)subAreaData;
96
+
97
+ /// <inheritdoc/>
98
+ public override void BeginActivationState()
99
+ {
100
+ inSubAreaActivation.SetValue(false);
101
+
102
+ ResubscribeLeaveInput?.Invoke();
103
+ }
104
+
105
+ #region Leave Input
106
+
107
+ /// <summary>
108
+ ///
109
+ /// </summary>
110
+ /// <param name="context"></param>
111
+ protected virtual void Release(CallbackContext context)
112
+ {
113
+ ServiceLocator.GetService<IInputManager>().GetLeave().performed -= Release;
114
+
115
+ if (!inLeaveProcess.Value && !inMenu.Value && !inDialogue.Value)
116
+ CheckRelease();
117
+ else
118
+ ResubscribeLeaveInput?.Invoke();
119
+ }
120
+
121
+ /// <summary>
122
+ ///
123
+ /// </summary>
124
+ protected virtual void CheckRelease()
125
+ {
126
+ SetAccessibility(false);
127
+
128
+ if (!Data.leaveData.IsUnlocked())
129
+ OnLeavingLocked();
130
+ else
131
+ PromptLeavingSubArea();
132
+ }
133
+
134
+ /// <summary>
135
+ ///
136
+ /// </summary>
137
+ protected virtual void OnLeavingLocked()
138
+ {
139
+ if (TryPlayingDialogue(null, Data.leaveData.lockDialogues))
140
+ SubscribeEndDialogueEvent(AfterLock);
141
+ else
142
+ PromptLeavingSubArea();
143
+ }
144
+
145
+ /// <summary>
146
+ ///
147
+ /// </summary>
148
+ protected virtual void PromptLeavingSubArea()
149
+ {
150
+ SubscribeChoices();
151
+
152
+ Dialogue dialogue = (Dialogue)ServiceLocator.GetService<LeaveAskManager>().GetLeaveAskDialogue();
153
+
154
+ dialogueManager.StartDialogue(null, dialogue, true);
155
+ }
156
+
157
+ /// <summary>
158
+ ///
159
+ /// </summary>
160
+ protected virtual void SubscribeChoices()
161
+ {
162
+ ServiceLocator.GetService<IChoiceManager>().SubscribeChoice(0, Deactivate);
163
+
164
+ ServiceLocator.GetService<IChoiceManager>().SubscribeChoice(1, DummyNoOption);
165
+ }
166
+
167
+ /// <summary>
168
+ ///
169
+ /// </summary>
170
+ protected virtual void DummyNoOption()
171
+ {
172
+ UnsubscribeChoices();
173
+
174
+ EventSystem.current.SetSelectedGameObject(null);
175
+
176
+ DialogueEventSystem.TriggerEvent(onDidntLeaveEvent);
177
+
178
+ AfterLock();
179
+
180
+ ResubscribeLeaveInput?.Invoke();
181
+ }
182
+
183
+ /// <summary>
184
+ ///
185
+ /// </summary>
186
+ protected virtual void UnsubscribeChoices()
187
+ {
188
+ ServiceLocator.GetService<IChoiceManager>().UnsubscribeChoice(0, Deactivate);
189
+
190
+ ServiceLocator.GetService<IChoiceManager>().UnsubscribeChoice(1, DummyNoOption);
191
+ }
192
+
193
+ /// <summary>
194
+ ///
195
+ /// </summary>
196
+ /// <remarks>
197
+ ///
198
+ /// </remarks>
199
+ protected virtual void AfterLock()
200
+ {
201
+ UnsubscribeEndDialogueEvent(AfterLock);
202
+
203
+ SetAccessibility(true);
204
+
205
+ ResubscribeLeaveInput?.Invoke();
206
+ }
207
+
208
+ /// <summary>
209
+ ///
210
+ /// </summary>
211
+ protected virtual void SetAccessibility(bool to)
212
+ {
213
+ inLeaveProcess.SetValue(!to);
214
+
215
+ playerSystem.TPFDScript.enabled = to;
216
+
217
+ hasMenuAccess.SetValue(to);
218
+ }
219
+
220
+ #endregion
221
+
222
+ #region Deactivation
223
+
224
+ /// <summary>
225
+ ///
226
+ /// </summary>
227
+ protected virtual void Deactivate()
228
+ {
229
+ UnsubscribeChoices();
230
+
231
+ StartCoroutine(Deactivation());
232
+ }
233
+
234
+ /// <summary>
235
+ ///
236
+ /// </summary>
237
+ protected virtual IEnumerator Deactivation()
238
+ {
239
+ if (AlreadyInTPFD())
240
+ yield return DeactivateTPFD();
241
+ else
242
+ yield return DeactivateThreeD();
243
+
244
+ OnSAMDeactivateVisuals.Raise();
245
+
246
+ TurnOffDisplayedObjectName();
247
+
248
+ objectGroup.EnableItems(false);
249
+
250
+ if (AlreadyInTPFD())
251
+ yield return PreDeactivateTPFD();
252
+
253
+ EndOfActivationHandler();
254
+ }
255
+
256
+ /// <summary>
257
+ ///
258
+ /// </summary>
259
+ protected virtual IEnumerator DeactivateTPFD()
260
+ {
261
+ if (!ServiceLocator.GetService<GlobalFade>().IsDark)
262
+ {
263
+ yield return new WaitForSeconds(leaveAskAnimationDuration);
264
+
265
+ yield return ServiceLocator.GetService<GlobalFade>().FadeToRoutine(fadeTime);
266
+ }
267
+
268
+ tpfdManager.enabled = false;
269
+
270
+ foreach (TPFDManager manager in managers)
271
+ {
272
+ manager.enabled = true;
273
+
274
+ manager.SetPnCCamera();
275
+ }
276
+ }
277
+
278
+ /// <summary>
279
+ ///
280
+ /// </summary>
281
+ protected virtual IEnumerator DeactivateThreeD()
282
+ {
283
+ playerSystem.EnableBehaviours(false);
284
+
285
+ playerSystem.enabled = false;
286
+
287
+ inTPFD.Value = false;
288
+
289
+ SmoothMouseLook mouse = mainCamera.GetComponent<SmoothMouseLook>();
290
+
291
+ mouse.SetCorePos(Data.returnAbs); // was new Vector2(1.401298e-45f, 1.401298e-45f)
292
+
293
+ yield return MoveCameraToPosition(Data.returnPosition, Data.returnRotation, panToBodyTime, panToBodyBufferTime);
294
+
295
+ playerSystem.enabled = true;
296
+
297
+ playerSystem.EnableBehaviours(true);
298
+ }
299
+
300
+ /// <summary>
301
+ ///
302
+ /// </summary>
303
+ protected virtual IEnumerator PreDeactivateTPFD()
304
+ {
305
+ yield return new WaitUntil(() => ServiceLocator.GetService<GlobalFade>().IsDark);
306
+
307
+ playerSystem.enabled = true;
308
+
309
+ playerSystem.TPFDScript.enabled = true;
310
+ }
311
+
312
+ /// <inheritdoc/>
313
+ public override void EndOfActivationHandler()
314
+ {
315
+ subAreaCollider.enabled = true;
316
+
317
+ Data.SetActivated(false);
318
+
319
+ inLeaveProcess.SetValue(false);
320
+
321
+ if (!AlreadyInTPFD())
322
+ inDialogue.Value = false;
323
+
324
+ if (AlreadyInTPFD())
325
+ StartCoroutine(PostDeactivateTPFD());
326
+ else
327
+ FinishHandler();
328
+ }
329
+
330
+ /// <summary>
331
+ ///
332
+ /// </summary>
333
+ protected IEnumerator PostDeactivateTPFD()
334
+ {
335
+ yield return new WaitForSeconds(fadeTime);
336
+
337
+ FinishHandler();
338
+
339
+ yield return new WaitUntil(() => !inDialogue.Value);
340
+
341
+ yield return ServiceLocator.GetService<GlobalFade>().FadeOutRoutine(fadeTime);
342
+
343
+ UnityEngine.Debug.Log($"REPORT: {gameObject.name} Added Back TPFD Door Controls");
344
+
345
+ GetTPFDDoors().ForEach(door => door.AddDoorControl());
346
+ }
347
+
348
+ #endregion
349
+ }
350
350
  }