diff --git a/CoroutineUtils.cs b/CoroutineUtils.cs index f1e835b..a8f88ce 100644 --- a/CoroutineUtils.cs +++ b/CoroutineUtils.cs @@ -16,16 +16,35 @@ namespace NEG.Utils } } + public static void ActionAfterFrames(this MonoBehaviour mono, int count, Action action) + { + mono.StartCoroutine(ActionAfterFrames(count, action)); + } + + public static IEnumerator ActionAfterFrames(int count, Action action) + { + yield return WaitForFrames(count); + action?.Invoke(); + } + public static IEnumerator ActionAfterEndOfFrame(Action action) { yield return WaitForEndOfFrame; action?.Invoke(); } - + public static void ActionAtNextFrame(this MonoBehaviour mono, Action action) => mono.StartCoroutine(ActionAtNextFrame(action)); public static IEnumerator ActionAtNextFrame(Action action) { yield return null; action?.Invoke(); } + + public static void ActionAfterTime(this MonoBehaviour mono, float time, Action action) => mono.StartCoroutine(ActionAfterTime(time, action)); + + public static IEnumerator ActionAfterTime(float time, Action action) + { + yield return new WaitForSeconds(time); + action?.Invoke(); + } } } \ No newline at end of file diff --git a/Editor/BuildingUtils.cs b/Editor/BuildingUtils.cs new file mode 100644 index 0000000..7dca265 --- /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 = true, + 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 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 diff --git a/UiToolkit.meta b/UiToolkit.meta new file mode 100644 index 0000000..e6b2986 --- /dev/null +++ b/UiToolkit.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0c452ac88625d6c46a12fb35375d8019 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UiToolkit/MultiSelectChips.meta b/UiToolkit/MultiSelectChips.meta new file mode 100644 index 0000000..21b9cbc --- /dev/null +++ b/UiToolkit/MultiSelectChips.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b1091fdb6a84af3488e7772b53a5f875 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UiToolkit/MultiSelectChips/MultiSelectChips.cs b/UiToolkit/MultiSelectChips/MultiSelectChips.cs new file mode 100644 index 0000000..aee960e --- /dev/null +++ b/UiToolkit/MultiSelectChips/MultiSelectChips.cs @@ -0,0 +1,127 @@ +#if ADDRESSABLES && UI_ELEMENTS +using UnityEngine; +using UnityEngine.UIElements; +using UnityEngine.AddressableAssets; +using UnityEngine.ResourceManagement.AsyncOperations; +using System; +using System.Collections; +using System.ComponentModel; + +public class MultiSelectChips : VisualElement +{ + public string LabelText + { + get => label.text; + set + { + if (!string.IsNullOrEmpty(value)) + { + if (label == null) + { + InitLabel(); + } + + label.text = value; + } + else if (label != null) + { + label.RemoveFromHierarchy(); + label = null; + } + } + } + + public IList ItemsSource + { + get => itemsSource; + + set + { + itemsSource = value; + UpdateItems(); + } + } + + private Label label; + private AsyncOperationHandle uxmlHandle, itemUxmlHandle; + + private VisualTreeAsset itemPrefab; + + private IList itemsSource; + + public new class UxmlFactory : UxmlFactory + { + + } + + public new class UxmlTraits : VisualElement.UxmlTraits + { + private readonly UxmlStringAttributeDescription label; + + public UxmlTraits() + { + label = new() + { + name = "label" + }; + } + + public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) + { + base.Init(ve, bag, cc); + ((MultiSelectChips)ve).LabelText = label.GetValueFromBag(bag, cc); + } + } + + public MultiSelectChips() : base() + { + uxmlHandle = Addressables.LoadAssetAsync("NegUiToolkits/MultiSelectChips.uxml"); + itemUxmlHandle = Addressables.LoadAssetAsync("NegUiToolkits/MultiSelectChipsItem.uxml"); + uxmlHandle.Completed += OnUxmlLoaded; + itemUxmlHandle.Completed += OnItemUxmlLoaded; + } + + public void UpdateItems() + { + if (itemPrefab == null) + return; + } + + private void InitLabel() + { + label = new Label() + { + pickingMode = PickingMode.Ignore + }; + Add(label); + } + + private void OnUxmlLoaded(AsyncOperationHandle operation) + { + if (operation.Status == AsyncOperationStatus.Succeeded) + { + Add(operation.Result.Instantiate()); + Addressables.Release(uxmlHandle); + } + else + { + Debug.LogError($"Asset failed to load."); + } + } + + private void OnItemUxmlLoaded(AsyncOperationHandle operation) + { + + if (operation.Status == AsyncOperationStatus.Succeeded) + { + itemPrefab = operation.Result; + Addressables.Release(itemUxmlHandle); + UpdateItems(); + } + else + { + Debug.LogError($"Asset failed to load."); + } + } +} +#endif \ No newline at end of file diff --git a/UiToolkit/MultiSelectChips/MultiSelectChips.cs.meta b/UiToolkit/MultiSelectChips/MultiSelectChips.cs.meta new file mode 100644 index 0000000..b4a9aa7 --- /dev/null +++ b/UiToolkit/MultiSelectChips/MultiSelectChips.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4bbcd96ba00647146aac6667496c426d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UiToolkit/MultiSelectChips/MultiSelectChips.uxml b/UiToolkit/MultiSelectChips/MultiSelectChips.uxml new file mode 100644 index 0000000..1a24e53 --- /dev/null +++ b/UiToolkit/MultiSelectChips/MultiSelectChips.uxml @@ -0,0 +1,6 @@ + + + + + + diff --git a/UiToolkit/MultiSelectChips/MultiSelectChips.uxml.meta b/UiToolkit/MultiSelectChips/MultiSelectChips.uxml.meta new file mode 100644 index 0000000..41a759e --- /dev/null +++ b/UiToolkit/MultiSelectChips/MultiSelectChips.uxml.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 28ecbe3f92afaca4faeec3e9fb3af6a2 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}