From 425c0a7251cab72209b73cdff25087439903e5da Mon Sep 17 00:00:00 2001 From: Hubert Mattusch Date: Mon, 28 Nov 2022 15:48:58 +0100 Subject: [PATCH 01/12] Add building utils --- Editor/BuildingUtils.cs | 84 ++++++++++++++++++++++++++++++++++++ Editor/BuildingUtils.cs.meta | 3 ++ 2 files changed, 87 insertions(+) create mode 100644 Editor/BuildingUtils.cs create mode 100644 Editor/BuildingUtils.cs.meta diff --git a/Editor/BuildingUtils.cs b/Editor/BuildingUtils.cs new file mode 100644 index 0000000..bf225f5 --- /dev/null +++ b/Editor/BuildingUtils.cs @@ -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 = false, + UseShellExecute = false + }; + var process = Process.Start(processInfo); + process.WaitForExit(); + Debug.Log(process.ExitCode); + process.Close(); + } +} \ No newline at end of file diff --git a/Editor/BuildingUtils.cs.meta b/Editor/BuildingUtils.cs.meta new file mode 100644 index 0000000..5458af4 --- /dev/null +++ b/Editor/BuildingUtils.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1e90ce49e16b4cecb77bf258651f6209 +timeCreated: 1669642124 \ No newline at end of file From 1e3aa619ebad739f843c806ef2ad86c80d94559a Mon Sep 17 00:00:00 2001 From: Hubert Mattusch Date: Mon, 28 Nov 2022 18:37:59 +0100 Subject: [PATCH 02/12] Hide cmd window --- Editor/BuildingUtils.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Editor/BuildingUtils.cs b/Editor/BuildingUtils.cs index bf225f5..7dca265 100644 --- a/Editor/BuildingUtils.cs +++ b/Editor/BuildingUtils.cs @@ -73,7 +73,7 @@ public static class BuildingUtils var processInfo = new ProcessStartInfo("cmd.exe", $"/c {command}") { - CreateNoWindow = false, + CreateNoWindow = true, UseShellExecute = false }; var process = Process.Start(processInfo); From 00057a04b812344369745c35ba401f285cd1e5aa Mon Sep 17 00:00:00 2001 From: Hubert Mattusch Date: Wed, 30 Nov 2022 04:22:46 +0100 Subject: [PATCH 03/12] Add guit to asset path --- Editor/GUIDToAssetPath.cs | 41 ++++++++++++++++++++++++++++++++++ Editor/GUIDToAssetPath.cs.meta | 3 +++ 2 files changed, 44 insertions(+) create mode 100644 Editor/GUIDToAssetPath.cs create mode 100644 Editor/GUIDToAssetPath.cs.meta diff --git a/Editor/GUIDToAssetPath.cs b/Editor/GUIDToAssetPath.cs new file mode 100644 index 0000000..f4e5aae --- /dev/null +++ b/Editor/GUIDToAssetPath.cs @@ -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; + } +} \ No newline at end of file diff --git a/Editor/GUIDToAssetPath.cs.meta b/Editor/GUIDToAssetPath.cs.meta new file mode 100644 index 0000000..693beae --- /dev/null +++ b/Editor/GUIDToAssetPath.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ee5c0a00075140f28ac5e6ff46e9a6b3 +timeCreated: 1669777021 \ No newline at end of file From 38bee6d169cefd2e9eae308c037a3c8c5bac6caa Mon Sep 17 00:00:00 2001 From: Hubert Mattusch Date: Fri, 16 Dec 2022 02:28:51 +0100 Subject: [PATCH 04/12] Cleanup + add asmdef --- .../EditorMultipleInstances.meta | 0 .../EditorMultipleInstances}/Editor.meta | 0 .../Editor/EditorInstanceCreator.cs | 0 .../Editor/EditorInstanceCreator.cs.meta | 0 .../EditorMultipleInstances}/LICENSE | 0 .../EditorMultipleInstances}/LICENSE.meta | 0 .../Editor => Editor}/RequireInterfaceDrawer.cs | 0 .../RequireInterfaceDrawer.cs.meta | 0 NEG.Utils.asmdef | 16 ++++++++++++++++ NEG.Utils.asmdef.meta | 7 +++++++ ...eAttribute.cs => RequireInterfaceAttribute.cs | 0 ....cs.meta => RequireInterfaceAttribute.cs.meta | 0 12 files changed, 23 insertions(+) rename EditorMultipleInstances.meta => Editor/EditorMultipleInstances.meta (100%) rename {EditorMultipleInstances => Editor/EditorMultipleInstances}/Editor.meta (100%) rename {EditorMultipleInstances => Editor/EditorMultipleInstances}/Editor/EditorInstanceCreator.cs (100%) rename {EditorMultipleInstances => Editor/EditorMultipleInstances}/Editor/EditorInstanceCreator.cs.meta (100%) rename {EditorMultipleInstances => Editor/EditorMultipleInstances}/LICENSE (100%) rename {EditorMultipleInstances => Editor/EditorMultipleInstances}/LICENSE.meta (100%) rename {RequireInterface/Editor => Editor}/RequireInterfaceDrawer.cs (100%) rename {RequireInterface/Editor => Editor}/RequireInterfaceDrawer.cs.meta (100%) create mode 100644 NEG.Utils.asmdef create mode 100644 NEG.Utils.asmdef.meta rename RequireInterface/RequireInterfaceAttribute.cs => RequireInterfaceAttribute.cs (100%) rename RequireInterface/RequireInterfaceAttribute.cs.meta => RequireInterfaceAttribute.cs.meta (100%) diff --git a/EditorMultipleInstances.meta b/Editor/EditorMultipleInstances.meta similarity index 100% rename from EditorMultipleInstances.meta rename to Editor/EditorMultipleInstances.meta diff --git a/EditorMultipleInstances/Editor.meta b/Editor/EditorMultipleInstances/Editor.meta similarity index 100% rename from EditorMultipleInstances/Editor.meta rename to Editor/EditorMultipleInstances/Editor.meta diff --git a/EditorMultipleInstances/Editor/EditorInstanceCreator.cs b/Editor/EditorMultipleInstances/Editor/EditorInstanceCreator.cs similarity index 100% rename from EditorMultipleInstances/Editor/EditorInstanceCreator.cs rename to Editor/EditorMultipleInstances/Editor/EditorInstanceCreator.cs diff --git a/EditorMultipleInstances/Editor/EditorInstanceCreator.cs.meta b/Editor/EditorMultipleInstances/Editor/EditorInstanceCreator.cs.meta similarity index 100% rename from EditorMultipleInstances/Editor/EditorInstanceCreator.cs.meta rename to Editor/EditorMultipleInstances/Editor/EditorInstanceCreator.cs.meta diff --git a/EditorMultipleInstances/LICENSE b/Editor/EditorMultipleInstances/LICENSE similarity index 100% rename from EditorMultipleInstances/LICENSE rename to Editor/EditorMultipleInstances/LICENSE diff --git a/EditorMultipleInstances/LICENSE.meta b/Editor/EditorMultipleInstances/LICENSE.meta similarity index 100% rename from EditorMultipleInstances/LICENSE.meta rename to Editor/EditorMultipleInstances/LICENSE.meta diff --git a/RequireInterface/Editor/RequireInterfaceDrawer.cs b/Editor/RequireInterfaceDrawer.cs similarity index 100% rename from RequireInterface/Editor/RequireInterfaceDrawer.cs rename to Editor/RequireInterfaceDrawer.cs diff --git a/RequireInterface/Editor/RequireInterfaceDrawer.cs.meta b/Editor/RequireInterfaceDrawer.cs.meta similarity index 100% rename from RequireInterface/Editor/RequireInterfaceDrawer.cs.meta rename to Editor/RequireInterfaceDrawer.cs.meta diff --git a/NEG.Utils.asmdef b/NEG.Utils.asmdef new file mode 100644 index 0000000..1f68761 --- /dev/null +++ b/NEG.Utils.asmdef @@ -0,0 +1,16 @@ +{ + "name": "NEG.Utils", + "rootNamespace": "", + "references": [ + "GUID:6055be8ebefd69e48b49212b09b47b2f" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/NEG.Utils.asmdef.meta b/NEG.Utils.asmdef.meta new file mode 100644 index 0000000..cfd68b0 --- /dev/null +++ b/NEG.Utils.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3c4294719a93e3c4e831a9ff0c261e8a +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/RequireInterface/RequireInterfaceAttribute.cs b/RequireInterfaceAttribute.cs similarity index 100% rename from RequireInterface/RequireInterfaceAttribute.cs rename to RequireInterfaceAttribute.cs diff --git a/RequireInterface/RequireInterfaceAttribute.cs.meta b/RequireInterfaceAttribute.cs.meta similarity index 100% rename from RequireInterface/RequireInterfaceAttribute.cs.meta rename to RequireInterfaceAttribute.cs.meta From 11cbaac33df93e256863bccc35fb720345c7a032 Mon Sep 17 00:00:00 2001 From: LubieKakao1212 Date: Fri, 16 Dec 2022 21:29:30 +0100 Subject: [PATCH 05/12] dictionary extensions --- Collections.meta | 8 +++++ Collections/DictionaryExtensions.cs | 41 ++++++++++++++++++++++++ Collections/DictionaryExtensions.cs.meta | 11 +++++++ 3 files changed, 60 insertions(+) create mode 100644 Collections.meta create mode 100644 Collections/DictionaryExtensions.cs create mode 100644 Collections/DictionaryExtensions.cs.meta diff --git a/Collections.meta b/Collections.meta new file mode 100644 index 0000000..d087cf9 --- /dev/null +++ b/Collections.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9b25b74f42726e94585fe6ae4b9dd947 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Collections/DictionaryExtensions.cs b/Collections/DictionaryExtensions.cs new file mode 100644 index 0000000..f848b45 --- /dev/null +++ b/Collections/DictionaryExtensions.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; + +namespace NEG.Utils.Collections +{ + public static class DictionaryExtensions + { + /// + /// Adds an element to a dictionary if there was none assigned to specified , otherwise replaces the existing + /// + /// true if element was added, false if it was replaced + public static bool AddOrUpdate(this Dictionary dict, K key, V value) + { + if (dict.ContainsKey(key)) + { + dict[key] = value; + return false; + } + else + { + dict.Add(key, value); + return true; + } + } + + + /// + /// Gets a value from the dictionary under a specified key or sets it if there was no assoiation then return the associated value + /// + /// + public static V GetOrSetToDefault(this Dictionary dict, K key, V defaultValue) + { + if (dict.TryGetValue(key, out V value)) + { + return value; + } + dict.Add(key, defaultValue); + + return defaultValue; + } + } +} diff --git a/Collections/DictionaryExtensions.cs.meta b/Collections/DictionaryExtensions.cs.meta new file mode 100644 index 0000000..d6cb872 --- /dev/null +++ b/Collections/DictionaryExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a2c99d7a9a2f8184f8b8e94c01723ec6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From c60b15dc517ed685476059ecb5ef1a73fbb4bce5 Mon Sep 17 00:00:00 2001 From: LubieKakao1212 Date: Fri, 16 Dec 2022 21:30:23 +0100 Subject: [PATCH 06/12] time machines --- Timing.meta | 8 +++++ Timing/AutoTimeMachine.cs | 33 ++++++++++++++++++ Timing/AutoTimeMachine.cs.meta | 11 ++++++ Timing/TimeMachine.cs | 64 ++++++++++++++++++++++++++++++++++ Timing/TimeMachine.cs.meta | 11 ++++++ 5 files changed, 127 insertions(+) create mode 100644 Timing.meta create mode 100644 Timing/AutoTimeMachine.cs create mode 100644 Timing/AutoTimeMachine.cs.meta create mode 100644 Timing/TimeMachine.cs create mode 100644 Timing/TimeMachine.cs.meta diff --git a/Timing.meta b/Timing.meta new file mode 100644 index 0000000..aa993a9 --- /dev/null +++ b/Timing.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d3f27225e5dd00546b927b1a8bd253ee +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Timing/AutoTimeMachine.cs b/Timing/AutoTimeMachine.cs new file mode 100644 index 0000000..6380ecc --- /dev/null +++ b/Timing/AutoTimeMachine.cs @@ -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(); + } + + /// + /// Forwards the time by given amount, triggers assigned action relevant amount of times + /// + /// Amount of time to forward by + public void Forward(double time) + { + machine.Forward(time); + int rolls = machine.MultiWarp(Interval); + for (int i = 0; i < rolls; i++) + { + Action(); + } + } + } +} diff --git a/Timing/AutoTimeMachine.cs.meta b/Timing/AutoTimeMachine.cs.meta new file mode 100644 index 0000000..3c13533 --- /dev/null +++ b/Timing/AutoTimeMachine.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cf2d68c5a76882f4ead172644f643fd5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Timing/TimeMachine.cs b/Timing/TimeMachine.cs new file mode 100644 index 0000000..e253bdc --- /dev/null +++ b/Timing/TimeMachine.cs @@ -0,0 +1,64 @@ +using System; + +namespace NEG.Utils.Timing +{ + public class TimeMachine + { + private double time; + + public TimeMachine() + { + time = 0; + } + + /// + /// Adds time int this TimeMachine + /// + /// Amount of time to be added + public void Forward(double time) + { + this.time += time; + } + + /// + /// Decreeses the amount of time in this TimeMashine by up to given amount + /// + /// + /// Amount of time decressed + public double Warp(double maxTime) + { + double timeLeft = time - maxTime; + time = Math.Max(timeLeft, 0); + return Math.Min(maxTime + timeLeft, maxTime); + } + + /// + /// Attempts to decrese the amount of time in this TimeMachine
+ /// If there is at least time accumulated in this machine subtructs that amount and returns true, otherwise returns false + ///
+ /// + public bool TryWarp(double time) + { + if (this.time >= time) + { + this.time -= time; + return true; + } + return false; + } + + /// + /// Result is equivalent to calling as many times as possible, but is faster fo larger values + /// + /// Single unit of warp time, must be non negative/param> + /// Maximum amount of warps, must be non negative + /// Amount of warps + public int MultiWarp(double interval, int limit = int.MaxValue) + { + int result = (int)Math.Floor(time / interval); + result = Math.Clamp(result, 0, limit); + time -= result * interval; + return result; + } + } +} diff --git a/Timing/TimeMachine.cs.meta b/Timing/TimeMachine.cs.meta new file mode 100644 index 0000000..5b85c31 --- /dev/null +++ b/Timing/TimeMachine.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2f4db23cbb7389a41bf48808a3d5696f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 90caf11c6c23d7d4f1ff18ba04e76668b31a117e Mon Sep 17 00:00:00 2001 From: LubieKakao1212 Date: Mon, 19 Dec 2022 13:54:07 +0000 Subject: [PATCH 07/12] Applied suggestions --- Collections/DictionaryExtensions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Collections/DictionaryExtensions.cs b/Collections/DictionaryExtensions.cs index f848b45..aae8985 100644 --- a/Collections/DictionaryExtensions.cs +++ b/Collections/DictionaryExtensions.cs @@ -5,7 +5,7 @@ namespace NEG.Utils.Collections public static class DictionaryExtensions { /// - /// Adds an element to a dictionary if there was none assigned to specified , otherwise replaces the existing + /// Adds given value to a dictionary if there was no element at given , replaces element with otherwise. /// /// true if element was added, false if it was replaced public static bool AddOrUpdate(this Dictionary dict, K key, V value) @@ -24,9 +24,9 @@ namespace NEG.Utils.Collections /// - /// Gets a value from the dictionary under a specified key or sets it if there was no assoiation then return the associated value + /// Gets a value from the dictionary under a specified key or adds it if did not exist and returns . /// - /// + /// value under a given if it exists, otherwise public static V GetOrSetToDefault(this Dictionary dict, K key, V defaultValue) { if (dict.TryGetValue(key, out V value)) From 927d835d2e367007ab3590af547892758ac6a193 Mon Sep 17 00:00:00 2001 From: LubieKakao1212 Date: Mon, 19 Dec 2022 15:23:50 +0100 Subject: [PATCH 08/12] Improved naming and documentation --- Timing/TimeMachine.cs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Timing/TimeMachine.cs b/Timing/TimeMachine.cs index e253bdc..9cef9b7 100644 --- a/Timing/TimeMachine.cs +++ b/Timing/TimeMachine.cs @@ -12,32 +12,38 @@ namespace NEG.Utils.Timing } /// - /// Adds time int this TimeMachine + /// Adds time into the TimeMachine /// /// Amount of time to be added - public void Forward(double time) + public void Accumulate(double time) { this.time += time; } /// - /// Decreeses the amount of time in this TimeMashine by up to given amount + /// Retrieves given amount of time from the TimeMachine /// /// - /// Amount of time decressed - public double Warp(double maxTime) + /// Amount of time retrievend + 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); } /// - /// Attempts to decrese the amount of time in this TimeMachine
- /// If there is at least time accumulated in this machine subtructs that amount and returns true, otherwise returns false + /// Attempts to retrieves given amount of time from the TimeMachine
+ /// If there is enough accumulated in this machine subtructs that amount and returns true, otherwise returns false ///
/// - public bool TryWarp(double time) + public bool TryRetrieve(double time) { if (this.time >= time) { @@ -48,12 +54,12 @@ namespace NEG.Utils.Timing } /// - /// Result is equivalent to calling as many times as possible, but is faster fo larger values + /// Result is equivalent to calling as many times as possible, but is faster for larger values /// - /// Single unit of warp time, must be non negative/param> - /// Maximum amount of warps, must be non negative + /// Single unit of warp time, must be positive/param> + /// Maximum amount of warps, must be positive /// Amount of warps - public int MultiWarp(double interval, int limit = int.MaxValue) + public int RetrieveAll(double interval, int limit = int.MaxValue) { int result = (int)Math.Floor(time / interval); result = Math.Clamp(result, 0, limit); From df046e33039602181384f7f31be7d5c54b5a3806 Mon Sep 17 00:00:00 2001 From: LubieKakao1212 Date: Mon, 19 Dec 2022 19:35:14 +0100 Subject: [PATCH 09/12] Fixed AutoTimeMachine --- Timing/AutoTimeMachine.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Timing/AutoTimeMachine.cs b/Timing/AutoTimeMachine.cs index 6380ecc..6bcf59f 100644 --- a/Timing/AutoTimeMachine.cs +++ b/Timing/AutoTimeMachine.cs @@ -22,8 +22,8 @@ namespace NEG.Utils.Timing /// Amount of time to forward by public void Forward(double time) { - machine.Forward(time); - int rolls = machine.MultiWarp(Interval); + machine.Accumulate(time); + int rolls = machine.RetrieveAll(Interval); for (int i = 0; i < rolls; i++) { Action(); From 5f65b80b8dc7d203ec428ca88199ca240f06274f Mon Sep 17 00:00:00 2001 From: Hubert Mattusch Date: Tue, 20 Dec 2022 03:13:04 +0100 Subject: [PATCH 10/12] Add tools --- AutoSceneChanger.cs | 13 +++ AutoSceneChanger.cs.meta | 11 ++ Editor/ComponentsAdditionalItems.meta | 8 ++ .../RectTransformSetBasedOnImage.cs | 22 ++++ .../RectTransformSetBasedOnImage.cs.meta | 11 ++ Editor/ToolsWindowBase.cs | 107 ++++++++++++++++++ Editor/ToolsWindowBase.cs.meta | 3 + 7 files changed, 175 insertions(+) create mode 100644 AutoSceneChanger.cs create mode 100644 AutoSceneChanger.cs.meta create mode 100644 Editor/ComponentsAdditionalItems.meta create mode 100644 Editor/ComponentsAdditionalItems/RectTransformSetBasedOnImage.cs create mode 100644 Editor/ComponentsAdditionalItems/RectTransformSetBasedOnImage.cs.meta create mode 100644 Editor/ToolsWindowBase.cs create mode 100644 Editor/ToolsWindowBase.cs.meta diff --git a/AutoSceneChanger.cs b/AutoSceneChanger.cs new file mode 100644 index 0000000..c7b60ea --- /dev/null +++ b/AutoSceneChanger.cs @@ -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 + } +} + diff --git a/AutoSceneChanger.cs.meta b/AutoSceneChanger.cs.meta new file mode 100644 index 0000000..c7db448 --- /dev/null +++ b/AutoSceneChanger.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eac2f9a681087504998bbeb40cd8516a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ComponentsAdditionalItems.meta b/Editor/ComponentsAdditionalItems.meta new file mode 100644 index 0000000..3129799 --- /dev/null +++ b/Editor/ComponentsAdditionalItems.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d683d64cc04efcf479b41c84b51cf7fe +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ComponentsAdditionalItems/RectTransformSetBasedOnImage.cs b/Editor/ComponentsAdditionalItems/RectTransformSetBasedOnImage.cs new file mode 100644 index 0000000..f1f1691 --- /dev/null +++ b/Editor/ComponentsAdditionalItems/RectTransformSetBasedOnImage.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/Editor/ComponentsAdditionalItems/RectTransformSetBasedOnImage.cs.meta b/Editor/ComponentsAdditionalItems/RectTransformSetBasedOnImage.cs.meta new file mode 100644 index 0000000..b1a832b --- /dev/null +++ b/Editor/ComponentsAdditionalItems/RectTransformSetBasedOnImage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 614a58a9665e7cf4182834f1fb3c0096 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ToolsWindowBase.cs b/Editor/ToolsWindowBase.cs new file mode 100644 index 0000000..64c8bdf --- /dev/null +++ b/Editor/ToolsWindowBase.cs @@ -0,0 +1,107 @@ +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(); + 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; + 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; + } + + } + } +} \ No newline at end of file diff --git a/Editor/ToolsWindowBase.cs.meta b/Editor/ToolsWindowBase.cs.meta new file mode 100644 index 0000000..407b91d --- /dev/null +++ b/Editor/ToolsWindowBase.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 76faf7fadf7c40d88dec1a8ee4da5cb6 +timeCreated: 1671500708 \ No newline at end of file From 9791cf70f71e497402efd8d5884ac88f8f96586a Mon Sep 17 00:00:00 2001 From: Hubert Mattusch Date: Tue, 20 Dec 2022 23:38:18 +0100 Subject: [PATCH 11/12] Add save when exiting scene --- Editor/ToolsWindowBase.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Editor/ToolsWindowBase.cs b/Editor/ToolsWindowBase.cs index 64c8bdf..d200732 100644 --- a/Editor/ToolsWindowBase.cs +++ b/Editor/ToolsWindowBase.cs @@ -77,6 +77,7 @@ namespace NegUtils.Editor { if(!EditorPrefs.GetBool("StartFromSceneIndex0")) return; + EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo(); EditorPrefs.SetString("LastOpenedScenePath", EditorSceneManager.GetSceneManagerSetup()[0].path); EditorSceneManager.OpenScene(EditorBuildSettings.scenes[0].path); } From 57bc81065e5ce6f43b47fef1655ca24e3ab65058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Osi=C5=84ski?= Date: Tue, 3 Jan 2023 12:09:37 +0000 Subject: [PATCH 12/12] Apply 1 suggestion(s) to 1 file(s) --- Timing/TimeMachine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Timing/TimeMachine.cs b/Timing/TimeMachine.cs index 9cef9b7..02cc9bf 100644 --- a/Timing/TimeMachine.cs +++ b/Timing/TimeMachine.cs @@ -61,7 +61,7 @@ namespace NEG.Utils.Timing /// Amount of warps public int RetrieveAll(double interval, int limit = int.MaxValue) { - int result = (int)Math.Floor(time / interval); + int result = Mathf.FloorToInt(time / interval); result = Math.Clamp(result, 0, limit); time -= result * interval; return result;