fr.jeanf.universal.player 0.8.38 → 0.8.40

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,88 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using jeanf.EventSystem;
4
+ using UnityEngine;
5
+
6
+ public class FunctionTimer {
7
+ private static List<FunctionTimer> activeTimerList;
8
+ private static GameObject initGameObject;
9
+
10
+ private static void InitIfNeeded() {
11
+ if (initGameObject == null) {
12
+ initGameObject = new GameObject("FunctionTimer_InitGameObject");
13
+ activeTimerList = new List<FunctionTimer>();
14
+ }
15
+ }
16
+
17
+ public static FunctionTimer Create(Action action, float timer, string timerName = null) {
18
+ InitIfNeeded();
19
+ GameObject gameObject = new GameObject("FunctionTimer", typeof(MonoBehaviourHook));
20
+
21
+ FunctionTimer functionTimer = new FunctionTimer(action, timer, timerName, gameObject);
22
+
23
+ gameObject.GetComponent<MonoBehaviourHook>().onUpdate = functionTimer.Update;
24
+
25
+ activeTimerList.Add(functionTimer);
26
+
27
+ return functionTimer;
28
+ }
29
+ private static void RemoveTimer(FunctionTimer functionTimer) {
30
+ InitIfNeeded();
31
+ activeTimerList.Remove(functionTimer);
32
+ }
33
+
34
+ public static void StopTimer(string timerName) {
35
+ if (activeTimerList == null || timerName == null) return;
36
+
37
+ for (var i = 0; i < activeTimerList.Count; i++)
38
+ {
39
+ if (activeTimerList[i].timerName != timerName) continue;
40
+ // Stop this timer
41
+ activeTimerList[i].DestroySelf();
42
+ i--;
43
+ }
44
+ }
45
+
46
+
47
+
48
+ // Dummy class to have access to MonoBehaviour functions
49
+ private class MonoBehaviourHook : MonoBehaviour {
50
+ public Action onUpdate;
51
+ private void Update()
52
+ {
53
+ onUpdate?.Invoke();
54
+ }
55
+ }
56
+
57
+ private Action action;
58
+ private float timer;
59
+ private string timerName;
60
+ private GameObject gameObject;
61
+ private bool isDestroyed;
62
+ private FloatEventChannelSO validationChannel;
63
+ private float remainingTime;
64
+
65
+ private FunctionTimer(Action action, float timer, string timerName, GameObject gameObject) {
66
+ this.action = action;
67
+ this.timer = timer;
68
+ this.timerName = timerName;
69
+ this.gameObject = gameObject;
70
+ isDestroyed = false;
71
+ }
72
+
73
+ public void Update()
74
+ {
75
+ if (isDestroyed) return;
76
+ timer -= Time.deltaTime;
77
+ if (!(timer < 0)) return;
78
+ // Trigger the action
79
+ action();
80
+ DestroySelf();
81
+ }
82
+
83
+ private void DestroySelf() {
84
+ isDestroyed = true;
85
+ UnityEngine.Object.Destroy(gameObject);
86
+ RemoveTimer(this);
87
+ }
88
+ }
@@ -0,0 +1,2 @@
1
+ fileFormatVersion: 2
2
+ guid: 03ddfe9683082bd42bafeedae387e534
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: c48b0a62ed268744fa87c0b616e24236
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -44,7 +44,6 @@ namespace jeanf.universalplayer
44
44
 
45
45
  private void SetCurrentControlSchemeOnSwitch()
46
46
  {
47
- Debug.Log("PLAYER - Changing Control Scheme to"+ playerInput.currentControlScheme);
48
47
  switch (playerInput.currentControlScheme)
49
48
  {
50
49
  case "Keyboard&Mouse":
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fr.jeanf.universal.player",
3
3
 
4
- "version": "0.8.38",
4
+ "version": "0.8.40",
5
5
 
6
6
  "displayName": "Universal Player",
7
7
  "description": "This package contains a universal player working in URP & HDRP for Mouse+Keyboard or VR",