Skip to content

Commit

Permalink
1.3.5增加 TimeManager.cs 相关逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
QinZhuo committed Apr 23, 2021
1 parent 2029c5b commit 3d8171b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Runtime/QTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public T this[TKey key]
base.Remove(obj);
dic.Remove(obj.Key);
}
public void RemoveKey(TKey key)
{
Remove(this[key]);
}
public new void Clear()
{
base.Clear();
Expand Down
55 changes: 55 additions & 0 deletions Runtime/TimeManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace QTool
{
public static class TimeManager
{
public static void Clear()
{
timeScaleList.Clear();
UpdateTimeScale();
}
public static event System.Action<float> OnScaleChange;

private static void UpdateTimeScale()
{
var value = 1f;
foreach (var kv in timeScaleList)
{
value *= kv.Value;
}
Time.timeScale = value;
OnScaleChange?.Invoke(value);
}
public static float RealDeltaTime
{
get
{
return Time.unscaledDeltaTime;
}
}
public static float DeltaTime
{
get
{
return Time.deltaTime;
}
}

static QDcitionary<object, float> timeScaleList = new QDcitionary<object, float>();
public static void ChangeScale(object obj, float timeScale)
{
if (timeScale >= 0)
{
timeScaleList[obj] = timeScale;
UpdateTimeScale();
}
}
public static void RevertScale(object obj)
{
timeScaleList.RemoveKey(obj);
UpdateTimeScale();
}
}
}
11 changes: 11 additions & 0 deletions Runtime/TimeManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.qtool.qtool",

"version": "1.5.2",
"version": "1.5.3",
"displayName": "QTool",
"description": "QTool",
"unity": "2019.1",
Expand Down

0 comments on commit 3d8171b

Please sign in to comment.