net.dreditor.purchasing 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.
- package/.attestation.p7m +0 -0
- package/BufferedSelectedUICacher.cs +74 -0
- package/BufferedSelectedUICacher.cs.meta +2 -0
- package/DREditor.Purchasing.asmdef +19 -0
- package/DREditor.Purchasing.asmdef.meta +7 -0
- package/DigitArrow.cs +144 -0
- package/DigitArrow.cs.meta +11 -0
- package/DisplayCurrencyDigits.cs +123 -0
- package/DisplayCurrencyDigits.cs.meta +2 -0
- package/DisplayDigit.cs +84 -0
- package/DisplayDigit.cs.meta +2 -0
- package/DisplayDigits.cs +148 -0
- package/DisplayDigits.cs.meta +2 -0
- package/EnableInputOnPurchaseComplete.cs +12 -0
- package/EnableInputOnPurchaseComplete.cs.meta +2 -0
- package/FollowSelectedObject.cs +20 -0
- package/FollowSelectedObject.cs.meta +2 -0
- package/IDigitPlace.cs +28 -0
- package/IDigitPlace.cs.meta +2 -0
- package/IntPurchaseInputHandler.cs +78 -0
- package/IntPurchaseInputHandler.cs.meta +2 -0
- package/PurchaseInputHandlerBase.cs +133 -0
- package/PurchaseInputHandlerBase.cs.meta +2 -0
- package/Samples~/Buffered_Selected_UI_Cacher.prefab +48 -0
- package/Samples~/Buffered_Selected_UI_Cacher.prefab.meta +7 -0
- package/Samples~/Enable_Input_On_Purchase_Complete.prefab +55 -0
- package/Samples~/Enable_Input_On_Purchase_Complete.prefab.meta +7 -0
- package/Samples~/FTE_Currency_Arrows_ETemplate.prefab +248 -0
- package/Samples~/FTE_Currency_Arrows_ETemplate.prefab.meta +7 -0
- package/Samples~/FTE_Currency_Canvas_ETemplate.prefab +736 -0
- package/Samples~/FTE_Currency_Canvas_ETemplate.prefab.meta +7 -0
- package/Samples~/FTE_Input_Amount_Display_ETemplate.prefab +646 -0
- package/Samples~/FTE_Input_Amount_Display_ETemplate.prefab.meta +7 -0
- package/Samples~/FTE_Owned_Amount_Display_ETemplate.prefab +263 -0
- package/Samples~/FTE_Owned_Amount_Display_ETemplate.prefab.meta +7 -0
- package/Samples~/FTE_Purchase_Complete_Handler.prefab +57 -0
- package/Samples~/FTE_Purchase_Complete_Handler.prefab.meta +7 -0
- package/Samples~/Hundreds_Digit.prefab +201 -0
- package/Samples~/Hundreds_Digit.prefab.meta +7 -0
- package/Samples~/On_Cant_Purchase_Listener.prefab +52 -0
- package/Samples~/On_Cant_Purchase_Listener.prefab.meta +7 -0
- package/Samples~/On_Purchase_Listener.prefab +52 -0
- package/Samples~/On_Purchase_Listener.prefab.meta +7 -0
- package/Samples~/Ones_Digit.prefab +220 -0
- package/Samples~/Ones_Digit.prefab.meta +7 -0
- package/Samples~/Tens_Digit.prefab +201 -0
- package/Samples~/Tens_Digit.prefab.meta +7 -0
- package/SelectedUICacher.cs +76 -0
- package/SelectedUICacher.cs.meta +2 -0
- package/package.json +40 -4
- package/package.json.meta +7 -0
- package/README.md +0 -3
package/.attestation.p7m
ADDED
|
Binary file
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using System;
|
|
3
|
+
using System.Collections;
|
|
4
|
+
using UnityEngine;
|
|
5
|
+
|
|
6
|
+
namespace DREditor.Purchasing
|
|
7
|
+
{
|
|
8
|
+
/// <summary>
|
|
9
|
+
///
|
|
10
|
+
/// </summary>
|
|
11
|
+
public class BufferedSelectedUICacher : SelectedUICacher
|
|
12
|
+
{
|
|
13
|
+
/// <summary>
|
|
14
|
+
///
|
|
15
|
+
/// </summary>
|
|
16
|
+
[Header("")]
|
|
17
|
+
[Space]
|
|
18
|
+
[Tooltip("")]
|
|
19
|
+
[SerializeField] protected float selectBufferDuration = 0.5f;
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
/// <summary>
|
|
23
|
+
///
|
|
24
|
+
/// </summary>
|
|
25
|
+
protected bool waitingThroughBuffer = false;
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
/// <inheritdoc/>
|
|
29
|
+
public override void CacheObject() => CacheObjectResponse()?.Invoke();
|
|
30
|
+
|
|
31
|
+
/// <summary>
|
|
32
|
+
///
|
|
33
|
+
/// </summary>
|
|
34
|
+
/// <returns></returns>
|
|
35
|
+
protected virtual Action CacheObjectResponse() => waitingThroughBuffer ? ResetBuffer : base.CacheObject;
|
|
36
|
+
|
|
37
|
+
/// <summary>
|
|
38
|
+
///
|
|
39
|
+
/// </summary>
|
|
40
|
+
protected virtual void ResetBuffer()
|
|
41
|
+
{
|
|
42
|
+
StopAllCoroutines();
|
|
43
|
+
|
|
44
|
+
SetWaitingThroughBuffer(false);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
/// <inheritdoc/>
|
|
49
|
+
protected override bool ShouldSelectCachedObject() => !waitingThroughBuffer && base.ShouldSelectCachedObject();
|
|
50
|
+
|
|
51
|
+
/// <inheritdoc/>
|
|
52
|
+
protected override void SelectCachedObject() => StartCoroutine(BufferSelection());
|
|
53
|
+
|
|
54
|
+
/// <summary>
|
|
55
|
+
///
|
|
56
|
+
/// </summary>
|
|
57
|
+
protected virtual IEnumerator BufferSelection()
|
|
58
|
+
{
|
|
59
|
+
SetWaitingThroughBuffer(true);
|
|
60
|
+
|
|
61
|
+
yield return new WaitForSeconds(selectBufferDuration);
|
|
62
|
+
|
|
63
|
+
base.SelectCachedObject();
|
|
64
|
+
|
|
65
|
+
ResetBuffer();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/// <summary>
|
|
69
|
+
///
|
|
70
|
+
/// </summary>
|
|
71
|
+
/// <param name="waitingThroughBuffer"></param>
|
|
72
|
+
protected virtual void SetWaitingThroughBuffer(bool waitingThroughBuffer) => this.waitingThroughBuffer = waitingThroughBuffer;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "DREditor.Purchasing",
|
|
3
|
+
"rootNamespace": "",
|
|
4
|
+
"references": [
|
|
5
|
+
"Unity.InputSystem",
|
|
6
|
+
"Unity.TextMeshPro",
|
|
7
|
+
"DREditor",
|
|
8
|
+
"DREditor.EventObjectServices"
|
|
9
|
+
],
|
|
10
|
+
"includePlatforms": [],
|
|
11
|
+
"excludePlatforms": [],
|
|
12
|
+
"allowUnsafeCode": false,
|
|
13
|
+
"overrideReferences": false,
|
|
14
|
+
"precompiledReferences": [],
|
|
15
|
+
"autoReferenced": true,
|
|
16
|
+
"defineConstraints": [],
|
|
17
|
+
"versionDefines": [],
|
|
18
|
+
"noEngineReferences": false
|
|
19
|
+
}
|
package/DigitArrow.cs
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
#if DOTWEEN
|
|
3
|
+
using DG.Tweening;
|
|
4
|
+
#endif
|
|
5
|
+
using UnityEngine;
|
|
6
|
+
using UnityEngine.UI;
|
|
7
|
+
|
|
8
|
+
namespace DREditor.Purchasing
|
|
9
|
+
{
|
|
10
|
+
/// <summary>
|
|
11
|
+
///
|
|
12
|
+
/// </summary>
|
|
13
|
+
[RequireComponent(typeof(Image))]
|
|
14
|
+
public class DigitArrow : MonoBehaviour
|
|
15
|
+
{
|
|
16
|
+
/// <summary>
|
|
17
|
+
///
|
|
18
|
+
/// </summary>
|
|
19
|
+
[Header("")]
|
|
20
|
+
[Space]
|
|
21
|
+
[Header("")]
|
|
22
|
+
[Space]
|
|
23
|
+
[Tooltip("")]
|
|
24
|
+
[SerializeField] protected bool debugReset = false;
|
|
25
|
+
|
|
26
|
+
/// <summary>
|
|
27
|
+
///
|
|
28
|
+
/// </summary>
|
|
29
|
+
[Tooltip("")]
|
|
30
|
+
[SerializeField] protected Vector3 resetPosition;
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
/// <summary>
|
|
34
|
+
///
|
|
35
|
+
/// </summary>
|
|
36
|
+
[Header("")]
|
|
37
|
+
[Space]
|
|
38
|
+
[Tooltip("")]
|
|
39
|
+
[SerializeField] protected Vector3 direction = Vector3.up;
|
|
40
|
+
|
|
41
|
+
/// <summary>
|
|
42
|
+
///
|
|
43
|
+
/// </summary>
|
|
44
|
+
[Tooltip("")]
|
|
45
|
+
[SerializeField] protected float duration = 0.2f;
|
|
46
|
+
|
|
47
|
+
/// <summary>
|
|
48
|
+
///
|
|
49
|
+
/// </summary>
|
|
50
|
+
[Tooltip("")]
|
|
51
|
+
[SerializeField] protected float directionMultiplier = 7;
|
|
52
|
+
|
|
53
|
+
/// <summary>
|
|
54
|
+
///
|
|
55
|
+
/// </summary>
|
|
56
|
+
[Tooltip("")]
|
|
57
|
+
[SerializeField] protected bool ignoreTimeScale = false;
|
|
58
|
+
#if DOTWEEN
|
|
59
|
+
/// <summary>
|
|
60
|
+
///
|
|
61
|
+
/// </summary>
|
|
62
|
+
[Tooltip("")]
|
|
63
|
+
[SerializeField] protected Ease easeCurve = Ease.Linear;
|
|
64
|
+
#endif
|
|
65
|
+
/// <summary>
|
|
66
|
+
///
|
|
67
|
+
/// </summary>
|
|
68
|
+
[Tooltip("")]
|
|
69
|
+
[SerializeField] protected int loops = 0;
|
|
70
|
+
#if DOTWEEN
|
|
71
|
+
/// <summary>
|
|
72
|
+
///
|
|
73
|
+
/// </summary>
|
|
74
|
+
[Tooltip("")]
|
|
75
|
+
[SerializeField] protected LoopType loopType = LoopType.Yoyo;
|
|
76
|
+
#endif
|
|
77
|
+
/// <summary>
|
|
78
|
+
///
|
|
79
|
+
/// </summary>
|
|
80
|
+
[Tooltip("")]
|
|
81
|
+
[SerializeField] protected float delay = 0f;
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
protected virtual void Awake() => Initialize();
|
|
85
|
+
|
|
86
|
+
protected virtual void OnValidate() => Initialize();
|
|
87
|
+
|
|
88
|
+
/// <summary>
|
|
89
|
+
///
|
|
90
|
+
/// </summary>
|
|
91
|
+
protected virtual void Initialize() => resetPosition = transform.localPosition;
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
protected virtual void Start() => StartAnimatingArrow();
|
|
95
|
+
|
|
96
|
+
protected virtual void Update()
|
|
97
|
+
{
|
|
98
|
+
if (debugReset)
|
|
99
|
+
StartAnimatingArrow();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/// <summary>
|
|
103
|
+
///
|
|
104
|
+
/// </summary>
|
|
105
|
+
protected virtual void StartAnimatingArrow()
|
|
106
|
+
{
|
|
107
|
+
ResetArrow();
|
|
108
|
+
|
|
109
|
+
AnimateArrow();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/// <summary>
|
|
113
|
+
///
|
|
114
|
+
/// </summary>
|
|
115
|
+
protected virtual void ResetArrow()
|
|
116
|
+
{
|
|
117
|
+
debugReset = false;
|
|
118
|
+
#if DOTWEEN
|
|
119
|
+
transform.DOKill();
|
|
120
|
+
#endif
|
|
121
|
+
transform.localPosition = resetPosition;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/// <summary>
|
|
125
|
+
///
|
|
126
|
+
/// </summary>
|
|
127
|
+
protected virtual void AnimateArrow()
|
|
128
|
+
{
|
|
129
|
+
#if DOTWEEN
|
|
130
|
+
transform.DOLocalMove(GetEndPosition(), duration)
|
|
131
|
+
.SetUpdate(ignoreTimeScale)
|
|
132
|
+
.SetEase(easeCurve)
|
|
133
|
+
.SetLoops(loops, loopType)
|
|
134
|
+
.SetDelay(delay);
|
|
135
|
+
#endif
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/// <summary>
|
|
139
|
+
///
|
|
140
|
+
/// </summary>
|
|
141
|
+
/// <returns></returns>
|
|
142
|
+
protected virtual Vector3 GetEndPosition() => resetPosition + (direction * directionMultiplier);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using DREditor.EventObjects;
|
|
3
|
+
using DREditor.EventObjectServices;
|
|
4
|
+
using DREditor.Saving.Handlers;
|
|
5
|
+
using DREditor.Utility;
|
|
6
|
+
using System.Collections.Generic;
|
|
7
|
+
using System.Linq;
|
|
8
|
+
using UnityEngine;
|
|
9
|
+
|
|
10
|
+
namespace DREditor.Purchasing
|
|
11
|
+
{
|
|
12
|
+
/// <summary>
|
|
13
|
+
///
|
|
14
|
+
/// </summary>
|
|
15
|
+
[ClassHeader(nameof(ControlledComponent) + ", " + nameof(DisplayDigits) +
|
|
16
|
+
"\n\n")]
|
|
17
|
+
public class DisplayCurrencyDigits : DisplayDigits
|
|
18
|
+
{
|
|
19
|
+
/// <summary>
|
|
20
|
+
///
|
|
21
|
+
/// </summary>
|
|
22
|
+
[Header("")]
|
|
23
|
+
[Divider]
|
|
24
|
+
[Tooltip("")]
|
|
25
|
+
[SerializeField] protected List<IntWithEventListener> digits = new();
|
|
26
|
+
|
|
27
|
+
/// <summary>
|
|
28
|
+
///
|
|
29
|
+
/// </summary>
|
|
30
|
+
[Tooltip("")]
|
|
31
|
+
[SerializeField] protected CurrencyHandler<int> currencyHandler = null;
|
|
32
|
+
|
|
33
|
+
/// <summary>
|
|
34
|
+
///
|
|
35
|
+
/// </summary>
|
|
36
|
+
[Tooltip("")]
|
|
37
|
+
[SerializeField] protected IntWithEvent paidAmount = null;
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
/// <summary>
|
|
41
|
+
///
|
|
42
|
+
/// </summary>
|
|
43
|
+
protected IDigitPlace selectedDigit;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
/// <inheritdoc/>
|
|
47
|
+
protected override void Awake()
|
|
48
|
+
{
|
|
49
|
+
base.Awake();
|
|
50
|
+
|
|
51
|
+
paidAmount.SetValue(Zero);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
/// <inheritdoc/>
|
|
56
|
+
protected override void InitializeSelectedDigit() =>
|
|
57
|
+
selectedDigit = digits.GetSelectedObjectOfType<IDigitPlace>();
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
/// <inheritdoc/>
|
|
61
|
+
protected override void ProcessInputAmount()
|
|
62
|
+
{
|
|
63
|
+
if (DigitsShouldBeUpdated())
|
|
64
|
+
UpdateDigitsFrom(CalculateDigitAmount());
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/// <summary>
|
|
68
|
+
///
|
|
69
|
+
/// </summary>
|
|
70
|
+
/// <returns></returns>
|
|
71
|
+
protected virtual bool DigitsShouldBeUpdated() => HandlersValid() && !DecreasingOnZero() && !IncreasingWhenDigitsMaxed();
|
|
72
|
+
|
|
73
|
+
/// <summary>
|
|
74
|
+
///
|
|
75
|
+
/// </summary>
|
|
76
|
+
/// <returns></returns>
|
|
77
|
+
protected virtual bool HandlersValid() => selectedDigit != null && currencyHandler != null;
|
|
78
|
+
|
|
79
|
+
/// <summary>
|
|
80
|
+
///
|
|
81
|
+
/// </summary>
|
|
82
|
+
/// <returns></returns>
|
|
83
|
+
protected virtual bool DecreasingOnZero() => directionalRate <= Zero && paidAmount.Value == Zero;
|
|
84
|
+
|
|
85
|
+
/// <summary>
|
|
86
|
+
///
|
|
87
|
+
/// </summary>
|
|
88
|
+
/// <returns></returns>
|
|
89
|
+
protected virtual bool IncreasingWhenDigitsMaxed() =>
|
|
90
|
+
directionalRate == inputDirectionalRate && ForwardDigitsMaxed(selectedDigit);
|
|
91
|
+
|
|
92
|
+
/// <summary>
|
|
93
|
+
///
|
|
94
|
+
/// </summary>
|
|
95
|
+
/// <param name="starting"></param>
|
|
96
|
+
/// <returns></returns>
|
|
97
|
+
protected virtual bool ForwardDigitsMaxed(IDigitPlace starting) =>
|
|
98
|
+
digits.OfType<IDigitPlace>()
|
|
99
|
+
.SkipWhile(digit => digit != starting)
|
|
100
|
+
.All(digit => digit.DisplayingMaxDigit());
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
/// <summary>
|
|
104
|
+
///
|
|
105
|
+
/// </summary>
|
|
106
|
+
/// <param name="amount"></param>
|
|
107
|
+
protected virtual void UpdateDigitsFrom(int amount)
|
|
108
|
+
{
|
|
109
|
+
if (currencyHandler.GetCurrency() + amount < Zero || paidAmount.Value + amount < Zero)
|
|
110
|
+
paidAmount.SetValue(Zero);
|
|
111
|
+
else if (paidAmount.Value + amount <= currencyHandler.GetCurrency())
|
|
112
|
+
paidAmount.SetValue(paidAmount.Value + amount);
|
|
113
|
+
else
|
|
114
|
+
paidAmount.Invoke();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/// <summary>
|
|
118
|
+
///
|
|
119
|
+
/// </summary>
|
|
120
|
+
/// <returns></returns>
|
|
121
|
+
protected virtual int CalculateDigitAmount() => selectedDigit.GetDigitPlace() * directionalRate;
|
|
122
|
+
}
|
|
123
|
+
}
|
package/DisplayDigit.cs
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using DREditor;
|
|
3
|
+
using DREditor.EventObjectServices;
|
|
4
|
+
using TMPro;
|
|
5
|
+
using UnityEngine;
|
|
6
|
+
|
|
7
|
+
namespace DREditor.Purchasing
|
|
8
|
+
{
|
|
9
|
+
/// <summary>
|
|
10
|
+
///
|
|
11
|
+
/// </summary>
|
|
12
|
+
[ClassHeader(nameof(IntWithEventListener) + ", " + nameof(IDigitPlace) +
|
|
13
|
+
"\n\n")]
|
|
14
|
+
public class DisplayDigit : IntWithEventListener, IDigitPlace
|
|
15
|
+
{
|
|
16
|
+
/// <summary>
|
|
17
|
+
///
|
|
18
|
+
/// </summary>
|
|
19
|
+
[Tooltip("")]
|
|
20
|
+
[SerializeField] protected TMP_Text digitText;
|
|
21
|
+
|
|
22
|
+
/// <summary>
|
|
23
|
+
///
|
|
24
|
+
/// </summary>
|
|
25
|
+
[Tooltip("")]
|
|
26
|
+
[SerializeField] protected int digitPlace = 1;
|
|
27
|
+
|
|
28
|
+
/// <summary>
|
|
29
|
+
///
|
|
30
|
+
/// </summary>
|
|
31
|
+
[Range(0, 9)]
|
|
32
|
+
[Tooltip("")]
|
|
33
|
+
[SerializeField] protected int maxDigit = 9;
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
/// <summary>
|
|
37
|
+
///
|
|
38
|
+
/// </summary>
|
|
39
|
+
private const int DigitModulus = 10;
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
protected virtual void Awake()
|
|
43
|
+
{
|
|
44
|
+
if (DigitPlaceInvalid())
|
|
45
|
+
UnityEngine.Debug.LogError("ALERT: THE DIGIT PLACE IS NOT VALID! Valid Examples: 1, 10, 100");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// <summary>
|
|
49
|
+
///
|
|
50
|
+
/// </summary>
|
|
51
|
+
/// <returns></returns>
|
|
52
|
+
protected virtual bool DigitPlaceInvalid() => digitPlace == 0 || (digitPlace > 1 && digitPlace % DigitModulus != 0);
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
/// <inheritdoc/>
|
|
56
|
+
protected override void OnValueChanged(int updatedValue)
|
|
57
|
+
{
|
|
58
|
+
base.OnValueChanged(updatedValue);
|
|
59
|
+
|
|
60
|
+
UpdateDisplayedDigit();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/// <summary>
|
|
64
|
+
///
|
|
65
|
+
/// </summary>
|
|
66
|
+
protected virtual void UpdateDisplayedDigit() => digitText.text = CalculateDigit().ToString();
|
|
67
|
+
|
|
68
|
+
/// <summary>
|
|
69
|
+
///
|
|
70
|
+
/// </summary>
|
|
71
|
+
/// <returns></returns>
|
|
72
|
+
protected virtual int CalculateDigit() => UpdatedValue < digitPlace ? 0 : UpdatedValue / digitPlace % DigitModulus;
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
/// <inheritdoc/>
|
|
76
|
+
public virtual int GetDigitPlace() => digitPlace;
|
|
77
|
+
|
|
78
|
+
/// <inheritdoc/>
|
|
79
|
+
public virtual string GetDisplayedDigit() => digitText.text;
|
|
80
|
+
|
|
81
|
+
/// <inheritdoc/>
|
|
82
|
+
public virtual bool DisplayingMaxDigit() => GetDisplayedDigit() == maxDigit.ToString();
|
|
83
|
+
}
|
|
84
|
+
}
|
package/DisplayDigits.cs
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using DREditor.EventObjects;
|
|
3
|
+
using UnityEngine;
|
|
4
|
+
using UnityEngine.InputSystem;
|
|
5
|
+
using static UnityEngine.InputSystem.InputAction;
|
|
6
|
+
|
|
7
|
+
namespace DREditor.Purchasing
|
|
8
|
+
{
|
|
9
|
+
/// <summary>
|
|
10
|
+
///
|
|
11
|
+
/// </summary>
|
|
12
|
+
public abstract class DisplayDigits : ControlledComponent
|
|
13
|
+
{
|
|
14
|
+
/// <summary>
|
|
15
|
+
///
|
|
16
|
+
/// </summary>
|
|
17
|
+
[Header("")]
|
|
18
|
+
[Divider]
|
|
19
|
+
[Tooltip("")]
|
|
20
|
+
[SerializeField] protected InputActionReference move = null;
|
|
21
|
+
|
|
22
|
+
/// <summary>
|
|
23
|
+
///
|
|
24
|
+
/// </summary>
|
|
25
|
+
[Tooltip("")]
|
|
26
|
+
[SerializeField] protected bool useHorizontalInput = false;
|
|
27
|
+
|
|
28
|
+
/// <summary>
|
|
29
|
+
///
|
|
30
|
+
/// </summary>
|
|
31
|
+
[Tooltip("")]
|
|
32
|
+
[SerializeField] protected int inputDirectionalRate = 1;
|
|
33
|
+
|
|
34
|
+
/// <summary>
|
|
35
|
+
///
|
|
36
|
+
/// </summary>
|
|
37
|
+
[Tooltip("")]
|
|
38
|
+
[SerializeField] protected float deadThreshold = 0;
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
/// <summary>
|
|
42
|
+
///
|
|
43
|
+
/// </summary>
|
|
44
|
+
protected int directionalRate = 0;
|
|
45
|
+
|
|
46
|
+
/// <summary>
|
|
47
|
+
///
|
|
48
|
+
/// </summary>
|
|
49
|
+
protected CallbackContext context;
|
|
50
|
+
|
|
51
|
+
/// <summary>
|
|
52
|
+
///
|
|
53
|
+
/// </summary>
|
|
54
|
+
protected readonly int Zero = 0;
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
/// <inheritdoc/>
|
|
58
|
+
public override void ActivateControls() => move.action.started += UpdateDisplayedCurrency;
|
|
59
|
+
|
|
60
|
+
/// <inheritdoc/>
|
|
61
|
+
public override void DeactivateControls() => move.action.started -= UpdateDisplayedCurrency;
|
|
62
|
+
|
|
63
|
+
/// <summary>
|
|
64
|
+
///
|
|
65
|
+
/// </summary>
|
|
66
|
+
/// <param name="context"></param>
|
|
67
|
+
protected virtual void UpdateDisplayedCurrency(CallbackContext context)
|
|
68
|
+
{
|
|
69
|
+
InitializeOnInput(context);
|
|
70
|
+
|
|
71
|
+
ProcessInputAmount();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/// <summary>
|
|
75
|
+
///
|
|
76
|
+
/// </summary>
|
|
77
|
+
protected abstract void ProcessInputAmount();
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
/// <summary>
|
|
81
|
+
///
|
|
82
|
+
/// </summary>
|
|
83
|
+
/// <param name="context"></param>
|
|
84
|
+
protected virtual void InitializeOnInput(CallbackContext context)
|
|
85
|
+
{
|
|
86
|
+
InitializeInputContext(context);
|
|
87
|
+
|
|
88
|
+
InitializeDirectionalRate();
|
|
89
|
+
|
|
90
|
+
InitializeSelectedDigit();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// <summary>
|
|
94
|
+
///
|
|
95
|
+
/// </summary>
|
|
96
|
+
/// <param name="context"></param>
|
|
97
|
+
protected virtual void InitializeInputContext(CallbackContext context) => this.context = context;
|
|
98
|
+
|
|
99
|
+
/// <summary>
|
|
100
|
+
///
|
|
101
|
+
/// </summary>
|
|
102
|
+
protected virtual void InitializeDirectionalRate() => directionalRate = inputDirectionalRate * (int)CalculateDirection();
|
|
103
|
+
|
|
104
|
+
/// <summary>
|
|
105
|
+
///
|
|
106
|
+
/// </summary>
|
|
107
|
+
/// <returns></returns>
|
|
108
|
+
protected virtual float CalculateDirection() => DirectionIsValid() ? Mathf.Sign(GetAxis()) : Zero;
|
|
109
|
+
|
|
110
|
+
/// <summary>
|
|
111
|
+
///
|
|
112
|
+
/// </summary>
|
|
113
|
+
/// <returns></returns>
|
|
114
|
+
protected virtual bool DirectionIsValid() => InputPastDeadZone() && !MovingAlongSelectionAxis();
|
|
115
|
+
|
|
116
|
+
/// <summary>
|
|
117
|
+
///
|
|
118
|
+
/// </summary>
|
|
119
|
+
/// <returns></returns>
|
|
120
|
+
protected virtual bool InputPastDeadZone() => Mathf.Abs(GetAxis()) > deadThreshold;
|
|
121
|
+
|
|
122
|
+
/// <summary>
|
|
123
|
+
///
|
|
124
|
+
/// </summary>
|
|
125
|
+
/// <returns></returns>
|
|
126
|
+
protected virtual bool MovingAlongSelectionAxis() => Mathf.Abs(GetOppositeAxis()) > Mathf.Abs(GetAxis());
|
|
127
|
+
|
|
128
|
+
/// <summary>
|
|
129
|
+
///
|
|
130
|
+
/// </summary>
|
|
131
|
+
/// <returns></returns>
|
|
132
|
+
protected virtual float GetAxis() =>
|
|
133
|
+
useHorizontalInput ? context.ReadValue<Vector2>().x : context.ReadValue<Vector2>().y;
|
|
134
|
+
|
|
135
|
+
/// <summary>
|
|
136
|
+
///
|
|
137
|
+
/// </summary>
|
|
138
|
+
/// <returns></returns>
|
|
139
|
+
protected virtual float GetOppositeAxis() =>
|
|
140
|
+
GetAxis() == context.ReadValue<Vector2>().x ? context.ReadValue<Vector2>().y : context.ReadValue<Vector2>().x;
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
/// <summary>
|
|
144
|
+
///
|
|
145
|
+
/// </summary>
|
|
146
|
+
protected abstract void InitializeSelectedDigit();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using DREditor.EventObjects;
|
|
3
|
+
|
|
4
|
+
namespace DREditor.Purchasing
|
|
5
|
+
{
|
|
6
|
+
/// <summary>
|
|
7
|
+
///
|
|
8
|
+
/// </summary>
|
|
9
|
+
[ClassHeader(nameof(SetInputOnSceneEvent) + ", " + nameof(SceneEventListener) +
|
|
10
|
+
"\n\n")]
|
|
11
|
+
public class EnableInputOnPurchaseComplete : SetInputOnSceneEvent { }
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using DREditor;
|
|
3
|
+
using UnityEngine;
|
|
4
|
+
using UnityEngine.EventSystems;
|
|
5
|
+
|
|
6
|
+
namespace DREditor.Purchasing
|
|
7
|
+
{
|
|
8
|
+
/// <summary>
|
|
9
|
+
///
|
|
10
|
+
/// </summary>
|
|
11
|
+
[ClassHeader("")]
|
|
12
|
+
public class FollowSelectedObject : MonoBehaviour
|
|
13
|
+
{
|
|
14
|
+
protected virtual void LateUpdate()
|
|
15
|
+
{
|
|
16
|
+
if (EventSystem.current.currentSelectedGameObject != null)
|
|
17
|
+
transform.position = EventSystem.current.currentSelectedGameObject.transform.position;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|