├── .gitattributes ├── Unity ├── .gitattributes ├── Assets │ ├── Plugins │ │ ├── TextMesh Pro │ │ │ ├── Resources │ │ │ │ ├── LineBreaking Leading Characters.txt │ │ │ │ ├── LineBreaking Following Characters.txt │ │ │ │ ├── TMP Settings.asset │ │ │ │ ├── Fonts & Materials │ │ │ │ │ ├── LiberationSans SDF - Outline.mat │ │ │ │ │ └── LiberationSans SDF - Drop Shadow.mat │ │ │ │ └── Style Sheets │ │ │ │ │ └── Default Style Sheet.asset │ │ │ ├── Sprites │ │ │ │ ├── EmojiOne.png │ │ │ │ ├── EmojiOne Attribution.txt │ │ │ │ └── EmojiOne.json │ │ │ ├── Fonts │ │ │ │ ├── LiberationSans.ttf │ │ │ │ └── LiberationSans - OFL.txt │ │ │ ├── Documentation │ │ │ │ └── TextMesh Pro User Guide 2016.pdf │ │ │ └── Shaders │ │ │ │ ├── TMPro.cginc │ │ │ │ ├── TMPro_Properties.cginc │ │ │ │ ├── TMP_Sprite.shader │ │ │ │ ├── TMP_SDF-Mobile SSD.shader │ │ │ │ ├── TMPro_Surface.cginc │ │ │ │ ├── TMP_Bitmap.shader │ │ │ │ ├── TMP_SDF-Surface-Mobile.shader │ │ │ │ ├── TMP_Bitmap-Custom-Atlas.shader │ │ │ │ ├── TMP_Bitmap-Mobile.shader │ │ │ │ ├── TMP_SDF-Surface.shader │ │ │ │ └── TMPro_Mobile.cginc │ │ ├── System.Runtime.CompilerServices.Unsafe.dll │ │ ├── ZString │ │ │ ├── IResettableBufferWriter.cs │ │ │ ├── Number │ │ │ │ ├── NumberFormatInfoEx.cs │ │ │ │ ├── BufferEx.cs │ │ │ │ ├── FloatEx.cs │ │ │ │ ├── DecimalEx.cs │ │ │ │ ├── FormattingHelpers.cs │ │ │ │ ├── Number.NumberBuffer.cs │ │ │ │ ├── HexConverter.cs │ │ │ │ └── GuidEx.cs │ │ │ ├── Unity │ │ │ │ └── TextMeshProExtensions.SetStringBuilder.cs │ │ │ ├── package.json │ │ │ ├── NestedStringBuilderCreationException.cs │ │ │ ├── ZString.asmdef │ │ │ ├── ExceptionUtil.cs │ │ │ ├── ReadOnlyListAdaptor.cs │ │ │ ├── EnumUtil.cs │ │ │ ├── PreparedFormatHelper.cs │ │ │ └── ZStringWriter.cs │ │ └── StringPool │ │ │ ├── StringPool.asmdef │ │ │ ├── Unity │ │ │ └── StringPoolForUnity.cs │ │ │ ├── Unsafe │ │ │ └── DummyString.cs │ │ │ ├── StringPoolExtensions.cs │ │ │ ├── BitOperationsHelpers.cs │ │ │ ├── Utilities.cs │ │ │ ├── Gen2GcCallback.cs │ │ │ └── StringPoolEventSource.cs │ └── Examples │ │ ├── Example8 │ │ ├── Example8.asmdef │ │ └── Example8.cs │ │ ├── Example7 │ │ ├── Example7.uss │ │ ├── Example7.uxml │ │ ├── Example7.asset │ │ └── Example7.cs │ │ ├── Example3 │ │ └── Example3.cs │ │ ├── Example2 │ │ └── Example2.cs │ │ ├── Example1 │ │ └── Example1.cs │ │ ├── Example5 │ │ └── Example5.cs │ │ ├── Example4 │ │ └── Example4.cs │ │ └── Example6 │ │ └── Example6.cs ├── ProjectSettings │ ├── ProjectVersion.txt │ ├── ClusterInputManager.asset │ ├── PresetManager.asset │ ├── EditorBuildSettings.asset │ ├── XRSettings.asset │ ├── VersionControlSettings.asset │ ├── TimeManager.asset │ ├── VFXManager.asset │ ├── AudioManager.asset │ ├── TagManager.asset │ ├── PackageManagerSettings.asset │ ├── EditorSettings.asset │ ├── UnityConnectSettings.asset │ ├── DynamicsManager.asset │ ├── MemorySettings.asset │ ├── NavMeshAreas.asset │ ├── Physics2DSettings.asset │ ├── GraphicsSettings.asset │ └── SceneTemplateSettings.json └── .gitignore ├── Examples ├── Examples.csproj └── Examples │ ├── StrongReference`1.cs │ ├── WebSockets.cs │ └── Program.cs ├── StringPool ├── StringPool │ ├── Unsafe │ │ └── DummyString.cs │ ├── StringPoolExtensions.cs │ ├── BitOperationsHelpers.cs │ ├── Utilities.cs │ ├── Gen2GcCallback.cs │ └── StringPoolEventSource.cs └── StringPool.csproj ├── LICENSE ├── StringPool.sln └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Unity/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Unity/Assets/Plugins/TextMesh Pro/Resources/LineBreaking Leading Characters.txt: -------------------------------------------------------------------------------- 1 | ([{〔〈《「『【〘〖〝‘“⦅«$—…‥〳〴〵\[({£¥"々〇$¥₩ # -------------------------------------------------------------------------------- /Unity/ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 2022.3.61f1 2 | m_EditorVersionWithRevision: 2022.3.61f1 (6c53ebaf375d) 3 | -------------------------------------------------------------------------------- /Unity/Assets/Plugins/TextMesh Pro/Sprites/EmojiOne.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molth/StringPool/HEAD/Unity/Assets/Plugins/TextMesh Pro/Sprites/EmojiOne.png -------------------------------------------------------------------------------- /Unity/Assets/Plugins/TextMesh Pro/Fonts/LiberationSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molth/StringPool/HEAD/Unity/Assets/Plugins/TextMesh Pro/Fonts/LiberationSans.ttf -------------------------------------------------------------------------------- /Unity/Assets/Plugins/System.Runtime.CompilerServices.Unsafe.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molth/StringPool/HEAD/Unity/Assets/Plugins/System.Runtime.CompilerServices.Unsafe.dll -------------------------------------------------------------------------------- /Unity/Assets/Plugins/TextMesh Pro/Resources/LineBreaking Following Characters.txt: -------------------------------------------------------------------------------- 1 | )]}〕〉》」』】〙〗〟’”⦆»ヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ々〻‐゠–〜?!‼⁇⁈⁉・、%,.:;。!?]):;=}¢°"†‡℃〆%,. -------------------------------------------------------------------------------- /Unity/ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!236 &1 4 | ClusterInputManager: 5 | m_ObjectHideFlags: 0 6 | m_Inputs: [] 7 | -------------------------------------------------------------------------------- /Unity/Assets/Plugins/TextMesh Pro/Documentation/TextMesh Pro User Guide 2016.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molth/StringPool/HEAD/Unity/Assets/Plugins/TextMesh Pro/Documentation/TextMesh Pro User Guide 2016.pdf -------------------------------------------------------------------------------- /Unity/ProjectSettings/PresetManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1386491679 &1 4 | PresetManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_DefaultPresets: {} 8 | -------------------------------------------------------------------------------- /Unity/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1045 &1 4 | EditorBuildSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Scenes: [] 8 | m_configObjects: {} 9 | -------------------------------------------------------------------------------- /Unity/ProjectSettings/XRSettings.asset: -------------------------------------------------------------------------------- 1 | { 2 | "m_SettingKeys": [ 3 | "VR Device Disabled", 4 | "VR Device User Alert" 5 | ], 6 | "m_SettingValues": [ 7 | "False", 8 | "False" 9 | ] 10 | } -------------------------------------------------------------------------------- /Unity/Assets/Plugins/TextMesh Pro/Sprites/EmojiOne Attribution.txt: -------------------------------------------------------------------------------- 1 | This sample of beautiful emojis are provided by EmojiOne https://www.emojione.com/ 2 | 3 | Please visit their website to view the complete set of their emojis and review their licensing terms. -------------------------------------------------------------------------------- /Unity/ProjectSettings/VersionControlSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!890905787 &1 4 | VersionControlSettings: 5 | m_ObjectHideFlags: 0 6 | m_Mode: Visible Meta Files 7 | m_CollabEditorSettings: 8 | inProgressEnabled: 1 9 | -------------------------------------------------------------------------------- /Unity/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!5 &1 4 | TimeManager: 5 | m_ObjectHideFlags: 0 6 | Fixed Timestep: 0.02 7 | Maximum Allowed Timestep: 0.33333334 8 | m_TimeScale: 1 9 | Maximum Particle Timestep: 0.03 10 | -------------------------------------------------------------------------------- /Unity/Assets/Plugins/ZString/IResettableBufferWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Buffers; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Cysharp.Text 7 | { 8 | public interface IResettableBufferWriter : IBufferWriter 9 | { 10 | void Reset(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Unity/ProjectSettings/VFXManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!937362698 &1 4 | VFXManager: 5 | m_ObjectHideFlags: 0 6 | m_IndirectShader: {fileID: 0} 7 | m_CopyBufferShader: {fileID: 0} 8 | m_SortShader: {fileID: 0} 9 | m_StripUpdateShader: {fileID: 0} 10 | m_RenderPipeSettingsPath: 11 | m_FixedTimeStep: 0.016666668 12 | m_MaxDeltaTime: 0.05 13 | -------------------------------------------------------------------------------- /Unity/Assets/Plugins/StringPool/StringPool.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "StringPool", 3 | "rootNamespace": "System.Buffers", 4 | "references": [], 5 | "includePlatforms": [], 6 | "excludePlatforms": [], 7 | "allowUnsafeCode": true, 8 | "overrideReferences": false, 9 | "precompiledReferences": [], 10 | "autoReferenced": true, 11 | "defineConstraints": [], 12 | "versionDefines": [], 13 | "noEngineReferences": false 14 | } -------------------------------------------------------------------------------- /Unity/Assets/Plugins/ZString/Number/NumberFormatInfoEx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Text; 5 | 6 | namespace System 7 | { 8 | internal static class NumberFormatInfoEx 9 | { 10 | internal static bool HasInvariantNumberSigns(this NumberFormatInfo info) 11 | { 12 | return info.PositiveSign == "+" && info.NegativeSign == "-"; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Unity/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!11 &1 4 | AudioManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Volume: 1 8 | Rolloff Scale: 1 9 | Doppler Factor: 1 10 | Default Speaker Mode: 2 11 | m_SampleRate: 0 12 | m_DSPBufferSize: 1024 13 | m_VirtualVoiceCount: 512 14 | m_RealVoiceCount: 32 15 | m_SpatializerPlugin: 16 | m_AmbisonicDecoderPlugin: 17 | m_DisableAudio: 0 18 | m_VirtualizeEffects: 1 19 | m_RequestedDSPBufferSize: 1024 20 | -------------------------------------------------------------------------------- /Unity/Assets/Plugins/ZString/Unity/TextMeshProExtensions.SetStringBuilder.cs: -------------------------------------------------------------------------------- 1 | #if ZSTRING_TEXTMESHPRO_SUPPORT 2 | using System; 3 | using TMPro; 4 | 5 | namespace Cysharp.Text 6 | { 7 | public static partial class TextMeshProExtensions 8 | { 9 | public static void SetText(this TMP_Text text, Utf16ValueStringBuilder stringBuilder) 10 | { 11 | var array = stringBuilder.AsArraySegment(); 12 | text.SetCharArray(array.Array, array.Offset, array.Count); 13 | } 14 | } 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /Unity/Assets/Examples/Example8/Example8.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Example8", 3 | "rootNamespace": "", 4 | "references": [ 5 | "GUID:ec7b4b213246c7d489d3555c9196c113", 6 | "GUID:e0cd26848372d4e5c891c569017e11f1" 7 | ], 8 | "includePlatforms": [], 9 | "excludePlatforms": [], 10 | "allowUnsafeCode": true, 11 | "overrideReferences": false, 12 | "precompiledReferences": [], 13 | "autoReferenced": true, 14 | "defineConstraints": [], 15 | "versionDefines": [], 16 | "noEngineReferences": false 17 | } -------------------------------------------------------------------------------- /Unity/Assets/Plugins/ZString/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.cysharp.zstring", 3 | "displayName": "ZString", 4 | "version": "2.6.0", 5 | "unity": "2018.4", 6 | "description": "Zero Allocation StringBuilder for .NET Core and Unity.", 7 | "keywords": [ 8 | "String", 9 | "Performance" 10 | ], 11 | "license": "MIT", 12 | "category": "Scripting", 13 | "dependencies": {}, 14 | "samples": [ 15 | { 16 | "displayName": "Required Managed DLLs", 17 | "description": "Import Required Managed DLLs", 18 | "path": "Samples~/RequiredManagedDLLs" 19 | } 20 | ] 21 | } -------------------------------------------------------------------------------- /Unity/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!78 &1 4 | TagManager: 5 | serializedVersion: 2 6 | tags: [] 7 | layers: 8 | - Default 9 | - TransparentFX 10 | - Ignore Raycast 11 | - 12 | - Water 13 | - UI 14 | - 15 | - 16 | - 17 | - 18 | - 19 | - 20 | - 21 | - 22 | - 23 | - 24 | - 25 | - 26 | - 27 | - 28 | - 29 | - 30 | - 31 | - 32 | - 33 | - 34 | - 35 | - 36 | - 37 | - 38 | - 39 | - 40 | m_SortingLayers: 41 | - name: Default 42 | uniqueID: 0 43 | locked: 0 44 | -------------------------------------------------------------------------------- /Unity/Assets/Plugins/StringPool/Unity/StringPoolForUnity.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Profiling; 3 | 4 | namespace System.Buffers.Unity 5 | { 6 | internal static class StringPoolForUnity 7 | { 8 | [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)] 9 | private static void Initialize() 10 | { 11 | StringPool.Custom(GetMemoryPressure); 12 | return; 13 | 14 | static double GetMemoryPressure() => Profiler.GetTotalAllocatedMemoryLong() / (double)((long)SystemInfo.systemMemorySize * 1024 * 1024); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Examples/Examples.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | false 9 | ConsoleApp1 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Unity/Assets/Examples/Example7/Example7.uss: -------------------------------------------------------------------------------- 1 | .game-ui { 2 | position: absolute; 3 | top: 20px; 4 | left: 20px; 5 | background-color: rgba(0, 0, 0, 0.5); 6 | padding: 10px; 7 | border-radius: 5px; 8 | } 9 | 10 | .health-container { 11 | flex-direction: row; 12 | align-items: center; 13 | margin-bottom: 10px; 14 | } 15 | 16 | .health-text { 17 | color: #ff0000; 18 | font-size: 18px; 19 | } 20 | 21 | .status-text { 22 | color: #ff0000; 23 | font-size: 18px; 24 | margin-left: 5px; 25 | } 26 | 27 | .action-button { 28 | width: 120px; 29 | height: 40px; 30 | background-color: #4CAF50; 31 | color: white; 32 | } -------------------------------------------------------------------------------- /Examples/Examples/StrongReference`1.cs: -------------------------------------------------------------------------------- 1 | namespace Examples 2 | { 3 | public class StrongReference : IDisposable where T : class, IDisposable 4 | { 5 | public T? Value; 6 | 7 | public StrongReference(T value) 8 | { 9 | if (value == null) 10 | throw new ArgumentNullException(nameof(value)); 11 | 12 | Value = value; 13 | } 14 | 15 | ~StrongReference() => Dispose(); 16 | 17 | public void Dispose() 18 | { 19 | T? value = Interlocked.Exchange(ref Value, null); 20 | if (value == null) 21 | return; 22 | 23 | GC.SuppressFinalize(this); 24 | value.Dispose(); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Unity/Assets/Plugins/ZString/NestedStringBuilderCreationException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Cysharp.Text 4 | { 5 | // Currently, this class is internals. 6 | internal class NestedStringBuilderCreationException : InvalidOperationException 7 | { 8 | internal protected NestedStringBuilderCreationException(string typeName, string extraMessage = "") 9 | : base($"A nested call with `notNested: true`, or Either You forgot to call {typeName}.Dispose() of in the past.{extraMessage}") 10 | { 11 | } 12 | 13 | internal protected NestedStringBuilderCreationException(string message, Exception innerException) : base(message, innerException) 14 | { 15 | } 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Unity/Assets/Plugins/ZString/ZString.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ZString", 3 | "references": [ 4 | "Unity.TextMeshPro" 5 | ], 6 | "includePlatforms": [], 7 | "excludePlatforms": [], 8 | "allowUnsafeCode": true, 9 | "overrideReferences": false, 10 | "precompiledReferences": [], 11 | "autoReferenced": true, 12 | "defineConstraints": [], 13 | "versionDefines": [ 14 | { 15 | "name": "com.unity.textmeshpro", 16 | "expression": "", 17 | "define": "ZSTRING_TEXTMESHPRO_SUPPORT" 18 | }, 19 | { 20 | "name": "com.unity.ugui", 21 | "expression": "2.0.0", 22 | "define": "ZSTRING_TEXTMESHPRO_SUPPORT" 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /Unity/Assets/Plugins/ZString/Number/BufferEx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace System 6 | { 7 | internal static class BufferEx 8 | { 9 | internal static unsafe void ZeroMemory(byte* dest, uint len) 10 | { 11 | if (len == 0) return; 12 | 13 | for (int i = 0; i < len; i++) 14 | { 15 | dest[i] = 0; 16 | } 17 | } 18 | 19 | internal static unsafe void Memcpy(byte* dest, byte* src, int len) 20 | { 21 | if (len == 0) return; 22 | for (int i = 0; i < len; i++) 23 | { 24 | dest[i] = src[i]; 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Unity/Assets/Examples/Example7/Example7.uxml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Unity/Assets/Plugins/ZString/ExceptionUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Cysharp.Text 6 | { 7 | internal static class ExceptionUtil 8 | { 9 | internal static void ThrowArgumentException(string paramName) 10 | { 11 | throw new ArgumentException("Can't format argument.", paramName); 12 | } 13 | 14 | internal static void ThrowFormatException() 15 | { 16 | throw new FormatException("Index (zero based) must be greater than or equal to zero and less than the size of the argument list."); 17 | } 18 | 19 | internal static void ThrowFormatError() 20 | { 21 | throw new FormatException("Input string was not in a correct format."); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Unity/Assets/Examples/Example3/Example3.cs: -------------------------------------------------------------------------------- 1 | using System.Buffers; 2 | using Cysharp.Text; 3 | using TMPro; 4 | using UnityEngine; 5 | 6 | namespace Examples 7 | { 8 | public sealed class Example3 : MonoBehaviour 9 | { 10 | public TMP_Text text; 11 | private string _str; 12 | 13 | private void Update() 14 | { 15 | if (Input.GetKeyDown(KeyCode.Space)) 16 | { 17 | if (_str != null) 18 | StringPool.Shared.Return(_str); 19 | 20 | _str = StringPool.Shared.Rent(10000); 21 | 22 | using var builder = ZString.CreateStringBuilder(); 23 | builder.Append("Herta"); 24 | 25 | var span = StringPool.AsSpan(_str); 26 | builder.TryCopyTo(span, out _); 27 | 28 | text.text = _str; 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Unity/Assets/Plugins/ZString/ReadOnlyListAdaptor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | 4 | namespace Cysharp.Text 5 | { 6 | /// 7 | /// Most IList interface-implementing classes implement the IReadOnlyList interface. 8 | /// This is for the rare class that does not implement the IList interface. 9 | /// 10 | /// 11 | internal readonly struct ReadOnlyListAdaptor : IReadOnlyList 12 | { 13 | readonly IList _list; 14 | 15 | public ReadOnlyListAdaptor(IList list) => _list = list; 16 | 17 | public T this[int index] => _list[index]; 18 | 19 | public int Count => _list.Count; 20 | 21 | public IEnumerator GetEnumerator() => _list.GetEnumerator(); 22 | 23 | IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /StringPool/StringPool/Unsafe/DummyString.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | 4 | using System.Runtime.InteropServices; 5 | 6 | #pragma warning disable CS0169 7 | #pragma warning disable CS1591 8 | #pragma warning disable CS8602 9 | #pragma warning disable CS8632 10 | 11 | // ReSharper disable ALL 12 | 13 | namespace System.Buffers 14 | { 15 | /// 16 | /// Mimics the internal layout of System.String for unsafe field manipulation. 17 | /// 18 | [StructLayout(LayoutKind.Sequential)] 19 | internal sealed class DummyString 20 | { 21 | /// 22 | /// Maps to System.String._stringLength for unsafe length modification. 23 | /// 24 | public int _stringLength; 25 | 26 | /// 27 | /// Maps to System.String._firstChar (unused but required for layout matching). 28 | /// 29 | private char _firstChar; 30 | } 31 | } -------------------------------------------------------------------------------- /Unity/Assets/Examples/Example2/Example2.cs: -------------------------------------------------------------------------------- 1 | using System.Buffers; 2 | using Cysharp.Text; 3 | using UnityEngine; 4 | 5 | namespace Examples 6 | { 7 | public sealed class Example2 : MonoBehaviour 8 | { 9 | private void Update() 10 | { 11 | if (Input.GetKeyDown(KeyCode.Space)) 12 | { 13 | using (var builder1 = ZString.CreateStringBuilder()) 14 | { 15 | builder1.Append("Big Herta"); 16 | var str1 = StringPool.Shared.Rent(builder1.AsSpan()); 17 | Debug.Log(str1); 18 | StringPool.Shared.Return(str1); 19 | } 20 | 21 | using (var builder2 = ZString.CreateStringBuilder()) 22 | { 23 | builder2.Append("Small Herta"); 24 | var str2 = StringPool.Shared.Rent(builder2.AsSpan()); 25 | Debug.Log(str2); 26 | StringPool.Shared.Return(str2); 27 | } 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Unity/Assets/Plugins/StringPool/Unsafe/DummyString.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | 4 | using System.Runtime.InteropServices; 5 | 6 | #pragma warning disable CS0169 7 | #pragma warning disable CS1591 8 | #pragma warning disable CS8602 9 | #pragma warning disable CS8632 10 | 11 | // ReSharper disable ALL 12 | 13 | namespace System.Buffers 14 | { 15 | /// 16 | /// Mimics the internal layout of System.String for unsafe field manipulation. 17 | /// 18 | [StructLayout(LayoutKind.Sequential)] 19 | internal sealed class DummyString 20 | { 21 | /// 22 | /// Maps to System.String._stringLength for unsafe length modification. 23 | /// 24 | public int _stringLength; 25 | 26 | /// 27 | /// Maps to System.String._firstChar (unused but required for layout matching). 28 | /// 29 | private char _firstChar; 30 | } 31 | } -------------------------------------------------------------------------------- /Unity/ProjectSettings/PackageManagerSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &1 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 61 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 13964, guid: 0000000000000000e000000000000000, type: 0} 13 | m_Name: 14 | m_EditorClassIdentifier: 15 | m_EnablePreReleasePackages: 0 16 | m_EnablePackageDependencies: 0 17 | m_AdvancedSettingsExpanded: 1 18 | m_ScopedRegistriesSettingsExpanded: 1 19 | m_SeeAllPackageVersions: 0 20 | oneTimeWarningShown: 0 21 | m_Registries: 22 | - m_Id: main 23 | m_Name: 24 | m_Url: https://packages.unity.com 25 | m_Scopes: [] 26 | m_IsDefault: 1 27 | m_Capabilities: 7 28 | m_UserSelectedRegistryName: 29 | m_UserAddingNewScopedRegistry: 0 30 | m_RegistryInfoDraft: 31 | m_Modified: 0 32 | m_ErrorMessage: 33 | m_UserModificationsInstanceId: -830 34 | m_OriginalInstanceId: -832 35 | m_LoadAssets: 0 36 | -------------------------------------------------------------------------------- /Unity/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!159 &1 4 | EditorSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 11 7 | m_ExternalVersionControlSupport: Visible Meta Files 8 | m_SerializationMode: 2 9 | m_LineEndingsForNewScripts: 0 10 | m_DefaultBehaviorMode: 0 11 | m_PrefabRegularEnvironment: {fileID: 0} 12 | m_PrefabUIEnvironment: {fileID: 0} 13 | m_SpritePackerMode: 0 14 | m_SpritePackerPaddingPower: 1 15 | m_EtcTextureCompressorBehavior: 1 16 | m_EtcTextureFastCompressor: 1 17 | m_EtcTextureNormalCompressor: 2 18 | m_EtcTextureBestCompressor: 4 19 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef;rsp;asmref 20 | m_ProjectGenerationRootNamespace: 21 | m_CollabEditorSettings: 22 | inProgressEnabled: 1 23 | m_EnableTextureStreamingInEditMode: 1 24 | m_EnableTextureStreamingInPlayMode: 1 25 | m_AsyncShaderCompilation: 1 26 | m_EnterPlayModeOptionsEnabled: 0 27 | m_EnterPlayModeOptions: 3 28 | m_ShowLightmapResolutionOverlay: 1 29 | m_UseLegacyProbeSampleCount: 0 30 | m_SerializeInlineMappingsOnOneLine: 1 31 | -------------------------------------------------------------------------------- /Unity/ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!310 &1 4 | UnityConnectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 1 7 | m_Enabled: 0 8 | m_TestMode: 0 9 | m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events 10 | m_EventUrl: https://cdp.cloud.unity3d.com/v1/events 11 | m_ConfigUrl: https://config.uca.cloud.unity3d.com 12 | m_DashboardUrl: https://dashboard.unity3d.com 13 | m_TestInitMode: 0 14 | CrashReportingSettings: 15 | m_EventUrl: https://perf-events.cloud.unity3d.com 16 | m_Enabled: 0 17 | m_LogBufferSize: 10 18 | m_CaptureEditorExceptions: 1 19 | UnityPurchasingSettings: 20 | m_Enabled: 0 21 | m_TestMode: 0 22 | UnityAnalyticsSettings: 23 | m_Enabled: 0 24 | m_TestMode: 0 25 | m_InitializeOnStartup: 1 26 | m_PackageRequiringCoreStatsPresent: 0 27 | UnityAdsSettings: 28 | m_Enabled: 0 29 | m_InitializeOnStartup: 1 30 | m_TestMode: 0 31 | m_IosGameId: 32 | m_AndroidGameId: 33 | m_GameIds: {} 34 | m_GameId: 35 | PerformanceReportingSettings: 36 | m_Enabled: 0 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Molth Nevin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Unity/Assets/Examples/Example1/Example1.cs: -------------------------------------------------------------------------------- 1 | using System.Buffers; 2 | using UnityEngine; 3 | 4 | namespace Examples 5 | { 6 | public sealed class Example1 : MonoBehaviour 7 | { 8 | private void Update() 9 | { 10 | if (Input.GetKeyDown(KeyCode.Space)) 11 | { 12 | // Span 13 | var str1 = StringPool.Shared.Rent("Big Herta".Length); 14 | { 15 | var span = StringPool.AsSpan(str1); 16 | for (var i = 0; i < "Big Herta".Length; i++) 17 | span[i] = "Big Herta"[i]; 18 | 19 | Debug.Log(str1); 20 | 21 | StringPool.Shared.Return(str1); 22 | } 23 | 24 | // ReadOnlySpan 25 | var str2 = StringPool.Shared.Rent("Small Herta"); 26 | { 27 | Debug.Log(str2); 28 | 29 | StringPool.Shared.Return(str2); 30 | } 31 | 32 | // same 33 | Debug.Log(ReferenceEquals(str1, str2)); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /StringPool.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StringPool", "StringPool\StringPool.csproj", "{53956BAB-9E7D-4541-A97C-05BFB6429A41}" 4 | EndProject 5 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples", "Examples\Examples.csproj", "{D77D8CE8-808B-4E79-9364-0CBC4A3EAFDC}" 6 | EndProject 7 | Global 8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 9 | Debug|Any CPU = Debug|Any CPU 10 | Release|Any CPU = Release|Any CPU 11 | EndGlobalSection 12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 | {53956BAB-9E7D-4541-A97C-05BFB6429A41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 14 | {53956BAB-9E7D-4541-A97C-05BFB6429A41}.Debug|Any CPU.Build.0 = Debug|Any CPU 15 | {53956BAB-9E7D-4541-A97C-05BFB6429A41}.Release|Any CPU.ActiveCfg = Release|Any CPU 16 | {53956BAB-9E7D-4541-A97C-05BFB6429A41}.Release|Any CPU.Build.0 = Release|Any CPU 17 | {D77D8CE8-808B-4E79-9364-0CBC4A3EAFDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 18 | {D77D8CE8-808B-4E79-9364-0CBC4A3EAFDC}.Debug|Any CPU.Build.0 = Debug|Any CPU 19 | {D77D8CE8-808B-4E79-9364-0CBC4A3EAFDC}.Release|Any CPU.ActiveCfg = Release|Any CPU 20 | {D77D8CE8-808B-4E79-9364-0CBC4A3EAFDC}.Release|Any CPU.Build.0 = Release|Any CPU 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Unity/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!55 &1 4 | PhysicsManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 11 7 | m_Gravity: {x: 0, y: -9.81, z: 0} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_BounceThreshold: 2 10 | m_SleepThreshold: 0.005 11 | m_DefaultContactOffset: 0.01 12 | m_DefaultSolverIterations: 6 13 | m_DefaultSolverVelocityIterations: 1 14 | m_QueriesHitBackfaces: 0 15 | m_QueriesHitTriggers: 1 16 | m_EnableAdaptiveForce: 0 17 | m_ClothInterCollisionDistance: 0 18 | m_ClothInterCollisionStiffness: 0 19 | m_ContactsGeneration: 1 20 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 21 | m_AutoSimulation: 1 22 | m_AutoSyncTransforms: 0 23 | m_ReuseCollisionCallbacks: 1 24 | m_ClothInterCollisionSettingsToggle: 0 25 | m_ContactPairsMode: 0 26 | m_BroadphaseType: 0 27 | m_WorldBounds: 28 | m_Center: {x: 0, y: 0, z: 0} 29 | m_Extent: {x: 250, y: 250, z: 250} 30 | m_WorldSubdivisions: 8 31 | m_FrictionType: 0 32 | m_EnableEnhancedDeterminism: 0 33 | m_EnableUnifiedHeightmaps: 1 34 | m_DefaultMaxAngluarSpeed: 7 35 | -------------------------------------------------------------------------------- /Unity/ProjectSettings/MemorySettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!387306366 &1 4 | MemorySettings: 5 | m_ObjectHideFlags: 0 6 | m_EditorMemorySettings: 7 | m_MainAllocatorBlockSize: -1 8 | m_ThreadAllocatorBlockSize: -1 9 | m_MainGfxBlockSize: -1 10 | m_ThreadGfxBlockSize: -1 11 | m_CacheBlockSize: -1 12 | m_TypetreeBlockSize: -1 13 | m_ProfilerBlockSize: -1 14 | m_ProfilerEditorBlockSize: -1 15 | m_BucketAllocatorGranularity: -1 16 | m_BucketAllocatorBucketsCount: -1 17 | m_BucketAllocatorBlockSize: -1 18 | m_BucketAllocatorBlockCount: -1 19 | m_ProfilerBucketAllocatorGranularity: -1 20 | m_ProfilerBucketAllocatorBucketsCount: -1 21 | m_ProfilerBucketAllocatorBlockSize: -1 22 | m_ProfilerBucketAllocatorBlockCount: -1 23 | m_TempAllocatorSizeMain: -1 24 | m_JobTempAllocatorBlockSize: -1 25 | m_BackgroundJobTempAllocatorBlockSize: -1 26 | m_JobTempAllocatorReducedBlockSize: -1 27 | m_TempAllocatorSizeGIBakingWorker: -1 28 | m_TempAllocatorSizeNavMeshWorker: -1 29 | m_TempAllocatorSizeAudioWorker: -1 30 | m_TempAllocatorSizeCloudWorker: -1 31 | m_TempAllocatorSizeGfx: -1 32 | m_TempAllocatorSizeJobWorker: -1 33 | m_TempAllocatorSizeBackgroundWorker: -1 34 | m_TempAllocatorSizePreloadManager: -1 35 | m_PlatformMemorySettings: {} 36 | -------------------------------------------------------------------------------- /Unity/Assets/Plugins/ZString/Number/FloatEx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.CompilerServices; 4 | using System.Text; 5 | 6 | namespace System 7 | { 8 | internal static class FloatEx 9 | { 10 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 11 | public static unsafe bool IsFinite(double d) 12 | { 13 | long bits = BitConverter.DoubleToInt64Bits(d); 14 | return (bits & 0x7FFFFFFFFFFFFFFF) < 0x7FF0000000000000; 15 | } 16 | 17 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 18 | public static unsafe bool IsNegative(double d) 19 | { 20 | return BitConverter.DoubleToInt64Bits(d) < 0; 21 | } 22 | 23 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 24 | public static bool IsFinite(float f) 25 | { 26 | int bits = SingleToInt32Bits(f); 27 | return (bits & 0x7FFFFFFF) < 0x7F800000; 28 | } 29 | 30 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 31 | public static unsafe bool IsNegative(float f) 32 | { 33 | return SingleToInt32Bits(f) < 0; 34 | } 35 | 36 | 37 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 38 | public static unsafe int SingleToInt32Bits(float value) 39 | { 40 | return *((int*)&value); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Unity/Assets/Examples/Example7/Example7.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 19101, guid: 0000000000000000e000000000000000, type: 0} 13 | m_Name: Example7 14 | m_EditorClassIdentifier: 15 | themeUss: {fileID: -4733365628477956816, guid: 9df88423d0016bd43857b005706375e4, type: 3} 16 | m_TargetTexture: {fileID: 0} 17 | m_ScaleMode: 1 18 | m_ReferenceSpritePixelsPerUnit: 100 19 | m_Scale: 1 20 | m_ReferenceDpi: 96 21 | m_FallbackDpi: 96 22 | m_ReferenceResolution: {x: 1200, y: 800} 23 | m_ScreenMatchMode: 0 24 | m_Match: 0 25 | m_SortingOrder: 0 26 | m_TargetDisplay: 0 27 | m_ClearDepthStencil: 1 28 | m_ClearColor: 0 29 | m_ColorClearValue: {r: 0, g: 0, b: 0, a: 0} 30 | m_DynamicAtlasSettings: 31 | m_MinAtlasSize: 64 32 | m_MaxAtlasSize: 4096 33 | m_MaxSubTextureSize: 64 34 | m_ActiveFilters: -1 35 | m_AtlasBlitShader: {fileID: 9101, guid: 0000000000000000f000000000000000, type: 0} 36 | m_RuntimeShader: {fileID: 9100, guid: 0000000000000000f000000000000000, type: 0} 37 | m_RuntimeWorldShader: {fileID: 9102, guid: 0000000000000000f000000000000000, type: 0} 38 | textSettings: {fileID: 0} 39 | -------------------------------------------------------------------------------- /Unity/.gitignore: -------------------------------------------------------------------------------- 1 | # This .gitignore file should be placed at the root of your Unity project directory 2 | # 3 | # Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore 4 | # 5 | /[Ll]ibrary/ 6 | /[Tt]emp/ 7 | /[Oo]bj/ 8 | /[Bb]uild/ 9 | /[Bb]uilds/ 10 | /[Ll]ogs/ 11 | /[Uu]ser[Ss]ettings/ 12 | 13 | # MemoryCaptures can get excessive in size. 14 | # They also could contain extremely sensitive data 15 | /[Mm]emoryCaptures/ 16 | 17 | # Recordings can get excessive in size 18 | /[Rr]ecordings/ 19 | 20 | # Uncomment this line if you wish to ignore the asset store tools plugin 21 | # /[Aa]ssets/AssetStoreTools* 22 | 23 | # Autogenerated Jetbrains Rider plugin 24 | /[Aa]ssets/Plugins/Editor/JetBrains* 25 | 26 | # Visual Studio cache directory 27 | .vs/ 28 | 29 | # Gradle cache directory 30 | .gradle/ 31 | 32 | # Autogenerated VS/MD/Consulo solution and project files 33 | ExportedObj/ 34 | .consulo/ 35 | *.csproj 36 | *.unityproj 37 | *.sln 38 | *.suo 39 | *.tmp 40 | *.user 41 | *.userprefs 42 | *.pidb 43 | *.booproj 44 | *.svd 45 | *.pdb 46 | *.mdb 47 | *.opendb 48 | *.VC.db 49 | 50 | # Unity3D generated meta files 51 | *.pidb.meta 52 | *.pdb.meta 53 | *.mdb.meta 54 | 55 | # Unity3D generated file on crash reports 56 | sysinfo.txt 57 | 58 | # Builds 59 | *.apk 60 | *.aab 61 | *.unitypackage 62 | *.app 63 | 64 | # Crashlytics generated file 65 | crashlytics-build.properties 66 | 67 | # Packed Addressables 68 | /[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin* 69 | 70 | # Temporary auto-generated Android Assets 71 | /[Aa]ssets/[Ss]treamingAssets/aa.meta 72 | /[Aa]ssets/[Ss]treamingAssets/aa/* 73 | -------------------------------------------------------------------------------- /Unity/Assets/Examples/Example5/Example5.cs: -------------------------------------------------------------------------------- 1 | using System.Buffers; 2 | using Cysharp.Text; 3 | using TMPro; 4 | using UnityEngine; 5 | 6 | namespace Examples 7 | { 8 | public class Example5 : MonoBehaviour 9 | { 10 | public TMP_Text text; 11 | private UnsafeString _str; 12 | 13 | private void Start() 14 | { 15 | _str = new UnsafeString(); 16 | } 17 | 18 | private void Update() 19 | { 20 | if (Input.GetKeyDown(KeyCode.A)) 21 | { 22 | using (var builder = ZString.CreateStringBuilder()) 23 | { 24 | builder.Append("Big Herta"); 25 | _str.SetText(builder.AsSpan()); 26 | 27 | // TODO: must refresh reference 28 | text.text = null; 29 | 30 | text.text = _str; 31 | Debug.Log(text.text.Length); 32 | } 33 | } 34 | 35 | if (Input.GetKeyDown(KeyCode.B)) 36 | { 37 | using (var builder = ZString.CreateStringBuilder()) 38 | { 39 | builder.Append("Small Herta"); 40 | _str.SetText(builder.AsSpan()); 41 | 42 | // TODO: must refresh reference 43 | text.text = null; 44 | 45 | text.text = _str; 46 | Debug.Log(text.text.Length); 47 | } 48 | } 49 | } 50 | 51 | private void OnDestroy() 52 | { 53 | _str.Dispose(); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /StringPool/StringPool/StringPoolExtensions.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | 4 | // ReSharper disable ALL 5 | 6 | namespace System.Buffers 7 | { 8 | /// 9 | /// Provides extensions for StringPool. 10 | /// 11 | public static class StringPoolExtensions 12 | { 13 | /// 14 | /// Retrieves a buffer that is at least the requested length. 15 | /// 16 | /// The instance to rent from. 17 | /// The buffer of the array needed. 18 | /// 19 | /// An array that is at least 's length. 20 | /// 21 | /// 22 | /// This buffer is loaned to the caller and should be returned to the same pool via 23 | /// so that it may be reused in subsequent usage of . 24 | /// It is not a fatal error to not return a rented buffer, but failure to do so may lead to 25 | /// decreased application performance, as the pool may need to create a new buffer to replace 26 | /// the one lost. 27 | /// 28 | public static string Rent(this StringPool pool, ReadOnlySpan buffer) 29 | { 30 | string array = pool.Rent(buffer.Length); 31 | 32 | Span span = StringPool.AsSpan(array); 33 | buffer.CopyTo(span); 34 | 35 | return array; 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Unity/Assets/Plugins/StringPool/StringPoolExtensions.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | 4 | // ReSharper disable ALL 5 | 6 | namespace System.Buffers 7 | { 8 | /// 9 | /// Provides extensions for StringPool. 10 | /// 11 | public static class StringPoolExtensions 12 | { 13 | /// 14 | /// Retrieves a buffer that is at least the requested length. 15 | /// 16 | /// The instance to rent from. 17 | /// The buffer of the array needed. 18 | /// 19 | /// An array that is at least 's length. 20 | /// 21 | /// 22 | /// This buffer is loaned to the caller and should be returned to the same pool via 23 | /// so that it may be reused in subsequent usage of . 24 | /// It is not a fatal error to not return a rented buffer, but failure to do so may lead to 25 | /// decreased application performance, as the pool may need to create a new buffer to replace 26 | /// the one lost. 27 | /// 28 | public static string Rent(this StringPool pool, ReadOnlySpan buffer) 29 | { 30 | string array = pool.Rent(buffer.Length); 31 | 32 | Span span = StringPool.AsSpan(array); 33 | buffer.CopyTo(span); 34 | 35 | return array; 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Unity/ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!126 &1 4 | NavMeshProjectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | areas: 8 | - name: Walkable 9 | cost: 1 10 | - name: Not Walkable 11 | cost: 1 12 | - name: Jump 13 | cost: 2 14 | - name: 15 | cost: 1 16 | - name: 17 | cost: 1 18 | - name: 19 | cost: 1 20 | - name: 21 | cost: 1 22 | - name: 23 | cost: 1 24 | - name: 25 | cost: 1 26 | - name: 27 | cost: 1 28 | - name: 29 | cost: 1 30 | - name: 31 | cost: 1 32 | - name: 33 | cost: 1 34 | - name: 35 | cost: 1 36 | - name: 37 | cost: 1 38 | - name: 39 | cost: 1 40 | - name: 41 | cost: 1 42 | - name: 43 | cost: 1 44 | - name: 45 | cost: 1 46 | - name: 47 | cost: 1 48 | - name: 49 | cost: 1 50 | - name: 51 | cost: 1 52 | - name: 53 | cost: 1 54 | - name: 55 | cost: 1 56 | - name: 57 | cost: 1 58 | - name: 59 | cost: 1 60 | - name: 61 | cost: 1 62 | - name: 63 | cost: 1 64 | - name: 65 | cost: 1 66 | - name: 67 | cost: 1 68 | - name: 69 | cost: 1 70 | - name: 71 | cost: 1 72 | m_LastAgentTypeID: -887442657 73 | m_Settings: 74 | - serializedVersion: 2 75 | agentTypeID: 0 76 | agentRadius: 0.5 77 | agentHeight: 2 78 | agentSlope: 45 79 | agentClimb: 0.75 80 | ledgeDropHeight: 0 81 | maxJumpAcrossDistance: 0 82 | minRegionArea: 2 83 | manualCellSize: 0 84 | cellSize: 0.16666667 85 | manualTileSize: 0 86 | tileSize: 256 87 | accuratePlacement: 0 88 | debug: 89 | m_Flags: 0 90 | m_SettingNames: 91 | - Humanoid 92 | -------------------------------------------------------------------------------- /StringPool/StringPool/BitOperationsHelpers.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | 4 | using System.Runtime.CompilerServices; 5 | #if NET5_0_OR_GREATER 6 | using System.Numerics; 7 | #else 8 | using System.Runtime.InteropServices; 9 | #endif 10 | 11 | // ReSharper disable ALL 12 | 13 | namespace System.Buffers 14 | { 15 | internal static class BitOperationsHelpers 16 | { 17 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 18 | public static int Log2(ulong value) 19 | { 20 | #if NET5_0_OR_GREATER 21 | return BitOperations.Log2(value); 22 | #else 23 | value |= 1UL; 24 | uint num = (uint)(value >> 32); 25 | return num == 0U ? Log2((uint)value) : 32 + Log2(num); 26 | #endif 27 | } 28 | 29 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 30 | public static int Log2(uint value) 31 | { 32 | #if NET5_0_OR_GREATER 33 | return BitOperations.Log2(value); 34 | #else 35 | value |= 1; 36 | value |= value >> 1; 37 | value |= value >> 2; 38 | value |= value >> 4; 39 | value |= value >> 8; 40 | value |= value >> 16; 41 | return Unsafe.AddByteOffset(ref MemoryMarshal.GetReference(Log2DeBruijn), (nint)(int)((value * 130329821U) >> 27)); 42 | #endif 43 | } 44 | 45 | #if !NET5_0_OR_GREATER 46 | private static ReadOnlySpan Log2DeBruijn => new byte[32] 47 | { 48 | 0, 9, 1, 10, 13, 21, 2, 29, 49 | 11, 14, 16, 18, 22, 25, 3, 30, 50 | 8, 12, 20, 28, 15, 17, 24, 7, 51 | 19, 27, 23, 6, 26, 5, 4, 31 52 | }; 53 | #endif 54 | } 55 | } -------------------------------------------------------------------------------- /Unity/Assets/Plugins/StringPool/BitOperationsHelpers.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | 4 | using System.Runtime.CompilerServices; 5 | #if NET5_0_OR_GREATER 6 | using System.Numerics; 7 | #else 8 | using System.Runtime.InteropServices; 9 | #endif 10 | 11 | // ReSharper disable ALL 12 | 13 | namespace System.Buffers 14 | { 15 | internal static class BitOperationsHelpers 16 | { 17 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 18 | public static int Log2(ulong value) 19 | { 20 | #if NET5_0_OR_GREATER 21 | return BitOperations.Log2(value); 22 | #else 23 | value |= 1UL; 24 | uint num = (uint)(value >> 32); 25 | return num == 0U ? Log2((uint)value) : 32 + Log2(num); 26 | #endif 27 | } 28 | 29 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 30 | public static int Log2(uint value) 31 | { 32 | #if NET5_0_OR_GREATER 33 | return BitOperations.Log2(value); 34 | #else 35 | value |= 1; 36 | value |= value >> 1; 37 | value |= value >> 2; 38 | value |= value >> 4; 39 | value |= value >> 8; 40 | value |= value >> 16; 41 | return Unsafe.AddByteOffset(ref MemoryMarshal.GetReference(Log2DeBruijn), (nint)(int)((value * 130329821U) >> 27)); 42 | #endif 43 | } 44 | 45 | #if !NET5_0_OR_GREATER 46 | private static ReadOnlySpan Log2DeBruijn => new byte[32] 47 | { 48 | 0, 9, 1, 10, 13, 21, 2, 29, 49 | 11, 14, 16, 18, 22, 25, 3, 30, 50 | 8, 12, 20, 28, 15, 17, 24, 7, 51 | 19, 27, 23, 6, 26, 5, 4, 31 52 | }; 53 | #endif 54 | } 55 | } -------------------------------------------------------------------------------- /Unity/Assets/Plugins/TextMesh Pro/Resources/TMP Settings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: 2705215ac5b84b70bacc50632be6e391, type: 3} 13 | m_Name: TMP Settings 14 | m_EditorClassIdentifier: 15 | m_enableWordWrapping: 1 16 | m_enableKerning: 1 17 | m_enableExtraPadding: 0 18 | m_enableTintAllSprites: 0 19 | m_enableParseEscapeCharacters: 1 20 | m_EnableRaycastTarget: 1 21 | m_GetFontFeaturesAtRuntime: 1 22 | m_missingGlyphCharacter: 0 23 | m_warningsDisabled: 0 24 | m_defaultFontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} 25 | m_defaultFontAssetPath: Fonts & Materials/ 26 | m_defaultFontSize: 36 27 | m_defaultAutoSizeMinRatio: 0.5 28 | m_defaultAutoSizeMaxRatio: 2 29 | m_defaultTextMeshProTextContainerSize: {x: 20, y: 5} 30 | m_defaultTextMeshProUITextContainerSize: {x: 200, y: 50} 31 | m_autoSizeTextContainer: 0 32 | m_fallbackFontAssets: [] 33 | m_matchMaterialPreset: 1 34 | m_defaultSpriteAsset: {fileID: 11400000, guid: c41005c129ba4d66911b75229fd70b45, 35 | type: 2} 36 | m_defaultSpriteAssetPath: Sprite Assets/ 37 | m_enableEmojiSupport: 1 38 | m_MissingCharacterSpriteUnicode: 0 39 | m_defaultColorGradientPresetsPath: Color Gradient Presets/ 40 | m_defaultStyleSheet: {fileID: 11400000, guid: f952c082cb03451daed3ee968ac6c63e, 41 | type: 2} 42 | m_StyleSheetsResourcePath: 43 | m_leadingCharacters: {fileID: 4900000, guid: d82c1b31c7e74239bff1220585707d2b, type: 3} 44 | m_followingCharacters: {fileID: 4900000, guid: fade42e8bc714b018fac513c043d323b, 45 | type: 3} 46 | m_UseModernHangulLineBreakingRules: 0 47 | -------------------------------------------------------------------------------- /Unity/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!19 &1 4 | Physics2DSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 4 7 | m_Gravity: {x: 0, y: -9.81} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_VelocityIterations: 8 10 | m_PositionIterations: 3 11 | m_VelocityThreshold: 1 12 | m_MaxLinearCorrection: 0.2 13 | m_MaxAngularCorrection: 8 14 | m_MaxTranslationSpeed: 100 15 | m_MaxRotationSpeed: 360 16 | m_BaumgarteScale: 0.2 17 | m_BaumgarteTimeOfImpactScale: 0.75 18 | m_TimeToSleep: 0.5 19 | m_LinearSleepTolerance: 0.01 20 | m_AngularSleepTolerance: 2 21 | m_DefaultContactOffset: 0.01 22 | m_JobOptions: 23 | serializedVersion: 2 24 | useMultithreading: 0 25 | useConsistencySorting: 0 26 | m_InterpolationPosesPerJob: 100 27 | m_NewContactsPerJob: 30 28 | m_CollideContactsPerJob: 100 29 | m_ClearFlagsPerJob: 200 30 | m_ClearBodyForcesPerJob: 200 31 | m_SyncDiscreteFixturesPerJob: 50 32 | m_SyncContinuousFixturesPerJob: 50 33 | m_FindNearestContactsPerJob: 100 34 | m_UpdateTriggerContactsPerJob: 100 35 | m_IslandSolverCostThreshold: 100 36 | m_IslandSolverBodyCostScale: 1 37 | m_IslandSolverContactCostScale: 10 38 | m_IslandSolverJointCostScale: 10 39 | m_IslandSolverBodiesPerJob: 50 40 | m_IslandSolverContactsPerJob: 50 41 | m_AutoSimulation: 1 42 | m_QueriesHitTriggers: 1 43 | m_QueriesStartInColliders: 1 44 | m_CallbacksOnDisable: 1 45 | m_ReuseCollisionCallbacks: 1 46 | m_AutoSyncTransforms: 0 47 | m_AlwaysShowColliders: 0 48 | m_ShowColliderSleep: 1 49 | m_ShowColliderContacts: 0 50 | m_ShowColliderAABB: 0 51 | m_ContactArrowScale: 0.2 52 | m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412} 53 | m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} 54 | m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} 55 | m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} 56 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 57 | -------------------------------------------------------------------------------- /Unity/Assets/Plugins/ZString/EnumUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Buffers; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Cysharp.Text 7 | { 8 | internal static class EnumUtil 9 | // where T : Enum 10 | { 11 | const string InvalidName = "$"; 12 | 13 | static readonly Dictionary names; 14 | static readonly Dictionary utf8names; 15 | 16 | static EnumUtil() 17 | { 18 | var enumNames = Enum.GetNames(typeof(T)); 19 | var values = 20 | #if NET7_0_OR_GREATER 21 | Enum.GetValuesAsUnderlyingType(typeof(T)); 22 | #else 23 | Enum.GetValues(typeof(T)); 24 | #endif 25 | names = new Dictionary(enumNames.Length); 26 | utf8names = new Dictionary(enumNames.Length); 27 | for (int i = 0; i < enumNames.Length; i++) 28 | { 29 | var value = (T)values.GetValue(i)!; 30 | if (names.ContainsKey(value)) 31 | { 32 | // already registered = invalid. 33 | names[value] = InvalidName; 34 | utf8names[value] = Array.Empty(); // byte[0] == Invalid. 35 | } 36 | else 37 | { 38 | names.Add(value, enumNames[i]); 39 | utf8names.Add(value, Encoding.UTF8.GetBytes(enumNames[i])); 40 | } 41 | } 42 | } 43 | 44 | public static bool TryFormatUtf16(T value, Span dest, out int written, ReadOnlySpan _) 45 | { 46 | if (!names.TryGetValue(value, out var v) || v == InvalidName) 47 | { 48 | v = value!.ToString(); // T is Enum, not null always 49 | } 50 | 51 | written = v.Length; 52 | return v.AsSpan().TryCopyTo(dest); 53 | } 54 | 55 | public static bool TryFormatUtf8(T value, Span dest, out int written, StandardFormat _) 56 | { 57 | if (!utf8names.TryGetValue(value, out var v) || v.Length == 0) 58 | { 59 | v = Encoding.UTF8.GetBytes(value!.ToString()); 60 | } 61 | 62 | written = v.Length; 63 | return v.AsSpan().TryCopyTo(dest); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /StringPool/StringPool.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net9.0;net8.0;net7.0;net6.0;net5.0;netstandard2.1 5 | System.Buffers 6 | disable 7 | enable 8 | 9 | true 10 | 11 | StringPool 12 | 1.0.4 13 | Molth Nevin 14 | Hell 15 | High performance StringPool base on ArrayPool. 16 | https://github.com/Molth/StringPool 17 | MIT 18 | string;pool;performance 19 | 20 | ./nupkgs 21 | README.md 22 | true 23 | 24 | $(MSBuildThisFileDirectory)../ 25 | 26 | 27 | 28 | 9.0 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | true 38 | \ 39 | README.md 40 | 41 | 42 | 43 | true 44 | \ 45 | LICENSE 46 | 47 | 48 | 49 | 50 | true 51 | 52 | 53 | 54 | false 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /Unity/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!30 &1 4 | GraphicsSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 13 7 | m_Deferred: 8 | m_Mode: 1 9 | m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0} 10 | m_DeferredReflections: 11 | m_Mode: 1 12 | m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0} 13 | m_ScreenSpaceShadows: 14 | m_Mode: 1 15 | m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0} 16 | m_LegacyDeferred: 17 | m_Mode: 1 18 | m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0} 19 | m_DepthNormals: 20 | m_Mode: 1 21 | m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0} 22 | m_MotionVectors: 23 | m_Mode: 1 24 | m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0} 25 | m_LightHalo: 26 | m_Mode: 1 27 | m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0} 28 | m_LensFlare: 29 | m_Mode: 1 30 | m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0} 31 | m_AlwaysIncludedShaders: 32 | - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} 33 | - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0} 34 | - {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0} 35 | - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0} 36 | - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} 37 | - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} 38 | m_PreloadedShaders: [] 39 | m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, 40 | type: 0} 41 | m_CustomRenderPipeline: {fileID: 0} 42 | m_TransparencySortMode: 0 43 | m_TransparencySortAxis: {x: 0, y: 0, z: 1} 44 | m_DefaultRenderingPath: 1 45 | m_DefaultMobileRenderingPath: 1 46 | m_TierSettings: [] 47 | m_LightmapStripping: 0 48 | m_FogStripping: 0 49 | m_InstancingStripping: 0 50 | m_LightmapKeepPlain: 1 51 | m_LightmapKeepDirCombined: 1 52 | m_LightmapKeepDynamicPlain: 1 53 | m_LightmapKeepDynamicDirCombined: 1 54 | m_LightmapKeepShadowMask: 1 55 | m_LightmapKeepSubtractive: 1 56 | m_FogKeepLinear: 1 57 | m_FogKeepExp: 1 58 | m_FogKeepExp2: 1 59 | m_AlbedoSwatchInfos: [] 60 | m_LightsUseLinearIntensity: 0 61 | m_LightsUseColorTemperature: 0 62 | m_LogWhenShaderIsCompiled: 0 63 | m_AllowEnlightenSupportForUpgradedProject: 0 64 | -------------------------------------------------------------------------------- /Unity/Assets/Plugins/TextMesh Pro/Shaders/TMPro.cginc: -------------------------------------------------------------------------------- 1 | float2 UnpackUV(float uv) 2 | { 3 | float2 output; 4 | output.x = floor(uv / 4096); 5 | output.y = uv - 4096 * output.x; 6 | 7 | return output * 0.001953125; 8 | } 9 | 10 | fixed4 GetColor(half d, fixed4 faceColor, fixed4 outlineColor, half outline, half softness) 11 | { 12 | half faceAlpha = 1-saturate((d - outline * 0.5 + softness * 0.5) / (1.0 + softness)); 13 | half outlineAlpha = saturate((d + outline * 0.5)) * sqrt(min(1.0, outline)); 14 | 15 | faceColor.rgb *= faceColor.a; 16 | outlineColor.rgb *= outlineColor.a; 17 | 18 | faceColor = lerp(faceColor, outlineColor, outlineAlpha); 19 | 20 | faceColor *= faceAlpha; 21 | 22 | return faceColor; 23 | } 24 | 25 | float3 GetSurfaceNormal(float4 h, float bias) 26 | { 27 | bool raisedBevel = step(1, fmod(_ShaderFlags, 2)); 28 | 29 | h += bias+_BevelOffset; 30 | 31 | float bevelWidth = max(.01, _OutlineWidth+_BevelWidth); 32 | 33 | // Track outline 34 | h -= .5; 35 | h /= bevelWidth; 36 | h = saturate(h+.5); 37 | 38 | if(raisedBevel) h = 1 - abs(h*2.0 - 1.0); 39 | h = lerp(h, sin(h*3.141592/2.0), _BevelRoundness); 40 | h = min(h, 1.0-_BevelClamp); 41 | h *= _Bevel * bevelWidth * _GradientScale * -2.0; 42 | 43 | float3 va = normalize(float3(1.0, 0.0, h.y - h.x)); 44 | float3 vb = normalize(float3(0.0, -1.0, h.w - h.z)); 45 | 46 | return cross(va, vb); 47 | } 48 | 49 | float3 GetSurfaceNormal(float2 uv, float bias, float3 delta) 50 | { 51 | // Read "height field" 52 | float4 h = {tex2D(_MainTex, uv - delta.xz).a, 53 | tex2D(_MainTex, uv + delta.xz).a, 54 | tex2D(_MainTex, uv - delta.zy).a, 55 | tex2D(_MainTex, uv + delta.zy).a}; 56 | 57 | return GetSurfaceNormal(h, bias); 58 | } 59 | 60 | float3 GetSpecular(float3 n, float3 l) 61 | { 62 | float spec = pow(max(0.0, dot(n, l)), _Reflectivity); 63 | return _SpecularColor.rgb * spec * _SpecularPower; 64 | } 65 | 66 | float4 GetGlowColor(float d, float scale) 67 | { 68 | float glow = d - (_GlowOffset*_ScaleRatioB) * 0.5 * scale; 69 | float t = lerp(_GlowInner, (_GlowOuter * _ScaleRatioB), step(0.0, glow)) * 0.5 * scale; 70 | glow = saturate(abs(glow/(1.0 + t))); 71 | glow = 1.0-pow(glow, _GlowPower); 72 | glow *= sqrt(min(1.0, t)); // Fade off glow thinner than 1 screen pixel 73 | return float4(_GlowColor.rgb, saturate(_GlowColor.a * glow * 2)); 74 | } 75 | 76 | float4 BlendARGB(float4 overlying, float4 underlying) 77 | { 78 | overlying.rgb *= overlying.a; 79 | underlying.rgb *= underlying.a; 80 | float3 blended = overlying.rgb + ((1-overlying.a)*underlying.rgb); 81 | float alpha = underlying.a + (1-underlying.a)*overlying.a; 82 | return float4(blended, alpha); 83 | } 84 | 85 | -------------------------------------------------------------------------------- /Unity/Assets/Examples/Example4/Example4.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Buffers; 3 | using Cysharp.Text; 4 | using UnityEngine; 5 | 6 | namespace Examples 7 | { 8 | public sealed class Example4 : MonoBehaviour 9 | { 10 | private void Update() 11 | { 12 | if (Input.GetKeyDown(KeyCode.A)) 13 | { 14 | ExecuteMethod("Method_A", () => 15 | { 16 | for (var i = 0; i < 1000; i++) 17 | { 18 | using (var builder1 = ZString.CreateStringBuilder()) 19 | { 20 | builder1.Append(Guid.NewGuid()); 21 | builder1.Append("Big Herta"); 22 | var text1 = StringPool.Shared.Rent(builder1.AsSpan()); 23 | Debug.Log(text1); 24 | StringPool.Shared.Return(text1); 25 | } 26 | 27 | using (var builder2 = ZString.CreateStringBuilder()) 28 | { 29 | builder2.Append(Guid.NewGuid()); 30 | builder2.Append("Small Herta"); 31 | var text2 = StringPool.Shared.Rent(builder2.AsSpan()); 32 | Debug.Log(text2); 33 | StringPool.Shared.Return(text2); 34 | } 35 | } 36 | }); 37 | } 38 | 39 | if (Input.GetKeyDown(KeyCode.B)) 40 | { 41 | ExecuteMethod("Method_B", () => 42 | { 43 | for (var i = 0; i < 1000; i++) 44 | { 45 | using (var builder1 = ZString.CreateStringBuilder()) 46 | { 47 | builder1.Append(Guid.NewGuid()); 48 | builder1.Append("Big Herta"); 49 | Debug.Log(builder1); 50 | } 51 | 52 | using (var builder2 = ZString.CreateStringBuilder()) 53 | { 54 | builder2.Append(Guid.NewGuid()); 55 | builder2.Append("Small Herta"); 56 | Debug.Log(builder2); 57 | } 58 | } 59 | }); 60 | } 61 | } 62 | 63 | private void ExecuteMethod(string methodName, Action action) 64 | { 65 | GC.Collect(); 66 | GC.WaitForPendingFinalizers(); 67 | 68 | var startMemory = GC.GetTotalMemory(true); 69 | 70 | action(); 71 | 72 | GC.Collect(); 73 | GC.WaitForPendingFinalizers(); 74 | 75 | var endMemory = GC.GetTotalMemory(false); 76 | 77 | Debug.Log($"[{methodName}] GC Analysis:\r\n" + 78 | $"- Memory Delta: {(endMemory - startMemory) / 1024.0:F2} KB\r\n" + 79 | $"- Total Memory: {endMemory / 1024.0:F2} KB"); 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /Unity/Assets/Examples/Example7/Example7.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Buffers; 3 | using System.Runtime.InteropServices; 4 | using Cysharp.Text; 5 | using UnityEngine; 6 | using UnityEngine.UIElements; 7 | 8 | namespace Examples 9 | { 10 | public class Example7 : MonoBehaviour 11 | { 12 | [SerializeField] private UIDocument uiDocument; 13 | private Label healthLabel; 14 | private Label statusLabel; 15 | private Button attackButton; 16 | private int health = 100; 17 | private string _healthText; 18 | private UnsafeString _statusText; 19 | 20 | private void OnEnable() 21 | { 22 | _statusText ??= new UnsafeString(); 23 | 24 | var root = uiDocument.rootVisualElement; 25 | healthLabel = root.Q