├── .gitignore ├── LICENSE ├── LICENSE.meta ├── README.md ├── README.md.meta ├── Scenes.meta ├── Scenes ├── Misc.unity └── Misc.unity.meta ├── Scripts.meta ├── Scripts ├── Extensions.meta ├── Extensions │ ├── BoundsExtensions.cs │ ├── BoundsExtensions.cs.meta │ ├── CameraExtensions.cs │ ├── CameraExtensions.cs.meta │ ├── CanvasExtensions.cs │ ├── CanvasExtensions.cs.meta │ ├── ColliderExtensions.cs │ ├── ColliderExtensions.cs.meta │ ├── ComponentExtensions.cs │ ├── ComponentExtensions.cs.meta │ ├── ExceptionExtensions.cs │ ├── ExceptionExtensions.cs.meta │ ├── Extensions.cs │ ├── Extensions.cs.meta │ ├── FileInfoExtensions.cs │ ├── FileInfoExtensions.cs.meta │ ├── FloatExtensions.cs │ ├── FloatExtensions.cs.meta │ ├── GameObjectExtensions.cs │ ├── GameObjectExtensions.cs.meta │ ├── GenericEnumerableExtensions.cs │ ├── GenericEnumerableExtensions.cs.meta │ ├── KeyValuePairExtensions.cs │ ├── KeyValuePairExtensions.cs.meta │ ├── MaterialExtensions.cs │ ├── MaterialExtensions.cs.meta │ ├── MeshExtensions.cs │ ├── MeshExtensions.cs.meta │ ├── PathExtensions.cs │ ├── PathExtensions.cs.meta │ ├── RandomExtensions.cs │ ├── RandomExtensions.cs.meta │ ├── RectExtensions.cs │ ├── RectExtensions.cs.meta │ ├── RectTransformExtensions.cs │ ├── RectTransformExtensions.cs.meta │ ├── RenderTextureExtensions.cs │ ├── RenderTextureExtensions.cs.meta │ ├── RigidbodyExtensions.cs │ ├── RigidbodyExtensions.cs.meta │ ├── StringExtensions.cs │ ├── StringExtensions.cs.meta │ ├── Texture2DExtensions.cs │ ├── Texture2DExtensions.cs.meta │ ├── TransformExtensions.cs │ ├── TransformExtensions.cs.meta │ ├── TypeExtensions.cs │ ├── TypeExtensions.cs.meta │ ├── VectorExtensions.cs │ └── VectorExtensions.cs.meta ├── Gizmos.meta ├── Gizmos │ ├── ShowGizmoCapsule.cs │ └── ShowGizmoCapsule.cs.meta ├── Misc.meta ├── Misc │ ├── BoundsTest.cs │ ├── BoundsTest.cs.meta │ ├── Editor.meta │ └── Editor │ │ ├── BoundsTestEditor.cs │ │ └── BoundsTestEditor.cs.meta ├── Util.meta └── Util │ ├── AssertUtils.cs │ ├── AssertUtils.cs.meta │ ├── BoolBuffer.cs │ ├── BoolBuffer.cs.meta │ ├── BoxColliderData.cs │ ├── BoxColliderData.cs.meta │ ├── BoxTriangleIntersector.cs │ ├── BoxTriangleIntersector.cs.meta │ ├── BoxTriangleIntersectorOld.cs │ ├── BoxTriangleIntersectorOld.cs.meta │ ├── ByteArrayComparer.cs │ ├── ByteArrayComparer.cs.meta │ ├── ByteUtils.cs │ ├── ByteUtils.cs.meta │ ├── Callbacks.meta │ ├── Callbacks │ ├── CollisionCallback.cs │ ├── CollisionCallback.cs.meta │ ├── OnDestroyCallback.cs │ ├── OnDestroyCallback.cs.meta │ ├── OnDisableCallback.cs │ ├── OnDisableCallback.cs.meta │ ├── OnDragCallback.cs │ ├── OnDragCallback.cs.meta │ ├── OnDrawGizmoCallback.cs │ ├── OnDrawGizmoCallback.cs.meta │ ├── OnPointerClickCallback.cs │ ├── OnPointerClickCallback.cs.meta │ ├── OnPointerDownCallback.cs │ ├── OnPointerDownCallback.cs.meta │ ├── OnPointerEnterCallback.cs │ ├── OnPointerEnterCallback.cs.meta │ ├── OnPointerExitCallback.cs │ ├── OnPointerExitCallback.cs.meta │ ├── OnPointerUpCallback.cs │ ├── OnPointerUpCallback.cs.meta │ ├── OnPostRender.cs │ ├── OnPostRender.cs.meta │ ├── OnPreCullCallback.cs │ ├── OnPreCullCallback.cs.meta │ ├── OnRectTransformDimensionsChangeCallback.cs │ ├── OnRectTransformDimensionsChangeCallback.cs.meta │ ├── TriggerCallback.cs │ └── TriggerCallback.cs.meta │ ├── CapsuleColliderData.cs │ ├── CapsuleColliderData.cs.meta │ ├── CircularBuffer.cs │ ├── CircularBuffer.cs.meta │ ├── ColliderData.cs │ ├── ColliderData.cs.meta │ ├── Conversions.meta │ ├── Conversions │ ├── BigEndianBitConverter.cs │ ├── BigEndianBitConverter.cs.meta │ ├── DoubleConverter.cs │ ├── DoubleConverter.cs.meta │ ├── EndianBitConverter.cs │ ├── EndianBitConverter.cs.meta │ ├── Endianness.cs │ ├── Endianness.cs.meta │ ├── LittleEndianBitConverter.cs │ └── LittleEndianBitConverter.cs.meta │ ├── CylinderBounds.cs │ ├── CylinderBounds.cs.meta │ ├── DI.meta │ ├── DI │ ├── DependencyInjection.cs │ ├── DependencyInjection.cs.meta │ ├── DependencyInjectionUtils.cs │ └── DependencyInjectionUtils.cs.meta │ ├── DebugActions.cs │ ├── DebugActions.cs.meta │ ├── DontDestroyOnLoad.cs │ ├── DontDestroyOnLoad.cs.meta │ ├── Easing.cs │ ├── Easing.cs.meta │ ├── Editor.meta │ ├── Editor │ ├── AssetPostprocessorUtils.cs │ ├── AssetPostprocessorUtils.cs.meta │ ├── EditorUtils.cs │ ├── EditorUtils.cs.meta │ ├── InspectorCategoryEditor.cs │ ├── InspectorCategoryEditor.cs.meta │ ├── QuickActions.cs │ ├── QuickActions.cs.meta │ ├── ReadOnlyDrawer.cs │ ├── ReadOnlyDrawer.cs.meta │ ├── SceneList.cs │ ├── SceneList.cs.meta │ ├── ScreenshotUtilityEditor.cs │ ├── ScreenshotUtilityEditor.cs.meta │ ├── SimpleEditor.cs │ ├── SimpleEditor.cs.meta │ ├── Tools.cs │ └── Tools.cs.meta │ ├── EnumUtils.cs │ ├── EnumUtils.cs.meta │ ├── FastBounds.cs │ ├── FastBounds.cs.meta │ ├── FastPool.cs │ ├── FastPool.cs.meta │ ├── FastPoolWithCallback.cs │ ├── FastPoolWithCallback.cs.meta │ ├── FasterBounds.cs │ ├── FasterBounds.cs.meta │ ├── GameGizmoUtils.cs │ ├── GameGizmoUtils.cs.meta │ ├── GameObjectStates.cs │ ├── GameObjectStates.cs.meta │ ├── GizmoUtils.cs │ ├── GizmoUtils.cs.meta │ ├── Gizmos.meta │ ├── Gizmos │ ├── EditorGizmoProvider.cs │ ├── EditorGizmoProvider.cs.meta │ ├── GameGizmoProvider.cs │ ├── GameGizmoProvider.cs.meta │ ├── IGizmoPresenter.cs │ ├── IGizmoPresenter.cs.meta │ ├── IGizmoProvider.cs │ └── IGizmoProvider.cs.meta │ ├── GuildGenerator.cs │ ├── GuildGenerator.cs.meta │ ├── Icons.meta │ ├── Icons │ ├── Editor.meta │ ├── Editor │ │ ├── IconExplorer.cs │ │ └── IconExplorer.cs.meta │ ├── IconFont.cs │ └── IconFont.cs.meta │ ├── InspectorCategory.cs │ ├── InspectorCategory.cs.meta │ ├── LayoutUtils.cs │ ├── LayoutUtils.cs.meta │ ├── Line.cs │ ├── Line.cs.meta │ ├── LookAtTransform.cs │ ├── LookAtTransform.cs.meta │ ├── MeshBuilder.cs │ ├── MeshBuilder.cs.meta │ ├── MeshSerializer.cs │ ├── MeshSerializer.cs.meta │ ├── MeshTransform.cs │ ├── MeshTransform.cs.meta │ ├── MeshUtility.cs │ ├── MeshUtility.cs.meta │ ├── MeshUtilityV2.cs │ ├── MeshUtilityV2.cs.meta │ ├── MeshUtils.cs │ ├── MeshUtils.cs.meta │ ├── MinimalSphereBounds.cs │ ├── MinimalSphereBounds.cs.meta │ ├── OneShotEvent.cs │ ├── OneShotEvent.cs.meta │ ├── OrderedIndexPool.cs │ ├── OrderedIndexPool.cs.meta │ ├── PauseEditorAfterTime.cs │ ├── PauseEditorAfterTime.cs.meta │ ├── PhysicsUtils.cs │ ├── PhysicsUtils.cs.meta │ ├── Pool.cs │ ├── Pool.cs.meta │ ├── PriorityPool.cs │ ├── PriorityPool.cs.meta │ ├── PriorityQueue.cs │ ├── PriorityQueue.cs.meta │ ├── PropertyDrawers.meta │ ├── PropertyDrawers │ ├── CustomObjectPickerAttribute.cs │ ├── CustomObjectPickerAttribute.cs.meta │ ├── Editor.meta │ ├── Editor │ │ ├── CustomObjectPickerEditorWindow.cs │ │ ├── CustomObjectPickerEditorWindow.cs.meta │ │ ├── CustomObjectPickerPropertyDrawer.cs │ │ ├── CustomObjectPickerPropertyDrawer.cs.meta │ │ ├── OfTypeDrawer.cs │ │ ├── OfTypeDrawer.cs.meta │ │ ├── SingleUnityLayerPropertyDrawer.cs │ │ └── SingleUnityLayerPropertyDrawer.cs.meta │ ├── OfTypeAttribute.cs │ ├── OfTypeAttribute.cs.meta │ ├── SingleUnityLayer.cs │ └── SingleUnityLayer.cs.meta │ ├── Range.cs │ ├── Range.cs.meta │ ├── ReadOnlyAttribute.cs │ ├── ReadOnlyAttribute.cs.meta │ ├── SceneSingleton.cs │ ├── SceneSingleton.cs.meta │ ├── ScreenshotUtility.cs │ ├── ScreenshotUtility.cs.meta │ ├── SequentialIdGenerator.cs │ ├── SequentialIdGenerator.cs.meta │ ├── ShowBounds.cs │ ├── ShowBounds.cs.meta │ ├── ShowNormals.cs │ ├── ShowNormals.cs.meta │ ├── Singleton.cs │ ├── Singleton.cs.meta │ ├── SmallestEnclosingCircle.cs │ ├── SmallestEnclosingCircle.cs.meta │ ├── SphereBounds.cs │ ├── SphereBounds.cs.meta │ ├── SphereColliderData.cs │ ├── SphereColliderData.cs.meta │ ├── SynchronizePosition.cs │ ├── SynchronizePosition.cs.meta │ ├── TransformData.cs │ ├── TransformData.cs.meta │ ├── UnityMainThreadDispatcher.cs │ ├── UnityMainThreadDispatcher.cs.meta │ ├── Utils.cs │ └── Utils.cs.meta ├── Shaders.meta ├── Shaders ├── HiddenPass.shader ├── HiddenPass.shader.meta ├── Vertex Color.shader └── Vertex Color.shader.meta ├── Tests.meta └── Tests ├── Editor.meta └── Editor ├── Extensions.meta ├── Extensions ├── FloatExtensionsTests.cs ├── FloatExtensionsTests.cs.meta ├── VectorExtensionsTests.cs └── VectorExtensionsTests.cs.meta ├── Utils.meta └── Utils ├── CircularBufferTests.cs ├── CircularBufferTests.cs.meta ├── OrderedIndexPoolTests.cs ├── OrderedIndexPoolTests.cs.meta ├── PhysicsButtonUtilsTests.cs ├── PhysicsButtonUtilsTests.cs.meta ├── PhysicsUtilsTests.cs ├── PhysicsUtilsTests.cs.meta ├── PriorityPoolTests.cs ├── PriorityPoolTests.cs.meta ├── UtilsTests.cs └── UtilsTests.cs.meta /.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/master/Unity.gitignore 4 | # 5 | /[Ll]ibrary/ 6 | /[Tt]emp/ 7 | /[Oo]bj/ 8 | /[Bb]uild/ 9 | /[Bb]uilds/ 10 | /[Ll]ogs/ 11 | /[Mm]emoryCaptures/ 12 | 13 | # Asset meta data should only be ignored when the corresponding asset is also ignored 14 | !/[Aa]ssets/**/*.meta 15 | 16 | # Uncomment this line if you wish to ignore the asset store tools plugin 17 | # /[Aa]ssets/AssetStoreTools* 18 | 19 | # Autogenerated Jetbrains Rider plugin 20 | [Aa]ssets/Plugins/Editor/JetBrains* 21 | 22 | # Visual Studio cache directory 23 | .vs/ 24 | 25 | # Gradle cache directory 26 | .gradle/ 27 | 28 | # Autogenerated VS/MD/Consulo solution and project files 29 | ExportedObj/ 30 | .consulo/ 31 | *.csproj 32 | *.unityproj 33 | *.sln 34 | *.suo 35 | *.tmp 36 | *.user 37 | *.userprefs 38 | *.pidb 39 | *.booproj 40 | *.svd 41 | *.pdb 42 | *.mdb 43 | *.opendb 44 | *.VC.db 45 | 46 | # Unity3D generated meta files 47 | *.pidb.meta 48 | *.pdb.meta 49 | *.mdb.meta 50 | 51 | # Unity3D generated file on crash reports 52 | sysinfo.txt 53 | 54 | # Builds 55 | *.apk 56 | *.unitypackage 57 | 58 | # Crashlytics generated file 59 | crashlytics-build.properties 60 | 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Elastic Sea 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 | -------------------------------------------------------------------------------- /LICENSE.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: feebf2c112528b4439d656d39aab6e7b 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unity Framework 2 | 3 | Collection of utility methods. 4 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d870090b2188d7b4abae5c90e86bd291 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 680112a336754c9e8d4d92d6c87c528c 3 | timeCreated: 1689606431 -------------------------------------------------------------------------------- /Scenes/Misc.unity: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!29 &1 4 | OcclusionCullingSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_OcclusionBakeSettings: 8 | smallestOccluder: 5 9 | smallestHole: 0.25 10 | backfaceThreshold: 100 11 | m_SceneGUID: 00000000000000000000000000000000 12 | m_OcclusionCullingData: {fileID: 0} 13 | --- !u!104 &2 14 | RenderSettings: 15 | m_ObjectHideFlags: 0 16 | serializedVersion: 9 17 | m_Fog: 0 18 | m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} 19 | m_FogMode: 3 20 | m_FogDensity: 0.01 21 | m_LinearFogStart: 0 22 | m_LinearFogEnd: 300 23 | m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} 24 | m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} 25 | m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} 26 | m_AmbientIntensity: 1 27 | m_AmbientMode: 0 28 | m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} 29 | m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} 30 | m_HaloStrength: 0.5 31 | m_FlareStrength: 1 32 | m_FlareFadeSpeed: 3 33 | m_HaloTexture: {fileID: 0} 34 | m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} 35 | m_DefaultReflectionMode: 0 36 | m_DefaultReflectionResolution: 128 37 | m_ReflectionBounces: 1 38 | m_ReflectionIntensity: 1 39 | m_CustomReflection: {fileID: 0} 40 | m_Sun: {fileID: 0} 41 | m_IndirectSpecularColor: {r: 0.12731749, g: 0.13414757, b: 0.1210787, a: 1} 42 | m_UseRadianceAmbientProbe: 0 43 | --- !u!157 &3 44 | LightmapSettings: 45 | m_ObjectHideFlags: 0 46 | serializedVersion: 12 47 | m_GIWorkflowMode: 1 48 | m_GISettings: 49 | serializedVersion: 2 50 | m_BounceScale: 1 51 | m_IndirectOutputScale: 1 52 | m_AlbedoBoost: 1 53 | m_EnvironmentLightingMode: 0 54 | m_EnableBakedLightmaps: 1 55 | m_EnableRealtimeLightmaps: 0 56 | m_LightmapEditorSettings: 57 | serializedVersion: 12 58 | m_Resolution: 2 59 | m_BakeResolution: 40 60 | m_AtlasSize: 1024 61 | m_AO: 0 62 | m_AOMaxDistance: 1 63 | m_CompAOExponent: 1 64 | m_CompAOExponentDirect: 0 65 | m_ExtractAmbientOcclusion: 0 66 | m_Padding: 2 67 | m_LightmapParameters: {fileID: 0} 68 | m_LightmapsBakeMode: 1 69 | m_TextureCompression: 1 70 | m_FinalGather: 0 71 | m_FinalGatherFiltering: 1 72 | m_FinalGatherRayCount: 256 73 | m_ReflectionCompression: 2 74 | m_MixedBakeMode: 2 75 | m_BakeBackend: 1 76 | m_PVRSampling: 1 77 | m_PVRDirectSampleCount: 32 78 | m_PVRSampleCount: 512 79 | m_PVRBounces: 2 80 | m_PVREnvironmentSampleCount: 256 81 | m_PVREnvironmentReferencePointCount: 2048 82 | m_PVRFilteringMode: 1 83 | m_PVRDenoiserTypeDirect: 1 84 | m_PVRDenoiserTypeIndirect: 1 85 | m_PVRDenoiserTypeAO: 1 86 | m_PVRFilterTypeDirect: 0 87 | m_PVRFilterTypeIndirect: 0 88 | m_PVRFilterTypeAO: 0 89 | m_PVREnvironmentMIS: 1 90 | m_PVRCulling: 1 91 | m_PVRFilteringGaussRadiusDirect: 1 92 | m_PVRFilteringGaussRadiusIndirect: 5 93 | m_PVRFilteringGaussRadiusAO: 2 94 | m_PVRFilteringAtrousPositionSigmaDirect: 0.5 95 | m_PVRFilteringAtrousPositionSigmaIndirect: 2 96 | m_PVRFilteringAtrousPositionSigmaAO: 1 97 | m_ExportTrainingData: 0 98 | m_TrainingDataDestination: TrainingData 99 | m_LightProbeSampleCountMultiplier: 4 100 | m_LightingDataAsset: {fileID: 0} 101 | m_LightingSettings: {fileID: 0} 102 | --- !u!196 &4 103 | NavMeshSettings: 104 | serializedVersion: 2 105 | m_ObjectHideFlags: 0 106 | m_BuildSettings: 107 | serializedVersion: 2 108 | agentTypeID: 0 109 | agentRadius: 0.5 110 | agentHeight: 2 111 | agentSlope: 45 112 | agentClimb: 0.4 113 | ledgeDropHeight: 0 114 | maxJumpAcrossDistance: 0 115 | minRegionArea: 2 116 | manualCellSize: 0 117 | cellSize: 0.16666667 118 | manualTileSize: 0 119 | tileSize: 256 120 | accuratePlacement: 0 121 | maxJobWorkers: 0 122 | preserveTilesOutsideBounds: 0 123 | debug: 124 | m_Flags: 0 125 | m_NavMeshData: {fileID: 0} 126 | --- !u!1 &1551054001 127 | GameObject: 128 | m_ObjectHideFlags: 0 129 | m_CorrespondingSourceObject: {fileID: 0} 130 | m_PrefabInstance: {fileID: 0} 131 | m_PrefabAsset: {fileID: 0} 132 | serializedVersion: 6 133 | m_Component: 134 | - component: {fileID: 1551054002} 135 | - component: {fileID: 1551054003} 136 | m_Layer: 0 137 | m_Name: Bounds 138 | m_TagString: Untagged 139 | m_Icon: {fileID: 0} 140 | m_NavMeshLayer: 0 141 | m_StaticEditorFlags: 0 142 | m_IsActive: 1 143 | --- !u!4 &1551054002 144 | Transform: 145 | m_ObjectHideFlags: 0 146 | m_CorrespondingSourceObject: {fileID: 0} 147 | m_PrefabInstance: {fileID: 0} 148 | m_PrefabAsset: {fileID: 0} 149 | m_GameObject: {fileID: 1551054001} 150 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 151 | m_LocalPosition: {x: 0, y: 0, z: 0} 152 | m_LocalScale: {x: 1, y: 1, z: 1} 153 | m_ConstrainProportionsScale: 0 154 | m_Children: [] 155 | m_Father: {fileID: 0} 156 | m_RootOrder: 0 157 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 158 | --- !u!114 &1551054003 159 | MonoBehaviour: 160 | m_ObjectHideFlags: 0 161 | m_CorrespondingSourceObject: {fileID: 0} 162 | m_PrefabInstance: {fileID: 0} 163 | m_PrefabAsset: {fileID: 0} 164 | m_GameObject: {fileID: 1551054001} 165 | m_Enabled: 1 166 | m_EditorHideFlags: 0 167 | m_Script: {fileID: 11500000, guid: ac10d3a60eead0540b9b9fba32f2a9b2, type: 3} 168 | m_Name: 169 | m_EditorClassIdentifier: 170 | pointsCount: 100 171 | Type: 1 172 | -------------------------------------------------------------------------------- /Scenes/Misc.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aefd1c7e13835e84e9495e4f458a17ea 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 29db699fd98db874dac42320e98f2821 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Scripts/Extensions.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9fd9e6c538a41c24c832319e8d6c9abf 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Scripts/Extensions/BoundsExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3079498e378151242abf5937c8b8d063 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Extensions/CameraExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using ElasticSea.Framework.Scripts.Extensions; 3 | using UnityEngine; 4 | using UnityEngine.Experimental.Rendering; 5 | 6 | namespace ElasticSea.Framework.Extensions 7 | { 8 | public static class CameraExtensions 9 | { 10 | /// 11 | /// Fill camera viewrect with gameobject 12 | /// 13 | public static void FillCameraView(this Camera camera, GameObject gameObject, float boundsMultiplier = 1) 14 | { 15 | var vertices = gameObject.GetWorldVertexPositions(); 16 | var center = vertices.Average(); 17 | var radius = vertices.Select(v => (center - v).magnitude).Max(); 18 | 19 | camera.FillCameraView(center, radius * boundsMultiplier); 20 | } 21 | 22 | /// 23 | /// Fill camera viewrect with object at position with radius 24 | /// 25 | public static void FillCameraView(this Camera camera, Vector3 targetPosition, float targetRadius) 26 | { 27 | if (camera.orthographic) 28 | { 29 | camera.transform.position = targetPosition - camera.transform.forward * (targetRadius + camera.nearClipPlane); 30 | camera.orthographicSize = targetRadius / Mathf.Min(camera.aspect, 1); 31 | } 32 | else 33 | { 34 | var distance = camera.GetFillCameraViewDistance(targetRadius); 35 | camera.transform.position = targetPosition - camera.transform.forward * distance; 36 | } 37 | } 38 | 39 | /// 40 | /// Get distance from the camera to the object based on the objects sphere radius and camera fov 41 | /// 42 | public static float GetFillCameraViewDistance(this Camera camera, float targetRadius) 43 | { 44 | // Get the horizontal FOV, since it may be the limiting of the two FOVs to properly encapsulate the objects 45 | var horizontalFov = 2f * Mathf.Atan(Mathf.Tan(camera.fieldOfView * Mathf.Deg2Rad / 2f) * camera.aspect) * Mathf.Rad2Deg; 46 | // Use the smaller FOV as it limits what would get cut off by the frustum 47 | var fov = Mathf.Min(camera.fieldOfView, horizontalFov); 48 | 49 | // var distance = radius / Mathf.Tan((camera.fieldOfView * Mathf.Deg2Rad) / 2f); 50 | // Take sin so the whole sphere is in the view 51 | return targetRadius / Mathf.Sin((fov * Mathf.Deg2Rad) / 2f); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /Scripts/Extensions/CameraExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c0e43537cc1b4c9baa6952c43cc34cab 3 | timeCreated: 1615909124 -------------------------------------------------------------------------------- /Scripts/Extensions/CanvasExtensions.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Scripts.Extensions 4 | { 5 | public static class CanvasExtensions 6 | { 7 | public static Texture2D Render(this Canvas canvas, TextureFormat format, string renderLayerName, int width, int height) 8 | { 9 | var previousLayer = canvas.gameObject.layer; 10 | var previousRenderMode = canvas.renderMode; 11 | var previousWorldCamera = canvas.worldCamera; 12 | 13 | canvas.gameObject.layer = LayerMask.NameToLayer(renderLayerName); 14 | canvas.renderMode = RenderMode.ScreenSpaceCamera; 15 | var cam = new GameObject().AddComponent(); 16 | cam.enabled = false; 17 | // Enabling HDR makes the background black 18 | cam.allowHDR = false; 19 | cam.cullingMask = LayerMask.GetMask(renderLayerName); 20 | cam.clearFlags = CameraClearFlags.Color; 21 | cam.targetTexture = new RenderTexture(width, height, 32, RenderTextureFormat.ARGB32); 22 | canvas.worldCamera = cam; 23 | cam.Render(); 24 | var texture = cam.targetTexture.ToTexture2D(format); 25 | GameObject.DestroyImmediate(cam.targetTexture); 26 | GameObject.DestroyImmediate(cam.gameObject); 27 | 28 | canvas.gameObject.layer = previousLayer; 29 | canvas.renderMode = previousRenderMode; 30 | canvas.worldCamera = previousWorldCamera; 31 | return texture; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Scripts/Extensions/CanvasExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0f50fb8def1e41308d140402ba7c1e71 3 | timeCreated: 1656184364 -------------------------------------------------------------------------------- /Scripts/Extensions/ColliderExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8c4cf5b629ad41ea866c408f5f685aaf 3 | timeCreated: 1619093505 -------------------------------------------------------------------------------- /Scripts/Extensions/ComponentExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Extensions 5 | { 6 | public static class ComponentExtensions 7 | { 8 | public static Component GetOrAddComponent(this Component c, Type componentType) 9 | { 10 | return c.gameObject.GetOrAddComponent(componentType); 11 | } 12 | 13 | public static T GetOrAddComponent(this Component c) where T : Component 14 | { 15 | return c.gameObject.GetOrAddComponent(); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Scripts/Extensions/ComponentExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4a306cc18a4c1ce40a02307aa78501fd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Extensions/ExceptionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ElasticSea.Framework.Extensions 5 | { 6 | public static class ExceptionExtensions 7 | { 8 | public static IEnumerable GetAllMessages(this Exception exception) 9 | { 10 | while (exception != null) 11 | { 12 | yield return exception.Message; 13 | exception = exception.InnerException; 14 | } 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Scripts/Extensions/ExceptionExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 916b0f1e4ffd49c4afadf63d2cd4e989 3 | timeCreated: 1606024523 -------------------------------------------------------------------------------- /Scripts/Extensions/Extensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d5aaf28d4b8cf7409c87e4cc94d9c26 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Extensions/FileInfoExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace ElasticSea.Framework.Extensions 4 | { 5 | public static class FileInfoExtensions 6 | { 7 | public static byte[] ToBytes(this FileInfo fileInfo) 8 | { 9 | return File.ReadAllBytes(fileInfo.FullName); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Scripts/Extensions/FileInfoExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c0654f93c81341ca97b75649fec43a9d 3 | timeCreated: 1702953997 -------------------------------------------------------------------------------- /Scripts/Extensions/FloatExtensions.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Extensions 4 | { 5 | public static class FloatExtensions 6 | { 7 | public static float RoundTo(this float value, float roundTo) 8 | { 9 | return (float)(Mathf.RoundToInt((value) / roundTo) * (double)roundTo); 10 | } 11 | 12 | public static float FloorTo(this float value, float roundTo) 13 | { 14 | return (float)(Mathf.FloorToInt((value) / roundTo) * (double)roundTo); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Scripts/Extensions/FloatExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d69c8abbeceb42e8832fb80a86618da9 3 | timeCreated: 1616078109 -------------------------------------------------------------------------------- /Scripts/Extensions/GameObjectExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a4c029e58d3976d4c9d7caf693b9643b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Extensions/GenericEnumerableExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 87ca1853ec74d1345908aff929878472 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Extensions/KeyValuePairExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ElasticSea.Framework.Extensions 4 | { 5 | public static class KeyValuePairExtensions 6 | { 7 | public static void Deconstruct(this KeyValuePair tuple, out T1 key, out T2 value) 8 | { 9 | key = tuple.Key; 10 | value = tuple.Value; 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Scripts/Extensions/KeyValuePairExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9bf28372ad8e4f709032dbc9a8d6fb0b 3 | timeCreated: 1607123646 -------------------------------------------------------------------------------- /Scripts/Extensions/MaterialExtensions.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Rendering; 3 | 4 | namespace ElasticSea.Framework.Extensions 5 | { 6 | public static class MaterialExtensions 7 | { 8 | public enum Mode 9 | { 10 | Opaque, 11 | Cutout, 12 | Fade, 13 | Transparent 14 | } 15 | 16 | public static void SetupMaterialWithBlendMode(this Material material, Mode blendMode) 17 | { 18 | switch (blendMode) 19 | { 20 | case Mode.Opaque: 21 | material.SetInt("_SrcBlend", (int)BlendMode.One); 22 | material.SetInt("_DstBlend", (int)BlendMode.Zero); 23 | material.SetInt("_ZWrite", 1); 24 | material.DisableKeyword("_ALPHATEST_ON"); 25 | material.DisableKeyword("_ALPHABLEND_ON"); 26 | material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); 27 | material.renderQueue = -1; 28 | break; 29 | case Mode.Cutout: 30 | material.SetInt("_SrcBlend", (int)BlendMode.One); 31 | material.SetInt("_DstBlend", (int)BlendMode.Zero); 32 | material.SetInt("_ZWrite", 1); 33 | material.EnableKeyword("_ALPHATEST_ON"); 34 | material.DisableKeyword("_ALPHABLEND_ON"); 35 | material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); 36 | material.renderQueue = 2450; 37 | break; 38 | case Mode.Fade: 39 | material.SetInt("_SrcBlend", (int)BlendMode.SrcAlpha); 40 | material.SetInt("_DstBlend", (int)BlendMode.OneMinusSrcAlpha); 41 | material.SetInt("_ZWrite", 1); 42 | material.DisableKeyword("_ALPHATEST_ON"); 43 | material.EnableKeyword("_ALPHABLEND_ON"); 44 | material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); 45 | material.renderQueue = 3000; 46 | break; 47 | case Mode.Transparent: 48 | material.SetInt("_SrcBlend", (int)BlendMode.One); 49 | material.SetInt("_DstBlend", (int)BlendMode.OneMinusSrcAlpha); 50 | material.SetInt("_ZWrite", 0); 51 | material.DisableKeyword("_ALPHATEST_ON"); 52 | material.DisableKeyword("_ALPHABLEND_ON"); 53 | material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); 54 | material.renderQueue = 3000; 55 | break; 56 | } 57 | } 58 | 59 | public static void EnableKeyword(this Material material, string keyword, bool enabled) 60 | { 61 | if (enabled) 62 | { 63 | material.EnableKeyword(keyword); 64 | } 65 | else 66 | { 67 | material.DisableKeyword(keyword); 68 | } 69 | } 70 | 71 | public static void SetNormal(this Material material, Texture2D normal) 72 | { 73 | material.EnableKeyword("_NORMALMAP"); 74 | material.SetTexture("_BumpMap", normal); 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /Scripts/Extensions/MaterialExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a8c85c4f94df4d96b8fd151b9ad88759 3 | timeCreated: 1607022929 -------------------------------------------------------------------------------- /Scripts/Extensions/MeshExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8e809b42f39f48fbb49edaedbc59a8aa 3 | timeCreated: 1610808507 -------------------------------------------------------------------------------- /Scripts/Extensions/PathExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace ElasticSea.Framework.Scripts.Extensions 4 | { 5 | public static class PathExtensions 6 | { 7 | public static void EnsureDirectory(this FileInfo fileInfo) 8 | { 9 | fileInfo.Directory.EnsureDirectory(); 10 | } 11 | 12 | public static void EnsureDirectory(this DirectoryInfo dir, bool clear = false) 13 | { 14 | if (dir.Exists) 15 | { 16 | if (clear) 17 | { 18 | dir.Delete(true); 19 | dir.Create(); 20 | } 21 | } 22 | else 23 | { 24 | dir.Create(); 25 | } 26 | } 27 | 28 | public static FileInfo File(this DirectoryInfo dir, string path) 29 | { 30 | return new FileInfo(Path.Combine(dir.FullName, path)); 31 | } 32 | 33 | public static void Write(this FileInfo file, byte[] bytes) 34 | { 35 | System.IO.File.WriteAllBytes(file.FullName, bytes); 36 | } 37 | 38 | public static void Write(this FileInfo file, string text) 39 | { 40 | System.IO.File.WriteAllText(file.FullName, text); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Scripts/Extensions/PathExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4cff1aea9ecf43a1a09dc19d6c24387b 3 | timeCreated: 1681119240 -------------------------------------------------------------------------------- /Scripts/Extensions/RandomExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ElasticSea.Framework.Scripts.Extensions 4 | { 5 | public static class RandomExtensions 6 | { 7 | public static bool Probability(this Random random, float probability) => random.NextDouble() <= probability; 8 | public static bool FlipCoin(this Random random) => random.NextDouble() >= 0.5; 9 | public static int RollDice(this Random random, int sides) => random.Next(1, sides); 10 | } 11 | } -------------------------------------------------------------------------------- /Scripts/Extensions/RandomExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 74fa7b0b186d43679545bbca67aee927 3 | timeCreated: 1624013143 -------------------------------------------------------------------------------- /Scripts/Extensions/RectExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using ElasticSea.Framework.Extensions; 4 | using UnityEngine; 5 | 6 | namespace ElasticSea.Framework.Scripts.Extensions 7 | { 8 | public static class RectExtensions 9 | { 10 | public static Rect Encapsulate(this IEnumerable rects) 11 | { 12 | return rects.ToArray().Encapsulate(); 13 | } 14 | 15 | public static Rect Encapsulate(this Rect rect, Rect other) 16 | { 17 | var final = new Rect(); 18 | final.min = rect.min.Min(other.min); 19 | final.max = rect.max.Max(other.max); 20 | return final; 21 | } 22 | 23 | public static Rect Encapsulate(this Rect[] rects) 24 | { 25 | var length = rects.Length; 26 | if (length == 0) 27 | { 28 | return default; 29 | } 30 | 31 | var rect = rects[0]; 32 | for (var i = 1; i < length; i++) 33 | { 34 | var otherRect = rects[i]; 35 | rect.min = rect.min.Min(otherRect.min); 36 | rect.max = rect.max.Max(otherRect.max); 37 | } 38 | 39 | return rect; 40 | } 41 | 42 | public static Rect Grow(this Rect rect, float growBy) 43 | { 44 | return rect.Grow(new Vector2(growBy, growBy)); 45 | } 46 | 47 | public static Rect Grow(this Rect rect, Vector2 growBy) 48 | { 49 | return Rect.MinMaxRect(rect.xMin - growBy.x, rect.yMin - growBy.y, rect.xMax + growBy.x, rect.yMax + growBy.y); 50 | } 51 | 52 | public static Rect Shrink(this Rect rect, float shrinkBy) 53 | { 54 | return rect.Grow(-shrinkBy); 55 | } 56 | 57 | public static Rect Shrink(this Rect rect, Vector2 shrinkBy) 58 | { 59 | return rect.Grow(-shrinkBy); 60 | } 61 | 62 | public static Rect Move(this Rect rect, Vector2 moveBy) 63 | { 64 | var newRect = new Rect(rect); 65 | newRect.position += moveBy; 66 | return newRect; 67 | } 68 | 69 | public static (Rect left, Rect right) SplitHorizontal(this Rect rect) 70 | { 71 | var centerPoint = Mathf.Lerp(rect.xMin, rect.xMax, 0.5f); 72 | var left = Rect.MinMaxRect(rect.xMin, rect.yMin, centerPoint, rect.yMax); 73 | var right = Rect.MinMaxRect(centerPoint, rect.yMin, rect.xMax, rect.yMax); 74 | return (left, right); 75 | } 76 | 77 | public static (Rect bottom, Rect top) SplitVertical(this Rect rect) 78 | { 79 | var centerPoint = Mathf.Lerp(rect.yMin, rect.yMax, 0.5f); 80 | var bottom = Rect.MinMaxRect(rect.xMin, rect.yMin, rect.xMax, centerPoint); 81 | var top = Rect.MinMaxRect(rect.xMin, centerPoint, rect.xMax, rect.yMax); 82 | return (bottom, top); 83 | } 84 | 85 | public static Vector2[] Vertices(this Rect rect) 86 | { 87 | return new Vector2[] 88 | { 89 | new (rect.xMin, rect.yMin), 90 | new (rect.xMin, rect.yMax), 91 | new (rect.xMax, rect.yMax), 92 | new (rect.xMax, rect.yMin), 93 | }; 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /Scripts/Extensions/RectExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ad29d0fe27df497fbf672f802d29a6b9 3 | timeCreated: 1663699284 -------------------------------------------------------------------------------- /Scripts/Extensions/RectTransformExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ec96f959bb14b1e4e84f3395232c0391 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Extensions/RenderTextureExtensions.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Experimental.Rendering; 3 | 4 | namespace ElasticSea.Framework.Scripts.Extensions 5 | { 6 | public static class RenderTextureExtensions 7 | { 8 | public static Texture2D ToTexture2D(this RenderTexture renderTexture, TextureFormat textureFormat = TextureFormat.ARGB32, bool mipmaps = true) 9 | { 10 | var activeRenderTexture = RenderTexture.active; 11 | 12 | var texture = new Texture2D(renderTexture.width, renderTexture.height, textureFormat, mipmaps); 13 | RenderTexture.active = renderTexture; 14 | texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0); 15 | texture.Apply(); 16 | 17 | RenderTexture.active = activeRenderTexture; 18 | 19 | return texture; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Scripts/Extensions/RenderTextureExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 92e3f787b2ad4043b9de64a3c0866138 3 | timeCreated: 1656184762 -------------------------------------------------------------------------------- /Scripts/Extensions/RigidbodyExtensions.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Scripts.Extensions 4 | { 5 | public static class RigidbodyExtensions 6 | { 7 | public static Vector3 WorldCenterOfMass(this Rigidbody rigidbody) 8 | { 9 | return rigidbody.transform.TransformPoint(rigidbody.centerOfMass); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Scripts/Extensions/RigidbodyExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 180db247537b44ac87b97544786f01b9 3 | timeCreated: 1622928828 -------------------------------------------------------------------------------- /Scripts/Extensions/StringExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db2ae094e2234d0cbdeedfee851343d8 3 | timeCreated: 1602346871 -------------------------------------------------------------------------------- /Scripts/Extensions/Texture2DExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | using UnityEngine; 5 | 6 | namespace ElasticSea.Framework.Scripts.Extensions 7 | { 8 | public static class Texture2DExtensions 9 | { 10 | public static Color AverageColor(this Texture2D texture) 11 | { 12 | var colors = texture.GetPixels32(); 13 | var r = 0f; 14 | var g = 0f; 15 | var b = 0f; 16 | var a = 0f; 17 | var length = colors.Length; 18 | 19 | for (var i = 0; i < length; i++) 20 | { 21 | var c = colors[i]; 22 | r += c.r / 255f; 23 | g += c.g / 255f; 24 | b += c.b / 255f; 25 | a += c.a / 255f; 26 | } 27 | 28 | return new Color(r / length, g / length, b / length, a / length); 29 | } 30 | 31 | public delegate Color GetPixel(int x, int y); 32 | public delegate Color Build(GetPixel getPixel, int x, int y); 33 | public static Color[] ConvertMt(this Color[] pixels, int width, int height, Build build) 34 | { 35 | var output = new Color[width * height]; 36 | 37 | var chunkSize = width * height / (SystemInfo.processorCount * 8); 38 | 39 | var workPackages = new List<(int start, int end)>(); 40 | 41 | var sizeBudget = output.Length; 42 | var i = 0; 43 | while (sizeBudget > 0) 44 | { 45 | var currentChunk = Mathf.Min(chunkSize, sizeBudget); 46 | 47 | workPackages.Add((i, i + currentChunk)); 48 | sizeBudget -= currentChunk; 49 | i += currentChunk; 50 | } 51 | 52 | GetPixel getPixel = (x, y) => pixels[y * width + x]; 53 | 54 | Parallel.ForEach(workPackages, tuple => 55 | { 56 | var (start, end) = tuple; 57 | for (var j = start; j < end; j++) 58 | { 59 | var x = j % width; 60 | var y = j / width; 61 | output[j] = build(getPixel, x, y); 62 | } 63 | }); 64 | 65 | return output; 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /Scripts/Extensions/Texture2DExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 89cbba2254f04245a7991a4ba1742444 3 | timeCreated: 1663687026 -------------------------------------------------------------------------------- /Scripts/Extensions/TransformExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d70bae96df53457eacfed21a9fdcc819 3 | timeCreated: 1602346920 -------------------------------------------------------------------------------- /Scripts/Extensions/TypeExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ElasticSea.Framework.Extensions 5 | { 6 | public static class TypeExtensions 7 | { 8 | 9 | public static string GetNameWithoutGenericArity(this Type t) 10 | { 11 | var name = t.Name; 12 | var index = name.IndexOf('`'); 13 | return index == -1 ? name : name.Substring(0, index); 14 | } 15 | 16 | public static string SimpleName(this Type t) 17 | { 18 | return t.GetNameWithoutGenericArity().SplitPascalCase(); 19 | } 20 | 21 | private static readonly Dictionary TypeAliases = new Dictionary 22 | { 23 | { typeof(byte), "byte" }, 24 | { typeof(sbyte), "sbyte" }, 25 | { typeof(short), "short" }, 26 | { typeof(ushort), "ushort" }, 27 | { typeof(int), "int" }, 28 | { typeof(uint), "uint" }, 29 | { typeof(long), "long" }, 30 | { typeof(ulong), "ulong" }, 31 | { typeof(float), "float" }, 32 | { typeof(double), "double" }, 33 | { typeof(decimal), "decimal" }, 34 | { typeof(object), "object" }, 35 | { typeof(bool), "bool" }, 36 | { typeof(char), "char" }, 37 | { typeof(string), "string" }, 38 | { typeof(void), "void" } 39 | }; 40 | 41 | public static string GetSimpleAliasName(this Type type) 42 | { 43 | return (TypeAliases.ContainsKey(type) ? TypeAliases[type] : type.GetNameWithoutGenericArity()).SplitPascalCase(); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Scripts/Extensions/TypeExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4cfd3a3fac1d4941a547f997b54b2dc6 3 | timeCreated: 1615909391 -------------------------------------------------------------------------------- /Scripts/Extensions/VectorExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 71f8447a0b084520aac01172f18bf97f 3 | timeCreated: 1602346899 -------------------------------------------------------------------------------- /Scripts/Gizmos.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4de037a4306045fcabf69cbac15a03c1 3 | timeCreated: 1691483962 -------------------------------------------------------------------------------- /Scripts/Gizmos/ShowGizmoCapsule.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using UnityEditor; 3 | #endif 4 | using UnityEngine; 5 | 6 | namespace ElasticSea.Framework.Gizmo 7 | { 8 | public class ShowGizmoCapsule : MonoBehaviour 9 | { 10 | public float Radius; 11 | public float Height; 12 | public Color Color; 13 | public bool OnDrawGizmosEnabled = true; 14 | public bool OnDrawGizmosSelectedEnabled = false; 15 | 16 | private void OnDrawGizmos() 17 | { 18 | if (OnDrawGizmosEnabled) 19 | { 20 | OnDraw(); 21 | } 22 | } 23 | 24 | private void OnDrawGizmosSelected() 25 | { 26 | if (OnDrawGizmosSelectedEnabled) 27 | { 28 | OnDraw(); 29 | } 30 | } 31 | 32 | private void OnDraw() 33 | { 34 | DrawWireCapsule(Radius, Height, Color); 35 | } 36 | 37 | public void DrawWireCapsule(float _radius, float _height, Color _color) 38 | { 39 | #if UNITY_EDITOR 40 | Handles.color = _color; 41 | Handles.matrix = transform.localToWorldMatrix; 42 | 43 | var pointOffset = (_height - (_radius * 2)) / 2; 44 | 45 | //draw sideways 46 | Handles.DrawWireArc(Vector3.up * pointOffset, Vector3.left, Vector3.back, -180, _radius); 47 | Handles.DrawLine(new Vector3(0, pointOffset, -_radius), new Vector3(0, -pointOffset, -_radius)); 48 | Handles.DrawLine(new Vector3(0, pointOffset, _radius), new Vector3(0, -pointOffset, _radius)); 49 | Handles.DrawWireArc(Vector3.down * pointOffset, Vector3.left, Vector3.back, 180, _radius); 50 | //draw frontways 51 | Handles.DrawWireArc(Vector3.up * pointOffset, Vector3.back, Vector3.left, 180, _radius); 52 | Handles.DrawLine(new Vector3(-_radius, pointOffset, 0), new Vector3(-_radius, -pointOffset, 0)); 53 | Handles.DrawLine(new Vector3(_radius, pointOffset, 0), new Vector3(_radius, -pointOffset, 0)); 54 | Handles.DrawWireArc(Vector3.down * pointOffset, Vector3.back, Vector3.left, -180, _radius); 55 | //draw center 56 | Handles.DrawWireDisc(Vector3.up * pointOffset, Vector3.up, _radius); 57 | Handles.DrawWireDisc(Vector3.down * pointOffset, Vector3.up, _radius); 58 | #endif 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /Scripts/Gizmos/ShowGizmoCapsule.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ca020720243a4c53afb9a6c8f4925a0a 3 | timeCreated: 1691483990 -------------------------------------------------------------------------------- /Scripts/Misc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cefe3a3ed9f04296812ebddd53346ee9 3 | timeCreated: 1689606498 -------------------------------------------------------------------------------- /Scripts/Misc/BoundsTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Linq; 4 | using ElasticSea.Framework.Extensions; 5 | using ElasticSea.Framework.Util; 6 | using UnityEngine; 7 | using Random = System.Random; 8 | 9 | namespace ElasticSea.Framework.Scripts.Misc 10 | { 11 | public class BoundsTest : MonoBehaviour 12 | { 13 | public enum TestType 14 | { 15 | FastCircle, Circle 16 | } 17 | 18 | [SerializeField] private int pointsCount; 19 | [SerializeField] private TestType Type; 20 | public TimeSpan Elapsed { get; private set; } 21 | 22 | private void OnDrawGizmos() 23 | { 24 | var transforms = transform.Children(); 25 | if (transforms.Any()) 26 | { 27 | foreach (var t in transforms) 28 | { 29 | Gizmos.DrawWireSphere(t.position, 0.01f); 30 | } 31 | var points = transforms.Select(t => t.position).ToArray(); 32 | 33 | Gizmos.color = Color.yellow; 34 | 35 | switch (Type) 36 | { 37 | case TestType.FastCircle: 38 | DrawCircle(points, BoundsExtensions.ToFastCircleBounds); 39 | break; 40 | case TestType.Circle: 41 | DrawCircle(points, BoundsExtensions.ToCircleBounds); 42 | break; 43 | default: 44 | throw new ArgumentOutOfRangeException(); 45 | } 46 | } 47 | } 48 | 49 | private void DrawCircle(Vector3[] points, Func factory) 50 | { 51 | var points2d2 = points.Select(p => new Vector2(p.x, p.z)).ToArray(); 52 | 53 | var sw = Stopwatch.StartNew(); 54 | var circle2 = factory(points2d2); 55 | Elapsed = sw.Elapsed; 56 | Gizmos.DrawWireSphere(circle2.center.ToXZ(), 0.01f); 57 | 58 | GizmoUtils.DrawCircle(circle2.center.ToXZ(), Vector3.up, circle2.radius, 512); 59 | } 60 | 61 | public void SpawnPoints() 62 | { 63 | transform.DestroyChildren(true); 64 | 65 | var rng = new Random(); 66 | for (int i = 0; i < pointsCount; i++) 67 | { 68 | var point = new GameObject("Point " + (i + 1)); 69 | point.transform.SetParent(transform, false); 70 | 71 | var angle = (float)(rng.NextDouble() * Mathf.PI * 2); 72 | var radius = (float)rng.NextDouble(); 73 | var x = Mathf.Cos(angle) * radius; 74 | var y = Mathf.Sin(angle) * radius; 75 | point.transform.position = new Vector3(x, 0, y); 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Scripts/Misc/BoundsTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ac10d3a60eead0540b9b9fba32f2a9b2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Misc/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6a7906375dd0450dba0c183a464ac792 3 | timeCreated: 1689606507 -------------------------------------------------------------------------------- /Scripts/Misc/Editor/BoundsTestEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Scripts.Misc.Editor 5 | { 6 | [CustomEditor(typeof(BoundsTest))] 7 | public class BoundsTestEditor : UnityEditor.Editor 8 | { 9 | public override void OnInspectorGUI() 10 | { 11 | base.OnInspectorGUI(); 12 | 13 | var boundsTest = (BoundsTest)target; 14 | 15 | if (GUILayout.Button("SpawnPoints")) 16 | { 17 | boundsTest.SpawnPoints(); 18 | } 19 | 20 | GUILayout.Label(boundsTest.Elapsed.ToString()); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Scripts/Misc/Editor/BoundsTestEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 07339289011e442083a0c0eef0c8311a 3 | timeCreated: 1689121606 -------------------------------------------------------------------------------- /Scripts/Util.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2f7458427b988f9479597cd33944ca81 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Scripts/Util/AssertUtils.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Assertions; 3 | 4 | namespace ElasticSea.Framework.Util 5 | { 6 | public class AssertUtils 7 | { 8 | public static void AreApproximatelyEqual(Vector3 expected, Vector3 actual) 9 | { 10 | Assert.AreApproximatelyEqual(expected.x, actual.x); 11 | Assert.AreApproximatelyEqual(expected.y, actual.y); 12 | Assert.AreApproximatelyEqual(expected.z, actual.z); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Scripts/Util/AssertUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 00f657ff47fd42139f78bde1ee423e16 3 | timeCreated: 1704874926 -------------------------------------------------------------------------------- /Scripts/Util/BoolBuffer.cs: -------------------------------------------------------------------------------- 1 | namespace ElasticSea.Framework.Util 2 | { 3 | public class BoolBuffer : CircularBuffer 4 | { 5 | public BoolBuffer(int capacity) : base(capacity) 6 | { 7 | } 8 | 9 | public bool Average() 10 | { 11 | var falseCount = 0; 12 | var trueCount = 0; 13 | var bufferLength = buffer.Length; 14 | 15 | for (var i = 0; i < bufferLength; i++) 16 | { 17 | if (buffer[i]) 18 | { 19 | trueCount++; 20 | } 21 | else 22 | { 23 | falseCount++; 24 | } 25 | } 26 | 27 | return trueCount > falseCount; 28 | } 29 | 30 | public void Clear(bool value = false) 31 | { 32 | var bufferLength = buffer.Length; 33 | for (var i = 0; i < bufferLength; i++) 34 | { 35 | buffer[i] = value; 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Scripts/Util/BoolBuffer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f7546aecae35409588ec1b6c9af447c7 3 | timeCreated: 1723825017 -------------------------------------------------------------------------------- /Scripts/Util/BoxColliderData.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util 4 | { 5 | public class BoxColliderData : ColliderData 6 | { 7 | public Vector3 Center; 8 | public Vector3 Size; 9 | 10 | public BoxColliderData(Vector3 center, Vector3 size) 11 | { 12 | Center = center; 13 | Size = size; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Scripts/Util/BoxColliderData.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1880adc406314f339e4a1603104cbc4a 3 | timeCreated: 1720810190 -------------------------------------------------------------------------------- /Scripts/Util/BoxTriangleIntersector.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Blocks.Meshbakers; 4 | using ElasticSea.Framework.Extensions; 5 | using UnityEngine; 6 | 7 | namespace ElasticSea.Framework.Scripts.Util 8 | { 9 | public class BoxTriangleIntersector 10 | { 11 | public static bool IsIntersecting(Bounds box, Vector3 t0, Vector3 t1, Vector3 t2) 12 | { 13 | var ibox = new FastBox(box); 14 | var itriangle = new FastTriangle(t0, t1, t2); 15 | 16 | return IsIntersecting(ibox, itriangle); 17 | } 18 | 19 | public class FastTriangle 20 | { 21 | public readonly Vector3 a; 22 | public readonly Vector3 b; 23 | public readonly Vector3 c; 24 | public readonly Vector3[] vertices; 25 | public readonly Vector3 normal; 26 | 27 | public FastTriangle(Vector3 t0, Vector3 t1, Vector3 t2) 28 | { 29 | this.a = t0; 30 | this.b = t1; 31 | this.c = t2; 32 | this.vertices = new[] { t0, t1, t2 }; 33 | this.normal = Vector3.Normalize(Vector3.Cross(b - a, c - a)); 34 | } 35 | } 36 | 37 | public class FastBox 38 | { 39 | public readonly Vector3 min; 40 | public readonly Vector3 max; 41 | public readonly Vector3[] vertices; 42 | public readonly float[] minCoords; 43 | public readonly float[] maxCoords; 44 | 45 | public FastBox(Bounds bounds) 46 | { 47 | min = bounds.min; 48 | max = bounds.max; 49 | vertices = bounds.GetVertices(); 50 | minCoords = new[] { min.x, min.y, min.z }; 51 | maxCoords = new[] { max.x, max.y, max.z }; 52 | } 53 | 54 | public FastBox(FastBounds bounds) 55 | { 56 | min = bounds.Min; 57 | max = bounds.Max; 58 | vertices = bounds.Vertices(); 59 | minCoords = new[] { min.x, min.y, min.z }; 60 | maxCoords = new[] { max.x, max.y, max.z }; 61 | } 62 | } 63 | 64 | private static readonly Vector3[] boxNormals = 65 | { 66 | new Vector3(1, 0, 0), 67 | new Vector3(0, 1, 0), 68 | new Vector3(0, 0, 1) 69 | }; 70 | 71 | public static bool IsIntersecting(FastBox box, FastTriangle fastTriangle) 72 | { 73 | float triangleMin, triangleMax; 74 | float boxMin, boxMax; 75 | 76 | // Test the box normals (x-, y- and z-axes) 77 | for (int i = 0; i < 3; i++) 78 | { 79 | Project(fastTriangle.vertices, boxNormals[i], out triangleMin, out triangleMax); 80 | if (triangleMax < box.minCoords[i] || triangleMin > box.maxCoords[i]) 81 | return false; // No intersection possible. 82 | } 83 | 84 | // Test the triangle normal 85 | var triangleOffset = Vector3.Dot(fastTriangle.normal, fastTriangle.a); 86 | Project(box.vertices, fastTriangle.normal, out boxMin, out boxMax); 87 | if (boxMax < triangleOffset || boxMin > triangleOffset) 88 | return false; // No intersection possible. 89 | 90 | // Test the nine edge cross-products 91 | Vector3[] triangleEdges = { 92 | fastTriangle.a - fastTriangle.b, 93 | fastTriangle.b - fastTriangle.c, 94 | fastTriangle.c - fastTriangle.a 95 | }; 96 | for (int i = 0; i < 3; i++) 97 | for (int j = 0; j < 3; j++) 98 | { 99 | // The box normals are the same as it's edge tangents 100 | var axis = Vector3.Cross(triangleEdges[i], boxNormals[j]); 101 | Project(box.vertices, axis, out boxMin, out boxMax); 102 | Project(fastTriangle.vertices, axis, out triangleMin, out triangleMax); 103 | if (boxMax <= triangleMin || boxMin >= triangleMax) 104 | return false; // No intersection possible 105 | } 106 | 107 | // No separating axis found. 108 | return true; 109 | } 110 | 111 | static void Project(Vector3[] points, Vector3 axis, out float min, out float max) 112 | { 113 | min = float.PositiveInfinity; 114 | max = float.NegativeInfinity; 115 | var length = points.Length; 116 | for (var i = 0; i < length; i++) 117 | { 118 | var point = points[i]; 119 | // TODO check next line performance on il2cpp vs Vecto3.Dot 120 | var val = axis.x * point.x + axis.y * point.y + axis.z * point.z; 121 | if (val < min) min = val; 122 | if (val > max) max = val; 123 | } 124 | } 125 | } 126 | } -------------------------------------------------------------------------------- /Scripts/Util/BoxTriangleIntersector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 148888b2239a4ed79b705e5eadfa188a 3 | timeCreated: 1679141523 -------------------------------------------------------------------------------- /Scripts/Util/BoxTriangleIntersectorOld.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b3daf83e8d05459187fd5e4622c98f75 3 | timeCreated: 1679141300 -------------------------------------------------------------------------------- /Scripts/Util/ByteArrayComparer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ElasticSea.Framework.Util 5 | { 6 | public class ByteArrayComparer : EqualityComparer 7 | { 8 | public override bool Equals(byte[] first, byte[] second) 9 | { 10 | if (first == null || second == null) { 11 | // null == null returns true. 12 | // non-null == null returns false. 13 | return first == second; 14 | } 15 | if (ReferenceEquals(first, second)) { 16 | return true; 17 | } 18 | if (first.Length != second.Length) { 19 | return false; 20 | } 21 | 22 | for (var i = 0; i < first.Length; i++) 23 | { 24 | if (first[i] != second[i]) 25 | { 26 | return false; 27 | } 28 | } 29 | 30 | return true; 31 | } 32 | 33 | public override int GetHashCode(byte[] obj) 34 | { 35 | if (obj == null) { 36 | throw new ArgumentNullException("obj"); 37 | } 38 | // quick and dirty, instantly identifies obviously different 39 | // arrays as being different 40 | return obj.Length; 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Scripts/Util/ByteArrayComparer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dcc10575afe71e14085e39b090bdac94 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/ByteUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 469761be3f9d8d4449c002cc308e3b4b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/Callbacks.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f7e1fdcfa78804d4e8a0ea190238b048 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/CollisionCallback.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util.Callbacks 4 | { 5 | public class CollisionCallback : MonoBehaviour 6 | { 7 | public delegate void CollisionHandler(Collision collision); 8 | 9 | public event CollisionHandler OnEnter; 10 | public event CollisionHandler OnStay; 11 | public event CollisionHandler OnExit; 12 | 13 | private void OnCollisionEnter(Collision collision) => OnEnter?.Invoke(collision); 14 | private void OnCollisionStay(Collision collision) => OnStay?.Invoke(collision); 15 | private void OnCollisionExit(Collision collision) => OnExit?.Invoke(collision); 16 | } 17 | } -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/CollisionCallback.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e80f72102387f1749a9f6bcef8ba8e29 3 | timeCreated: 1478873540 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnDestroyCallback.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Util.Callbacks 5 | { 6 | public class OnDestroyCallback : MonoBehaviour 7 | { 8 | public event Action OnDestroyEvent = () => { }; 9 | 10 | private void OnDestroy() 11 | { 12 | OnDestroyEvent(); 13 | foreach(var d in OnDestroyEvent.GetInvocationList()) 14 | { 15 | OnDestroyEvent -= (Action)d; 16 | } 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnDestroyCallback.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f0ae40073e7048898774c5f9264783ad 3 | timeCreated: 1549731932 -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnDisableCallback.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Scripts.Util.Callbacks 5 | { 6 | public class OnDisableCallback : MonoBehaviour 7 | { 8 | public event Action OnDisableEvent = () => { }; 9 | 10 | private void OnDisable() 11 | { 12 | OnDisableEvent(); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnDisableCallback.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 69c29a08e50844508a6fad34ecb38126 3 | timeCreated: 1668295675 -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnDragCallback.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using UnityEngine.EventSystems; 4 | 5 | namespace ElasticSea.Framework.Util.Callbacks 6 | { 7 | public class OnDragCallback : MonoBehaviour, IDragHandler 8 | { 9 | public event Action OnDragEvent = data => { }; 10 | public void OnDrag(PointerEventData eventData) => OnDragEvent(eventData); 11 | } 12 | } -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnDragCallback.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d0b0636675d9405cbc1e3c16af334127 3 | timeCreated: 1551617750 -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnDrawGizmoCallback.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util.Callbacks 4 | { 5 | public class OnDrawGizmoCallback : MonoBehaviour 6 | { 7 | public delegate void OnDrawGizmosHandler(); 8 | 9 | public event OnDrawGizmosHandler OnDrawGizmosEvent; 10 | public event OnDrawGizmosHandler OnDrawGizmosSelectedEvent; 11 | 12 | private void OnDrawGizmos() => OnDrawGizmosEvent?.Invoke(); 13 | private void OnDrawGizmosSelected() => OnDrawGizmosSelectedEvent?.Invoke(); 14 | } 15 | } -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnDrawGizmoCallback.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4b1e6b5eea034882aab1360c54fcb833 3 | timeCreated: 1708058130 -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnPointerClickCallback.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using UnityEngine.EventSystems; 4 | 5 | namespace ElasticSea.Framework.Util.Callbacks 6 | { 7 | public class OnPointerClickCallback : MonoBehaviour, IPointerClickHandler 8 | { 9 | public event Action OnPointerClickEvent = data => { }; 10 | public void OnPointerClick(PointerEventData eventData) => OnPointerClickEvent(eventData); 11 | } 12 | } -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnPointerClickCallback.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a0fc9443c8de40c0af4de32ef1d089dd 3 | timeCreated: 1554753472 -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnPointerDownCallback.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using UnityEngine.EventSystems; 4 | 5 | namespace ElasticSea.Framework.Util.Callbacks 6 | { 7 | public class OnPointerDownCallback : MonoBehaviour, IPointerDownHandler 8 | { 9 | public event Action OnPointerDownEvent = data => { }; 10 | public void OnPointerDown(PointerEventData eventData) => OnPointerDownEvent(eventData); 11 | } 12 | } -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnPointerDownCallback.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 789a7255cb594ab0a8b2064db9e5617e 3 | timeCreated: 1551617642 -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnPointerEnterCallback.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using UnityEngine.EventSystems; 4 | 5 | namespace ElasticSea.Framework.Util.Callbacks 6 | { 7 | public class OnPointerEnterCallback : MonoBehaviour, IPointerEnterHandler 8 | { 9 | public event Action OnPointerEnterEvent = data => { }; 10 | public void OnPointerEnter(PointerEventData eventData) => OnPointerEnterEvent(eventData); 11 | } 12 | } -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnPointerEnterCallback.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2587768b824040fb89f2331dcc0e6cb4 3 | timeCreated: 1551617720 -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnPointerExitCallback.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using UnityEngine.EventSystems; 4 | 5 | namespace ElasticSea.Framework.Util.Callbacks 6 | { 7 | public class OnPointerExitCallback : MonoBehaviour, IPointerExitHandler 8 | { 9 | public event Action OnPointerExitEvent = data => { }; 10 | public void OnPointerExit(PointerEventData eventData) => OnPointerExitEvent(eventData); 11 | } 12 | } -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnPointerExitCallback.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1d0c448388134b07b6b43033f38df9bd 3 | timeCreated: 1551617732 -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnPointerUpCallback.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using UnityEngine.EventSystems; 4 | 5 | namespace ElasticSea.Framework.Util.Callbacks 6 | { 7 | public class OnPointerUpCallback : MonoBehaviour, IPointerUpHandler 8 | { 9 | public event Action OnPointerUpEvent = data => { }; 10 | public void OnPointerUp(PointerEventData eventData) => OnPointerUpEvent(eventData); 11 | } 12 | } -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnPointerUpCallback.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d092f8a5463f48ca9dfb76f39a375aa3 3 | timeCreated: 1551617701 -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnPostRender.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util.Callbacks 4 | { 5 | public class OnPostRenderCallback : MonoBehaviour 6 | { 7 | public event OnPostRenderHandler OnPostRenderEvent; 8 | 9 | public delegate void OnPostRenderHandler(); 10 | 11 | private void OnPostRender() => OnPostRenderEvent?.Invoke(); 12 | } 13 | } -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnPostRender.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8911d5fd06704ee4ac7b186e0c340755 3 | timeCreated: 1708056913 -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnPreCullCallback.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util.Callbacks 4 | { 5 | public class OnPreCullCallback : MonoBehaviour 6 | { 7 | public delegate void OnPreCullHandler(); 8 | 9 | public event OnPreCullHandler OnPreCullEvent; 10 | 11 | private void OnPreCull() => OnPreCullEvent?.Invoke(); 12 | } 13 | } -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnPreCullCallback.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 334d2a71602e415aa61507ab81d1012f 3 | timeCreated: 1621962081 -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnRectTransformDimensionsChangeCallback.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Util.Callbacks 5 | { 6 | public class OnRectTransformDimensionsChangeCallback : MonoBehaviour 7 | { 8 | public event Action OnRectTransformDimensionsChangeEvent = () => { }; 9 | 10 | private void OnRectTransformDimensionsChange() 11 | { 12 | OnRectTransformDimensionsChangeEvent(); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/OnRectTransformDimensionsChangeCallback.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cfb4a9e201774fc9a4517fd32bfd7058 3 | timeCreated: 1638986657 -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/TriggerCallback.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util.Callbacks 4 | { 5 | public class TriggerCallback : MonoBehaviour 6 | { 7 | public delegate void TriggerHandler(Collider collider); 8 | 9 | public event TriggerHandler OnEnter; 10 | public event TriggerHandler OnStay; 11 | public event TriggerHandler OnExit; 12 | 13 | private void OnTriggerEnter(Collider collider) => OnEnter?.Invoke(collider); 14 | private void OnTriggerStay(Collider collider) => OnStay?.Invoke(collider); 15 | private void OnTriggerExit(Collider collider) => OnExit?.Invoke(collider); 16 | } 17 | } -------------------------------------------------------------------------------- /Scripts/Util/Callbacks/TriggerCallback.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6859cad787eee6440b91a69835a39037 3 | timeCreated: 1478873540 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scripts/Util/CapsuleColliderData.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util 4 | { 5 | public class CapsuleColliderData : ColliderData 6 | { 7 | public Vector3 Start; 8 | public Vector3 End; 9 | public float Radius; 10 | 11 | public CapsuleColliderData(Vector3 start, Vector3 end, float radius) 12 | { 13 | Start = start; 14 | End = end; 15 | Radius = radius; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Scripts/Util/CapsuleColliderData.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0ca4bedd11c54e138880203024f9593c 3 | timeCreated: 1720810220 -------------------------------------------------------------------------------- /Scripts/Util/CircularBuffer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace ElasticSea.Framework.Util 6 | { 7 | public class CircularBuffer : IEnumerable 8 | { 9 | protected T[] buffer; 10 | private int nextIndex; 11 | 12 | public CircularBuffer(int capacity) 13 | { 14 | buffer = new T[capacity]; 15 | Capacity = capacity; 16 | } 17 | 18 | public int Capacity { get; } 19 | 20 | public int Count { get; private set; } 21 | 22 | public bool IsFull => Count == Capacity; 23 | 24 | public IEnumerator GetEnumerator() 25 | { 26 | int start; 27 | int count; 28 | 29 | if (!IsFull) 30 | { 31 | start = 0; 32 | count = nextIndex; 33 | } 34 | else 35 | { 36 | start = nextIndex; 37 | count = start + Capacity; 38 | } 39 | 40 | for (var i = start; i < count; i++) 41 | { 42 | yield return buffer[i % Capacity]; 43 | } 44 | } 45 | 46 | IEnumerator IEnumerable.GetEnumerator() 47 | { 48 | return GetEnumerator(); 49 | } 50 | 51 | public void Add(T element) 52 | { 53 | buffer[nextIndex] = element; 54 | Count = Mathf.Min(Count + 1, Capacity); 55 | nextIndex = (nextIndex + 1) % Capacity; 56 | } 57 | 58 | public void Reset() 59 | { 60 | nextIndex = 0; 61 | Count = 0; 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /Scripts/Util/CircularBuffer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1b8ac4b678f1e7146b616a3a764860f3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/ColliderData.cs: -------------------------------------------------------------------------------- 1 | namespace ElasticSea.Framework.Util 2 | { 3 | public class ColliderData 4 | { 5 | 6 | } 7 | } -------------------------------------------------------------------------------- /Scripts/Util/ColliderData.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e9fe23bbd89d4be798e3bb759cea9dc4 3 | timeCreated: 1720810145 -------------------------------------------------------------------------------- /Scripts/Util/Conversions.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c34a2f4a213fc15439c62b4393556927 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Scripts/Util/Conversions/BigEndianBitConverter.cs: -------------------------------------------------------------------------------- 1 | namespace ElasticSea.Framework.Util.Conversions 2 | { 3 | /// 4 | /// Implementation of EndianBitConverter which converts to/from big-endian 5 | /// byte arrays. 6 | /// 7 | public sealed class BigEndianBitConverter : EndianBitConverter 8 | { 9 | /// 10 | /// Indicates the byte order ("endianess") in which data is converted using this class. 11 | /// 12 | /// 13 | /// Different computer architectures store data using different byte orders. "Big-endian" 14 | /// means the most significant byte is on the left end of a word. "Little-endian" means the 15 | /// most significant byte is on the right end of a word. 16 | /// 17 | /// true if this converter is little-endian, false otherwise. 18 | public sealed override bool IsLittleEndian() 19 | { 20 | return false; 21 | } 22 | 23 | /// 24 | /// Indicates the byte order ("endianess") in which data is converted using this class. 25 | /// 26 | public sealed override Endianness Endianness 27 | { 28 | get { return Endianness.BigEndian; } 29 | } 30 | 31 | /// 32 | /// Copies the specified number of bytes from value to buffer, starting at index. 33 | /// 34 | /// The value to copy 35 | /// The number of bytes to copy 36 | /// The buffer to copy the bytes into 37 | /// The index to start at 38 | protected override void CopyBytesImpl(long value, int bytes, byte[] buffer, int index) 39 | { 40 | int endOffset = index + bytes - 1; 41 | for (int i = 0; i < bytes; i++) 42 | { 43 | buffer[endOffset - i] = unchecked((byte) (value & 0xff)); 44 | value = value >> 8; 45 | } 46 | } 47 | 48 | /// 49 | /// Returns a value built from the specified number of bytes from the given buffer, 50 | /// starting at index. 51 | /// 52 | /// The data in byte array format 53 | /// The first index to use 54 | /// The number of bytes to use 55 | /// The value built from the given bytes 56 | protected override long FromBytes(byte[] buffer, int startIndex, int bytesToConvert) 57 | { 58 | long ret = 0; 59 | for (int i = 0; i < bytesToConvert; i++) 60 | { 61 | ret = unchecked((ret << 8) | buffer[startIndex + i]); 62 | } 63 | 64 | return ret; 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /Scripts/Util/Conversions/BigEndianBitConverter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c4842728e16e1c749b94d249f0471d2c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/Conversions/DoubleConverter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 92831c3b43cfd9142a0e87bcb195baf9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/Conversions/EndianBitConverter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ffb6e3f73d0831b458ec11b84167e172 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/Conversions/Endianness.cs: -------------------------------------------------------------------------------- 1 | namespace ElasticSea.Framework.Util.Conversions 2 | { 3 | /// 4 | /// Endianness of a converter 5 | /// 6 | public enum Endianness 7 | { 8 | /// 9 | /// Little endian - least significant byte first 10 | /// 11 | LittleEndian, 12 | 13 | /// 14 | /// Big endian - most significant byte first 15 | /// 16 | BigEndian 17 | } 18 | } -------------------------------------------------------------------------------- /Scripts/Util/Conversions/Endianness.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 46d37ef2b6991074d9e967212809dd49 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/Conversions/LittleEndianBitConverter.cs: -------------------------------------------------------------------------------- 1 | namespace ElasticSea.Framework.Util.Conversions 2 | { 3 | /// 4 | /// Implementation of EndianBitConverter which converts to/from little-endian 5 | /// byte arrays. 6 | /// 7 | public sealed class LittleEndianBitConverter : EndianBitConverter 8 | { 9 | /// 10 | /// Indicates the byte order ("endianess") in which data is converted using this class. 11 | /// 12 | /// 13 | /// Different computer architectures store data using different byte orders. "Big-endian" 14 | /// means the most significant byte is on the left end of a word. "Little-endian" means the 15 | /// most significant byte is on the right end of a word. 16 | /// 17 | /// true if this converter is little-endian, false otherwise. 18 | public sealed override bool IsLittleEndian() 19 | { 20 | return true; 21 | } 22 | 23 | /// 24 | /// Indicates the byte order ("endianess") in which data is converted using this class. 25 | /// 26 | public sealed override Endianness Endianness 27 | { 28 | get { return Endianness.LittleEndian; } 29 | } 30 | 31 | /// 32 | /// Copies the specified number of bytes from value to buffer, starting at index. 33 | /// 34 | /// The value to copy 35 | /// The number of bytes to copy 36 | /// The buffer to copy the bytes into 37 | /// The index to start at 38 | protected override void CopyBytesImpl(long value, int bytes, byte[] buffer, int index) 39 | { 40 | for (int i = 0; i < bytes; i++) 41 | { 42 | buffer[i + index] = unchecked((byte) (value & 0xff)); 43 | value = value >> 8; 44 | } 45 | } 46 | 47 | /// 48 | /// Returns a value built from the specified number of bytes from the given buffer, 49 | /// starting at index. 50 | /// 51 | /// The data in byte array format 52 | /// The first index to use 53 | /// The number of bytes to use 54 | /// The value built from the given bytes 55 | protected override long FromBytes(byte[] buffer, int startIndex, int bytesToConvert) 56 | { 57 | long ret = 0; 58 | for (int i = 0; i < bytesToConvert; i++) 59 | { 60 | ret = unchecked((ret << 8) | buffer[startIndex + bytesToConvert - 1 - i]); 61 | } 62 | 63 | return ret; 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /Scripts/Util/Conversions/LittleEndianBitConverter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: da7fe0a41490c9f4cb187d94d2d6d82a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/CylinderBounds.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Scripts.Util 5 | { 6 | [Serializable] 7 | public struct CylinderBounds 8 | { 9 | public float Height; 10 | public float Radius; 11 | public Vector3 Center; 12 | 13 | public CylinderBounds(Vector3 center, float radius, float height) 14 | { 15 | Height = height; 16 | Radius = radius; 17 | Center = center; 18 | } 19 | 20 | public Vector3 BottomCenter() 21 | { 22 | return Center - new Vector3(0, Height / 2, 0); 23 | } 24 | 25 | public Vector3 TopCenter() 26 | { 27 | return Center + new Vector3(0, Height / 2, 0); 28 | } 29 | 30 | public static bool operator ==(CylinderBounds c1, CylinderBounds c2) 31 | { 32 | return c1.Equals(c2); 33 | } 34 | 35 | public static bool operator !=(CylinderBounds c1, CylinderBounds c2) 36 | { 37 | return !c1.Equals(c2); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Scripts/Util/CylinderBounds.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 02d361494bbf47269f15ef65f0161fff 3 | timeCreated: 1679242266 -------------------------------------------------------------------------------- /Scripts/Util/DI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 277184506e799f94899e342a2e9eec81 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Scripts/Util/DI/DependencyInjection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ElasticSea.Framework.Scripts.Util.DI 4 | { 5 | public class DependencyInjectionAttribute : Attribute 6 | { 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /Scripts/Util/DI/DependencyInjection.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2c6666346bee0a14fadd3e90a9e0bd12 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/DI/DependencyInjectionUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using UnityEngine; 6 | 7 | namespace ElasticSea.Framework.Scripts.Util.DI 8 | { 9 | public static class DependencyInjectionUtils 10 | { 11 | private static Dictionary action)>> dict = new Dictionary action)>>(); 12 | private static List<(Type fieldType, Action action)> GetSetters(object mb) 13 | { 14 | var setters = new List<(Type, Action)>(); 15 | 16 | Type type= mb.GetType(); 17 | while (type != null && type != typeof(MonoBehaviour)) 18 | { 19 | var fields = type 20 | .GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) 21 | .Where(f => f.GetCustomAttribute() != null) 22 | .Select(f => (f.FieldType, (Action) ((m, value) => f.SetValue(m, value)))); 23 | 24 | var properties = type 25 | .GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) 26 | .Where(f => f.GetCustomAttribute() != null) 27 | .Select(f => (f.PropertyType, (Action) ((m, value) => f.SetValue(m, value)))); 28 | 29 | setters.AddRange(fields); 30 | setters.AddRange(properties); 31 | 32 | type = type.BaseType; 33 | } 34 | 35 | return setters; 36 | } 37 | 38 | public static void InjectGameobject(GameObject target, Dictionary map) 39 | { 40 | var monoBehaviours = target 41 | .GetComponentsInChildren(true) 42 | .Where(mb => mb != null); 43 | 44 | foreach (var mb in monoBehaviours) 45 | { 46 | Inject(mb, map); 47 | } 48 | } 49 | 50 | public static void Inject(object target, Dictionary map) 51 | { 52 | if (dict.ContainsKey(target.GetType()) == false) 53 | { 54 | dict[target.GetType()] = GetSetters(target); 55 | } 56 | 57 | var list = dict[target.GetType()]; 58 | for (var i = 0; i < list.Count; i++) 59 | { 60 | var (fieldType, action) = list[i]; 61 | if (map.ContainsKey(fieldType)) 62 | { 63 | action(target, map[fieldType]); 64 | } 65 | } 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /Scripts/Util/DI/DependencyInjectionUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5e91003fcb0e42999987c4f00a1584a6 3 | timeCreated: 1648061511 -------------------------------------------------------------------------------- /Scripts/Util/DebugActions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TMPro; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | 6 | namespace ElasticSea.Framework.Scripts.Util 7 | { 8 | public class DebugActions : MonoBehaviour 9 | { 10 | [SerializeField] private Transform container; 11 | [SerializeField] private Button buttonPrefab; 12 | 13 | public void AddAction(string action, Action callback) 14 | { 15 | var button = Instantiate(buttonPrefab); 16 | button.onClick.AddListener(() => callback()); 17 | button.GetComponentInChildren().text = action; 18 | button.transform.SetParent(container); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Scripts/Util/DebugActions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a17ffcdd816d5ad49a80359ca1c85792 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/DontDestroyOnLoad.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Scripts.Util 4 | { 5 | public class DontDestroyOnLoad : MonoBehaviour 6 | { 7 | private void Awake() 8 | { 9 | DontDestroyOnLoad(gameObject); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Scripts/Util/DontDestroyOnLoad.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3510ddd1eba1483592c94bd32242c455 3 | timeCreated: 1683341611 -------------------------------------------------------------------------------- /Scripts/Util/Easing.cs: -------------------------------------------------------------------------------- 1 | namespace ElasticSea.Framework.Util 2 | { 3 | public enum Easing 4 | { 5 | Unset, 6 | Linear, 7 | InSine, 8 | OutSine, 9 | InOutSine, 10 | InQuad, 11 | OutQuad, 12 | InOutQuad, 13 | InCubic, 14 | OutCubic, 15 | InOutCubic, 16 | InQuart, 17 | OutQuart, 18 | InOutQuart, 19 | InQuint, 20 | OutQuint, 21 | InOutQuint, 22 | InExpo, 23 | OutExpo, 24 | InOutExpo, 25 | InCirc, 26 | OutCirc, 27 | InOutCirc, 28 | InElastic, 29 | OutElastic, 30 | InOutElastic, 31 | InBack, 32 | OutBack, 33 | InOutBack, 34 | InBounce, 35 | OutBounce, 36 | InOutBounce, 37 | Flash, 38 | InFlash, 39 | OutFlash, 40 | InOutFlash, 41 | } 42 | } -------------------------------------------------------------------------------- /Scripts/Util/Easing.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d6e8f4aecbcf42c9b839b4c6afc12728 3 | timeCreated: 1693690758 -------------------------------------------------------------------------------- /Scripts/Util/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f400d1231b9a4cb8b0c249065feacd29 3 | timeCreated: 1602683873 -------------------------------------------------------------------------------- /Scripts/Util/Editor/AssetPostprocessorUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using ElasticSea.Framework.Extensions; 6 | using UnityEditor; 7 | using UnityEngine; 8 | 9 | namespace ElasticSea.Framework.Scripts.Util 10 | { 11 | public class AssetPostprocessorUtils 12 | { 13 | public static void ProcessMeshes(AssetPostprocessor assetPostprocessor, GameObject gameObject, params (string filename, string modelname, Action action)[] definitions) 14 | { 15 | var aa = definitions.ToArray(); 16 | 17 | if (aa.Length == 0) 18 | { 19 | return; 20 | } 21 | 22 | var importer = (ModelImporter) assetPostprocessor.assetImporter; 23 | var filename = Path.GetFileNameWithoutExtension(importer.assetPath); 24 | 25 | var filenames = aa.Select(a => a.filename).ToSet(); 26 | 27 | if (filenames.Contains(filename, StringComparer.InvariantCultureIgnoreCase) == false) 28 | { 29 | return; 30 | } 31 | 32 | var dict = new Dictionary>>(); 33 | foreach (var (fname, modelname, action) in aa) 34 | { 35 | var mname = modelname.ToLowerInvariant(); 36 | if (dict.ContainsKey(mname) == false) 37 | { 38 | dict[mname] = new List>(); 39 | } 40 | 41 | dict[mname].Add(action); 42 | } 43 | 44 | foreach (var mf in gameObject.GetComponentsInChildren()) 45 | { 46 | var mesh = mf.sharedMesh; 47 | 48 | if (dict.TryGetValue(mesh.name.ToLowerInvariant(), out var actions)) 49 | { 50 | foreach (var action in actions) 51 | { 52 | action(mf); 53 | } 54 | } 55 | } 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /Scripts/Util/Editor/AssetPostprocessorUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f3313392b6148974eae82f96d5edbb32 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/Editor/EditorUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using UnityEditor; 5 | using UnityEditor.UIElements; 6 | using UnityEngine; 7 | using UnityEngine.UIElements; 8 | 9 | namespace ElasticSea.Framework.Scripts.Util.Editor 10 | { 11 | public class EditorUtils 12 | { 13 | public static List FindAssetsByType() where T : UnityEngine.Object 14 | { 15 | List assets = new List(); 16 | string[] guids = AssetDatabase.FindAssets(string.Format("t:{0}", typeof(T))); 17 | for( int i = 0; i < guids.Length; i++ ) 18 | { 19 | string assetPath = AssetDatabase.GUIDToAssetPath( guids[i] ); 20 | T asset = AssetDatabase.LoadAssetAtPath( assetPath ); 21 | if( asset != null ) 22 | { 23 | assets.Add(asset); 24 | } 25 | } 26 | return assets; 27 | } 28 | 29 | public static GameObject[] GetPrefabsAtPath(string path) 30 | { 31 | var assets = AssetDatabase.FindAssets($"t:Prefab", new[] { path }); 32 | var foundAssets = new List(); 33 | 34 | foreach (var guid in assets) 35 | { 36 | foundAssets.Add(AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid))); 37 | } 38 | 39 | return foundAssets.ToArray(); 40 | } 41 | 42 | public static VisualElement BuildInspectorPropertiesVisualElement(SerializedObject obj) 43 | { 44 | VisualElement container = new VisualElement {name = obj.targetObject.name}; 45 | 46 | SerializedProperty iterator = obj.GetIterator(); 47 | Type targetType = obj.targetObject.GetType(); 48 | List members = new List(targetType.GetMembers()); 49 | 50 | if (!iterator.NextVisible(true)) return container; 51 | do 52 | { 53 | if (iterator.propertyPath == "m_Script" && obj.targetObject != null) 54 | { 55 | continue; 56 | } 57 | PropertyField propertyField = new PropertyField(iterator.Copy()) 58 | { 59 | name = "PropertyField:" + iterator.propertyPath, 60 | }; 61 | propertyField.Bind(iterator.serializedObject); 62 | 63 | MemberInfo member = members.Find(x => x.Name == propertyField.bindingPath); 64 | if (member != null) 65 | { 66 | IEnumerable headers = member.GetCustomAttributes(typeof(HeaderAttribute)); 67 | IEnumerable spaces = member.GetCustomAttributes(typeof(SpaceAttribute)); 68 | foreach (Attribute x in headers) 69 | { 70 | HeaderAttribute actual = (HeaderAttribute) x; 71 | Label header = new Label { text = actual.header}; 72 | header.style.unityFontStyleAndWeight = FontStyle.Bold; 73 | container.Add(new Label { text = " ", name = "Header Spacer"}); 74 | container.Add(header); 75 | } 76 | foreach (Attribute unused in spaces) 77 | { 78 | container.Add(new Label { text = " " }); 79 | } 80 | } 81 | 82 | container.Add(propertyField); 83 | } 84 | while (iterator.NextVisible(false)); 85 | 86 | return container; 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /Scripts/Util/Editor/EditorUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e4283924e2914138bd49c924a7b3bf5c 3 | timeCreated: 1683353672 -------------------------------------------------------------------------------- /Scripts/Util/Editor/InspectorCategoryEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Util.Editor 5 | { 6 | [CustomEditor(typeof(InspectorCategory))] 7 | public class InspectorCategoryEditor : UnityEditor.Editor 8 | { 9 | public override void OnInspectorGUI() 10 | { 11 | var imageCategory = (InspectorCategory)target; 12 | var rect = EditorGUILayout.GetControlRect(false, 0f); 13 | rect.height = EditorGUIUtility.singleLineHeight * 1.4f; 14 | rect.y -= rect.height; 15 | rect.x = 0; 16 | rect.xMax += 30; 17 | rect.yMax = 15; 18 | 19 | EditorGUI.DrawRect(rect, new Color(0.2f, 0.2f, 0.2f, 1f)); 20 | 21 | var black = new GUIStyle(EditorStyles.label); 22 | black.normal.textColor = Color.white; 23 | black.fontSize = 18; 24 | 25 | var textRect = new Rect(rect); 26 | textRect.x += 10; 27 | imageCategory.Category = EditorGUI.TextField(textRect, imageCategory.Category, black); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Scripts/Util/Editor/InspectorCategoryEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 01c6504e7b684e3cb0bc66a1842d6bcd 3 | timeCreated: 1732688608 -------------------------------------------------------------------------------- /Scripts/Util/Editor/QuickActions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using UnityEditor; 4 | using UnityEngine; 5 | 6 | namespace ElasticSea.Framework.Util.Editor 7 | { 8 | public class QuickActions : EditorWindow 9 | { 10 | [MenuItem("Window/Quick Actions")] 11 | public static void ShowWindow() => GetWindow(typeof(QuickActions), false, "Quick Actions"); 12 | 13 | private void OnGUI() 14 | { 15 | if (GUILayout.Button("Show Persistent Folder")) 16 | { 17 | Utils.OpenInExplorer(Application.persistentDataPath); 18 | } 19 | 20 | if (GUILayout.Button("Clear Persistent Folder")) 21 | { 22 | Directory.Delete(Application.persistentDataPath, true); 23 | } 24 | 25 | if (GUILayout.Button("Build Folder")) 26 | { 27 | Utils.OpenInExplorer(Path.Combine(new DirectoryInfo(Application.dataPath).Parent.FullName, "Build")); 28 | } 29 | 30 | if (GUILayout.Button("Bump Build Version")) 31 | { 32 | var version = new Version(Application.version); 33 | 34 | var main = version.Minor; 35 | var patch = version.Build; 36 | var build = PlayerSettings.iOS.buildNumber.ToInt() + 1; 37 | UpdateVersion(main, patch, build); 38 | } 39 | 40 | if (GUILayout.Button("Bump Minor Version")) 41 | { 42 | var version = new Version(Application.version); 43 | 44 | var main = version.Minor; 45 | var patch = version.Build+ 1; 46 | var build = 0; 47 | UpdateVersion(main, patch, build); 48 | } 49 | 50 | if (GUILayout.Button("Bump Major Version")) 51 | { 52 | var version = new Version(Application.version); 53 | 54 | var main = version.Minor + 1; 55 | var patch = 0; 56 | var build = 0; 57 | UpdateVersion(main, patch, build); 58 | } 59 | } 60 | 61 | private void UpdateVersion(int main, int patch, int build) 62 | { 63 | PlayerSettings.iOS.buildNumber = build.ToString(); 64 | PlayerSettings.macOS.buildNumber = build.ToString(); 65 | PlayerSettings.Android.bundleVersionCode = Convert.ToInt32($"{main}{patch}{build.ToString().PadLeft(2, '0')}"); 66 | PlayerSettings.bundleVersion = $"0.{main}.{patch}"; 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /Scripts/Util/Editor/QuickActions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1048d08f22e149568d19be38cc4053dc 3 | timeCreated: 1603033491 -------------------------------------------------------------------------------- /Scripts/Util/Editor/ReadOnlyDrawer.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Util.Editor 5 | { 6 | [CustomPropertyDrawer(typeof(ReadOnlyAttribute))] 7 | public class ReadOnlyDrawer : PropertyDrawer { 8 | 9 | public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { 10 | return EditorGUI.GetPropertyHeight(property, label, true); 11 | } 12 | 13 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { 14 | 15 | GUI.enabled = false; 16 | EditorGUI.PropertyField(position, property, label, true); 17 | GUI.enabled = true; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Scripts/Util/Editor/ReadOnlyDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e81591bba16c40f6a254ba2b3824cbe1 3 | timeCreated: 1711492265 -------------------------------------------------------------------------------- /Scripts/Util/Editor/SceneList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using System.Linq; 4 | using UnityEditor; 5 | using UnityEditor.SceneManagement; 6 | using UnityEngine; 7 | 8 | namespace ElasticSea.Framework.Util.Editor 9 | { 10 | public class SceneList : EditorWindow 11 | { 12 | private IEnumerable scenes = Enumerable.Empty(); 13 | 14 | [MenuItem("Window/Scene List")] 15 | public static void ShowWindow() => GetWindow(typeof(SceneList), false, "Scenes"); 16 | 17 | private void Update() 18 | { 19 | var newScenes = EditorBuildSettings.scenes.ToList(); 20 | if (scenes.SequenceEqual(newScenes) == false) 21 | { 22 | scenes = EditorBuildSettings.scenes.ToList(); 23 | Repaint(); 24 | } 25 | } 26 | 27 | private void OnGUI() 28 | { 29 | EditorGUILayout.BeginVertical(); 30 | 31 | foreach (var scene in EditorBuildSettings.scenes) 32 | { 33 | var name = Path.GetFileNameWithoutExtension(scene.path); 34 | 35 | GUI.backgroundColor = scene.enabled ? new Color(0.9f, 0.9f, 0.9f) : new Color(0.4f, 0.4f, 0.4f); 36 | if (GUILayout.Button(name)) 37 | { 38 | EditorSceneManager.OpenScene(scene.path); 39 | } 40 | } 41 | EditorGUILayout.EndVertical(); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Scripts/Util/Editor/SceneList.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 38b5280e627d59e4c91fc18aff4dcaa2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/Editor/ScreenshotUtilityEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Util.Editor 5 | { 6 | [CustomEditor(typeof(ScreenshotUtility))] 7 | public class ScreenshotUtilityEditor : UnityEditor.Editor 8 | { 9 | public override void OnInspectorGUI() 10 | { 11 | base.OnInspectorGUI(); 12 | if (GUILayout.Button("Render")) 13 | { 14 | (target as ScreenshotUtility).Render(); 15 | } 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Scripts/Util/Editor/ScreenshotUtilityEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2a80b2ce02a4448aaeb74fcac5b59a49 3 | timeCreated: 1658166593 -------------------------------------------------------------------------------- /Scripts/Util/Editor/SimpleEditor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using JetBrains.Annotations; 4 | using UnityEngine; 5 | 6 | namespace ElasticSea.Framework.Util.Editor 7 | { 8 | public abstract class SimpleEditor : UnityEditor.Editor 9 | { 10 | private object selected; 11 | protected abstract void OnGui(); 12 | 13 | public override void OnInspectorGUI() 14 | { 15 | base.OnInspectorGUI(); 16 | OnGui(); 17 | } 18 | 19 | protected T? SelectBox(IEnumerable elements, T? selected, Action callback) where T : struct, Enum 20 | { 21 | GUILayout.BeginHorizontal(); 22 | foreach (var e in elements) 23 | { 24 | var isSelected = Equals(selected, e); 25 | GUI.enabled = isSelected == false; 26 | if (GUILayout.Button(e.ToString())) 27 | { 28 | selected = e; 29 | callback(e); 30 | } 31 | GUI.enabled = true; 32 | } 33 | GUILayout.EndHorizontal(); 34 | return selected; 35 | } 36 | 37 | protected void ButtonsBox(IEnumerable elements, Action callback) 38 | { 39 | GUILayout.BeginHorizontal(); 40 | foreach (var e in elements) 41 | { 42 | if (GUILayout.Button(e.ToString())) 43 | { 44 | callback(e); 45 | } 46 | } 47 | GUILayout.EndHorizontal(); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Scripts/Util/Editor/SimpleEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d62c5908d83a4cd182b4c94a4760a0ed 3 | timeCreated: 1661433827 -------------------------------------------------------------------------------- /Scripts/Util/Editor/Tools.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Linq; 3 | using UnityEditor; 4 | using UnityEngine; 5 | 6 | namespace ElasticSea.Framework.Util.Editor 7 | { 8 | public class Tools 9 | { 10 | [MenuItem("Tools/Find duplicate resources")] 11 | public static void FixResource() 12 | { 13 | var groupedPaths = Directory 14 | .EnumerateDirectories(Application.dataPath, "Resources", SearchOption.AllDirectories) 15 | .Select(path => path.ToLowerInvariant()) 16 | .SelectMany(resourceDirPath => Directory.EnumerateFiles(resourceDirPath, "*", SearchOption.AllDirectories) 17 | .Select(path => path.ToLowerInvariant()) 18 | .Where(file => Path.GetExtension(file) != ".meta") 19 | .Select(file => (root:resourceDirPath, relative:file.Substring(resourceDirPath.Length + 1)))).GroupBy(tuple => tuple.Item2) 20 | .ToDictionary(g => g.Key, g => g.ToArray()); 21 | 22 | var duplicateResourcePaths = groupedPaths.Where(a => a.Value.Length > 1); 23 | 24 | foreach (var (resourceDirPath, grouped) in duplicateResourcePaths) 25 | { 26 | Debug.Log($"{resourceDirPath} {grouped.Length}"); 27 | for (var i = 0; i < grouped.Length; i++) 28 | { 29 | Debug.Log($"{i} {grouped[i].root}"); 30 | } 31 | } 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Scripts/Util/Editor/Tools.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 38e05ff93e584239a8328dfdcea0a9ef 3 | timeCreated: 1703591715 -------------------------------------------------------------------------------- /Scripts/Util/EnumUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ElasticSea.Framework.Util 4 | { 5 | public class EnumUtils where T : Enum 6 | { 7 | public static T Get(string name, bool ignoreCase = false) 8 | { 9 | return (T) Enum.Parse(typeof(T), name, ignoreCase); 10 | } 11 | 12 | public static int Count 13 | { 14 | get 15 | { 16 | if (!typeof(T).IsEnum) 17 | throw new ArgumentException("T must be an enumerated type"); 18 | 19 | return Enum.GetNames(typeof(T)).Length; 20 | } 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Scripts/Util/EnumUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 58f3bf4dc3a441c438acf536c72dc1ed 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/FastBounds.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using UnityEngine; 3 | 4 | namespace Blocks.Meshbakers 5 | { 6 | public class FastBounds 7 | { 8 | public Vector3 Min; 9 | public Vector3 Max; 10 | public Vector3 Size; 11 | 12 | public FastBounds(Bounds bounds) : this(bounds.min, bounds.max) 13 | { 14 | } 15 | 16 | public FastBounds(Vector3 min, Vector3 max) 17 | { 18 | Min = min; 19 | Max = max; 20 | Size = max - min; 21 | } 22 | 23 | public Vector3[] Vertices() 24 | { 25 | return new[] 26 | { 27 | new Vector3(Min.x, Min.y, Min.z), 28 | new Vector3(Min.x, Min.y, Max.z), 29 | new Vector3(Min.x, Max.y, Min.z), 30 | new Vector3(Min.x, Max.y, Max.z), 31 | new Vector3(Max.x, Min.y, Min.z), 32 | new Vector3(Max.x, Min.y, Max.z), 33 | new Vector3(Max.x, Max.y, Min.z), 34 | new Vector3(Max.x, Max.y, Max.z), 35 | }; 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Scripts/Util/FastBounds.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f63af0a577f341a1989b1509d132c9ad 3 | timeCreated: 1691258271 -------------------------------------------------------------------------------- /Scripts/Util/FastPool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Util 5 | { 6 | public class FastPool 7 | { 8 | private readonly Func creator; 9 | 10 | private T[] pool; 11 | private int count; 12 | private int poolSize; 13 | 14 | public FastPool(int initialCapacity, Func creator) 15 | { 16 | pool = new T[initialCapacity]; 17 | poolSize = pool.Length; 18 | this.creator = creator; 19 | 20 | for (var i = 0; i < initialCapacity; i++) 21 | { 22 | Put(creator()); 23 | } 24 | } 25 | 26 | public T Get() 27 | { 28 | if (count == 0) 29 | { 30 | return creator(); 31 | } 32 | 33 | return pool[--count]; 34 | } 35 | 36 | public void Put(T element) 37 | { 38 | if (count == poolSize) 39 | { 40 | var oldPool = pool; 41 | pool = new T[Mathf.Max(poolSize, 1) * 2]; 42 | Array.Copy(oldPool, pool, poolSize); 43 | poolSize = pool.Length; 44 | } 45 | pool[count++] = element; 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Scripts/Util/FastPool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e6838e718639493e9b3091c855b0e89c 3 | timeCreated: 1668731206 -------------------------------------------------------------------------------- /Scripts/Util/FastPoolWithCallback.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Util 5 | { 6 | public class FastPoolWithCallback 7 | { 8 | private readonly Func creator; 9 | private readonly Action putCallback; 10 | private readonly Action getCallback; 11 | 12 | private T[] pool; 13 | private int count; 14 | private int poolSize; 15 | 16 | public FastPoolWithCallback(int initialCapacity, Func creator, Action putCallback = null, Action getCallback = null) 17 | { 18 | pool = new T[initialCapacity]; 19 | poolSize = pool.Length; 20 | this.creator = creator; 21 | this.putCallback = putCallback; 22 | this.getCallback = getCallback; 23 | 24 | for (var i = 0; i < initialCapacity; i++) 25 | { 26 | Put(creator()); 27 | } 28 | } 29 | 30 | public T Get() 31 | { 32 | if (count == 0) 33 | { 34 | return creator(); 35 | } 36 | 37 | var element = pool[--count]; 38 | getCallback?.Invoke(element); 39 | return element; 40 | } 41 | 42 | public void Put(T element) 43 | { 44 | putCallback?.Invoke(element); 45 | 46 | if (count == poolSize) 47 | { 48 | var oldPool = pool; 49 | pool = new T[Mathf.Max(poolSize, 1) * 2]; 50 | Array.Copy(oldPool, pool, poolSize); 51 | poolSize = pool.Length; 52 | } 53 | pool[count++] = element; 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /Scripts/Util/FastPoolWithCallback.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a9cc00a7807d449a85314e63e5d4cf74 3 | timeCreated: 1736394425 -------------------------------------------------------------------------------- /Scripts/Util/FasterBounds.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util 4 | { 5 | public struct FasterBounds 6 | { 7 | public FasterBounds(float xmin, float ymin, float zmin, float xmax, float ymax, float zmax) 8 | { 9 | this.xmin = xmin; 10 | this.ymin = ymin; 11 | this.zmin = zmin; 12 | this.xmax = xmax; 13 | this.ymax = ymax; 14 | this.zmax = zmax; 15 | } 16 | 17 | public Bounds ToBounds() 18 | { 19 | var min = new Vector3(xmin, ymin, zmin); 20 | var max = new Vector3(xmax, ymax, zmax); 21 | return Utils.Bounds(min, max); 22 | } 23 | 24 | public float xmin; 25 | public float ymin; 26 | public float zmin; 27 | public float xmax; 28 | public float ymax; 29 | public float zmax; 30 | } 31 | } -------------------------------------------------------------------------------- /Scripts/Util/FasterBounds.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 57b082c393574b8f8477fc61a51d13fb 3 | timeCreated: 1705711754 -------------------------------------------------------------------------------- /Scripts/Util/GameGizmoUtils.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using ElasticSea.Framework.Extensions; 4 | using UnityEngine; 5 | 6 | namespace ElasticSea.Framework.Scripts.Util 7 | { 8 | public class GameGizmoUtils 9 | { 10 | public static GameObject DrawArrow(Vector3 from, Vector3 to, Color color, float killDelay = 0f) 11 | { 12 | return DrawArrow(from, to, from.Distance(to)/4, color, color, killDelay); 13 | } 14 | 15 | public static GameObject DrawArrow(Vector3 from, Vector3 to, float arrowHeadLength, Color bottom, Color top, float killDelay = 0f) 16 | { 17 | var go = new GameObject("Arrow"); 18 | go.AddComponent().mesh = BuildArrowMesh(to.Distance(from), arrowHeadLength, bottom, top); 19 | go.AddComponent().material = new Material(Shader.Find("Unlit/Vertex Color")); 20 | go.transform.position = from; 21 | go.transform.LookAt(to); 22 | go.transform.rotation *= Quaternion.Euler(90, 0, 0); 23 | 24 | if (killDelay > 0) 25 | { 26 | Object.Destroy(go, killDelay); 27 | } 28 | return go; 29 | } 30 | 31 | private static Mesh BuildArrowMesh(float distance, float arrowHeadLength, Color bottom, Color top) 32 | { 33 | var arrowHeadRadius = arrowHeadLength / 2.5f; 34 | var arrowLength = distance - arrowHeadLength; 35 | var segments = 32; 36 | var lineRadius = arrowHeadRadius / 4; 37 | 38 | var points = new List(); 39 | var segment = Mathf.PI * 2 / segments; 40 | for (int i = 0; i < segments; i++) 41 | { 42 | var x = Mathf.Cos(segment * i) * arrowHeadRadius; 43 | var y = Mathf.Sin(segment * i) * arrowHeadRadius; 44 | points.Add(new Vector3(x, arrowLength, y)); 45 | } 46 | 47 | var meshBuilder = new MeshBuilder(); 48 | 49 | // arrow head 50 | meshBuilder.AddCircle(points.ToArray(), new Vector3(0, arrowLength + arrowHeadLength, 0)); 51 | meshBuilder.AddCircle(points.ToArray(), new Vector3(0, arrowLength, 0), true); 52 | 53 | var points2 = new List(); 54 | for (int i = 0; i < segments; i++) 55 | { 56 | var x = Mathf.Cos(segment * i) * lineRadius; 57 | var y = Mathf.Sin(segment * i) * lineRadius; 58 | points2.Add(new Vector3(x, 0, y)); 59 | } 60 | 61 | var pointsBottom = points2.Select(p => new Vector3(p.x, arrowLength, p.z)).ToArray(); 62 | meshBuilder.AddStrip(points2.ToArray(), pointsBottom); 63 | meshBuilder.AddCircle(points2.ToArray(), new Vector3(0, 0, 0), true); 64 | var buildArrow = meshBuilder.GetMesh(); 65 | buildArrow.colors = buildArrow.vertices.Select(v => Color.Lerp(bottom, top, v.y / distance)).ToArray(); 66 | return buildArrow; 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /Scripts/Util/GameGizmoUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 636dc116c58946cea7f8f0956bf4b821 3 | timeCreated: 1688248161 -------------------------------------------------------------------------------- /Scripts/Util/GameObjectStates.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Scripts.Util 4 | { 5 | public class GameObjectStates 6 | { 7 | private GameObject[] gameObjects; 8 | 9 | public GameObjectStates(params GameObject[] gameObjects) 10 | { 11 | this.gameObjects = gameObjects; 12 | } 13 | 14 | public void Show(GameObject showGameObject) 15 | { 16 | var length = gameObjects.Length; 17 | for (var i = 0; i < length; i++) 18 | { 19 | var gameobject = gameObjects[i]; 20 | gameobject.SetActive(showGameObject == gameobject); 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Scripts/Util/GameObjectStates.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2760d6c26aed8c94588dfbb9ace32fcb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/GizmoUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2e5d1e34cda8944439802b7bdab758f7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/Gizmos.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8b110af83f634bdc95186b5805d1eef2 3 | timeCreated: 1708057236 -------------------------------------------------------------------------------- /Scripts/Util/Gizmos/EditorGizmoProvider.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util.Gizmo 4 | { 5 | public class EditorGizmoProvider : IGizmoProvider 6 | { 7 | public Matrix4x4 Matrix 8 | { 9 | set => Gizmos.matrix = value; 10 | } 11 | 12 | public Color Color 13 | { 14 | set => Gizmos.color = value; 15 | } 16 | 17 | public void DrawLine(Vector3 from, Vector3 to) 18 | { 19 | Gizmos.DrawLine(from, to); 20 | } 21 | 22 | public void DrawRay(Vector3 from, Vector3 direction) 23 | { 24 | Gizmos.DrawRay(from, direction); 25 | } 26 | 27 | public void DrawWireCapsule(Vector3 from, Vector3 to, float radius) 28 | { 29 | GizmoUtils.DrawWireCapsule(from, to, radius); 30 | } 31 | 32 | public void DrawWireCircle(Vector3 from, Vector3 normal, float radius) 33 | { 34 | GizmoUtils.DrawCircle(from, normal, radius, 32); 35 | } 36 | 37 | public void DrawSphere(Vector3 center, float radius) 38 | { 39 | Gizmos.DrawSphere(center, radius); 40 | } 41 | 42 | public void DrawWireSphere(Vector3 center, float radius) 43 | { 44 | Gizmos.DrawWireSphere(center, radius); 45 | } 46 | 47 | public void DrawWireCube(Vector3 center, Vector3 size) 48 | { 49 | Gizmos.DrawWireCube(center, size); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Scripts/Util/Gizmos/EditorGizmoProvider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a7c8785971204e5687fb1b0f78fa8c72 3 | timeCreated: 1708057937 -------------------------------------------------------------------------------- /Scripts/Util/Gizmos/GameGizmoProvider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 17c759b804924b65aa8393c5b70da099 3 | timeCreated: 1707954444 -------------------------------------------------------------------------------- /Scripts/Util/Gizmos/IGizmoPresenter.cs: -------------------------------------------------------------------------------- 1 | using ElasticSea.Framework.Extensions; 2 | using ElasticSea.Framework.Scripts.Util; 3 | using ElasticSea.Framework.Util.Callbacks; 4 | using UnityEngine; 5 | 6 | namespace ElasticSea.Framework.Util.Gizmo 7 | { 8 | public interface IGizmoPresenter 9 | { 10 | void OnGameOrEditorGizmoDraw(IGizmoProvider provider); 11 | 12 | public static void Setup(IGizmoPresenter presenter, MonoBehaviour target, Camera camera = null) 13 | { 14 | #if UNITY_EDITOR 15 | 16 | var gameGizmoProvider = new GameGizmoProvider(CreateMaterial(), MeshUtils.Icosphere(1)); 17 | var editorGizmoProvider = new EditorGizmoProvider(); 18 | 19 | void Draw(IGizmoProvider provider) 20 | { 21 | provider.Color = Color.white; 22 | provider.Matrix = Matrix4x4.identity; 23 | presenter.OnGameOrEditorGizmoDraw(provider); 24 | } 25 | 26 | camera = camera ?? Camera.main; 27 | if (camera) 28 | { 29 | camera.gameObject.GetOrAddComponent().OnPostRenderEvent += () => Draw(gameGizmoProvider); 30 | } 31 | 32 | target.gameObject.GetOrAddComponent().OnDrawGizmosEvent += () => Draw(editorGizmoProvider); 33 | #endif 34 | } 35 | 36 | public static void SetupGame(IGizmoPresenter presenter, Camera camera = null) 37 | { 38 | #if UNITY_EDITOR 39 | 40 | var gameGizmoProvider = new GameGizmoProvider(CreateMaterial(), MeshUtils.Icosphere(1)); 41 | 42 | void Draw(IGizmoProvider provider) 43 | { 44 | provider.Color = Color.white; 45 | provider.Matrix = Matrix4x4.identity; 46 | presenter.OnGameOrEditorGizmoDraw(provider); 47 | } 48 | 49 | camera = camera ?? Camera.main; 50 | camera.gameObject.GetOrAddComponent().OnPostRenderEvent += () => Draw(gameGizmoProvider); 51 | #endif 52 | } 53 | 54 | public static void DrawEditor(IGizmoPresenter presenter) 55 | { 56 | #if UNITY_EDITOR 57 | 58 | var editorGizmoProvider = new EditorGizmoProvider(); 59 | editorGizmoProvider.Color = Color.white; 60 | editorGizmoProvider.Matrix = Matrix4x4.identity; 61 | presenter.OnGameOrEditorGizmoDraw(editorGizmoProvider); 62 | #endif 63 | } 64 | 65 | private static Material CreateMaterial() 66 | { 67 | // Unity has a built-in shader that is useful for drawing 68 | // simple colored things. 69 | Shader shader = Shader.Find("Hidden/Internal-Colored"); 70 | var lineMaterial = new Material(shader); 71 | lineMaterial.hideFlags = HideFlags.HideAndDontSave; 72 | // Turn on alpha blending 73 | // lineMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); 74 | // lineMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); 75 | // Turn backface culling off 76 | lineMaterial.SetInt("_Cull", 0); 77 | // Turn off depth writes 78 | lineMaterial.SetInt("_ZWrite", 0); 79 | // Dont test the depth buffer 80 | lineMaterial.SetInt("_ZTest", 0); 81 | // Write at the end after everything 82 | lineMaterial.renderQueue = 5000; 83 | return lineMaterial; 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /Scripts/Util/Gizmos/IGizmoPresenter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7d7e1231fcab423b89fa94127bc4d7f4 3 | timeCreated: 1708058325 -------------------------------------------------------------------------------- /Scripts/Util/Gizmos/IGizmoProvider.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util.Gizmo 4 | { 5 | public interface IGizmoProvider 6 | { 7 | public Matrix4x4 Matrix { set; } 8 | public Color Color { set; } 9 | public void DrawLine(Vector3 from, Vector3 to); 10 | public void DrawRay(Vector3 from, Vector3 direction); 11 | public void DrawWireCapsule(Vector3 from, Vector3 to, float radius); 12 | public void DrawWireCircle(Vector3 center, Vector3 normal, float radius); 13 | public void DrawSphere(Vector3 center, float radius); 14 | public void DrawWireSphere(Vector3 center, float radius); 15 | public void DrawWireCube(Vector3 center, Vector3 size); 16 | } 17 | } -------------------------------------------------------------------------------- /Scripts/Util/Gizmos/IGizmoProvider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b68f266c6f794d0bb8ce924e436f9524 3 | timeCreated: 1708057271 -------------------------------------------------------------------------------- /Scripts/Util/GuildGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ElasticSea.Framework.Util; 3 | 4 | namespace ElasticSea.Framework.Scripts.Util 5 | { 6 | public class GuidGenerator 7 | { 8 | private readonly int length; 9 | private readonly HashSet taken; 10 | 11 | public GuidGenerator(int length) 12 | { 13 | this.length = length; 14 | this.taken = new HashSet(); 15 | } 16 | 17 | public string Next() 18 | { 19 | return Utils.GetUniqueHexNumber(taken, length); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Scripts/Util/GuildGenerator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 44a28689e52d76b439fd99bb68835ba1 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/Icons.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f889841c4e9966b48abcf4a664a7902e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Scripts/Util/Icons/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d6e3996dd64443d48ddcc894c08e0945 3 | timeCreated: 1683353726 -------------------------------------------------------------------------------- /Scripts/Util/Icons/Editor/IconExplorer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using DG.DOTweenEditor; 6 | using ElasticSea.Framework.Extensions; 7 | using UnityEditor; 8 | using UnityEngine; 9 | using EditorUtils = ElasticSea.Framework.Scripts.Util.Editor.EditorUtils; 10 | 11 | namespace ElasticSea.Framework.Scripts.Util.Icons 12 | { 13 | public class IconExplorer : EditorWindow 14 | { 15 | private IconFont pack; 16 | private string filterName; 17 | private int limit = 10; 18 | private bool dirty = true; 19 | private IEnumerable<(string name, int code)> configIcons; 20 | private Vector2 scrollPos; 21 | 22 | [MenuItem("Window/Icon Explorer")] 23 | public static IconExplorer Show() 24 | { 25 | return GetWindow("Icon Explorer"); 26 | } 27 | 28 | private void OnGUI() 29 | { 30 | var prevPack = pack; 31 | pack = (IconFont) EditorGUILayout.ObjectField(pack, typeof(IconFont), true); 32 | 33 | GUILayout.BeginHorizontal(); 34 | foreach (var font in EditorUtils.FindAssetsByType()) 35 | { 36 | if (GUILayout.Button(font.name)) 37 | { 38 | pack = font; 39 | } 40 | } 41 | GUILayout.EndHorizontal(); 42 | 43 | if (pack != prevPack) dirty = true; 44 | if (pack == null) return; 45 | var fontStyle = new GUIStyle(GUI.skin.label) {font = pack.Font, fontSize = 32}; 46 | 47 | EditorGUILayout.BeginHorizontal(); 48 | 49 | EditorGUILayout.BeginVertical(); 50 | EditorGUILayout.LabelField("Name"); 51 | var prevFilterName = filterName; 52 | filterName = EditorGUILayout.TextField(filterName); 53 | if (filterName != prevFilterName) dirty = true; 54 | EditorGUILayout.EndVertical(); 55 | 56 | EditorGUILayout.BeginVertical(); 57 | EditorGUILayout.LabelField("Limit"); 58 | var prevLimit = limit; 59 | limit = int.Parse(EditorGUILayout.TextField(limit.ToString())); 60 | if (limit != prevLimit) dirty = true; 61 | EditorGUILayout.EndVertical(); 62 | EditorGUILayout.EndHorizontal(); 63 | EditorGUILayout.Space(); 64 | 65 | if (configIcons == null || dirty) 66 | { 67 | var codepoints = new HashSet(); 68 | foreach (var c in filterName.Split(",").Select(s => ParseNoException(s, NumberStyles.HexNumber)).Where(c => c != 0)) 69 | { 70 | codepoints.Add(c); 71 | } 72 | foreach (var c in filterName.Split(",").Where(c => c.Length > 0)) 73 | { 74 | codepoints.Add(c[0]); 75 | } 76 | 77 | configIcons = GenerateConfig(pack) 78 | .Where(pair => filterName.IsNullOrEmpty() || pair.name.Contains(filterName) || codepoints.Contains(pair.code)) 79 | .Take(limit) 80 | .ToList(); 81 | } 82 | 83 | EditorGUILayout.BeginHorizontal(); 84 | scrollPos = EditorGUILayout.BeginScrollView(scrollPos); 85 | foreach (var (name, code) in configIcons.Select(x => (x.name, x.code))) 86 | { 87 | EditorGUILayout.BeginHorizontal(); 88 | if (GUILayout.Button(((char) code).ToString(), fontStyle, GUILayout.MinWidth(50), GUILayout.MinHeight(50),GUILayout.MaxWidth(50), GUILayout.MaxHeight(50))) 89 | { 90 | EditorGUIUtility.systemCopyBuffer = char.ToString((char)code); 91 | } 92 | EditorGUILayout.BeginVertical(); 93 | EditorGUILayout.TextField(name, GUILayout.ExpandWidth(false),GUILayout.MinHeight(25)); 94 | EditorGUILayout.TextField("U+" + code.ToString("X4"),GUILayout.MinHeight(25)); 95 | EditorGUILayout.EndVertical(); 96 | 97 | EditorGUILayout.EndHorizontal(); 98 | } 99 | EditorGUILayout.EndScrollView(); 100 | EditorGUILayout.EndHorizontal(); 101 | 102 | dirty = false; 103 | } 104 | 105 | private int ParseNoException(string text, NumberStyles numberStyles) 106 | { 107 | try 108 | { 109 | return int.Parse(text, numberStyles); 110 | } 111 | catch (Exception e) 112 | { 113 | return 0; 114 | } 115 | } 116 | 117 | private IEnumerable<(string name, int code)> GenerateConfig(IconFont iconPack) 118 | { 119 | return iconPack.CodePoints 120 | .Replace('\r', '\n') 121 | .Split('\n') 122 | .Where(s => s.IsNullOrEmpty() == false) 123 | .Select(s => 124 | { 125 | var split = s.Split(' '); 126 | var name = split[0]; 127 | var code = int.Parse(split[1], System.Globalization.NumberStyles.HexNumber); 128 | return (name, code); 129 | }); 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /Scripts/Util/Icons/Editor/IconExplorer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: efc2cb14f93248018b6d646e2a235663 3 | timeCreated: 1646499959 -------------------------------------------------------------------------------- /Scripts/Util/Icons/IconFont.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Scripts.Util.Icons 4 | { 5 | [CreateAssetMenu(fileName = "Icon Font", menuName = "Icons/Icon Font")] 6 | public class IconFont : ScriptableObject 7 | { 8 | [SerializeField] private Font font; 9 | [SerializeField] private TextAsset codepoints; 10 | 11 | public Font Font => font; 12 | public string CodePoints => codepoints.text; 13 | } 14 | } -------------------------------------------------------------------------------- /Scripts/Util/Icons/IconFont.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 097d01ff05f844ed9f55c0f74f8faabb 3 | timeCreated: 1683138935 -------------------------------------------------------------------------------- /Scripts/Util/InspectorCategory.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util 4 | { 5 | // Shows as a header in inspector and can be used for organizing the scripts 6 | public class InspectorCategory : MonoBehaviour 7 | { 8 | public string Category = "Category"; 9 | } 10 | } -------------------------------------------------------------------------------- /Scripts/Util/InspectorCategory.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b2da2c1dabf647a38542c54cb03432ee 3 | timeCreated: 1732688584 -------------------------------------------------------------------------------- /Scripts/Util/LayoutUtils.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | #if UNITY_EDITOR 5 | namespace ElasticSea.Framework.Util 6 | { 7 | public static class LayoutUtils 8 | { 9 | public static void Line(int height = 1, Color? color = null) 10 | { 11 | var rect = EditorGUILayout.GetControlRect(false, height); 12 | rect.height = height; 13 | EditorGUI.DrawRect(rect, color ?? new Color(0.5f, 0.5f, 0.5f, 1)); 14 | } 15 | } 16 | } 17 | #endif -------------------------------------------------------------------------------- /Scripts/Util/LayoutUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0b9d893c300d942409c64d24114cfe05 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/Line.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util 4 | { 5 | public struct Line 6 | { 7 | private readonly Vector3 start; 8 | private readonly Vector3 direction; 9 | private readonly float length; 10 | 11 | public Line(Ray ray, float length) : this(ray.origin, ray.direction, length) 12 | { 13 | } 14 | 15 | public Line(Vector3 start, Vector3 end) : this(start, (end-start).normalized, (end-start).magnitude) 16 | { 17 | } 18 | 19 | public Line(Vector3 start, Vector3 direction, float length) 20 | { 21 | this.start = start; 22 | this.direction = direction; 23 | this.length = length; 24 | } 25 | 26 | public Vector3 Start => start; 27 | public Vector3 End => start + direction * length; 28 | } 29 | } -------------------------------------------------------------------------------- /Scripts/Util/Line.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a711fc072e45410eb56eea76ef394bc3 3 | timeCreated: 1744575840 -------------------------------------------------------------------------------- /Scripts/Util/LookAtTransform.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Serialization; 3 | 4 | namespace ElasticSea.Framework.Scripts.Util 5 | { 6 | public class LookAtTransform : MonoBehaviour 7 | { 8 | public Transform target; 9 | 10 | public Transform Target 11 | { 12 | get => target; 13 | set 14 | { 15 | target = value; 16 | Update(); 17 | } 18 | } 19 | 20 | public void Update() 21 | { 22 | transform.rotation = Quaternion.LookRotation(target.forward, target.up); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Scripts/Util/LookAtTransform.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 915273ddc06241908c5fe133ced1d111 3 | timeCreated: 1683086531 -------------------------------------------------------------------------------- /Scripts/Util/MeshBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace ElasticSea.Framework.Scripts.Util 6 | { 7 | public class MeshBuilder 8 | { 9 | private List vertices = new(); 10 | private List triangles = new(); 11 | 12 | public void AddTriangle(Vector3 p0, Vector3 p1, Vector3 p2, bool flip = false) 13 | { 14 | var vCount = vertices.Count; 15 | if (flip) 16 | { 17 | (p2, p1) = (p1, p2); 18 | } 19 | 20 | vertices.Add(p0); 21 | vertices.Add(p1); 22 | vertices.Add(p2); 23 | triangles.Add(vCount + 0); 24 | triangles.Add(vCount + 1); 25 | triangles.Add(vCount + 2); 26 | } 27 | 28 | public void AddQuad(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, bool flip = false) 29 | { 30 | AddTriangle(p0, p1, p2, flip); 31 | AddTriangle(p0, p2, p3, flip); 32 | } 33 | 34 | public void AddStrip(Vector3[] points0, Vector3[] points1, bool flip = false) 35 | { 36 | if (points0.Length != points1.Length) 37 | { 38 | throw new Exception("Points needs to be same length"); 39 | } 40 | 41 | var length = points0.Length; 42 | for (var i = 0; i < length; i++) 43 | { 44 | var p00 = points0[i + 0]; 45 | var p01 = points0[(i + 1) % length]; 46 | var p10 = points1[i + 0]; 47 | var p11 = points1[(i + 1) % length]; 48 | 49 | AddQuad(p00, p10, p11, p01, flip); 50 | } 51 | } 52 | 53 | public void AddCircle(Vector3[] points, Vector3 center, bool flip = false) 54 | { 55 | for (var i = 0; i < points.Length; i++) 56 | { 57 | var p0 = points[i + 0]; 58 | var p1 = points[(i + 1) % points.Length]; 59 | AddTriangle(p0, center, p1, flip); 60 | } 61 | } 62 | 63 | public Mesh GetMesh() 64 | { 65 | var mesh = new Mesh() 66 | { 67 | vertices = vertices.ToArray(), 68 | triangles = triangles.ToArray() 69 | }; 70 | mesh.RecalculateBounds(); 71 | return mesh; 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /Scripts/Util/MeshBuilder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c419ee56d5b24c6688d924deb2dc1315 3 | timeCreated: 1688248196 -------------------------------------------------------------------------------- /Scripts/Util/MeshSerializer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ac0e0270fe2d7144e8dd352b6af81656 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/MeshTransform.cs: -------------------------------------------------------------------------------- 1 | using ElasticSea.Framework.Extensions; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Util 5 | { 6 | public class MeshTransform 7 | { 8 | private Mesh mesh; 9 | 10 | private readonly Vector3[] vertices; 11 | private readonly Vector3[] normals; 12 | private readonly Bounds bounds; 13 | 14 | public MeshTransform(Mesh mesh) 15 | { 16 | this.mesh = mesh; 17 | 18 | vertices = mesh.vertices; 19 | normals = mesh.normals; 20 | bounds = mesh.bounds; 21 | } 22 | 23 | public MeshTransform Scale(float scale) 24 | { 25 | return Scale(new Vector3(scale, scale, scale)); 26 | } 27 | 28 | public MeshTransform Scale(Vector3 scale) 29 | { 30 | var length = vertices.Length; 31 | for (int i = 0; i < length; i++) 32 | { 33 | vertices[i] = Vector3.Scale(vertices[i], scale); 34 | } 35 | 36 | return this; 37 | } 38 | 39 | public MeshTransform Translate(Vector3 translate) 40 | { 41 | var length = vertices.Length; 42 | for (int i = 0; i < length; i++) 43 | { 44 | vertices[i] += translate; 45 | } 46 | 47 | return this; 48 | } 49 | 50 | public MeshTransform RotateAround(Vector3 center, Vector3 axis, float angle) 51 | { 52 | var length = vertices.Length; 53 | for (int i = 0; i < length; i++) 54 | { 55 | var vec = vertices[i] - center; 56 | var rotation = Quaternion.AngleAxis(angle, axis); 57 | vertices[i] = rotation * vec + center; 58 | normals[i] = rotation * normals[i]; 59 | } 60 | 61 | return this; 62 | } 63 | 64 | public MeshTransform RotateAround(Vector3 axis, float angle) 65 | { 66 | return RotateAround(bounds.center, axis, angle); 67 | } 68 | 69 | public Mesh GetMesh() 70 | { 71 | var cloned = mesh.Clone(); 72 | cloned.vertices = vertices; 73 | cloned.normals = normals; 74 | cloned.RecalculateBounds(); 75 | return cloned; 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /Scripts/Util/MeshTransform.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dd76c8f9671b43ba88a373e97f03625b 3 | timeCreated: 1690582886 -------------------------------------------------------------------------------- /Scripts/Util/MeshUtility.cs: -------------------------------------------------------------------------------- 1 | using ElasticSea.Framework.Extensions; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Scripts.Util 5 | { 6 | public class MeshUtility 7 | { 8 | private readonly Mesh source; 9 | private readonly Mesh finalMesh; 10 | private readonly Vector3[] originalVertices; 11 | private readonly Vector2[] originalUvs; 12 | private readonly Bounds originalBounds; 13 | private readonly Vector3[] newVertices; 14 | private readonly Vector2[] newUvs; 15 | 16 | public Mesh Mesh => finalMesh; 17 | public Mesh Source => source; 18 | public Bounds Bounds => originalBounds; 19 | 20 | public MeshUtility(Mesh source) 21 | { 22 | this.source = source; 23 | this.originalVertices = source.vertices; 24 | this.originalBounds = source.bounds; 25 | this.originalUvs = source.uv; 26 | this.finalMesh = source.Clone(); 27 | this.newVertices = new Vector3[source.vertices.Length]; 28 | this.newUvs = new Vector2[source.uv.Length]; 29 | } 30 | 31 | public void ExtendMeshToBounds(Bounds boundsToMatch) 32 | { 33 | var bounds = originalBounds; 34 | 35 | // Center is at 0.5, 0.5, 0.5 36 | var boundsCenter = bounds.min + bounds.size.Multiply(Vector3.one * 0.5f); 37 | 38 | var minExtends = boundsToMatch.min - bounds.min + boundsCenter - bounds.center; 39 | var maxExtends = boundsToMatch.max - bounds.max + boundsCenter - bounds.center; 40 | 41 | for (var i = 0; i < originalVertices.Length; i++) 42 | { 43 | var vert = originalVertices[i]; 44 | var x = vert.x + (vert.x > boundsCenter.x / 2 ? maxExtends.x : minExtends.x); 45 | var y = vert.y + (vert.y > boundsCenter.y / 2 ? maxExtends.y : minExtends.y); 46 | var z = vert.z + (vert.z > boundsCenter.z / 2 ? maxExtends.z : minExtends.z); 47 | newVertices[i] = new Vector3(x, y, z) ; 48 | } 49 | 50 | finalMesh.vertices = newVertices; 51 | finalMesh.bounds = boundsToMatch; 52 | } 53 | 54 | public void ExtendMeshToBoundsX(float min, float max) 55 | { 56 | // Center is at 0.5, 0.5, 0.5 57 | var boundsCenter = originalBounds.min + originalBounds.size.Multiply(Vector3.one * 0.5f); 58 | 59 | var minExtends = min - originalBounds.min.x + boundsCenter.x - originalBounds.center.x; 60 | var maxExtends = max - originalBounds.max.x + boundsCenter.x - originalBounds.center.x; 61 | 62 | for (var i = 0; i < originalVertices.Length; i++) 63 | { 64 | var vert = originalVertices[i]; 65 | var x = vert.x + (vert.x > boundsCenter.x / 2 ? maxExtends : minExtends); 66 | var y = vert.y; 67 | var z = vert.z; 68 | newVertices[i] = new Vector3(x, y, z); 69 | } 70 | 71 | finalMesh.vertices = newVertices; 72 | 73 | var newBounds = originalBounds.SetMinMaxXOld(min, max); 74 | finalMesh.bounds = newBounds; 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /Scripts/Util/MeshUtility.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3326edfea3e14414ab459def34f7ef02 3 | timeCreated: 1680678074 -------------------------------------------------------------------------------- /Scripts/Util/MeshUtilityV2.cs: -------------------------------------------------------------------------------- 1 | using ElasticSea.Framework.Extensions; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Util 5 | { 6 | public class MeshUtilityV2 7 | { 8 | private readonly Mesh source; 9 | private readonly Mesh finalMesh; 10 | private readonly Vector3[] originalVertices; 11 | private readonly Bounds originalBounds; 12 | private readonly Vector3[] newVertices; 13 | 14 | public Mesh Mesh => finalMesh; 15 | public Mesh Source => source; 16 | public Bounds Bounds => originalBounds; 17 | 18 | public MeshUtilityV2(Mesh source) 19 | { 20 | this.source = source; 21 | this.originalVertices = source.vertices; 22 | this.originalBounds = source.bounds; 23 | this.finalMesh = source.Clone(); 24 | this.newVertices = new Vector3[source.vertices.Length]; 25 | } 26 | 27 | public delegate void UpdateVerticesHandler(Vector3[] originalVertices, Vector3[] newVertices); 28 | 29 | public void UpdateVertices(UpdateVerticesHandler factory) 30 | { 31 | factory(originalVertices, newVertices); 32 | 33 | finalMesh.vertices = newVertices; 34 | finalMesh.RecalculateBounds(); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Scripts/Util/MeshUtilityV2.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5ac1837ccd9449e6bb31baeca21f7eb2 3 | timeCreated: 1729374372 -------------------------------------------------------------------------------- /Scripts/Util/MeshUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7cb3e2f309bf3704295cad1b08114dd2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/MinimalSphereBounds.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ElasticSea.Framework.Extensions; 3 | using UnityEngine; 4 | using Random = UnityEngine.Random; 5 | 6 | namespace ElasticSea.Framework.Scripts.Util 7 | { 8 | public class MinimalSphereBounds 9 | { 10 | private static List _boundaryPoints; 11 | 12 | public static SphereBounds GetSphereBounds(List points) 13 | { 14 | if (_boundaryPoints == null) 15 | _boundaryPoints = new List(4); 16 | else 17 | _boundaryPoints.Clear(); 18 | 19 | return BallWithBounds(points); 20 | } 21 | 22 | static SphereBounds BallWithBounds(List contained) 23 | { 24 | if (contained.Count == 0 || _boundaryPoints.Count == 4) 25 | { 26 | switch (_boundaryPoints.Count) 27 | { 28 | case 0: 29 | return new SphereBounds(Vector3.zero, 0); 30 | case 1: 31 | return new SphereBounds(_boundaryPoints[0], 0); 32 | case 2: 33 | var halfSpan = 0.5f * (_boundaryPoints[1] - _boundaryPoints[0]); 34 | return new SphereBounds( 35 | _boundaryPoints[0] + halfSpan, 36 | halfSpan.magnitude 37 | ); 38 | case 3: 39 | return TriangleCircumSphere( 40 | _boundaryPoints[0], 41 | _boundaryPoints[1], 42 | _boundaryPoints[2] 43 | ); 44 | case 4: 45 | return TetrahedronCircumSphere( 46 | _boundaryPoints[0], 47 | _boundaryPoints[1], 48 | _boundaryPoints[2], 49 | _boundaryPoints[3] 50 | ); 51 | } 52 | } 53 | 54 | int last = contained.Count - 1; 55 | int removeAt = Random.Range(0, contained.Count); 56 | 57 | Vector3 removed = contained[removeAt]; 58 | contained[removeAt] = contained[last]; 59 | contained.RemoveAt(last); 60 | 61 | var ball = BallWithBounds(contained); 62 | 63 | if (!ball.Contains(removed)) 64 | { 65 | _boundaryPoints.Add(removed); 66 | ball = BallWithBounds(contained); 67 | _boundaryPoints.RemoveAt(_boundaryPoints.Count - 1); 68 | } 69 | 70 | contained.Add(removed); 71 | return ball; 72 | } 73 | 74 | static SphereBounds TriangleCircumSphere(Vector3 a, Vector3 b, Vector3 c) 75 | { 76 | Vector3 A = a - c; 77 | Vector3 B = b - c; 78 | 79 | Vector3 cross = Vector3.Cross(A, B); 80 | 81 | Vector3 center = c + Vector3.Cross(A.sqrMagnitude * B - B.sqrMagnitude * A, cross) / (2f * cross.sqrMagnitude); 82 | 83 | float radius = Vector3.Distance(a, center); 84 | 85 | return new SphereBounds(center, radius); 86 | } 87 | 88 | static SphereBounds TetrahedronCircumSphere( 89 | Vector3 p1, 90 | Vector3 p2, 91 | Vector3 p3, 92 | Vector3 p4 93 | ) 94 | { 95 | // Construct a matrix with the vectors as columns 96 | // (Xs on one row, Ys on the next... and the last row all 1s) 97 | Matrix4x4 matrix = new Matrix4x4(p1, p2, p3, p4); 98 | matrix.SetRow(3, Vector4.one); 99 | 100 | float a = matrix.determinant; 101 | 102 | // Copy the matrix so we can modify it 103 | // and still read rows from the original. 104 | var D = matrix; 105 | Vector3 center; 106 | 107 | Vector4 squares = new Vector4( 108 | p1.sqrMagnitude, 109 | p2.sqrMagnitude, 110 | p3.sqrMagnitude, 111 | p4.sqrMagnitude 112 | ); 113 | 114 | D.SetRow(0, squares); 115 | center.x = D.determinant; 116 | 117 | D.SetRow(1, matrix.GetRow(0)); 118 | center.y = -D.determinant; 119 | 120 | D.SetRow(2, matrix.GetRow(1)); 121 | center.z = D.determinant; 122 | 123 | center /= 2f * a; 124 | return new SphereBounds(center, Vector3.Distance(p1, center)); 125 | } 126 | } 127 | } -------------------------------------------------------------------------------- /Scripts/Util/MinimalSphereBounds.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4cbbb00065bd42cf9c469ca434c4dffb 3 | timeCreated: 1689119451 -------------------------------------------------------------------------------- /Scripts/Util/OneShotEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ElasticSea.Framework.Scripts.Util 4 | { 5 | public class OneShotEvent 6 | { 7 | private event Action internalEvent; 8 | 9 | public event Action SomeEvent = obj => { }; 10 | 11 | public OneShotEvent() 12 | { 13 | internalEvent += obj => 14 | { 15 | foreach (Action del in SomeEvent.GetInvocationList()) 16 | { 17 | del.DynamicInvoke(obj); 18 | SomeEvent -= del; 19 | } 20 | }; 21 | } 22 | 23 | public void Invoke(T value) 24 | { 25 | internalEvent.Invoke(value); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Scripts/Util/OneShotEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b21f4890810d4bb89352cc1e33868557 3 | timeCreated: 1681204157 -------------------------------------------------------------------------------- /Scripts/Util/OrderedIndexPool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ElasticSea.Framework.Util 4 | { 5 | public class OrderedIndexPool 6 | { 7 | private bool[] occupied = new bool[1]; 8 | private int count = 1; 9 | private int firstFreeIndex = 0; 10 | 11 | public int Get() 12 | { 13 | var freeIndex = firstFreeIndex; 14 | 15 | do 16 | { 17 | firstFreeIndex++; 18 | if (firstFreeIndex >= occupied.Length) 19 | { 20 | count *= 2; 21 | occupied = occupied.EnsureArray(count); 22 | } 23 | } while (occupied[firstFreeIndex]); 24 | 25 | 26 | occupied[freeIndex] = true; 27 | 28 | return freeIndex; 29 | } 30 | 31 | public void Put(int index) 32 | { 33 | if (index >= count) 34 | throw new Exception("index does not belong to this pool"); 35 | 36 | if (!occupied[index]) 37 | throw new Exception("Index is already in the pool"); 38 | 39 | occupied[index] = false; 40 | 41 | if (index < firstFreeIndex) 42 | firstFreeIndex = index; 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /Scripts/Util/OrderedIndexPool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 149494173ded4ce1a2f6aaed24267f5e 3 | timeCreated: 1747928446 -------------------------------------------------------------------------------- /Scripts/Util/PauseEditorAfterTime.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using UnityEditor; 3 | #endif 4 | using UnityEngine; 5 | 6 | namespace ElasticSea.Framework.Util 7 | { 8 | public class PauseEditorAfterTime : MonoBehaviour 9 | { 10 | [SerializeField] private float time; 11 | 12 | private bool paused; 13 | 14 | private void Update() 15 | { 16 | if (paused == false) 17 | { 18 | if (Time.time > time) 19 | { 20 | #if UNITY_EDITOR 21 | EditorApplication.isPaused = true; 22 | #endif 23 | paused = true; 24 | } 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Scripts/Util/PauseEditorAfterTime.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 939570d89a0045138d9e1ea88696c6b8 3 | timeCreated: 1702301441 -------------------------------------------------------------------------------- /Scripts/Util/PhysicsUtils.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Scripts.Util 4 | { 5 | public class PhysicsUtils 6 | { 7 | public static bool BoxTriangleIntersect(Bounds box, Vector3 t0, Vector3 t1, Vector3 t2) 8 | { 9 | return BoxTriangleIntersectorOld.IsIntersecting(box, t0, t1, t2); 10 | } 11 | 12 | public static bool BoxTriangleIntersectFast(BoxTriangleIntersector.FastBox box, BoxTriangleIntersector.FastTriangle triangle) 13 | { 14 | return BoxTriangleIntersector.IsIntersecting(box, triangle); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Scripts/Util/PhysicsUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a61ec49b55be4137af308e7478d6c293 3 | timeCreated: 1679141278 -------------------------------------------------------------------------------- /Scripts/Util/Pool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ElasticSea.Framework.Util 5 | { 6 | public class Pool 7 | { 8 | private readonly Func creator; 9 | private readonly Stack stack = new Stack(); 10 | private readonly Action activate; 11 | private readonly Action deactivate; 12 | 13 | public Pool(int initialCapacity, Func creator, Action activate = null, Action deactivate = null) 14 | { 15 | this.creator = creator; 16 | this.activate = activate; 17 | this.deactivate = deactivate; 18 | for (var i = 0; i < initialCapacity; i++) Put(creator()); 19 | } 20 | 21 | public T Get() 22 | { 23 | if (stack.Count == 0) 24 | { 25 | return creator(); 26 | } 27 | 28 | var element = stack.Pop(); 29 | activate?.Invoke(element); 30 | return element; 31 | } 32 | 33 | public void Put(T element) 34 | { 35 | stack.Push(element); 36 | deactivate?.Invoke(element); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Scripts/Util/Pool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a5a77628be3a3d149ac612ba185765de 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/PriorityPool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ElasticSea.Framework.Util 4 | { 5 | public class PriorityPool 6 | { 7 | private readonly Func creator; 8 | private readonly PriorityQueue stack = new(); 9 | private readonly Action activate; 10 | private readonly Action deactivate; 11 | 12 | public PriorityPool(int initialCapacity, Func creator, Action activate = null, Action deactivate = null) 13 | { 14 | this.creator = creator; 15 | this.activate = activate; 16 | this.deactivate = deactivate; 17 | for (var i = 0; i < initialCapacity; i++) Put(creator()); 18 | } 19 | 20 | public T Get() 21 | { 22 | if (stack.Count == 0) 23 | { 24 | return creator(); 25 | } 26 | 27 | var element = stack.Dequeue(); 28 | activate?.Invoke(element); 29 | return element; 30 | } 31 | 32 | public void Put(T element) 33 | { 34 | stack.Enqueue(element, element); 35 | deactivate?.Invoke(element); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Scripts/Util/PriorityPool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6b5cde48b01d4d68980ff9515ed449e3 3 | timeCreated: 1704493128 -------------------------------------------------------------------------------- /Scripts/Util/PriorityQueue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: af78e5d53d4640f5a56da6affb39c0bb 3 | timeCreated: 1704493454 -------------------------------------------------------------------------------- /Scripts/Util/PropertyDrawers.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 892419b775ba9304c886d41e9a23fc7d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Scripts/Util/PropertyDrawers/CustomObjectPickerAttribute.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util.PropertyDrawers 4 | { 5 | [System.AttributeUsage(System.AttributeTargets.Field, AllowMultiple = false, Inherited = true)] 6 | public class CustomObjectPickerAttribute : PropertyAttribute 7 | { 8 | public enum ResultObjectType 9 | { 10 | Scene, 11 | Asset, 12 | SceneOrAsset 13 | }; 14 | public System.Type[] typeRestrictions; 15 | public ResultObjectType resultObjectType; 16 | 17 | private CustomObjectPickerAttribute() { } 18 | 19 | public CustomObjectPickerAttribute(params System.Type[] typeRestrictions) : this(ResultObjectType.SceneOrAsset, typeRestrictions) 20 | { 21 | } 22 | 23 | public CustomObjectPickerAttribute(ResultObjectType resultObjectType, params System.Type[] typeRestrictions) 24 | { 25 | this.typeRestrictions = typeRestrictions; 26 | this.resultObjectType = resultObjectType; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Scripts/Util/PropertyDrawers/CustomObjectPickerAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 93858c5ee3f134f49a4afb4172a02886 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/PropertyDrawers/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2e73a95acb714f8fb5738afe2875c91d 3 | timeCreated: 1602962573 -------------------------------------------------------------------------------- /Scripts/Util/PropertyDrawers/Editor/CustomObjectPickerEditorWindow.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using UnityEditor; 4 | using UnityEngine; 5 | 6 | namespace ElasticSea.Framework.Util.PropertyDrawers.Editor 7 | { 8 | public class CustomObjectPickerEditorWindow : EditorWindow 9 | { 10 | public static void GetWindow(System.Type type, CustomObjectPickerAttribute attr, System.Action callback) 11 | { 12 | GetWindow(false, "Select Object", true); 13 | 14 | _callback = callback; 15 | FilterAssets(type, attr); 16 | } 17 | 18 | private static IEnumerable _allMatchingObjects; 19 | private static System.Action _callback; 20 | private Vector2 _scrollPos = Vector2.zero; 21 | 22 | 23 | protected void OnGUI() 24 | { 25 | _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos); 26 | { 27 | if (GUILayout.Button("None")) 28 | _callback.Invoke(null); 29 | 30 | foreach (var obj in _allMatchingObjects) 31 | { 32 | if (GUILayout.Button(obj.name)) 33 | _callback.Invoke(obj); 34 | } 35 | } 36 | EditorGUILayout.EndScrollView(); 37 | } 38 | 39 | 40 | private static void FilterAssets(System.Type type, CustomObjectPickerAttribute attr) 41 | { 42 | _allMatchingObjects = Resources.FindObjectsOfTypeAll(type); 43 | 44 | if (typeof(GameObject).IsAssignableFrom(type)) 45 | { 46 | if (attr.resultObjectType != CustomObjectPickerAttribute.ResultObjectType.SceneOrAsset) 47 | { 48 | if (attr.resultObjectType == CustomObjectPickerAttribute.ResultObjectType.Scene) 49 | _allMatchingObjects = _allMatchingObjects.Where(t => PrefabUtility.GetPrefabType(t as GameObject) != PrefabType.Prefab); 50 | 51 | if (attr.resultObjectType == CustomObjectPickerAttribute.ResultObjectType.Asset) 52 | _allMatchingObjects = _allMatchingObjects.Where(t => PrefabUtility.GetPrefabType(t as GameObject) == PrefabType.Prefab); 53 | } 54 | 55 | // if we're dealing with GameObject references, then we'll restrict outrselves to any 56 | // GameObject with components attached that possess all type limitations collectively 57 | foreach (var restrictionType in attr.typeRestrictions) 58 | _allMatchingObjects = _allMatchingObjects.Where(t => (t as GameObject).GetComponent(restrictionType) != null).ToList(); 59 | } 60 | else if (typeof(Component).IsAssignableFrom(type)) 61 | { 62 | if (attr.resultObjectType != CustomObjectPickerAttribute.ResultObjectType.SceneOrAsset) 63 | { 64 | if (attr.resultObjectType == CustomObjectPickerAttribute.ResultObjectType.Scene) 65 | _allMatchingObjects = _allMatchingObjects.Where(t => PrefabUtility.GetPrefabType((t as Component).gameObject) != PrefabType.Prefab); 66 | 67 | if (attr.resultObjectType == CustomObjectPickerAttribute.ResultObjectType.Asset) 68 | _allMatchingObjects = _allMatchingObjects.Where(t => PrefabUtility.GetPrefabType((t as Component).gameObject) == PrefabType.Prefab); 69 | } 70 | 71 | // if we're dealing with components, then we limit ourselves to components that derive 72 | // or implement all restriction type 73 | foreach (var restrictionType in attr.typeRestrictions) 74 | _allMatchingObjects = _allMatchingObjects.Where(t => restrictionType.IsAssignableFrom(t.GetType())); 75 | } 76 | else if (typeof(ScriptableObject).IsAssignableFrom(type)) 77 | { 78 | // ScriptableObjects are assets only, so we can skip the asset/scene object check 79 | foreach (var restrictionType in attr.typeRestrictions) 80 | _allMatchingObjects = _allMatchingObjects.Where(t => restrictionType.IsAssignableFrom(t.GetType())); 81 | } 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /Scripts/Util/PropertyDrawers/Editor/CustomObjectPickerEditorWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6e1354c52b6d9e44ca28e193792047c0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/PropertyDrawers/Editor/CustomObjectPickerPropertyDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 13c580de4ddd0084998ffb6a23df9617 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/PropertyDrawers/Editor/OfTypeDrawer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Reflection; 4 | using UnityEditor; 5 | using UnityEditor.UIElements; 6 | using UnityEngine; 7 | using UnityEngine.UIElements; 8 | using Object = UnityEngine.Object; 9 | 10 | namespace ElasticSea.Framework.Util.PropertyDrawers.Editor 11 | { 12 | [CustomPropertyDrawer(typeof(OfTypeAttribute))] 13 | public class OfTypeDrawer : PropertyDrawer 14 | { 15 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) 16 | { 17 | // Verify the property type is supported. 18 | if (property.propertyType != SerializedPropertyType.ObjectReference) 19 | { 20 | EditorGUI.LabelField(position, label.text, "Use OfType with ObjectReference properties only."); 21 | return; 22 | } 23 | OfTypeAttribute ofType = attribute as OfTypeAttribute; 24 | EditorGUI.BeginProperty(position, label, property); 25 | // Calculate the object field position and size 26 | Rect objectFieldPosition = position; 27 | objectFieldPosition.height = EditorGUIUtility.singleLineHeight; 28 | // Draw the object field and get the selected object 29 | Object objectValue = EditorGUI.ObjectField(objectFieldPosition, label, property.objectReferenceValue, fieldInfo.FieldType, true); 30 | // Validate the assigned object 31 | if (objectValue != null && !ofType.types.Any(t => t.IsAssignableFrom(objectValue.GetType()))) 32 | { 33 | property.objectReferenceValue = null; 34 | // Adjust the position for the help box below the object field 35 | Rect helpBoxPosition = position; 36 | helpBoxPosition.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; 37 | helpBoxPosition.height = EditorGUIUtility.singleLineHeight * 2; // Adjust height as needed 38 | EditorGUI.HelpBox(helpBoxPosition, $"This field only accepts types: {string.Join(", ", ofType.types.Select(t => t.Name))}", MessageType.Error); 39 | } 40 | else 41 | { 42 | property.objectReferenceValue = objectValue; 43 | } 44 | EditorGUI.EndProperty(); 45 | } 46 | 47 | public override VisualElement CreatePropertyGUI(SerializedProperty property) 48 | { 49 | // Check if the property type is of an object reference. 50 | if (property.propertyType != SerializedPropertyType.ObjectReference && 51 | property.propertyType != SerializedPropertyType.ExposedReference) 52 | { 53 | throw new System.ArgumentException("This attribute is not supported on properties of this property type.", 54 | nameof(property.propertyType)); 55 | } 56 | 57 | GetFieldInfoFromProperty(property, out var type); 58 | 59 | var ofType = attribute as OfTypeAttribute; 60 | 61 | // Set up the object field. 62 | var objectField = new ObjectField(property.displayName); 63 | objectField.AddToClassList(ObjectField.alignedFieldUssClassName); 64 | objectField.BindProperty(property); 65 | objectField.objectType = type; 66 | 67 | // Disable dropping if not assignable from drag and drop. 68 | objectField.RegisterCallback(dragUpdated => 69 | { 70 | if (!DragAndDrop.objectReferences.Any(obj 71 | => obj is GameObject gameObject ? FirstValidOrDefault(gameObject) : IsValid(obj))) 72 | { 73 | dragUpdated.PreventDefault(); 74 | } 75 | }); 76 | 77 | // Assign the appropriate value. 78 | objectField.RegisterValueChangedCallback(changed => 79 | { 80 | if (IsValid(changed.newValue)) 81 | { 82 | return; 83 | } 84 | else if (changed.newValue is GameObject gameObject || 85 | changed.newValue is Component component && (gameObject = component.gameObject)) 86 | { 87 | objectField.value = FirstValidOrDefault(gameObject); 88 | } 89 | else 90 | { 91 | objectField.value = null; 92 | } 93 | }); 94 | 95 | return objectField; 96 | 97 | // Helper methods. 98 | bool IsValid(Object obj) => 99 | !obj || type.IsAssignableFrom(obj.GetType()) && ofType.types.All(type => type.IsAssignableFrom(obj.GetType())); 100 | 101 | Component FirstValidOrDefault(GameObject gameObject) => gameObject.GetComponents().FirstOrDefault(IsValid); 102 | } 103 | 104 | private void GetFieldInfoFromProperty(SerializedProperty property, out Type type) 105 | { 106 | // INTERNAL UNITY FieldInfo UnityEditor.ScriptAttributeUtility.GetFieldInfoFromProperty(SerializedProperty property, out Type type); 107 | 108 | // Set up the type variables. 109 | var internalType = Type.GetType("UnityEditor.ScriptAttributeUtility, UnityEditor.CoreModule"); 110 | var method = internalType.GetMethod("GetFieldInfoFromProperty", BindingFlags.Static | BindingFlags.NonPublic); 111 | 112 | Type ttype = null; 113 | object[] args = { property, ttype }; 114 | method.Invoke(this, args); 115 | type = (Type)args[1]; 116 | } 117 | } 118 | } -------------------------------------------------------------------------------- /Scripts/Util/PropertyDrawers/Editor/OfTypeDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6b020c2bb97a4157a6baf955eb1b7b05 3 | timeCreated: 1712061304 -------------------------------------------------------------------------------- /Scripts/Util/PropertyDrawers/Editor/SingleUnityLayerPropertyDrawer.cs: -------------------------------------------------------------------------------- 1 | using ElasticSea.Framework.Util.PropertyDrawers; 2 | using UnityEditor; 3 | using UnityEngine; 4 | 5 | namespace Environment.Editor 6 | { 7 | [CustomPropertyDrawer(typeof(SingleUnityLayer))] 8 | public class SingleUnityLayerPropertyDrawer : PropertyDrawer 9 | { 10 | public override void OnGUI(Rect _position, SerializedProperty _property, GUIContent _label) 11 | { 12 | EditorGUI.BeginProperty(_position, GUIContent.none, _property); 13 | SerializedProperty layerIndex = _property.FindPropertyRelative("m_LayerIndex"); 14 | _position = EditorGUI.PrefixLabel(_position, GUIUtility.GetControlID(FocusType.Passive), _label); 15 | if (layerIndex != null) 16 | { 17 | layerIndex.intValue = EditorGUI.LayerField(_position, layerIndex.intValue); 18 | } 19 | EditorGUI.EndProperty( ); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Scripts/Util/PropertyDrawers/Editor/SingleUnityLayerPropertyDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 44c1f2a9a5fb4db48d29dc17730d1d85 3 | timeCreated: 1639543933 -------------------------------------------------------------------------------- /Scripts/Util/PropertyDrawers/OfTypeAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Util.PropertyDrawers 5 | { 6 | /// 7 | /// Specifies types that an Object needs to be of. Can be used to create an Object selector that allows interfaces. 8 | /// 9 | public class OfTypeAttribute : PropertyAttribute 10 | { 11 | public Type[] types; 12 | 13 | public OfTypeAttribute(Type type) 14 | { 15 | this.types = new Type[] { type }; 16 | } 17 | 18 | public OfTypeAttribute(params Type[] types) 19 | { 20 | this.types = types; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Scripts/Util/PropertyDrawers/OfTypeAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 42fe8f05130543109b99f59bc3a33e3c 3 | timeCreated: 1712058994 -------------------------------------------------------------------------------- /Scripts/Util/PropertyDrawers/SingleUnityLayer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util.PropertyDrawers 4 | { 5 | [System.Serializable] 6 | public class SingleUnityLayer 7 | { 8 | [SerializeField] private int m_LayerIndex = 0; 9 | 10 | public int LayerIndex => m_LayerIndex; 11 | 12 | public void Set(int _layerIndex) 13 | { 14 | if (_layerIndex > 0 && _layerIndex < 32) 15 | { 16 | m_LayerIndex = _layerIndex; 17 | } 18 | } 19 | 20 | public int Mask => 1 << m_LayerIndex; 21 | } 22 | } -------------------------------------------------------------------------------- /Scripts/Util/PropertyDrawers/SingleUnityLayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 75e225acad7fa4a43978cec8b4ad77f6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/Range.cs: -------------------------------------------------------------------------------- 1 | namespace ElasticSea.Framework.Util 2 | { 3 | public class Range 4 | { 5 | public float Min; 6 | public float Max; 7 | 8 | public Range(float min, float max) 9 | { 10 | Min = min; 11 | Max = max; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Scripts/Util/Range.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5392069363664b15935fa0649664ea9a 3 | timeCreated: 1602391091 -------------------------------------------------------------------------------- /Scripts/Util/ReadOnlyAttribute.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util 4 | { 5 | public class ReadOnlyAttribute : PropertyAttribute { } 6 | } -------------------------------------------------------------------------------- /Scripts/Util/ReadOnlyAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 200fb6a041eb42dd8b2beaa96c412d42 3 | timeCreated: 1711492219 -------------------------------------------------------------------------------- /Scripts/Util/SceneSingleton.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util 4 | { 5 | // Just like regular singleton, but we don't call DontDestroyOnLoad and free the instance on OnDestroy 6 | public abstract class SceneSingleton : MonoBehaviour where T : SceneSingleton 7 | { 8 | private static T instance; 9 | 10 | public static T Instance => instance ?? (instance = FindObjectOfType()); 11 | 12 | protected bool Awake() 13 | { 14 | if (Instance == null) 15 | { 16 | instance = (T)this; 17 | } 18 | 19 | if (Instance == this) 20 | { 21 | OnSingletonAwake(); 22 | return true; 23 | } 24 | 25 | DestroyImmediate(gameObject); 26 | return false; 27 | } 28 | 29 | private void OnDestroy() 30 | { 31 | if (Instance == this) 32 | { 33 | instance = null; 34 | } 35 | } 36 | 37 | protected abstract void OnSingletonAwake(); 38 | } 39 | } -------------------------------------------------------------------------------- /Scripts/Util/SceneSingleton.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ec2e26a43ced4815b6abb7fa2ebb3ec8 3 | timeCreated: 1550255469 -------------------------------------------------------------------------------- /Scripts/Util/ScreenshotUtility.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using ElasticSea.Framework.Scripts.Extensions; 3 | using UnityEngine; 4 | 5 | namespace ElasticSea.Framework.Util 6 | { 7 | [RequireComponent(typeof(Camera))] 8 | public class ScreenshotUtility : MonoBehaviour 9 | { 10 | [SerializeField] private int width = 1920; 11 | [SerializeField] private int height = 1080; 12 | [SerializeField] private float fieldOfView = 60; 13 | 14 | public void Render() 15 | { 16 | var cam = GetComponent(); 17 | 18 | var prevFov = cam.fieldOfView; 19 | var prevStereoTargetEye = cam.stereoTargetEye; 20 | 21 | cam.fieldOfView = fieldOfView; 22 | cam.stereoTargetEye = StereoTargetEyeMask.None; 23 | 24 | var rt = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32); 25 | cam.targetTexture = rt; 26 | cam.Render(); 27 | 28 | var tex = rt.ToTexture2D(TextureFormat.ARGB32); 29 | 30 | var pngBytes = tex.EncodeToPNG(); 31 | var path = Path.Combine(Application.persistentDataPath, "output.png"); 32 | File.WriteAllBytes(path, pngBytes); 33 | 34 | cam.fieldOfView = prevFov; 35 | cam.targetTexture = null; 36 | cam.stereoTargetEye = prevStereoTargetEye; 37 | Destroy(rt); 38 | Destroy(tex); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /Scripts/Util/ScreenshotUtility.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 469d76cdb0014c54687183b957e60789 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/SequentialIdGenerator.cs: -------------------------------------------------------------------------------- 1 | namespace ElasticSea.Framework.Util 2 | { 3 | public class SequentialIdGenerator 4 | { 5 | private readonly PriorityPool pool; 6 | 7 | public SequentialIdGenerator() 8 | { 9 | var id = 0; 10 | pool = new PriorityPool(0, () => 11 | { 12 | var generatedId = id; 13 | id++; 14 | return generatedId; 15 | }); 16 | } 17 | 18 | public int GenerateId() => pool.Get(); 19 | public void ReturnId(int id) => pool.Put(id); 20 | } 21 | } -------------------------------------------------------------------------------- /Scripts/Util/SequentialIdGenerator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1849cbeb07094f84af400da5e83c8f25 3 | timeCreated: 1704493996 -------------------------------------------------------------------------------- /Scripts/Util/ShowBounds.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util 4 | { 5 | public class ShowBounds : MonoBehaviour 6 | { 7 | [SerializeField] private Bounds bounds; 8 | [SerializeField] private Color color = Color.red; 9 | 10 | public Bounds Bounds 11 | { 12 | get => bounds; 13 | set => bounds = value; 14 | } 15 | 16 | public Color Color 17 | { 18 | get => color; 19 | set => color = value; 20 | } 21 | 22 | private void OnDrawGizmosSelected() 23 | { 24 | Gizmos.matrix = transform.localToWorldMatrix; 25 | Gizmos.color = color; 26 | Gizmos.DrawWireCube(bounds.center, bounds.size); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Scripts/Util/ShowBounds.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 872aeeb43ba1475da7665b8a864e0bb5 3 | timeCreated: 1709481500 -------------------------------------------------------------------------------- /Scripts/Util/ShowNormals.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util 4 | { 5 | public class ShowNormals : MonoBehaviour 6 | { 7 | [SerializeField] private float length = 1; 8 | [SerializeField] private int limit = -1; 9 | [SerializeField] private int offset = 0; 10 | 11 | [SerializeField] private MeshFilter mf; 12 | [SerializeField] private SkinnedMeshRenderer smr; 13 | [SerializeField] private Color startColor = Color.blue; 14 | [SerializeField] private Color endColor = Color.red; 15 | 16 | private void OnDrawGizmosSelected() 17 | { 18 | Mesh mesh = null; 19 | if (mf) 20 | { 21 | mesh = Application.isPlaying ? mf.mesh : mf.sharedMesh; 22 | } 23 | else if (smr) 24 | { 25 | mesh = smr.sharedMesh; 26 | } 27 | else if (GetComponent()) 28 | { 29 | mesh = Application.isPlaying ? GetComponent().mesh : GetComponent().sharedMesh; 30 | } 31 | else if (GetComponent()) 32 | { 33 | mesh = GetComponent().sharedMesh; 34 | } 35 | 36 | if (mesh != null) 37 | { 38 | var vertices = mesh.vertices; 39 | var normals = mesh.normals; 40 | 41 | var len = limit >= 0 ? Mathf.Min(limit, normals.Length) : normals.Length; 42 | 43 | for (var i = offset; i < offset + len; i++) 44 | { 45 | Gizmos.color = Color.Lerp(startColor, endColor, (float) i / (normals.Length - 1)); 46 | 47 | var worldPos = transform.TransformPoint(vertices[i]); 48 | var worldNormal = transform.TransformVector(normals[i]); 49 | Gizmos.DrawLine(worldPos, worldPos + worldNormal * length); 50 | } 51 | } 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /Scripts/Util/ShowNormals.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2f7f59a191cde35449f396f8c5134b53 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/Singleton.cs: -------------------------------------------------------------------------------- 1 | using ElasticSea.Framework.Extensions; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Util 5 | { 6 | public abstract class Singleton : MonoBehaviour where T : Singleton 7 | { 8 | private static T instance; 9 | 10 | public static T Instance 11 | { 12 | get 13 | { 14 | if (instance) 15 | { 16 | return instance; 17 | } 18 | 19 | instance = FindObjectOfType(); 20 | if (instance) 21 | { 22 | return instance; 23 | } 24 | 25 | instance = new GameObject(typeof(Singleton).GetSimpleAliasName()).AddComponent(); 26 | return instance; 27 | } 28 | } 29 | 30 | protected bool Awake() 31 | { 32 | if (Instance == null) 33 | { 34 | instance = (T)this; 35 | } 36 | 37 | if (Instance == this) 38 | { 39 | if (Application.isPlaying) DontDestroyOnLoad(gameObject); 40 | OnSingletonAwake(); 41 | return true; 42 | } 43 | 44 | DestroyImmediate(gameObject); 45 | return false; 46 | } 47 | 48 | protected abstract void OnSingletonAwake(); 49 | } 50 | } -------------------------------------------------------------------------------- /Scripts/Util/Singleton.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a4d29ef0322ec8247a7001877c14bfe3 3 | timeCreated: 1536795073 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Util/SmallestEnclosingCircle.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dfd882ad7214475e8ef9446cf5278ffa 3 | timeCreated: 1689120628 -------------------------------------------------------------------------------- /Scripts/Util/SphereBounds.cs: -------------------------------------------------------------------------------- 1 | using ElasticSea.Framework.Extensions; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Scripts.Util 5 | { 6 | public struct SphereBounds 7 | { 8 | public readonly Vector3 center; 9 | public readonly float radius; 10 | 11 | public SphereBounds(Vector3 center, float radius) 12 | { 13 | this.center = center; 14 | this.radius = radius; 15 | } 16 | 17 | public bool Contains(Vector3 point) 18 | { 19 | return point.Distance(center) <= radius; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Scripts/Util/SphereBounds.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2beef8258dc04e17961d02b7ad23f1ae 3 | timeCreated: 1689606821 -------------------------------------------------------------------------------- /Scripts/Util/SphereColliderData.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Util 4 | { 5 | public class SphereColliderData : ColliderData 6 | { 7 | public Vector3 Center; 8 | public float Radius; 9 | 10 | public SphereColliderData(Vector3 center, float radius) 11 | { 12 | Center = center; 13 | Radius = radius; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Scripts/Util/SphereColliderData.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f1bcadf477334f7198270bdf94c54799 3 | timeCreated: 1720810181 -------------------------------------------------------------------------------- /Scripts/Util/SynchronizePosition.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ElasticSea.Framework.Scripts.Util 4 | { 5 | public class SynchronizePosition : MonoBehaviour 6 | { 7 | [SerializeField] private Transform target; 8 | [SerializeField] private Vector3 offset; 9 | 10 | public Vector3 Offset 11 | { 12 | get => offset; 13 | set 14 | { 15 | offset = value; 16 | if (target) 17 | { 18 | Update(); 19 | } 20 | } 21 | } 22 | 23 | public Transform Target 24 | { 25 | get => target; 26 | set 27 | { 28 | target = value; 29 | Update(); 30 | } 31 | } 32 | 33 | public void Update() 34 | { 35 | transform.position = target.position + offset; 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Scripts/Util/SynchronizePosition.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cadbb657af334d8c9db7aa46b690f96f 3 | timeCreated: 1683086309 -------------------------------------------------------------------------------- /Scripts/Util/TransformData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace ElasticSea.Framework.Util 5 | { 6 | [Serializable] 7 | public class TransformData 8 | { 9 | public Vector3 Position; 10 | public Vector3 Rotation; 11 | } 12 | } -------------------------------------------------------------------------------- /Scripts/Util/TransformData.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6de5c04e37aa9bc4c9652f69aa70db2d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/UnityMainThreadDispatcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | using UnityEngine; 5 | 6 | namespace ElasticSea.Framework.Util 7 | { 8 | public class UnityMainThreadDispatcher : MonoBehaviour 9 | { 10 | private readonly Queue executionQueue = new Queue(); 11 | 12 | private void Update() 13 | { 14 | while (executionQueue.Count > 0) 15 | { 16 | executionQueue.Dequeue().Invoke(); 17 | } 18 | } 19 | 20 | public void Enqueue(Action action) 21 | { 22 | executionQueue.Enqueue(action); 23 | } 24 | 25 | public Task EnqueueAsync(Func action) 26 | { 27 | var tcs = new TaskCompletionSource(); 28 | executionQueue.Enqueue(() => 29 | { 30 | try 31 | { 32 | var result = action(); 33 | tcs.SetResult(result); 34 | } 35 | catch (Exception e) 36 | { 37 | tcs.SetException(e); 38 | } 39 | }); 40 | return tcs.Task; 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Scripts/Util/UnityMainThreadDispatcher.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1ecf1f251d050d44b966d14b0271ecaf 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Util/Utils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 49837b7742ff45a46862af8efa97400f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Shaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: de5923997c83b144792d56f8ff7fcfd1 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Shaders/HiddenPass.shader: -------------------------------------------------------------------------------- 1 | Shader "Hidden/HiddenPass" { 2 | SubShader 3 | { 4 | Tags {"Queue" = "Geometry-1" } 5 | 6 | Lighting Off 7 | 8 | Pass 9 | 10 | { 11 | ZWrite Off 12 | ColorMask 0 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Shaders/HiddenPass.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a6374a2e92f447844b6e1b60472e1096 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | preprocessorOverride: 0 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Shaders/Vertex Color.shader: -------------------------------------------------------------------------------- 1 | Shader "Unlit/Vertex Color" 2 | { 3 | SubShader 4 | { 5 | Pass 6 | { 7 | CGPROGRAM 8 | #pragma vertex vert 9 | #pragma fragment frag 10 | 11 | struct appdata 12 | { 13 | float4 vertex : POSITION; 14 | float4 color : COLOR; 15 | }; 16 | 17 | struct v2f 18 | { 19 | float4 vertex : SV_POSITION; 20 | float4 color : COLOR; 21 | }; 22 | 23 | v2f vert (appdata v) 24 | { 25 | v2f o; 26 | o.vertex = UnityObjectToClipPos(v.vertex); 27 | o.color = v.color; 28 | return o; 29 | } 30 | 31 | fixed4 frag (v2f i) : SV_Target 32 | { 33 | return i.color; 34 | } 35 | ENDCG 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Shaders/Vertex Color.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 22748c37e21d37544902a509c8fc6399 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | preprocessorOverride: 0 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Tests.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ac8cc06858f24a19b4135cfcf993e91a 3 | timeCreated: 1616078579 -------------------------------------------------------------------------------- /Tests/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c6daa4c420b94ccebfcf876eb24a9fcb 3 | timeCreated: 1616078572 -------------------------------------------------------------------------------- /Tests/Editor/Extensions.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 74939db836883bf4ca061f10ff902316 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Tests/Editor/Extensions/FloatExtensionsTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using ElasticSea.Framework.Extensions; 3 | using Assert = UnityEngine.Assertions.Assert; 4 | 5 | namespace ElasticSea.Framework.Tests.Extensions 6 | { 7 | public class FloatExtensionsTests 8 | { 9 | [TestCase(-0.06f, 0.02f, -0.06f)] 10 | [TestCase(-0.058f, 0.02f, -0.06f)] 11 | [TestCase(-0.062f, 0.02f, -0.06f)] 12 | public void TestApprox2(float input, float roundTo, float expected) 13 | { 14 | TestContext.AddFormatter(val => ((float)val).ToString("F6")); 15 | 16 | var output = input.RoundTo(roundTo); 17 | 18 | Assert.AreEqual(expected, output); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Tests/Editor/Extensions/FloatExtensionsTests.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1f694652c6eefae4ab20889b19c04ea3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Tests/Editor/Extensions/VectorExtensionsTests.cs: -------------------------------------------------------------------------------- 1 | using ElasticSea.Framework.Extensions; 2 | using NUnit.Framework; 3 | using UnityEngine; 4 | using Assert = UnityEngine.Assertions.Assert; 5 | 6 | namespace ElasticSea.Framework.Tests.Extensions 7 | { 8 | public class VectorExtensionsTests 9 | { 10 | [TestCase] 11 | public void TestInverseLerpMiddle() 12 | { 13 | var min = new Vector3(0, 0, 0); 14 | var max = new Vector3(1, 1, 1); 15 | var value = new Vector3(0.5f, 0.5f, 0.5f); 16 | var t = min.InverseLerpWeird(max, value); 17 | Assert.AreEqual(0.5f, t); 18 | } 19 | 20 | [TestCase] 21 | public void TestInverseLerpFrom() 22 | { 23 | var min = new Vector3(0, 0, 0); 24 | var max = new Vector3(1, 1, 1); 25 | var value = min; 26 | var t = min.InverseLerpWeird(max, value); 27 | Assert.AreEqual(0, t); 28 | } 29 | 30 | [TestCase] 31 | public void TestInverseLerpTo() 32 | { 33 | var min = new Vector3(0, 0, 0); 34 | var max = new Vector3(1, 1, 1); 35 | var value = max; 36 | var t = min.InverseLerpWeird(max, value); 37 | Assert.AreEqual(1, t); 38 | } 39 | 40 | [TestCase] 41 | public void TestInverseLerpOverflowBottom() 42 | { 43 | var min = new Vector3(0, 0, 0); 44 | var max = new Vector3(1, 1, 1); 45 | var value = new Vector3(-1, -1, -1); 46 | var t = min.InverseLerpWeird(max, value); 47 | Assert.AreEqual(-1, t); 48 | } 49 | 50 | [TestCase] 51 | public void TestInverseLerpOverflowTop() 52 | { 53 | var min = new Vector3(0, 0, 0); 54 | var max = new Vector3(1, 1, 1); 55 | var value = new Vector3(2, 2, 2); 56 | var t = min.InverseLerpWeird(max, value); 57 | Assert.AreEqual(2, t); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /Tests/Editor/Extensions/VectorExtensionsTests.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c744205e99a84c67961871aa9c43a7cd 3 | timeCreated: 1660845893 -------------------------------------------------------------------------------- /Tests/Editor/Utils.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 49b69e8941094b1c92efec62052ebfd5 3 | timeCreated: 1636861267 -------------------------------------------------------------------------------- /Tests/Editor/Utils/CircularBufferTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using NUnit.Framework; 4 | using ElasticSea.Framework.Util; 5 | 6 | namespace ElasticSea.Framework.Tests.Extensions 7 | { 8 | public class CircularBufferTests 9 | { 10 | [Test] 11 | public void TestHalfFilled() 12 | { 13 | var circularBuffer = new CircularBuffer(5) {1, 2, 3}; 14 | Assert.AreEqual(circularBuffer.Count, 3); 15 | Assert.AreEqual(circularBuffer.Capacity, 5); 16 | } 17 | 18 | [Test] 19 | public void TestHalfFilledEnumeration() 20 | { 21 | var circularBuffer = new CircularBuffer(5) {1, 2, 3}; 22 | CollectionAssert.AreEqual(new List {1, 2, 3}, circularBuffer.ToList()); 23 | } 24 | 25 | [Test] 26 | public void TestOverFilled() 27 | { 28 | var circularBuffer = new CircularBuffer(5) {1, 2, 3, 4, 5, 6, 7}; 29 | Assert.AreEqual(circularBuffer.Count, 5); 30 | Assert.AreEqual(circularBuffer.Capacity, 5); 31 | } 32 | 33 | [Test] 34 | public void TestOverFilledEnumeration() 35 | { 36 | var circularBuffer = new CircularBuffer(5) {1, 2, 3, 4, 5, 6, 7}; 37 | CollectionAssert.AreEqual(new List {3, 4, 5, 6, 7}, circularBuffer.ToList()); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Tests/Editor/Utils/CircularBufferTests.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 69172aeea29e42edaaa62bf2b5b6a51c 3 | timeCreated: 1636861269 -------------------------------------------------------------------------------- /Tests/Editor/Utils/OrderedIndexPoolTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Avatars.Hands.DynamicGrab; 3 | using ElasticSea.Framework.Util; 4 | using NUnit.Framework; 5 | 6 | namespace ElasticSea.Framework.Tests.Editor.Utils 7 | { 8 | [TestFixture] 9 | public class OrderedIndexPoolTests 10 | { 11 | private OrderedIndexPool pool; 12 | 13 | [SetUp] 14 | public void Setup() 15 | { 16 | pool = new OrderedIndexPool(); 17 | } 18 | 19 | [Test] 20 | public void Get_FirstCall_ReturnsZero() 21 | { 22 | Assert.AreEqual(0, pool.Get()); 23 | } 24 | 25 | [Test] 26 | public void Get_MultipleCalls_ReturnsSequentialIndices() 27 | { 28 | Assert.AreEqual(0, pool.Get()); 29 | Assert.AreEqual(1, pool.Get()); 30 | Assert.AreEqual(2, pool.Get()); 31 | } 32 | 33 | [Test] 34 | public void Put_FreesIndex_CanBeReusedByGet() 35 | { 36 | var id0 = pool.Get(); 37 | pool.Get(); 38 | 39 | pool.Put(id0); 40 | 41 | Assert.AreEqual(0, pool.Get()); 42 | } 43 | 44 | [Test] 45 | public void Put_IndexHigherThanCount_ThrowsException() 46 | { 47 | Assert.Throws(() => pool.Put(100)); 48 | } 49 | 50 | [Test] 51 | public void Put_AlreadyFreeIndex_ThrowsException() 52 | { 53 | int idx = pool.Get(); 54 | pool.Put(idx); 55 | Assert.Throws(() => pool.Put(idx)); // double free 56 | } 57 | 58 | [Test] 59 | public void Get_AfterPutReusesLowestFreeIndex() 60 | { 61 | pool.Get(); // 0 62 | pool.Get(); // 1 63 | pool.Get(); // 2 64 | 65 | pool.Put(1); 66 | pool.Put(0); 67 | 68 | Assert.AreEqual(0, pool.Get()); 69 | Assert.AreEqual(1, pool.Get()); 70 | Assert.AreEqual(3, pool.Get()); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Tests/Editor/Utils/OrderedIndexPoolTests.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 06275bea152144abb4f50bcccc408915 3 | timeCreated: 1747928536 -------------------------------------------------------------------------------- /Tests/Editor/Utils/PhysicsButtonUtilsTests.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e1b9ba8b83894948845b1005d44ca2f4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Tests/Editor/Utils/PhysicsUtilsTests.cs: -------------------------------------------------------------------------------- 1 | using ElasticSea.Framework.Scripts.Util; 2 | using ElasticSea.Framework.Util; 3 | using NUnit.Framework; 4 | using UnityEngine; 5 | 6 | namespace ElasticSea.Framework.Tests.Extensions 7 | { 8 | public class PhysicsUtilsTests 9 | { 10 | [Test] 11 | public void BoxTriangleIntersectorOldTest1() 12 | { 13 | var box = Utils.Bounds(Vector3.zero, Vector3.one * 10); 14 | var triangle = new[] { new Vector3(12, 9, 9), new Vector3(9, 12, 9), new Vector3(19, 19, 20) }; 15 | 16 | var intersect = BoxTriangleIntersectorOld.IsIntersecting(box, triangle[0], triangle[1], triangle[2]); 17 | Assert.AreEqual(false, intersect); 18 | } 19 | 20 | [Test] 21 | public void BoxTriangleIntersectorTest1() 22 | { 23 | var box = Utils.Bounds(Vector3.zero, Vector3.one * 10); 24 | var triangle = new[] { new Vector3(12, 9, 9), new Vector3(9, 12, 9), new Vector3(19, 19, 20) }; 25 | 26 | var intersect = BoxTriangleIntersector.IsIntersecting(box, triangle[0], triangle[1], triangle[2]); 27 | Assert.AreEqual(false, intersect); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Tests/Editor/Utils/PhysicsUtilsTests.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6f43e2f408044abd9e7cf53dd8623256 3 | timeCreated: 1679141436 -------------------------------------------------------------------------------- /Tests/Editor/Utils/PriorityPoolTests.cs: -------------------------------------------------------------------------------- 1 | using ElasticSea.Framework.Util; 2 | using NUnit.Framework; 3 | 4 | namespace ElasticSea.Framework.Tests.Util 5 | { 6 | public class PriorityPoolTests 7 | { 8 | [Test] 9 | public void PriorityPool() 10 | { 11 | var id = 0; 12 | var pool = new PriorityPool(0, () => 13 | { 14 | var generatedId = id; 15 | id++; 16 | return generatedId; 17 | }); 18 | 19 | Assert.AreEqual(0, pool.Get()); 20 | Assert.AreEqual(1, pool.Get()); 21 | Assert.AreEqual(2, pool.Get()); 22 | Assert.AreEqual(3, pool.Get()); 23 | Assert.AreEqual(4, pool.Get()); 24 | Assert.AreEqual(5, pool.Get()); 25 | 26 | pool.Put(3); 27 | pool.Put(4); 28 | pool.Put(1); 29 | 30 | Assert.AreEqual(1, pool.Get()); 31 | Assert.AreEqual(3, pool.Get()); 32 | Assert.AreEqual(4, pool.Get()); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Tests/Editor/Utils/PriorityPoolTests.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5e3a154ead0e40fba342c74cf90fd003 3 | timeCreated: 1704492965 -------------------------------------------------------------------------------- /Tests/Editor/Utils/UtilsTests.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ef438bf32367482587ce64ec2b719989 3 | timeCreated: 1664391364 --------------------------------------------------------------------------------