-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
153 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using UnityEngine; | ||
|
||
namespace Joyixir.Utils | ||
{ | ||
public class TimeScaler : MonoBehaviour | ||
{ | ||
private static float _defaultFixedDeltaTime; | ||
private static bool _timeScalerInitialized; | ||
private static bool _timeAlreadyScaled; | ||
|
||
private void Awake() | ||
{ | ||
if (_timeScalerInitialized) return; | ||
_defaultFixedDeltaTime = Time.fixedDeltaTime; | ||
_timeScalerInitialized = true; | ||
} | ||
|
||
public static void ScaleUnityTime(float slowdownFactor) | ||
{ | ||
if(!_timeScalerInitialized) | ||
Debug.LogError("Attach timescaler to a unity game object, you may see unexpected behavior if you don't."); | ||
if (_timeAlreadyScaled) | ||
{ | ||
Debug.LogWarning("Time is already scaled, pretending to scale unity default time scale."); | ||
SetUnityTimeScalesToNormal(); | ||
} | ||
|
||
Time.timeScale = slowdownFactor; | ||
Time.fixedDeltaTime = Time.timeScale * _defaultFixedDeltaTime; | ||
_timeAlreadyScaled = true; | ||
} | ||
|
||
public static void SetUnityTimeScalesToNormal() | ||
{ | ||
if(!_timeScalerInitialized) | ||
Debug.LogError("Attach timescaler to a unity game object, you may see unexpected behavior if you don't."); | ||
if (!_timeAlreadyScaled) return; | ||
Time.timeScale = 1; | ||
Time.fixedDeltaTime = _defaultFixedDeltaTime; | ||
_timeAlreadyScaled = false; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
{ | ||
"name": "com.joyixir.utility.Tests" | ||
} | ||
"name": "com.joyixir.utility.Tests", | ||
"rootNamespace": "", | ||
"references": [ | ||
"GUID:40a991db332574dbfb8099ed06e34f25", | ||
"GUID:7c04f0dfa9243c04681a55d90d3ff3fc", | ||
"GUID:e9745f6a32442194c8dc5a43e9ab86f9" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "com.joyixir.utility", | ||
"version": "1.0.0", | ||
"version": "1.0.2", | ||
"displayName": "Utility", | ||
"description": "Utility package containing Animator, Vector, List etc. extensions to help developers.", | ||
"documentationUrl": "https://github.com/joyixir/utility", | ||
|
@@ -17,5 +17,9 @@ | |
"email": "[email protected]", | ||
"url": "https://www.joyixir.com" | ||
}, | ||
"type": "tool" | ||
} | ||
"type": "tool", | ||
"repository": { | ||
"type" : "git", | ||
"url" : "https://github.com/joyixir/utility.git" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters