com.puzzlescapegames.services 1.2.0 → 1.2.2

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.
@@ -0,0 +1,54 @@
1
+ using System;
2
+ using UnityEditor;
3
+ using UnityEngine;
4
+
5
+ namespace PuzzlescapeGames.Atributes
6
+ {
7
+ [ CustomPropertyDrawer( typeof(TimeInfoAttribute) ) ]
8
+ public sealed class TimeInfoDrawer : PropertyDrawer
9
+ {
10
+ private const float _infoBoxHeight = 30f;
11
+
12
+ public override void OnGUI( Rect position, SerializedProperty property, GUIContent label )
13
+ {
14
+ Rect infoRect = new Rect( position.x, position.y, position.width, _infoBoxHeight );
15
+ Rect fieldRect = new Rect( position.x, position.y + _infoBoxHeight + 2, position.width, EditorGUIUtility.singleLineHeight );
16
+
17
+ if ( property.propertyType == SerializedPropertyType.Integer )
18
+ {
19
+ int duration = property.intValue;
20
+ string formattedTime = GetEditorTimeFormat( duration );
21
+
22
+ EditorGUI.HelpBox( infoRect, $"{formattedTime}", MessageType.Info );
23
+ }
24
+ else
25
+ {
26
+ EditorGUI.HelpBox( infoRect, "TimeInfo only int", MessageType.Warning );
27
+ }
28
+
29
+ EditorGUI.PropertyField( fieldRect, property, label );
30
+ }
31
+
32
+ public override float GetPropertyHeight( SerializedProperty property, GUIContent label )
33
+ {
34
+ return EditorGUIUtility.singleLineHeight + _infoBoxHeight + 6f;
35
+ }
36
+
37
+ private string GetEditorTimeFormat( int totalSeconds )
38
+ {
39
+ TimeSpan span = TimeSpan.FromSeconds( totalSeconds );
40
+
41
+ string result = "";
42
+ if ( span.Days > 0 )
43
+ result += $"{span.Days}d ";
44
+ if ( span.Hours > 0 || span.Days > 0 )
45
+ result += $"{span.Hours}h ";
46
+ if ( span.Minutes > 0 || span.Hours > 0 || span.Days > 0 )
47
+ result += $"{span.Minutes}m ";
48
+
49
+ result += $"{span.Seconds}s";
50
+
51
+ return result.Trim();
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 441fb4bb054b4808a4f8579ec8f35e32
3
+ timeCreated: 1741704204
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 11a143f5d3634f139384d88b2f6dc9d8
3
+ timeCreated: 1741707363
@@ -0,0 +1,6 @@
1
+ using UnityEngine;
2
+
3
+ namespace PuzzlescapeGames.Atributes
4
+ {
5
+ public sealed class TimeInfoAttribute : PropertyAttribute { }
6
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: ec854707de7443aaa21f3d6acd8c1235
3
+ timeCreated: 1741704150
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 3b1ffe2add8f4fefa0e049e2199130c9
3
+ timeCreated: 1741704136
@@ -7,14 +7,16 @@ namespace PuzzlescapeGames.Services.TickableService
7
7
  {
8
8
  public sealed class TickableService
9
9
  {
10
+ public event Action OnMinutesTick;
10
11
  public event Action OnSecondsTick;
11
12
 
12
13
  public TickableService()
13
14
  {
14
15
  SecondsTick( ThreadingUtils.QuitToken ).Forget();
16
+ MinutesTick( ThreadingUtils.QuitToken ).Forget();
15
17
  }
16
18
 
17
- private async UniTask SecondsTick( CancellationToken token )
19
+ private async UniTask SecondsTick( CancellationToken token = default )
18
20
  {
19
21
  bool isCanceled = false;
20
22
 
@@ -25,5 +27,17 @@ namespace PuzzlescapeGames.Services.TickableService
25
27
  isCanceled = await UniTask.WaitForSeconds( 1f, cancellationToken: token ).SuppressCancellationThrow();
26
28
  }
27
29
  }
30
+
31
+ private async UniTask MinutesTick( CancellationToken token = default )
32
+ {
33
+ bool isCanceled = false;
34
+
35
+ while ( !isCanceled )
36
+ {
37
+ OnMinutesTick?.Invoke();
38
+
39
+ isCanceled = await UniTask.WaitForSeconds( 60f, cancellationToken: token ).SuppressCancellationThrow();
40
+ }
41
+ }
28
42
  }
29
43
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name" : "com.puzzlescapegames.services",
3
3
  "displayName" : "Puzzlescape Games Services",
4
- "version" : "1.2.0",
4
+ "version" : "1.2.2",
5
5
  "author" : "Puzzlescape Games",
6
6
  "description" : "Common services.",
7
7
  "repository": {