Merge remote-tracking branch 'origin/main' into MultiSelectChip
This commit is contained in:
commit
32b208d1b6
13
AutoSceneChanger.cs
Normal file
13
AutoSceneChanger.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
|
namespace NEG.Utils
|
||||||
|
{
|
||||||
|
public class AutoSceneChanger : MonoBehaviour
|
||||||
|
{
|
||||||
|
#if !UNITY_EDITOR
|
||||||
|
private void Start() => SceneManager.LoadScene(1);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
11
AutoSceneChanger.cs.meta
Normal file
11
AutoSceneChanger.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: eac2f9a681087504998bbeb40cd8516a
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Collections.meta
Normal file
8
Collections.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9b25b74f42726e94585fe6ae4b9dd947
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
41
Collections/DictionaryExtensions.cs
Normal file
41
Collections/DictionaryExtensions.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace NEG.Utils.Collections
|
||||||
|
{
|
||||||
|
public static class DictionaryExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Adds given value to a dictionary if there was no element at given <paramref name="key"/>, replaces element with <paramref name="value"> otherwise.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>true if element was added, false if it was replaced</returns>
|
||||||
|
public static bool AddOrUpdate<K, V>(this Dictionary<K, V> dict, K key, V value)
|
||||||
|
{
|
||||||
|
if (dict.ContainsKey(key))
|
||||||
|
{
|
||||||
|
dict[key] = value;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dict.Add(key, value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value from the dictionary under a specified key or adds it if did not exist and returns <paramref name="defaultValue"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>value under a given <paramref name="key"/> if it exists, <paramref name="defaultValue"/> otherwise</returns>
|
||||||
|
public static V GetOrSetToDefault<K, V>(this Dictionary<K, V> dict, K key, V defaultValue)
|
||||||
|
{
|
||||||
|
if (dict.TryGetValue(key, out V value))
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
dict.Add(key, defaultValue);
|
||||||
|
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Collections/DictionaryExtensions.cs.meta
Normal file
11
Collections/DictionaryExtensions.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a2c99d7a9a2f8184f8b8e94c01723ec6
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
84
Editor/BuildingUtils.cs
Normal file
84
Editor/BuildingUtils.cs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
using Debug = UnityEngine.Debug;
|
||||||
|
|
||||||
|
public static class BuildingUtils
|
||||||
|
{
|
||||||
|
[MenuItem("Tools/Build/Steam/Release")]
|
||||||
|
public static void SteamRelease()
|
||||||
|
{
|
||||||
|
IncreaseBuildNumber();
|
||||||
|
BuildRelease();
|
||||||
|
UploadSteam();
|
||||||
|
}
|
||||||
|
|
||||||
|
[MenuItem("Tools/Build/Steam/Development")]
|
||||||
|
public static void SteamDevelopment()
|
||||||
|
{
|
||||||
|
IncreaseBuildNumber();
|
||||||
|
BuildDevelopment();
|
||||||
|
UploadSteam();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[MenuItem("Tools/Build/All Release")]
|
||||||
|
public static void BuildRelease()
|
||||||
|
{
|
||||||
|
BuildWindowsRelease();
|
||||||
|
}
|
||||||
|
|
||||||
|
[MenuItem("Tools/Build/All Development")]
|
||||||
|
public static void BuildDevelopment()
|
||||||
|
{
|
||||||
|
BuildWindowsDevelopment();
|
||||||
|
}
|
||||||
|
|
||||||
|
[MenuItem("Tools/Build/Platform/Windows/x64-Development")]
|
||||||
|
public static void BuildWindowsDevelopment() => BuildWindows(false);
|
||||||
|
|
||||||
|
[MenuItem("Tools/Build/Platform/Windows/x64-Release")]
|
||||||
|
public static void BuildWindowsRelease() => BuildWindows(true);
|
||||||
|
|
||||||
|
|
||||||
|
private static void BuildWindows(bool release)
|
||||||
|
{
|
||||||
|
var buildPlayerOptions = new BuildPlayerOptions { scenes = new string[EditorBuildSettings.scenes.Length] };
|
||||||
|
for (int i = 0; i < EditorBuildSettings.scenes.Length; i++)
|
||||||
|
{
|
||||||
|
buildPlayerOptions.scenes[i] = EditorBuildSettings.scenes[i].path;
|
||||||
|
}
|
||||||
|
|
||||||
|
buildPlayerOptions.target = BuildTarget.StandaloneWindows64;
|
||||||
|
buildPlayerOptions.options = release ? BuildOptions.None : BuildOptions.Development;
|
||||||
|
buildPlayerOptions.locationPathName = Application.dataPath +
|
||||||
|
$"/../../{Application.productName}-Steam/ContentBuilder/content/windows/{Application.productName}.exe";
|
||||||
|
BuildPipeline.BuildPlayer(buildPlayerOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void IncreaseBuildNumber()
|
||||||
|
{
|
||||||
|
string[] versionParts = PlayerSettings.bundleVersion.Split('.');
|
||||||
|
if (versionParts.Length != 3 || !int.TryParse(versionParts[2], out int version)) {
|
||||||
|
Debug.LogError("IncreaseBuildNumber failed to update version " + PlayerSettings.bundleVersion);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
versionParts[2] = (version + 1).ToString();
|
||||||
|
PlayerSettings.bundleVersion = string.Join(".", versionParts);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void UploadSteam()
|
||||||
|
{
|
||||||
|
string command = $"cd {Application.dataPath}/../../{Application.productName}-Steam/ContentBuilder && run_build.bat";
|
||||||
|
|
||||||
|
var processInfo = new ProcessStartInfo("cmd.exe", $"/c {command}")
|
||||||
|
{
|
||||||
|
CreateNoWindow = true,
|
||||||
|
UseShellExecute = false
|
||||||
|
};
|
||||||
|
var process = Process.Start(processInfo);
|
||||||
|
process.WaitForExit();
|
||||||
|
Debug.Log(process.ExitCode);
|
||||||
|
process.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Editor/BuildingUtils.cs.meta
Normal file
3
Editor/BuildingUtils.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1e90ce49e16b4cecb77bf258651f6209
|
||||||
|
timeCreated: 1669642124
|
||||||
8
Editor/ComponentsAdditionalItems.meta
Normal file
8
Editor/ComponentsAdditionalItems.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d683d64cc04efcf479b41c84b51cf7fe
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace NEG.Utils.Editor.ComponentsAdditionalItems
|
||||||
|
{
|
||||||
|
public static class RectTransformSetBasedOnImage
|
||||||
|
{
|
||||||
|
[MenuItem("CONTEXT/RectTransform/Set as inside of Image", false, 2000)]
|
||||||
|
public static void SetFillBasedOnImage(MenuCommand command)
|
||||||
|
{
|
||||||
|
var transform = (RectTransform)command.context;
|
||||||
|
if (!transform.TryGetComponent(out Image image))
|
||||||
|
return;
|
||||||
|
|
||||||
|
transform.anchorMin = Vector2.zero;
|
||||||
|
transform.anchorMax = Vector2.one;
|
||||||
|
transform.offsetMin = new Vector2(-image.sprite.border.x, -image.sprite.border.y);
|
||||||
|
transform.offsetMax = new Vector2(image.sprite.border.z, image.sprite.border.w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 614a58a9665e7cf4182834f1fb3c0096
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
41
Editor/GUIDToAssetPath.cs
Normal file
41
Editor/GUIDToAssetPath.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class GUIDToAssetPath : EditorWindow
|
||||||
|
{
|
||||||
|
string guid = "";
|
||||||
|
string path = "";
|
||||||
|
[MenuItem("Tools/GUIDToAssetPath")]
|
||||||
|
static void CreateWindow()
|
||||||
|
{
|
||||||
|
GUIDToAssetPath window = (GUIDToAssetPath)EditorWindow.GetWindowWithRect(typeof(GUIDToAssetPath), new Rect(0, 0, 400, 120));
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnGUI()
|
||||||
|
{
|
||||||
|
GUILayout.Label("Enter guid");
|
||||||
|
guid = GUILayout.TextField(guid);
|
||||||
|
GUILayout.BeginHorizontal();
|
||||||
|
GUILayout.FlexibleSpace();
|
||||||
|
if (GUILayout.Button("Get Asset Path",GUILayout.Width(120)))
|
||||||
|
path = GetAssetPath(guid);
|
||||||
|
GUILayout.FlexibleSpace();
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
|
GUILayout.BeginHorizontal();
|
||||||
|
GUILayout.FlexibleSpace();
|
||||||
|
if (GUILayout.Button("Abort", GUILayout.Width(120)))
|
||||||
|
Close();
|
||||||
|
GUILayout.FlexibleSpace();
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
|
GUILayout.Label(path);
|
||||||
|
}
|
||||||
|
static string GetAssetPath(string guid)
|
||||||
|
{
|
||||||
|
guid = guid.Replace("-", "");
|
||||||
|
|
||||||
|
string p = AssetDatabase.GUIDToAssetPath(guid);
|
||||||
|
Debug.Log(p);
|
||||||
|
if (p.Length == 0) p = "not found";
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Editor/GUIDToAssetPath.cs.meta
Normal file
3
Editor/GUIDToAssetPath.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ee5c0a00075140f28ac5e6ff46e9a6b3
|
||||||
|
timeCreated: 1669777021
|
||||||
108
Editor/ToolsWindowBase.cs
Normal file
108
Editor/ToolsWindowBase.cs
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEditor.SceneManagement;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
|
namespace NegUtils.Editor
|
||||||
|
{
|
||||||
|
[InitializeOnLoad]
|
||||||
|
public class ToolsWindowBase : EditorWindow
|
||||||
|
{
|
||||||
|
static ToolsWindowBase()
|
||||||
|
{
|
||||||
|
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MenuItem("Tools/Show Tools Window")]
|
||||||
|
private static void ShowWindow()
|
||||||
|
{
|
||||||
|
var window = GetWindow<ToolsWindowBase>();
|
||||||
|
window.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnGUI()
|
||||||
|
{
|
||||||
|
if (GUILayout.Button("Select Scene"))
|
||||||
|
ShowScenesList(GUILayoutUtility.GetLastRect());
|
||||||
|
|
||||||
|
bool startFromSceneIndex0 = EditorPrefs.GetBool("StartFromSceneIndex0");
|
||||||
|
bool newVal = GUILayout.Toggle(startFromSceneIndex0, "Start from scene with index 0 on start");
|
||||||
|
if (newVal != startFromSceneIndex0)
|
||||||
|
{
|
||||||
|
EditorPrefs.SetBool("StartFromSceneIndex0", newVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startFromSceneIndex0)
|
||||||
|
{
|
||||||
|
bool goToCurrentScene = EditorPrefs.GetBool("GoToCurrentSceneAfterPlay");
|
||||||
|
newVal = GUILayout.Toggle(goToCurrentScene, "Go to current scene after play");
|
||||||
|
if (newVal != goToCurrentScene)
|
||||||
|
{
|
||||||
|
EditorPrefs.SetBool("GoToCurrentSceneAfterPlay", newVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ShowScenesList(Rect position)
|
||||||
|
{
|
||||||
|
var menu = new GenericMenu();
|
||||||
|
|
||||||
|
string path = Application.dataPath + "/Scenes/Production";
|
||||||
|
string[] fileInfo = Directory.GetFiles(path, "*.unity");
|
||||||
|
|
||||||
|
foreach (string item in fileInfo)
|
||||||
|
{
|
||||||
|
string s = item;
|
||||||
|
menu.AddItem(new GUIContent(s.Remove(0, path.Length + 1).Remove(s.Length - path.Length - 7 ,6)), false, () => {
|
||||||
|
LoadScene(s);
|
||||||
|
});
|
||||||
|
menu.AddSeparator("");
|
||||||
|
}
|
||||||
|
menu.DropDown(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void LoadScene(string path)
|
||||||
|
{
|
||||||
|
EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
|
||||||
|
EditorSceneManager.OpenScene(path, OpenSceneMode.Single);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnPlayModeStateChanged(PlayModeStateChange state)
|
||||||
|
{
|
||||||
|
switch(state)
|
||||||
|
{
|
||||||
|
case PlayModeStateChange.ExitingEditMode:
|
||||||
|
{
|
||||||
|
if(!EditorPrefs.GetBool("StartFromSceneIndex0"))
|
||||||
|
return;
|
||||||
|
EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
|
||||||
|
EditorPrefs.SetString("LastOpenedScenePath", EditorSceneManager.GetSceneManagerSetup()[0].path);
|
||||||
|
EditorSceneManager.OpenScene(EditorBuildSettings.scenes[0].path);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PlayModeStateChange.EnteredPlayMode:
|
||||||
|
{
|
||||||
|
if(!EditorPrefs.GetBool("StartFromSceneIndex0"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (EditorPrefs.GetBool("GoToCurrentSceneAfterPlay"))
|
||||||
|
EditorSceneManager.LoadSceneInPlayMode(EditorPrefs.GetString("LastOpenedScenePath"),
|
||||||
|
new LoadSceneParameters(LoadSceneMode.Single));
|
||||||
|
else
|
||||||
|
SceneManager.LoadScene(1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PlayModeStateChange.EnteredEditMode:
|
||||||
|
{
|
||||||
|
if(!EditorPrefs.GetBool("StartFromSceneIndex0"))
|
||||||
|
return;
|
||||||
|
EditorSceneManager.OpenScene(EditorPrefs.GetString("LastOpenedScenePath"));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Editor/ToolsWindowBase.cs.meta
Normal file
3
Editor/ToolsWindowBase.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 76faf7fadf7c40d88dec1a8ee4da5cb6
|
||||||
|
timeCreated: 1671500708
|
||||||
16
NEG.Utils.asmdef
Normal file
16
NEG.Utils.asmdef
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "NEG.Utils",
|
||||||
|
"rootNamespace": "",
|
||||||
|
"references": [
|
||||||
|
"GUID:6055be8ebefd69e48b49212b09b47b2f"
|
||||||
|
],
|
||||||
|
"includePlatforms": [],
|
||||||
|
"excludePlatforms": [],
|
||||||
|
"allowUnsafeCode": false,
|
||||||
|
"overrideReferences": false,
|
||||||
|
"precompiledReferences": [],
|
||||||
|
"autoReferenced": true,
|
||||||
|
"defineConstraints": [],
|
||||||
|
"versionDefines": [],
|
||||||
|
"noEngineReferences": false
|
||||||
|
}
|
||||||
7
NEG.Utils.asmdef.meta
Normal file
7
NEG.Utils.asmdef.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3c4294719a93e3c4e831a9ff0c261e8a
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Timing.meta
Normal file
8
Timing.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d3f27225e5dd00546b927b1a8bd253ee
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
33
Timing/AutoTimeMachine.cs
Normal file
33
Timing/AutoTimeMachine.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace NEG.Utils.Timing
|
||||||
|
{
|
||||||
|
public class AutoTimeMachine
|
||||||
|
{
|
||||||
|
public double Interval { get; set; }
|
||||||
|
public Action Action { get; set; }
|
||||||
|
|
||||||
|
private readonly TimeMachine machine;
|
||||||
|
|
||||||
|
public AutoTimeMachine(Action action, double interval)
|
||||||
|
{
|
||||||
|
Action = action;
|
||||||
|
Interval = interval;
|
||||||
|
machine = new TimeMachine();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Forwards the time by given amount, triggers assigned action relevant amount of times
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="time">Amount of time to forward by</param>
|
||||||
|
public void Forward(double time)
|
||||||
|
{
|
||||||
|
machine.Accumulate(time);
|
||||||
|
int rolls = machine.RetrieveAll(Interval);
|
||||||
|
for (int i = 0; i < rolls; i++)
|
||||||
|
{
|
||||||
|
Action();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Timing/AutoTimeMachine.cs.meta
Normal file
11
Timing/AutoTimeMachine.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cf2d68c5a76882f4ead172644f643fd5
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
70
Timing/TimeMachine.cs
Normal file
70
Timing/TimeMachine.cs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace NEG.Utils.Timing
|
||||||
|
{
|
||||||
|
public class TimeMachine
|
||||||
|
{
|
||||||
|
private double time;
|
||||||
|
|
||||||
|
public TimeMachine()
|
||||||
|
{
|
||||||
|
time = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds time into the TimeMachine
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="time">Amount of time to be added</param>
|
||||||
|
public void Accumulate(double time)
|
||||||
|
{
|
||||||
|
this.time += time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves given amount of time from the TimeMachine
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="maxTime"></param>
|
||||||
|
/// <returns>Amount of time retrievend</returns>
|
||||||
|
public double Retrieve(double maxTime)
|
||||||
|
{
|
||||||
|
if(!Double.IsFinite(maxTime))
|
||||||
|
{
|
||||||
|
double timeRetrieved = time;
|
||||||
|
time = 0;
|
||||||
|
return timeRetrieved;
|
||||||
|
}
|
||||||
|
double timeLeft = time - maxTime;
|
||||||
|
time = Math.Max(timeLeft, 0);
|
||||||
|
return Math.Min(maxTime + timeLeft, maxTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attempts to retrieves given amount of time from the TimeMachine <br/>
|
||||||
|
/// If there is enough <paramref name="time"/> accumulated in this machine subtructs that amount and returns true, otherwise returns false
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="time"></param>
|
||||||
|
public bool TryRetrieve(double time)
|
||||||
|
{
|
||||||
|
if (this.time >= time)
|
||||||
|
{
|
||||||
|
this.time -= time;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Result is equivalent to calling <see cref="TryRetrieve(double)"/> as many times as possible, but is faster for larger <paramref name="limit"/> values
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="interval">Single unit of warp time, must be positive/param>
|
||||||
|
/// <param name="limit">Maximum amount of warps, must be positive</param>
|
||||||
|
/// <returns>Amount of warps</returns>
|
||||||
|
public int RetrieveAll(double interval, int limit = int.MaxValue)
|
||||||
|
{
|
||||||
|
int result = Mathf.FloorToInt(time / interval);
|
||||||
|
result = Math.Clamp(result, 0, limit);
|
||||||
|
time -= result * interval;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Timing/TimeMachine.cs.meta
Normal file
11
Timing/TimeMachine.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2f4db23cbb7389a41bf48808a3d5696f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
x
Reference in New Issue
Block a user