├── ProjectSettings ├── ProjectVersion.txt ├── ClusterInputManager.asset ├── NetworkManager.asset ├── TimeManager.asset ├── EditorBuildSettings.asset ├── VFXManager.asset ├── AudioManager.asset ├── TagManager.asset ├── EditorSettings.asset ├── PresetManager.asset ├── UnityConnectSettings.asset ├── DynamicsManager.asset ├── Physics2DSettings.asset ├── NavMeshAreas.asset └── GraphicsSettings.asset ├── Assets ├── Collision.meta ├── Collision │ ├── BVH.meta │ ├── Geometry.meta │ ├── BVH │ │ └── BVH.cs.meta │ ├── Geometry │ │ ├── 2D.meta │ │ ├── AABB.cs.meta │ │ ├── OBB.cs.meta │ │ ├── Plane.cs.meta │ │ ├── Ray.cs.meta │ │ ├── Sphere.cs.meta │ │ ├── 2D │ │ │ ├── Polygon.cs.meta │ │ │ ├── Rect.cs.meta │ │ │ ├── Segment.cs.meta │ │ │ ├── Polygon.cs │ │ │ ├── Segment.cs │ │ │ └── Rect.cs │ │ ├── BaseShape.cs.meta │ │ ├── Capsule.cs.meta │ │ ├── ColMesh.cs.meta │ │ ├── Cylinder.cs.meta │ │ ├── Triangle.cs.meta │ │ ├── ColMesh.cs │ │ ├── Cylinder.cs │ │ ├── Triangle.cs │ │ ├── Ray.cs │ │ ├── Sphere.cs │ │ ├── Plane.cs │ │ ├── OBB.cs │ │ ├── Capsule.cs │ │ ├── BaseShape.cs │ │ └── AABB.cs │ ├── UnityWarp.meta │ ├── ColliderProxy.cs.meta │ ├── CollisionUtils.meta │ ├── SpacePartition.meta │ ├── UnityWarp │ │ ├── Editor.meta │ │ ├── UnityColliderProxy.cs.meta │ │ ├── Editor │ │ │ ├── EditorColliderProxy.cs.meta │ │ │ └── EditorColliderProxy.cs │ │ ├── Test │ │ │ ├── DebugUnityColliderProxy.cs.meta │ │ │ ├── TestCollision3D.cs.meta │ │ │ └── DebugUnityColliderProxy.cs │ │ ├── Test.meta │ │ ├── DebugDraw.meta │ │ ├── DebugDraw │ │ │ ├── DebugExtension.cs.meta │ │ │ ├── EditorBaseShape.cs.meta │ │ │ └── EditorBaseShape.cs │ │ └── UnityColliderProxy.cs │ ├── SpacePartition │ │ ├── Cell.cs.meta │ │ ├── CObject.cs.meta │ │ ├── HierachyGrid.cs.meta │ │ ├── Algorithm.cs.meta │ │ ├── CObject.cs │ │ ├── Cell.cs │ │ └── Algorithm.cs │ ├── CollisionUtils │ │ ├── CollisionFuncs.cs.meta │ │ ├── CollisionMovingPrim.cs.meta │ │ ├── CollisionTestRayPrim.cs.meta │ │ ├── CollisionClosestPoint.cs.meta │ │ └── CollisionTestPrimPrim.cs.meta │ └── ColliderProxy.cs ├── Collision2D │ ├── Test.meta │ ├── CTransform2D.cs.meta │ ├── ColliderPart.cs.meta │ ├── ColliderProxy.cs.meta │ ├── Shape │ │ ├── CAABB.cs.meta │ │ ├── CCircle.cs.meta │ │ ├── COBB.cs.meta │ │ ├── CRay.cs.meta │ │ ├── CBaseShape.cs.meta │ │ ├── CPolygon.cs.meta │ │ ├── CSegment.cs.meta │ │ ├── CBaseShape.cs │ │ ├── CSegment.cs │ │ ├── CPolygon.cs │ │ ├── CCircle.cs │ │ ├── CAABB.cs │ │ ├── CRay.cs │ │ └── COBB.cs │ ├── ColliderPrefab.cs.meta │ ├── CollisionHelper.cs.meta │ ├── CollisionHelper1.cs.meta │ ├── CollisionSystem.cs.meta │ ├── ICollisionSystem.cs.meta │ ├── Test │ │ ├── RandomMove.cs.meta │ │ ├── TestQuadTree.cs.meta │ │ ├── ColliderProxyMono.cs.meta │ │ ├── RandomMove.cs │ │ └── ColliderProxyMono.cs │ ├── QuadTree │ │ ├── QuadTreeExt.cs.meta │ │ ├── BoundQuadTreeNode.cs.meta │ │ ├── BoundQuadTree.cs.meta │ │ └── QuadTreeExt.cs │ ├── ColliderPart.cs │ ├── Shape.meta │ ├── QuadTree.meta │ ├── Utils.cs.meta │ ├── ICollisionSystem.cs │ ├── CTransform2D.cs │ ├── ColliderPrefab.cs │ ├── ColliderProxy.cs │ └── CollisionHelper.cs ├── Math │ ├── BaseType │ │ ├── LRect.cs.meta │ │ ├── LAxis2D.cs.meta │ │ ├── LAxis3D.cs.meta │ │ ├── LFloat.cs.meta │ │ ├── LMatrix33.cs.meta │ │ ├── LVector2.cs.meta │ │ ├── LVector3.cs.meta │ │ ├── LQuaternion.cs.meta │ │ ├── LVector2Int.cs.meta │ │ ├── LVector3Int.cs.meta │ │ ├── LAxis2D.cs │ │ └── LAxis3D.cs │ ├── Editor.meta │ ├── LUT.meta │ ├── BaseType.meta │ ├── LMath.cs.meta │ ├── LRandom.cs.meta │ ├── LMathExtension.cs.meta │ ├── LMath_Vector.cs.meta │ ├── LUT │ │ ├── LUTAcos.cs.meta │ │ ├── LUTAsin.cs.meta │ │ ├── LUTAtan2.cs.meta │ │ └── LUTSinCos.cs.meta │ ├── Editor │ │ ├── EditorLFloat.cs.meta │ │ ├── EditorCreateLUT.cs.meta │ │ ├── EditorLVector2.cs.meta │ │ ├── EditorLVector3.cs.meta │ │ ├── EditorGUILayoutExt.cs.meta │ │ ├── EditorLVectorDrawTool.cs.meta │ │ ├── EditorGUILayoutExt.cs │ │ ├── EditorLVectorDrawTool.cs │ │ ├── EditorLFloat.cs │ │ ├── EditorLVector2.cs │ │ ├── EditorLVector3.cs │ │ └── EditorCreateLUT.cs │ ├── LMathExtension2.cs.meta │ ├── LMathExtension2.cs │ ├── LRandom.cs │ ├── LMathExtension.cs │ └── LMath_Vector.cs ├── NativeUtil │ ├── Buffer.cs.meta │ ├── NativePool.cs.meta │ ├── NativeHelper.cs.meta │ ├── Buffer.cs │ ├── NativePool.cs │ └── NativeHelper.cs ├── Octree │ ├── TestOCTree.cs.meta │ ├── Octree.unity.meta │ ├── Scripts.meta │ ├── Scripts │ │ ├── BoundsOctree.cs.meta │ │ ├── PointOctree.cs.meta │ │ ├── PointOctreeNode.cs.meta │ │ └── BoundsOctreeNode.cs.meta │ └── TestOCTree.cs ├── Collision2D_Unsafe │ ├── UnityWarp.meta │ ├── Utils.meta │ ├── Shape │ │ ├── OBB2D.cs.meta │ │ ├── Ray2D.cs.meta │ │ ├── AABB2D.cs.meta │ │ ├── Circle.cs.meta │ │ ├── IShape2D.cs.meta │ │ ├── Polygon.cs.meta │ │ ├── Transform2D.cs.meta │ │ ├── IShape2D.cs │ │ ├── Transform2D.cs │ │ ├── Ray2D.cs │ │ ├── Circle.cs │ │ ├── AABB2D.cs │ │ └── OBB2D.cs │ ├── ColliderConfig.cs.meta │ ├── QuadTree │ │ ├── PtrList.cs.meta │ │ ├── LDemoScript.cs.meta │ │ ├── PhysicsBody.cs.meta │ │ ├── RandomMove.cs.meta │ │ ├── CollisionFactory.cs.meta │ │ ├── CollisionSystem.cs.meta │ │ ├── CollisionTest.cs.meta │ │ ├── QuadTreeFactory.cs.meta │ │ ├── CollisionSystemQuadTree.cs.meta │ │ ├── QuadTree.cs.meta │ │ ├── QuadTreeFactory.cs │ │ ├── CollisionFactory.cs │ │ ├── RandomMove.cs │ │ ├── CollisionSystemQuadTree.cs │ │ ├── CollisionTest.cs │ │ ├── PhysicsBody.cs │ │ ├── PtrList.cs │ │ └── LDemoScript.cs │ ├── UnityWarp │ │ ├── Editor.meta │ │ ├── GizmosHelper.cs.meta │ │ ├── Test.meta │ │ ├── New Material.mat.meta │ │ ├── ShapeWrap.cs.meta │ │ ├── Test │ │ │ └── TestCollision2D.cs.meta │ │ ├── Editor │ │ │ ├── EditorCollider2DMono.cs.meta │ │ │ └── EditorCollider2DMono.cs │ │ ├── ShapeWrap.cs │ │ ├── New Material.mat │ │ └── GizmosHelper.cs │ ├── Utils │ │ ├── UnsafeUtils.cs.meta │ │ └── UnsafeUtils.cs │ ├── QuadTree.meta │ ├── Shape.meta │ └── ColliderConfig.cs ├── Math.meta ├── Octree.meta ├── Plugins.meta ├── Scenes.meta ├── Scenes │ ├── TestCollision2D.unity.meta │ ├── TestCollision3D.unity.meta │ ├── TestCollision2DQuadTree.unity.meta │ └── TestQuadTree.unity.meta ├── Temp.meta ├── Collision2D.meta ├── NativeUtil.meta ├── Plugins │ ├── Editor │ │ ├── JetBrains │ │ │ └── JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll │ │ └── JetBrains.meta │ └── Editor.meta ├── Collision2D_Unsafe.meta ├── TestRotation.cs.meta └── TestRotation.cs ├── .gitignore ├── README.md └── Packages └── manifest.json /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 2018.3.5f1 2 | -------------------------------------------------------------------------------- /Assets/Collision.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 41e65d9bb6b84fba96ddd3db7d2061f1 3 | timeCreated: 1553562604 -------------------------------------------------------------------------------- /Assets/Collision/BVH.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d76232241624d18b81ed13384199124 3 | timeCreated: 1553849422 -------------------------------------------------------------------------------- /Assets/Collision/Geometry.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ae97ec7a2eef4ff1a3769fd08599c109 3 | timeCreated: 1553584151 -------------------------------------------------------------------------------- /Assets/Collision2D/Test.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2f0e685c8fbb4bbea55f5b1dd6cde616 3 | timeCreated: 1564974344 -------------------------------------------------------------------------------- /Assets/Collision/BVH/BVH.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b2accd6460c348c5b67c7df51b51e982 3 | timeCreated: 1553849447 -------------------------------------------------------------------------------- /Assets/Collision/Geometry/2D.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fdc3e25ff02044ed8fcb7c335238f56d 3 | timeCreated: 1553732828 -------------------------------------------------------------------------------- /Assets/Collision/UnityWarp.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 17178980699a4a7cb665395094ea757a 3 | timeCreated: 1561017633 -------------------------------------------------------------------------------- /Assets/Math/BaseType/LRect.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3fc752c701854755b157270b1bbf6391 3 | timeCreated: 1564458844 -------------------------------------------------------------------------------- /Assets/NativeUtil/Buffer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f98f3a65e86f40e6b3e2db68aa698340 3 | timeCreated: 1564473559 -------------------------------------------------------------------------------- /Assets/Octree/TestOCTree.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 74546b590c384eb692b46f312c9a6b76 3 | timeCreated: 1564881670 -------------------------------------------------------------------------------- /Assets/Collision/ColliderProxy.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a651957e07054a9ea607faca93bac86a 3 | timeCreated: 1561018104 -------------------------------------------------------------------------------- /Assets/Collision/CollisionUtils.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6bc517ff250e4f6381aab228d2810986 3 | timeCreated: 1560990744 -------------------------------------------------------------------------------- /Assets/Collision/Geometry/AABB.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: caa85c3d450d461380cdb8181f9d4ec9 3 | timeCreated: 1553599142 -------------------------------------------------------------------------------- /Assets/Collision/Geometry/OBB.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c1d978f099347b7b19fc79aa22029d4 3 | timeCreated: 1553584576 -------------------------------------------------------------------------------- /Assets/Collision/Geometry/Plane.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e7b22a10a300467780b0f37d2ebf0373 3 | timeCreated: 1553562621 -------------------------------------------------------------------------------- /Assets/Collision/Geometry/Ray.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa56ccf6cd1843ada2f944f394c9eb6a 3 | timeCreated: 1553730471 -------------------------------------------------------------------------------- /Assets/Collision/Geometry/Sphere.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 349514351a6c402eaa1f916c16f269cd 3 | timeCreated: 1553584187 -------------------------------------------------------------------------------- /Assets/Collision/SpacePartition.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1876b112239a48bba97aca12be82c2e6 3 | timeCreated: 1553956078 -------------------------------------------------------------------------------- /Assets/Collision/UnityWarp/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 491ae4b053b9444695994fa46ecc6d87 3 | timeCreated: 1561019403 -------------------------------------------------------------------------------- /Assets/Collision2D/CTransform2D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1b9309b81b2b48309300b5c00550819c 3 | timeCreated: 1564997216 -------------------------------------------------------------------------------- /Assets/Collision2D/ColliderPart.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2d12b2d32efc4ac6998d9563fbec48fe 3 | timeCreated: 1564997225 -------------------------------------------------------------------------------- /Assets/Collision2D/ColliderProxy.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9ef0fe5f4a724bdc96ceec38881a78a8 3 | timeCreated: 1564973239 -------------------------------------------------------------------------------- /Assets/Collision2D/Shape/CAABB.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5f285ba6a3cf45388ea173ae0fa8afdc 3 | timeCreated: 1564997182 -------------------------------------------------------------------------------- /Assets/Collision2D/Shape/CCircle.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bb4fb0196f6549b0852dee56910b8094 3 | timeCreated: 1564997177 -------------------------------------------------------------------------------- /Assets/Collision2D/Shape/COBB.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1eaa6a3a6f974aceb2f9dc042643aa0b 3 | timeCreated: 1564997192 -------------------------------------------------------------------------------- /Assets/Collision2D/Shape/CRay.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4c129c2ef9b94503bbf940cf035ee809 3 | timeCreated: 1564997201 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/UnityWarp.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c5a0c7551c3047078d57c0aaad15c653 3 | timeCreated: 1556953570 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/Utils.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6c463b90aa594842891a664498e1bafc 3 | timeCreated: 1556937604 -------------------------------------------------------------------------------- /Assets/NativeUtil/NativePool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 90dd56bb3da54eaf81798271ad06df26 3 | timeCreated: 1564494968 -------------------------------------------------------------------------------- /Assets/Collision/Geometry/2D/Polygon.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 91c1ff14142a411ba5401e69a7e5d7df 3 | timeCreated: 1553604724 -------------------------------------------------------------------------------- /Assets/Collision/Geometry/2D/Rect.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2afcd16776b14ee5affa7a20176b084e 3 | timeCreated: 1553600394 -------------------------------------------------------------------------------- /Assets/Collision/Geometry/2D/Segment.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2e1a13824327438f868f5b5877dcea93 3 | timeCreated: 1553608121 -------------------------------------------------------------------------------- /Assets/Collision/Geometry/BaseShape.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eb7aaada696146da8d68085909693c5b 3 | timeCreated: 1553652863 -------------------------------------------------------------------------------- /Assets/Collision/Geometry/Capsule.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e690c066029f4c658ee6c3eb5f24aada 3 | timeCreated: 1553596623 -------------------------------------------------------------------------------- /Assets/Collision/Geometry/ColMesh.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 11687b156a10490990c8794ab95179c4 3 | timeCreated: 1553730826 -------------------------------------------------------------------------------- /Assets/Collision/Geometry/Cylinder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e623613b22b54616b3cb96a9eaabaa98 3 | timeCreated: 1553731351 -------------------------------------------------------------------------------- /Assets/Collision/Geometry/Triangle.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4f3739f0be2448daaca6654d651b0837 3 | timeCreated: 1553849712 -------------------------------------------------------------------------------- /Assets/Collision/SpacePartition/Cell.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 795b5f2f08e44642ab3563b8512da0e7 3 | timeCreated: 1553995307 -------------------------------------------------------------------------------- /Assets/Collision2D/ColliderPrefab.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d51b995093214400b1e6876dd723b072 3 | timeCreated: 1564997233 -------------------------------------------------------------------------------- /Assets/Collision2D/CollisionHelper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6d3f74357fc94cf49e1dc3693b6e6627 3 | timeCreated: 1564921158 -------------------------------------------------------------------------------- /Assets/Collision2D/CollisionHelper1.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 690fd9e1ae7a4bcd8341adec727d4064 3 | timeCreated: 1564920128 -------------------------------------------------------------------------------- /Assets/Collision2D/CollisionSystem.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2ee979339a2a4794b83c6dd3a499e9a9 3 | timeCreated: 1564922078 -------------------------------------------------------------------------------- /Assets/Collision2D/ICollisionSystem.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa0f8ec8565b4400912c30354dbb20ab 3 | timeCreated: 1564987175 -------------------------------------------------------------------------------- /Assets/Collision2D/Shape/CBaseShape.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6c0b3f0711084e62834e5e7783d4adea 3 | timeCreated: 1564997172 -------------------------------------------------------------------------------- /Assets/Collision2D/Shape/CPolygon.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f9481668ef4346a7b9d3e1453a248596 3 | timeCreated: 1564997197 -------------------------------------------------------------------------------- /Assets/Collision2D/Shape/CSegment.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8b574e2a20d2465597b2a42226c920a1 3 | timeCreated: 1564997206 -------------------------------------------------------------------------------- /Assets/Collision2D/Test/RandomMove.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cb7de96cb5a3487f9488b9b36329a5ff 3 | timeCreated: 1564973959 -------------------------------------------------------------------------------- /Assets/Collision2D/Test/TestQuadTree.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eedfedaddb6d44914acf75372dd6e5b0 3 | timeCreated: 1564881670 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/Shape/OBB2D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa2f336095c84072a8baaebf80848635 3 | timeCreated: 1564739017 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/Shape/Ray2D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b10e31c00f6545169901f78b507e8e19 3 | timeCreated: 1564739666 -------------------------------------------------------------------------------- /Assets/Collision/SpacePartition/CObject.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ac0a5091ef674726815712ab4d0c270e 3 | timeCreated: 1554000690 -------------------------------------------------------------------------------- /Assets/Collision2D/QuadTree/QuadTreeExt.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 84d80fea1724497e8773ecce142fe8d9 3 | timeCreated: 1565004709 -------------------------------------------------------------------------------- /Assets/Collision2D/Test/ColliderProxyMono.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2b8bb4c4f71844b7b6b0895ed00c1bf2 3 | timeCreated: 1564974310 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/ColliderConfig.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bed68acb97394f93b148496cdb1a7ef9 3 | timeCreated: 1556953889 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/PtrList.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 44a1b02270c44f239fbb630a86515676 3 | timeCreated: 1564496114 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/Shape/AABB2D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 680ecef5d5874c81ba54b1807e158970 3 | timeCreated: 1564538144 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/Shape/Circle.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e1b898240f584d11a825e5aa6a23b692 3 | timeCreated: 1564538128 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/Shape/IShape2D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5957de4861744f9fab927ec8e2a9d1b2 3 | timeCreated: 1564818135 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/Shape/Polygon.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 532cfd3934334307aee4b4b53284a319 3 | timeCreated: 1564813546 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/UnityWarp/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4ec4ec0490054bbfa5f608b5240edcf1 3 | timeCreated: 1556956067 -------------------------------------------------------------------------------- /Assets/Collision/CollisionUtils/CollisionFuncs.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a9ee4d596b38437cb29e758e28ef54a2 3 | timeCreated: 1553569798 -------------------------------------------------------------------------------- /Assets/Collision/SpacePartition/HierachyGrid.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b95ee9edde69433eaedb692521891ac7 3 | timeCreated: 1553956091 -------------------------------------------------------------------------------- /Assets/Collision/UnityWarp/UnityColliderProxy.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 62341334a0ca424085b927ae100cd9cb 3 | timeCreated: 1561017601 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/LDemoScript.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9f72170e2b8244408e39957b4be8c2c2 3 | timeCreated: 1564459875 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/PhysicsBody.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 76e88646ea624a1188aec371e2598c3e 3 | timeCreated: 1564459494 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/RandomMove.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2d54919cc300460da018a5c12c5da548 3 | timeCreated: 1564565644 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/Shape/Transform2D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 836547ad34df457b92572a7aa3701373 3 | timeCreated: 1564915411 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/Utils/UnsafeUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1b9a3ab09460446b899e522fc58c7ed5 3 | timeCreated: 1565057228 -------------------------------------------------------------------------------- /Assets/Collision/CollisionUtils/CollisionMovingPrim.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e08287174ed74ec4a8c4fb3f55a34579 3 | timeCreated: 1553607524 -------------------------------------------------------------------------------- /Assets/Collision/CollisionUtils/CollisionTestRayPrim.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a776575d09e0410ab6e0e4d26ea42e6b 3 | timeCreated: 1553605091 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/CollisionFactory.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3a4275b1385c42d88f90f2ff7b39fff9 3 | timeCreated: 1564495457 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/CollisionSystem.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 022d481cfe474bc38fcdd44c4786d3c5 3 | timeCreated: 1564538323 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/CollisionTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fcf5cdef0ef04133bdc10fc8ce98f770 3 | timeCreated: 1564543043 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/QuadTreeFactory.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9e131e3de3bd492f9dd7b13c8bb69d2f 3 | timeCreated: 1564542658 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/UnityWarp/GizmosHelper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a7ea8f34069b41808ea7bb41e94cc8d1 3 | timeCreated: 1564835805 -------------------------------------------------------------------------------- /Assets/Collision/CollisionUtils/CollisionClosestPoint.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b822faa2fb8342b98b4a1a45fbc19943 3 | timeCreated: 1553597714 -------------------------------------------------------------------------------- /Assets/Collision/CollisionUtils/CollisionTestPrimPrim.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 08f29225166545639e3db098c2b5d9bf 3 | timeCreated: 1553584306 -------------------------------------------------------------------------------- /Assets/Collision/UnityWarp/Editor/EditorColliderProxy.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c0d98d6a576f64f51aadde832b4348a9 3 | timeCreated: 1553595648 -------------------------------------------------------------------------------- /Assets/Collision/UnityWarp/Test/DebugUnityColliderProxy.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 41bf0cd20e1e406d94969c5c3a1ff05f 3 | timeCreated: 1553595648 -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/CollisionSystemQuadTree.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ba21cf4232a44e128187691fcc8d089e 3 | timeCreated: 1564538291 -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!236 &1 4 | ClusterInputManager: 5 | m_ObjectHideFlags: 0 6 | m_Inputs: [] 7 | -------------------------------------------------------------------------------- /Assets/Collision2D/ColliderPart.cs: -------------------------------------------------------------------------------- 1 | namespace Lockstep.Collision2D { 2 | public class ColliderPart { 3 | public CBaseShape collider; 4 | public CTransform2D transform; 5 | } 6 | } -------------------------------------------------------------------------------- /Assets/Octree/Octree.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b74e6bbc6342d43809bf32317d63565d 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/Math.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f0bfd8778d154427cae39995818a1426 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Octree.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d8f799c9047ef4c3b9a03aaaff50861f 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: acd37ae9c3bbd44c293683601a0516d7 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 318309651824340208b8d099859609d7 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes/TestCollision2D.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 58fe50fe933b847bdad2cf98b3611206 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/Scenes/TestCollision3D.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 263d92e94534e48efa9f070744bc7e68 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/Temp.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bb33bbbdee73047cb82bd78f5c69e840 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Collision2D.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3a7fa3170cf0b4bdfb87ee3f4ab4e475 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Math/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1312656cd4cd431b9e9d2a1397cbb9c2 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Math/LUT.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a89e77e999fa4672b3a7c1daed916d95 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/NativeUtil.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3f5a0724ecf334964bffe3d7bb5e7d54 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiepengTan/LockstepCollision/HEAD/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!149 &1 4 | NetworkManager: 5 | m_ObjectHideFlags: 0 6 | m_DebugLevel: 0 7 | m_Sendrate: 15 8 | m_AssetToPrefab: {} 9 | -------------------------------------------------------------------------------- /Assets/Collision2D/Shape.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db0f50880d1eb4267946aa162378ca5f 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Math/BaseType.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d621fe57d60e549f782acf642a3bae7a 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Octree/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fc185301a800b46c2b31a5aa88d26ece 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1f590ac85a836461cb402e68eae90763 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes/TestCollision2DQuadTree.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6c2932d06a0904c8e87391fc44a5b29f 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/Collision2D/QuadTree.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7a3ae5b3f36dc4f3aa1784159b88e7d4 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 37b1b080092ea4bccb73f0d8b486ec45 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Collision/UnityWarp/Test.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 555b9c470a06d46c29d01b9793c40d45 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f512f0e88fb16411e9c83ee86d88c45e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/Shape.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 634e79e688a32429e9b3200cb7cf3e77 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins/Editor/JetBrains.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4665e617672a347b1b9a2b6057cdabd6 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Collision/UnityWarp/DebugDraw.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 29cee3079b92e48ce8407b2f232b86da 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/UnityWarp/Test.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3eb251e54707e45f8a7670ab5429bcb1 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/UnityWarp/New Material.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e0f2c89a96b40464785ee00a2b037be4 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!5 &1 4 | TimeManager: 5 | m_ObjectHideFlags: 0 6 | Fixed Timestep: 0.02 7 | Maximum Allowed Timestep: 0.1 8 | m_TimeScale: 1 9 | Maximum Particle Timestep: 0.03 10 | -------------------------------------------------------------------------------- /Assets/Scenes/TestQuadTree.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: de80edc0fda14424a909c661042e65e3 3 | timeCreated: 1527540977 4 | licenseType: Free 5 | DefaultImporter: 6 | externalObjects: {} 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/Shape/IShape2D.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | 3 | namespace Lockstep.UnsafeCollision2D { 4 | public interface IShape2D { 5 | int TypeId { get; } 6 | void UpdatePosition(LVector2 npos); 7 | void UpdateRotation(LFloat deg); 8 | } 9 | } -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1045 &1 4 | EditorBuildSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Scenes: 8 | - enabled: 0 9 | path: 10 | guid: 00000000000000000000000000000000 11 | m_configObjects: {} 12 | -------------------------------------------------------------------------------- /Assets/Collision2D/Shape/CBaseShape.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | using Lockstep.UnsafeCollision2D; 3 | 4 | namespace Lockstep.Collision2D { 5 | public class CBaseShape { 6 | public virtual int TypeId => (int) EShape2D.EnumCount; 7 | public int id; 8 | public LFloat high; 9 | } 10 | } -------------------------------------------------------------------------------- /Assets/Math/LMath.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2d18baf4c5a5fa040acb12553893e2b4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/LRandom.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8ca700f6740f740e880fde7eaff7a14d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/TestRotation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b7bf7e49d5702452ea5102a64b1b62fa 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Collision2D/Utils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 094eeb46fef8e4cb1b7e4ec75360d545 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/LMathExtension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1449fe353d5c843e19ea69b856cca1a9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/LMath_Vector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dcbde6defc0ba46f4adbc502d74603d9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/LUT/LUTAcos.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ccbd34bc707b2e34c9568d998f8d5ba4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/LUT/LUTAsin.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bcb2517cc8be49ffbaf9b6a20dd97971 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/LUT/LUTAtan2.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4945a9ed760bf9844a6dcc81070d99d8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/LUT/LUTSinCos.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 14dfbe3b6a5ba6444b295a48bb25c523 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/BaseType/LAxis2D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 57136d0c9a494a18a6ac9bbf5bea44ac 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/BaseType/LAxis3D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ab86dbf770a64560b0ba66bb2b1781b9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/BaseType/LFloat.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 82823ea45e74b6a458ce27b3be49b897 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/BaseType/LMatrix33.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 19371da510f54442a7e21f55638ba85b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/BaseType/LVector2.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6aadb2034ce14554d8547fed1a514ad7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/BaseType/LVector3.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 58d75e00eb6928c46bc893b9cffcfd54 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/Editor/EditorLFloat.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e897a93db93594db29651d5ffcf119db 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/LMathExtension2.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dd1e6a68372e64ed3b8998da88f78213 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/NativeUtil/NativeHelper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0f0a12bd0c0174b05b83f9db4f8ba142 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Collision2D/Shape/CSegment.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | using Lockstep.UnsafeCollision2D; 3 | 4 | namespace Lockstep.Collision2D { 5 | public class CSegment : CBaseShape { 6 | public override int TypeId => (int) EShape2D.Segment; 7 | public LVector2 pos1; 8 | public LVector2 pos2; 9 | } 10 | } -------------------------------------------------------------------------------- /Assets/Math/BaseType/LQuaternion.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3f5b9c68b7314a8c855b232ba4f70ec8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/BaseType/LVector2Int.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9dd95e1cb0fdf4aa49c5d7b3196bdbcf 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/BaseType/LVector3Int.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ff59a34da75fa43978efde2b56c62f40 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/Editor/EditorCreateLUT.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1392f1ef9f6b441abbefd691b6f043c0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/Editor/EditorLVector2.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8efbf74de423a4f9cabc13bbe3154816 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/Editor/EditorLVector3.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 55b4be72906474eaca3aeccd2de650f2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Collision/SpacePartition/Algorithm.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 14c1d263f56e9424c836de2044f900da 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/Editor/EditorGUILayoutExt.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7bf875233cf714540a406ca0ae2b4db9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Math/Editor/EditorLVectorDrawTool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e5d2a90077c27437c88dc1b81ed4fdc8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Collision2D/QuadTree/BoundQuadTreeNode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1973e13c2fa2d4bff9bb064869e4fe7a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/QuadTree.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8e4a61eabd23c455e970233246dc0d4f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/UnityWarp/ShapeWrap.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9d4bc9e7f17ca48da8cde16feca17a70 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Collision/UnityWarp/DebugDraw/DebugExtension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b8c31fad9c50e0b48935ec9f0234354b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Collision/UnityWarp/Test/TestCollision3D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e68bf4f36a589417e8744d39ba6e5e01 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Collision/UnityWarp/DebugDraw/EditorBaseShape.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 35f5566651160437982d23d4f0668b9b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/UnityWarp/Test/TestCollision2D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5477ff523597c4158b7800896936f436 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /ProjectSettings/VFXManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!937362698 &1 4 | VFXManager: 5 | m_ObjectHideFlags: 0 6 | m_IndirectShader: {fileID: 0} 7 | m_CopyBufferShader: {fileID: 0} 8 | m_SortShader: {fileID: 0} 9 | m_RenderPipeSettingsPath: 10 | m_FixedTimeStep: 0.016666668 11 | m_MaxDeltaTime: 0.05 12 | -------------------------------------------------------------------------------- /Assets/Octree/Scripts/BoundsOctree.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: acb06913ab8ee284b8b436ed59cce729 3 | timeCreated: 1481513782 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Octree/Scripts/PointOctree.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9db0c90c9ab9af246b08fa68962659ae 3 | timeCreated: 1481513782 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Octree/Scripts/PointOctreeNode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7a3117d130f3f2b46b4761386f25c3b8 3 | timeCreated: 1481513782 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Collision/Geometry/2D/Polygon.cs: -------------------------------------------------------------------------------- 1 | namespace Lockstep.Collision 2 | { 3 | [System.Serializable] 4 | public partial class Polygon:BaseShape 5 | { 6 | 7 | /// 8 | /// Collision Type 9 | /// 10 | public override EColType ColType{get { return EColType.Polygon;}} 11 | } 12 | } -------------------------------------------------------------------------------- /Assets/Collision2D/QuadTree/BoundQuadTree.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d5478958d3ad74eb596bbc8d9da649c3 3 | timeCreated: 1481513782 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/UnityWarp/Editor/EditorCollider2DMono.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 51855f69327cd4569a538ed1c7e3bd71 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Octree/Scripts/BoundsOctreeNode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 098c3a5fece947a4ba701dc1f6723c21 3 | timeCreated: 1481513782 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Collision2D/Shape/CPolygon.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | using Lockstep.UnsafeCollision2D; 3 | 4 | namespace Lockstep.Collision2D { 5 | public class CPolygon : CCircle { 6 | public override int TypeId => (int) EShape2D.Polygon; 7 | public int vertexCount; 8 | public LFloat deg; 9 | public LVector2[] vertexes; 10 | } 11 | } -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/Shape/Transform2D.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | using Lockstep.Math; 3 | 4 | namespace Lockstep.UnsafeCollision2D { 5 | [StructLayout(LayoutKind.Sequential, Pack = NativeHelper.STRUCT_PACK)] 6 | public unsafe struct Transform2D { 7 | public LVector2 pos; 8 | public LFloat y; 9 | public LFloat deg; 10 | } 11 | } -------------------------------------------------------------------------------- /Assets/Collision2D/Shape/CCircle.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | using Lockstep.UnsafeCollision2D; 3 | 4 | namespace Lockstep.Collision2D { 5 | public class CCircle : CBaseShape { 6 | public override int TypeId => (int) EShape2D.Circle; 7 | public LFloat radius; 8 | 9 | public CCircle() : this(LFloat.zero){ } 10 | 11 | public CCircle(LFloat radius){ 12 | this.radius = radius; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Assets/Collision2D/Shape/CAABB.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | using Lockstep.UnsafeCollision2D; 3 | 4 | namespace Lockstep.Collision2D { 5 | public class CAABB : CCircle { 6 | public override int TypeId => (int) EShape2D.AABB; 7 | public LVector2 size; 8 | 9 | public CAABB() : base(){ } 10 | 11 | public CAABB(LVector2 size){ 12 | this.size = size; 13 | radius = size.magnitude; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!11 &1 4 | AudioManager: 5 | m_ObjectHideFlags: 0 6 | m_Volume: 1 7 | Rolloff Scale: 1 8 | Doppler Factor: 1 9 | Default Speaker Mode: 2 10 | m_SampleRate: 0 11 | m_DSPBufferSize: 1024 12 | m_VirtualVoiceCount: 512 13 | m_RealVoiceCount: 32 14 | m_SpatializerPlugin: 15 | m_AmbisonicDecoderPlugin: 16 | m_DisableAudio: 0 17 | m_VirtualizeEffects: 1 18 | -------------------------------------------------------------------------------- /Assets/Collision/UnityWarp/Test/DebugUnityColliderProxy.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_5_3_OR_NEWER 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using Lockstep.Collision; 5 | using Lockstep.Math; 6 | 7 | public class DebugUnityColliderProxy : UnityColliderProxy { 8 | public Material mat; 9 | 10 | protected override void Start(){ 11 | base.Start(); 12 | mat = new Material(GetComponent().material); 13 | GetComponent().material = mat; 14 | } 15 | 16 | } 17 | #endif -------------------------------------------------------------------------------- /Assets/Collision/Geometry/2D/Segment.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | 3 | namespace Lockstep.Collision 4 | { 5 | [System.Serializable] 6 | public partial class Segment:BaseShape 7 | { 8 | /// 9 | /// Collision Type 10 | /// 11 | public override EColType ColType{get { return EColType.Segment;}} 12 | 13 | public LVector3 b; 14 | public LVector3 e; 15 | 16 | public Segment(LVector3 b, LVector3 e) 17 | { 18 | this.b = b; 19 | this.e = e; 20 | } 21 | 22 | } 23 | } -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!78 &1 4 | TagManager: 5 | serializedVersion: 2 6 | tags: [] 7 | layers: 8 | - Default 9 | - TransparentFX 10 | - Ignore Raycast 11 | - 12 | - Water 13 | - UI 14 | - 15 | - 16 | - PostProcessing 17 | - 18 | - 19 | - 20 | - 21 | - 22 | - 23 | - 24 | - 25 | - 26 | - 27 | - 28 | - 29 | - 30 | - 31 | - 32 | - 33 | - 34 | - 35 | - 36 | - 37 | - 38 | - 39 | - 40 | m_SortingLayers: 41 | - name: Default 42 | uniqueID: 0 43 | locked: 0 44 | -------------------------------------------------------------------------------- /Assets/Collision2D/ICollisionSystem.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | 3 | namespace Lockstep.Collision2D { 4 | public interface ICollisionSystem { 5 | void DoStart(int[][] interestingMasks, int[] allTypes); 6 | void DoUpdate(); 7 | ColliderProxy GetCollider(int id); 8 | void AddCollider(ColliderProxy collider); 9 | void RemoveCollider(ColliderProxy collider); 10 | bool Raycast(int layerType, Ray2D checkRay, out LFloat t, out int id, LFloat maxDistance); 11 | bool Raycast(int layerType, Ray2D checkRay, out LFloat t, out int id); 12 | 13 | //for debug 14 | void DrawGizmos(); 15 | int ShowTreeId { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | [Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | [Ll]og/ 5 | [Bb]uild/ 6 | [Bb]uilds/ 7 | Assets/AssetStoreTools* 8 | [Aa]ssets/TempRes 9 | [Aa]ssets/Plugins/Editor/JetBrains/ 10 | .idea/ 11 | 12 | # Visual Studio cache directory 13 | .vs/ 14 | 15 | # Autogenerated VS/MD/Consulo solution and project files 16 | ExportedObj/ 17 | .consulo/ 18 | *.csproj 19 | *.unityproj 20 | *.sln 21 | *.suo 22 | *.tmp 23 | *.user 24 | *.userprefs 25 | *.pidb 26 | *.booproj 27 | *.svd 28 | *.pdb 29 | *.opendb 30 | 31 | # Unity3D generated meta files 32 | *.pidb.meta 33 | *.pdb.meta 34 | 35 | # Unity3D Generated File On Crash Reports 36 | sysinfo.txt 37 | 38 | # Builds 39 | *.apk 40 | *.unitypackage 41 | Assets/Collision/EditorExtensions/submodule.h 42 | Assets/Collision/EditorExtensions/submodule.h.meta 43 | -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/QuadTreeFactory.cs: -------------------------------------------------------------------------------- 1 | namespace Lockstep.UnsafeCollision2D { 2 | public unsafe class QuadTreeFactory { 3 | private static NativePool _treePool = NativeFactory.GetPool(sizeof(QuadTree)); 4 | 5 | public static Circle** AllocPtrBlock(int size){ 6 | return (Circle**) NativeFactory.GetPool(sizeof(void*) * size).ForceGet(); 7 | } 8 | 9 | public static void FreePtrBlock(void* ptr, int size){ 10 | NativeFactory.GetPool(sizeof(void*) * size).Return(ptr); 11 | } 12 | 13 | public static QuadTree* AllocQuadTree(){ 14 | return (QuadTree*) _treePool.ForceGet(); 15 | } 16 | 17 | public static void FreeQuadTree(QuadTree* treePtr){ 18 | _treePool.Return(treePtr); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/Shape/Ray2D.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | using Lockstep.Collision2D; 3 | using Lockstep.Math; 4 | 5 | namespace Lockstep.UnsafeCollision2D { 6 | [StructLayout(LayoutKind.Sequential, Pack = NativeHelper.STRUCT_PACK)] 7 | public unsafe struct Ray2D { 8 | public int _TypeId; 9 | public int TypeId => _TypeId; 10 | public int Id; 11 | public LVector2 pos; 12 | public LVector2 dir; 13 | public Ray2D( int id, LVector2 pos, LVector2 dir){ 14 | this._TypeId = (int) EShape2D.Ray; 15 | this.Id = id; 16 | this.pos = pos; 17 | this.dir = dir; 18 | } 19 | public void UpdatePosition(LVector2 pos){this.pos = pos;} 20 | public void UpdateRotation(LFloat deg){} 21 | } 22 | } -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!159 &1 4 | EditorSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 7 7 | m_ExternalVersionControlSupport: Visible Meta Files 8 | m_SerializationMode: 2 9 | m_LineEndingsForNewScripts: 2 10 | m_DefaultBehaviorMode: 0 11 | m_PrefabRegularEnvironment: {fileID: 0} 12 | m_PrefabUIEnvironment: {fileID: 0} 13 | m_SpritePackerMode: 0 14 | m_SpritePackerPaddingPower: 1 15 | m_EtcTextureCompressorBehavior: 1 16 | m_EtcTextureFastCompressor: 1 17 | m_EtcTextureNormalCompressor: 2 18 | m_EtcTextureBestCompressor: 4 19 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef 20 | m_ProjectGenerationRootNamespace: 21 | m_CollabEditorSettings: 22 | inProgressEnabled: 1 23 | m_EnableTextureStreamingInPlayMode: 1 24 | -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/CollisionFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lockstep.UnsafeCollision2D { 4 | public unsafe class CollisionFactory { 5 | private static NativePool _spherePool = NativeFactory.GetPool(sizeof(Circle)); 6 | private static NativePool _aabbPool = NativeFactory.GetPool(sizeof(AABB2D)); 7 | 8 | public static Circle* AllocSphere(){ 9 | return (Circle*) _spherePool.ForceGet(); 10 | } 11 | 12 | public static AABB2D* AllocAABB(){ 13 | return (AABB2D*) _aabbPool.ForceGet(); 14 | } 15 | 16 | public static void Free(Circle* ptr){ 17 | _spherePool.Return(ptr); 18 | } 19 | 20 | public static void Free(AABB2D* ptr){ 21 | _aabbPool.Return(ptr); 22 | } 23 | 24 | } 25 | } -------------------------------------------------------------------------------- /Assets/Math/Editor/EditorGUILayoutExt.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using UnityEngine; 3 | using Lockstep.Math; 4 | 5 | namespace UnityEditor { 6 | public static class EditorGUILayoutExt { 7 | public static LFloat FloatField( string label,LFloat value,params GUILayoutOption[] options){ 8 | return EditorGUILayout.FloatField(label, value.ToFloat(),options).ToLFloat(); 9 | } 10 | public static LVector2 Vector2Field( string label,LVector2 value,params GUILayoutOption[] options){ 11 | return EditorGUILayout.Vector2Field(label, value.ToVector2(),options).ToLVector2(); 12 | } 13 | public static LVector2 Vector3Field( string label,LVector3 value,params GUILayoutOption[] options){ 14 | return EditorGUILayout.Vector3Field(label, value.ToVector3(),options).ToLVector3(); 15 | } 16 | } 17 | } 18 | #endif -------------------------------------------------------------------------------- /Assets/Collision2D/Shape/CRay.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | using Lockstep.Math; 3 | using Lockstep.UnsafeCollision2D; 4 | 5 | namespace Lockstep.Collision2D { 6 | public class CRay : CBaseShape { 7 | public override int TypeId => (int) EShape2D.Ray; 8 | public LVector2 pos; 9 | public LVector2 dir; 10 | } 11 | 12 | [StructLayout(LayoutKind.Sequential, Pack = NativeHelper.STRUCT_PACK)] 13 | public unsafe struct Ray2D { 14 | public int TypeId => (int) EShape2D.Ray; 15 | public LVector2 origin; 16 | public LVector2 direction; 17 | } 18 | 19 | [StructLayout(LayoutKind.Sequential, Pack = NativeHelper.STRUCT_PACK)] 20 | public struct LRaycastHit2D { 21 | public LVector2 point; 22 | public LFloat distance; 23 | public int colliderId; 24 | 25 | } 26 | } -------------------------------------------------------------------------------- /ProjectSettings/PresetManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1386491679 &1 4 | PresetManager: 5 | m_ObjectHideFlags: 0 6 | m_DefaultList: 7 | - type: 8 | m_NativeTypeID: 108 9 | m_ManagedTypePPtr: {fileID: 0} 10 | m_ManagedTypeFallback: 11 | defaultPresets: 12 | - m_Preset: {fileID: 2655988077585873504, guid: c1cf8506f04ef2c4a88b64b6c4202eea, 13 | type: 2} 14 | - type: 15 | m_NativeTypeID: 1020 16 | m_ManagedTypePPtr: {fileID: 0} 17 | m_ManagedTypeFallback: 18 | defaultPresets: 19 | - m_Preset: {fileID: 2655988077585873504, guid: 0cd792cc87e492d43b4e95b205fc5cc6, 20 | type: 2} 21 | - type: 22 | m_NativeTypeID: 1006 23 | m_ManagedTypePPtr: {fileID: 0} 24 | m_ManagedTypeFallback: 25 | defaultPresets: 26 | - m_Preset: {fileID: 2655988077585873504, guid: 7a99f8aa944efe94cb9bd74562b7d5f9, 27 | type: 2} 28 | -------------------------------------------------------------------------------- /Assets/Math/Editor/EditorLVectorDrawTool.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using Lockstep.Math; 5 | using UnityEngine; 6 | using UnityEditor; 7 | 8 | public static class EditorLVectorDrawTool { 9 | public const float LableWidthOffset = 45; 10 | public const float LableWid = 20; 11 | 12 | public static void DrawField(Rect position, float initX, ref float offset, float lableWid, float filedWid, 13 | SerializedProperty property, GUIContent label){ 14 | var lableRect = new Rect(initX + offset, position.y, 70, position.height); 15 | EditorGUI.LabelField(lableRect, label.text); 16 | var valRect = new Rect(initX + offset + lableWid, position.y, filedWid, position.height); 17 | var fVal = EditorGUI.FloatField(valRect, property.intValue * 1.0f / LFloat.Precision); 18 | property.intValue = (int) (fVal * LFloat.Precision); 19 | offset += filedWid + lableWid; 20 | } 21 | } 22 | #endif -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!310 &1 4 | UnityConnectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 1 7 | m_Enabled: 0 8 | m_TestMode: 0 9 | m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events 10 | m_EventUrl: https://cdp.cloud.unity3d.com/v1/events 11 | m_ConfigUrl: https://config.uca.cloud.unity3d.com 12 | m_TestInitMode: 0 13 | CrashReportingSettings: 14 | m_EventUrl: https://perf-events.cloud.unity3d.com 15 | m_Enabled: 0 16 | m_LogBufferSize: 10 17 | m_CaptureEditorExceptions: 1 18 | UnityPurchasingSettings: 19 | m_Enabled: 0 20 | m_TestMode: 0 21 | UnityAnalyticsSettings: 22 | m_Enabled: 1 23 | m_TestMode: 0 24 | m_InitializeOnStartup: 1 25 | UnityAdsSettings: 26 | m_Enabled: 0 27 | m_InitializeOnStartup: 1 28 | m_TestMode: 0 29 | m_IosGameId: 30 | m_AndroidGameId: 31 | m_GameIds: {} 32 | m_GameId: 33 | PerformanceReportingSettings: 34 | m_Enabled: 0 35 | -------------------------------------------------------------------------------- /Assets/Collision/Geometry/2D/Rect.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | using System.Runtime.CompilerServices; 3 | using Lockstep.Math; 4 | using static Lockstep.Math.LMath; 5 | using Point2D = Lockstep.Math.LVector2; 6 | 7 | namespace Lockstep.Collision 8 | { 9 | [System.Serializable] 10 | public partial class Rect : BaseShape 11 | { 12 | /// 13 | /// Collision Type 14 | /// 15 | public override EColType ColType 16 | { 17 | get { return EColType.Rect; } 18 | } 19 | 20 | /// 21 | /// // center point of rectangle 22 | /// 23 | public LVector3 c; 24 | 25 | /// 26 | /// unit vectors determining local x and y axes for the rectangle 27 | /// 28 | public LAxis2D u; 29 | 30 | /// 31 | /// the halfwidth extents of the rectangle along the axes 32 | /// 33 | public LVector2 e; 34 | 35 | 36 | }; 37 | } -------------------------------------------------------------------------------- /Assets/Collision/Geometry/ColMesh.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | 3 | namespace Lockstep.Collision 4 | { 5 | [System.Serializable] 6 | /// 7 | /// 碰撞网格 建议仅在静态情况下使用 8 | /// 9 | public partial class ColMesh : BaseShape 10 | { 11 | /// 12 | /// Collision Type 13 | /// 14 | public override EColType ColType 15 | { 16 | get { return EColType.ColMesh; } 17 | } 18 | 19 | public int verticesCount; 20 | public LVector3[] vertices; 21 | public LVector3[] triangles; 22 | public LVector3[] normal; 23 | public AABB bounds; 24 | protected Sphere boundSphere; 25 | 26 | public ColMesh(UnityEngine.Mesh mesh) 27 | { 28 | } 29 | 30 | public override Sphere GetBoundSphere() 31 | { 32 | return boundSphere; 33 | } 34 | 35 | public override bool TestWithShape(BaseShape shape) 36 | { 37 | return shape.TestWith(this); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Assets/Collision/Geometry/Cylinder.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | using static Lockstep.Math.LMath; 3 | using Point2D = Lockstep.Math.LVector2; 4 | 5 | namespace Lockstep.Collision 6 | { 7 | [System.Serializable] 8 | /// 9 | /// TODO implement 10 | /// 11 | public partial class Cylinder:BaseShape 12 | { 13 | public override EColType ColType{get { return EColType.Capsule;}} 14 | /// 15 | /// Medial line segment start point 16 | /// 17 | public LVector3 a; 18 | 19 | /// 20 | /// Medial line segment end point 21 | /// 22 | public LVector3 b; 23 | 24 | /// 25 | /// Radius 26 | /// 27 | public LFloat r; 28 | 29 | public override Sphere GetBoundSphere() 30 | { 31 | return new Sphere((a+b)*LFloat.half,(b-a).magnitude*LFloat.half + r); 32 | } 33 | public override bool TestWithShape(BaseShape shape) 34 | { 35 | return shape.TestWith(this); 36 | } 37 | }; 38 | } -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/Shape/Circle.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | using Lockstep.Collision2D; 3 | using Lockstep.Math; 4 | 5 | namespace Lockstep.UnsafeCollision2D { 6 | [StructLayout(LayoutKind.Sequential, Pack = NativeHelper.STRUCT_PACK)] 7 | public unsafe struct Circle :IShape2D{ 8 | public int _TypeId; 9 | public int TypeId => _TypeId; 10 | public int Id; 11 | public LVector2 pos; 12 | public LFloat radius; 13 | public QuadTree* ParentNode; 14 | public int _debugId; 15 | 16 | public LFloat SqrRadius => radius * radius; 17 | public Circle(int typeid, int id, LVector2 pos, LFloat radius){ 18 | this._TypeId = typeid; 19 | this.Id = id; 20 | this.pos = pos; 21 | this.radius = radius; 22 | ParentNode = null; 23 | _debugId = 0; 24 | } 25 | public Circle( int id, LVector2 pos, LFloat radius):this((int) EShape2D.Circle,id,pos,radius){} 26 | 27 | public void UpdatePosition(LVector2 pos){this.pos = pos;} 28 | public void UpdateRotation(LFloat deg){} 29 | } 30 | } -------------------------------------------------------------------------------- /Assets/Math/Editor/EditorLFloat.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using Lockstep.Math; 5 | using UnityEngine; 6 | using UnityEditor; 7 | 8 | [CustomPropertyDrawer(typeof(LFloat))] 9 | public class EditorLFloat : UnityEditor.PropertyDrawer { 10 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label){ 11 | var xProperty = property.FindPropertyRelative("_val"); 12 | float LabelWidth = EditorGUIUtility.labelWidth - EditorLVectorDrawTool.LableWidthOffset; 13 | float lableWid = EditorLVectorDrawTool.LableWid; 14 | var labelRect = new Rect(position.x, position.y, LabelWidth, position.height); 15 | EditorGUI.LabelField(labelRect, label); 16 | float filedWid = (position.width - LabelWidth); 17 | float initX = position.x + LabelWidth; 18 | var valRect = new Rect(initX, position.y, filedWid, position.height); 19 | var fVal = EditorGUI.FloatField(valRect, xProperty.intValue * 1.0f / LFloat.Precision); 20 | xProperty.intValue = (int) (fVal * LFloat.Precision); 21 | } 22 | } 23 | #endif -------------------------------------------------------------------------------- /Assets/Collision2D/CTransform2D.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | using Lockstep.Math; 3 | 4 | namespace Lockstep.Collision2D { 5 | public class CTransform2D { 6 | public LVector2 pos; 7 | public LFloat y; 8 | public LFloat deg; 9 | 10 | public CTransform2D(LVector2 pos, LFloat y) : this(pos, y, LFloat.zero){ } 11 | public CTransform2D(LVector2 pos) : this(pos, LFloat.zero, LFloat.zero){ } 12 | 13 | public CTransform2D(LVector2 pos, LFloat y, LFloat deg){ 14 | this.pos = pos; 15 | this.y = y; 16 | this.deg = deg; 17 | } 18 | 19 | 20 | public void Reset(){ 21 | pos = LVector2.zero; 22 | y = LFloat.zero; 23 | deg = LFloat.zero; 24 | } 25 | 26 | public static Transform2D operator +(CTransform2D a, CTransform2D b){ 27 | return new Transform2D {pos = a.pos + b.pos, y = a.y + b.y, deg = a.deg + b.deg}; 28 | } 29 | } 30 | 31 | [StructLayout(LayoutKind.Sequential, Pack = NativeHelper.STRUCT_PACK)] 32 | public unsafe struct Transform2D { 33 | public LVector2 pos; 34 | public LFloat y; 35 | public LFloat deg; 36 | } 37 | } -------------------------------------------------------------------------------- /Assets/Collision2D/Shape/COBB.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | using Lockstep.UnsafeCollision2D; 3 | 4 | namespace Lockstep.Collision2D { 5 | public class COBB : CAABB { 6 | public override int TypeId => (int) EShape2D.OBB; 7 | public LFloat deg; 8 | public LVector2 up; 9 | 10 | public COBB(LVector2 size, LFloat deg) : base(size){ 11 | this.deg = deg; 12 | SetDeg(deg); 13 | } 14 | 15 | public COBB(LVector2 size, LVector2 up) : base(size){ 16 | SetUp(up); 17 | } 18 | 19 | //CCW 旋转角度 20 | public void Rotate(LFloat rdeg){ 21 | deg += rdeg; 22 | if (deg > 360 || deg < -360) { 23 | deg = deg - (deg / 360 * 360); 24 | } 25 | 26 | SetDeg(deg); 27 | } 28 | 29 | public void SetUp(LVector2 up){ 30 | this.up = up; 31 | this.deg = LMath.Atan2(-up.x, up.y); 32 | } 33 | 34 | public void SetDeg(LFloat rdeg){ 35 | deg = rdeg; 36 | var rad = LMath.Deg2Rad * deg; 37 | var c = LMath.Cos(rad); 38 | var s = LMath.Sin(rad); 39 | up = new LVector2(-s, c); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/Shape/AABB2D.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | using Lockstep.Collision2D; 3 | using Lockstep.Math; 4 | 5 | namespace Lockstep.UnsafeCollision2D { 6 | [StructLayout(LayoutKind.Sequential, Pack = NativeHelper.STRUCT_PACK)] 7 | public unsafe struct AABB2D :IShape2D{ 8 | public Circle BoundSphere; 9 | 10 | public int TypeId { 11 | get => BoundSphere.TypeId; 12 | } 13 | 14 | public int Id { 15 | get => BoundSphere.Id; 16 | set => BoundSphere.Id = value; 17 | } 18 | 19 | public LVector2 pos { 20 | get => BoundSphere.pos; 21 | set => BoundSphere.pos = value; 22 | } 23 | 24 | public LFloat radius { 25 | get => BoundSphere.radius; 26 | set => BoundSphere.radius = value; 27 | } 28 | 29 | public LVector2 size; 30 | 31 | public AABB2D(int id, LVector2 pos, LVector2 size){ 32 | BoundSphere = new Circle((int) EShape2D.AABB, id, pos, size.magnitude); 33 | this.size = size; 34 | } 35 | public void UpdatePosition(LVector2 pos){this.pos = pos;} 36 | public void UpdateRotation(LFloat deg){} 37 | } 38 | } -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!55 &1 4 | PhysicsManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 8 7 | m_Gravity: {x: 0, y: -9.81, z: 0} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_BounceThreshold: 2 10 | m_SleepThreshold: 0.005 11 | m_DefaultContactOffset: 0.01 12 | m_DefaultSolverIterations: 6 13 | m_DefaultSolverVelocityIterations: 1 14 | m_QueriesHitBackfaces: 0 15 | m_QueriesHitTriggers: 1 16 | m_EnableAdaptiveForce: 0 17 | m_ClothInterCollisionDistance: 0 18 | m_ClothInterCollisionStiffness: 0 19 | m_ContactsGeneration: 1 20 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 21 | m_AutoSimulation: 1 22 | m_AutoSyncTransforms: 0 23 | m_ReuseCollisionCallbacks: 1 24 | m_ClothInterCollisionSettingsToggle: 0 25 | m_ContactPairsMode: 0 26 | m_BroadphaseType: 0 27 | m_WorldBounds: 28 | m_Center: {x: 0, y: 0, z: 0} 29 | m_Extent: {x: 250, y: 250, z: 250} 30 | m_WorldSubdivisions: 8 31 | -------------------------------------------------------------------------------- /Assets/Math/Editor/EditorLVector2.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using Lockstep.Math; 5 | using UnityEngine; 6 | using UnityEditor; 7 | 8 | [CustomPropertyDrawer(typeof(LVector2))] 9 | public class EditorLVector2 : UnityEditor.PropertyDrawer { 10 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label){ 11 | var xProperty = property.FindPropertyRelative("_x"); 12 | var yProperty = property.FindPropertyRelative("_y"); 13 | float LabelWidth = EditorGUIUtility.labelWidth - EditorLVectorDrawTool.LableWidthOffset; 14 | float lableWid = EditorLVectorDrawTool.LableWid; 15 | 16 | var labelRect = new Rect(position.x, position.y, LabelWidth, position.height); 17 | EditorGUI.LabelField(labelRect, label); 18 | float filedWid = (position.width - LabelWidth) / 2 - lableWid; 19 | float initX = position.x + LabelWidth; 20 | float offset = 0; 21 | EditorLVectorDrawTool.DrawField(position, initX, ref offset, lableWid, filedWid, xProperty, new GUIContent("x:")); 22 | EditorLVectorDrawTool.DrawField(position, initX, ref offset, lableWid, filedWid, yProperty, new GUIContent("y:")); 23 | } 24 | } 25 | #endif -------------------------------------------------------------------------------- /Assets/Math/BaseType/LAxis2D.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | using static Lockstep.Math.LMath; 3 | 4 | namespace Lockstep.Math 5 | { 6 | 7 | public struct LAxis2D 8 | { 9 | public LVector3 x; 10 | public LVector3 y; 11 | 12 | public static readonly LAxis2D identity = new LAxis2D(LVector3.right, LVector3.up); 13 | public LAxis2D(LVector3 x, LVector3 y) 14 | { 15 | this.x = x; 16 | this.y = y; 17 | } 18 | public LVector3 this[int index] 19 | { 20 | get 21 | { 22 | switch (index) 23 | { 24 | case 0: return x; 25 | case 1: return y; 26 | default: throw new System.IndexOutOfRangeException("vector idx invalid" + index); 27 | } 28 | } 29 | 30 | set 31 | { 32 | switch (index) 33 | { 34 | case 0: 35 | x = value; 36 | break; 37 | case 1: 38 | y = value; 39 | break; 40 | default: throw new System.IndexOutOfRangeException("vector idx invalid" + index); 41 | } 42 | } 43 | } 44 | } 45 | 46 | 47 | 48 | } -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/UnityWarp/ShapeWrap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.InteropServices; 4 | using Lockstep.Collision; 5 | using Lockstep.Collision2D; 6 | using Lockstep.Math; 7 | using UnityEngine; 8 | using UnityEngine.Profiling; 9 | 10 | namespace Lockstep.UnsafeCollision2D { 11 | public unsafe class ShapeWrap { 12 | public virtual int TypeId { get; } 13 | } 14 | 15 | public unsafe class ShapeWrapCircle : ShapeWrap { 16 | public Circle shape; 17 | public override int TypeId => (int) EShape2D.Circle; 18 | } 19 | 20 | public unsafe class ShapeWrapAABB : ShapeWrap { 21 | public AABB2D shape; 22 | public override int TypeId => (int) EShape2D.AABB; 23 | } 24 | 25 | public unsafe class ShapeWrapOBB : ShapeWrap { 26 | public OBB2D shape; 27 | public override int TypeId => (int) EShape2D.OBB; 28 | } 29 | 30 | public unsafe class ShapeWrapPolygon : ShapeWrap { 31 | public Polygon shape; 32 | public override int TypeId => (int) EShape2D.Polygon; 33 | public List points = new List(); 34 | 35 | public void AddPoint(LVector2 point){ 36 | points.Add(point); 37 | } 38 | 39 | public void RemovePoint(int idx){ 40 | points.RemoveAt(idx); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Assets/Collision/SpacePartition/CObject.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | using Point2D = Lockstep.Math.LVector2; 3 | using Shape = Lockstep.Collision.BaseShape; 4 | 5 | namespace Lockstep.Collision { 6 | /// 7 | /// Collision Object 8 | /// 9 | public partial class CObject { 10 | public int ID { private set; get; } 11 | public CObject pNextObject; // Embedded link to next hgrid object 12 | public CObject pPreObject; 13 | public LVector3 pos; // x, y (and z) position for sphere (or top left AABB corner) 14 | public LFloat radius; // Radius for bounding sphere (or width of AABB) 15 | public int bucket; // Index of hash bucket object is in 16 | public int level; // Grid level for the object 17 | public Cell cellPos; // which cell it belong to 18 | public byte layerMaskIdx;//layer mask for speed up collision detection 19 | public uint LayerMask { 20 | get { return 1u << (layerMaskIdx + 1); } 21 | } 22 | 23 | public CObject(int layerMaskIdx){ 24 | ID = ++SID; 25 | if (SID == int.MaxValue) { 26 | SID = 0; 27 | } 28 | this.layerMaskIdx = (byte)layerMaskIdx; 29 | } 30 | 31 | private static int SID = 0; 32 | 33 | public override int GetHashCode(){ 34 | return ID; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Assets/Collision2D/ColliderPrefab.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Lockstep.Math; 3 | using Lockstep.UnsafeCollision2D; 4 | using UnityEngine; 5 | 6 | namespace Lockstep.Collision2D { 7 | public class ColliderPrefab { 8 | public List parts = new List(); 9 | public CBaseShape collider => parts[0].collider; 10 | public CTransform2D transform => parts[0].transform; 11 | 12 | public LRect GetBounds(){ 13 | //TODO 14 | var col = collider; 15 | var tran = transform; 16 | var type = (EShape2D) col.TypeId; 17 | switch (type) { 18 | case EShape2D.Circle: { 19 | var radius = ((CCircle) col).radius; 20 | return LRect.CreateRect(tran.pos, new LVector2(radius, radius)); 21 | } 22 | case EShape2D.AABB: { 23 | var halfSize = ((CAABB) col).size; 24 | return LRect.CreateRect(tran.pos, halfSize); 25 | } 26 | case EShape2D.OBB: { 27 | var radius = ((COBB) col).radius; 28 | return LRect.CreateRect(tran.pos, new LVector2(radius, radius)); 29 | } 30 | } 31 | 32 | Debug.LogError("No support type" + type); 33 | 34 | return new LRect(); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Assets/Math/Editor/EditorLVector3.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using Lockstep.Math; 5 | using UnityEngine; 6 | using UnityEditor; 7 | 8 | 9 | [CustomPropertyDrawer(typeof(LVector3))] 10 | public class EditorLVector3 : UnityEditor.PropertyDrawer { 11 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label){ 12 | var xProperty = property.FindPropertyRelative("_x"); 13 | var yProperty = property.FindPropertyRelative("_y"); 14 | float LabelWidth = EditorGUIUtility.labelWidth - EditorLVectorDrawTool.LableWidthOffset; 15 | float lableWid = EditorLVectorDrawTool.LableWid; 16 | 17 | var labelRect = new Rect(position.x, position.y, LabelWidth, position.height); 18 | EditorGUI.LabelField(labelRect, label); 19 | float filedWid = (position.width - LabelWidth) / 3 - lableWid; 20 | float initX = position.x + LabelWidth; 21 | float offset = 0; 22 | EditorLVectorDrawTool.DrawField(position, initX, ref offset, lableWid, filedWid, xProperty, new GUIContent("x:")); 23 | EditorLVectorDrawTool.DrawField(position, initX, ref offset, lableWid, filedWid, yProperty, new GUIContent("y:")); 24 | EditorLVectorDrawTool.DrawField(position, initX, ref offset, lableWid, filedWid, yProperty, new GUIContent("z:")); 25 | } 26 | } 27 | #endif -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/RandomMove.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Timers; 3 | using UnityEngine; 4 | using Random = System.Random; 5 | 6 | namespace Lockstep.UnsafeCollision2D { 7 | public class RandomMove : MonoBehaviour { 8 | public float moveSpd = 5; 9 | public static Vector2 border; 10 | private Vector3 targetPos; 11 | public float targetChangedInterval = 3; 12 | 13 | 14 | private void Start(){ 15 | timer = targetChangedInterval; 16 | } 17 | 18 | private float timer; 19 | 20 | private void Update(){ 21 | float deltaTime = 0.04f; 22 | 23 | Vector3 pos = transform.position; 24 | if (targetPos != pos) { 25 | pos += (targetPos - transform.position).normalized * moveSpd * deltaTime; 26 | } 27 | 28 | timer += deltaTime; 29 | 30 | if (timer > targetChangedInterval) { 31 | timer = 0; 32 | CalcTargetPos(); 33 | } 34 | 35 | transform.position = pos; 36 | } 37 | 38 | private void CalcTargetPos(){ 39 | Vector3 _poss = transform.position; 40 | _poss.x = random.Next(0, (int) (100000)) * 0.001f; 41 | _poss.z = random.Next(0, (int) (100000)) * 0.001f; 42 | targetPos = _poss; 43 | } 44 | 45 | public Random random => LDemoScript.random; 46 | } 47 | } -------------------------------------------------------------------------------- /Assets/Collision/UnityWarp/UnityColliderProxy.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | using UnityEngine; 3 | 4 | namespace Lockstep.Collision { 5 | public class UnityColliderProxy : ColliderProxy { 6 | protected Vector3 _lastPosition; 7 | protected Quaternion _lastRotation; 8 | 9 | protected virtual void Start(){ 10 | _lastPosition = transform.position; 11 | _lastRotation = transform.rotation; 12 | } 13 | 14 | protected virtual void Update(){ 15 | //check pos or rotation changed 16 | var diffPos = _lastPosition != transform.position; 17 | 18 | var diffRot = _lastRotation != transform.rotation; 19 | if (diffPos) { 20 | _lastPosition = transform.position; 21 | UpdatePosition(transform.position.ToLVector3()); 22 | } 23 | 24 | if (diffRot) { 25 | _lastRotation = transform.rotation; 26 | UpdateRotation(transform.forward.ToLVector3(), transform.up.ToLVector3()); 27 | } 28 | } 29 | #if UNITY_EDITOR 30 | private void OnDrawGizmos(){ 31 | return; 32 | if (allCollider[0] is Capsule) { 33 | int i = 0; 34 | } 35 | foreach (var col in allCollider) { 36 | col.OnDrawGizmos(true, Color.green); 37 | } 38 | //boundSphere?.OnDrawGizmos(true, Color.red); 39 | } 40 | #endif 41 | 42 | } 43 | } -------------------------------------------------------------------------------- /Assets/Collision/SpacePartition/Cell.cs: -------------------------------------------------------------------------------- 1 | using Point2D = Lockstep.Math.LVector2; 2 | using Shape = Lockstep.Collision.BaseShape; 3 | 4 | 5 | namespace Lockstep.Collision { 6 | 7 | 8 | 9 | public struct Cell { 10 | public int x, y, z; 11 | 12 | public Cell(int px, int py, int pz){ 13 | x = px; 14 | y = py; 15 | z = pz; 16 | } 17 | 18 | public static bool operator ==(Cell lhs, Cell rhs){ 19 | return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z; 20 | } 21 | 22 | public static bool operator !=(Cell lhs, Cell rhs){ 23 | return lhs.x != rhs.x || lhs.y != rhs.y || lhs.z != rhs.z; 24 | } 25 | 26 | public override bool Equals(object o){ 27 | if (o == null) { 28 | return false; 29 | } 30 | 31 | Cell other = (Cell) o; 32 | return this.x == other.x && this.y == other.y && this.z == other.z; 33 | } 34 | 35 | 36 | public bool Equals(Cell other){ 37 | return this.x == other.x && this.y == other.y && this.z == other.z; 38 | } 39 | 40 | const uint __h1 = 0x8da6b343; // Large multiplicative constants; 41 | const uint __h2 = 0xd8163841; // here arbitrarily chosen primes 42 | const uint __h3 = 0xcb1ab31f; 43 | 44 | public override int GetHashCode(){ 45 | return (int) (__h1 * x + __h2 * y + __h3 * z); 46 | } 47 | }; 48 | } -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/CollisionSystemQuadTree.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Collision2D; 2 | using UnityEngine.Profiling; 3 | 4 | namespace Lockstep.UnsafeCollision2D { 5 | /// 6 | /// Queries a QuadTree to test for collisions with only nearby bodies 7 | /// 8 | public unsafe class CollisionSystemQuadTree : CollisionSystem { 9 | ///// Constructor ///// 10 | 11 | public CollisionSystemQuadTree(QuadTree* tree){ 12 | _quadTree = tree; 13 | } 14 | 15 | ///// Fields ///// 16 | 17 | private QuadTree* _quadTree; 18 | 19 | ///// Methods ///// 20 | 21 | 22 | public override void DetectBodyVsBody(){ 23 | countDetectBodyVsBody = 0; 24 | IteratePtrs(OnShapePtr); 25 | } 26 | 27 | void OnShapePtr(Circle* body1){ 28 | countDetectBodyVsBody++; 29 | Profiler.BeginSample("GetBodies"); 30 | var bodies = _quadTree->GetBodies(new LRect(body1->pos,((AABB2D*)body1)->size)); 31 | Profiler.EndSample(); 32 | Profiler.BeginSample("Test"); 33 | var count = bodies.Count; 34 | for (int i = 0; i < count; i++) { 35 | var body2 = (Circle*) bodies[i]; 36 | if (body2 == null || body1 == body2) { 37 | continue; 38 | } 39 | 40 | Test(body1, body2); 41 | } 42 | Profiler.EndSample(); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LockstepCollision 2 | 3 | - A deterministic collision detected lib 4 | 5 | ## **Collision2D** 6 | 7 | 8 | 9 | ### Collision 2D 介绍视频 10 | [https://www.bilibili.com/video/av62382378/][3] 11 | 12 | ### **Done** 13 | - AABB 14 | - Circle 15 | - OBB 16 | - Polygon 17 | - Ray 18 | - QuadTree SpacePatition 19 | 20 | 21 |

22 | 23 | 24 |

25 | 26 | 27 | 28 | ## **Collision3D** 29 | 30 | ### **Done** 31 | - AABB 32 | - OBB 33 | - Capsule 34 | - Sphere 35 | 36 | ### **TODO** 37 | - Mesh 38 | - SpacePartition 39 | 40 | 41 |

42 | 43 | 44 | ## **References:** 45 | - Deterministic Math lib: [https://github.com/JiepengTan/LockstepMath][1] 46 | - Lockstep framework: [https://github.com/JiepengTan/LockstepPlatform][2] 47 | 48 | 49 | [1]: https://github.com/JiepengTan/LockstepMath 50 | [2]: https://github.com/JiepengTan/LockstepPlatform 51 | [3]: https://www.bilibili.com/video/av62382378/ 52 | -------------------------------------------------------------------------------- /Assets/Collision2D/Test/RandomMove.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Random = UnityEngine.Random; 3 | 4 | namespace Lockstep.Collision2D { 5 | public class RandomMove : MonoBehaviour { 6 | public Vector3 targetPos = new Vector3(); 7 | public float halfworldSize; 8 | public float spd = 3; 9 | public float updateInterval = 50; 10 | private float timer = 0; 11 | public bool isNeedRotate = false; 12 | 13 | public float rotateSpd = 60; 14 | void Start(){ 15 | spd = spd * Random.Range(1.0f, 2.0f); 16 | rotateSpd = rotateSpd * Random.Range(1.0f, 2.0f); 17 | UpdateTargetPos(); 18 | } 19 | 20 | void UpdateTargetPos(){ 21 | targetPos = new Vector3(Random.Range(-halfworldSize, halfworldSize), 0, 22 | Random.Range(-halfworldSize, halfworldSize)); 23 | } 24 | 25 | private void Update(){ 26 | timer += Time.deltaTime; 27 | if (timer > updateInterval) { 28 | timer = 0; 29 | UpdateTargetPos(); 30 | } 31 | 32 | if ((transform.position - targetPos).sqrMagnitude < 1) { 33 | UpdateTargetPos(); 34 | } 35 | 36 | if (isNeedRotate) { 37 | var deg = transform.localRotation.eulerAngles.y; 38 | transform.localRotation = Quaternion.Euler(0,deg + Time.deltaTime * rotateSpd,0); 39 | } 40 | 41 | transform.position += (targetPos - transform.position).normalized * Time.deltaTime * spd; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!19 &1 4 | Physics2DSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 4 7 | m_Gravity: {x: 0, y: -9.81} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_VelocityIterations: 8 10 | m_PositionIterations: 3 11 | m_VelocityThreshold: 1 12 | m_MaxLinearCorrection: 0.2 13 | m_MaxAngularCorrection: 8 14 | m_MaxTranslationSpeed: 100 15 | m_MaxRotationSpeed: 360 16 | m_BaumgarteScale: 0.2 17 | m_BaumgarteTimeOfImpactScale: 0.75 18 | m_TimeToSleep: 0.5 19 | m_LinearSleepTolerance: 0.01 20 | m_AngularSleepTolerance: 2 21 | m_DefaultContactOffset: 0.01 22 | m_AutoSimulation: 1 23 | m_QueriesHitTriggers: 1 24 | m_QueriesStartInColliders: 1 25 | m_ChangeStopsCallbacks: 0 26 | m_CallbacksOnDisable: 1 27 | m_ReuseCollisionCallbacks: 1 28 | m_AutoSyncTransforms: 0 29 | m_AlwaysShowColliders: 0 30 | m_ShowColliderSleep: 1 31 | m_ShowColliderContacts: 0 32 | m_ShowColliderAABB: 0 33 | m_ContactArrowScale: 0.2 34 | m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412} 35 | m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} 36 | m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} 37 | m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} 38 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 39 | -------------------------------------------------------------------------------- /Packages/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "com.unity.ads": "2.0.8", 4 | "com.unity.analytics": "3.2.2", 5 | "com.unity.collab-proxy": "1.2.15", 6 | "com.unity.package-manager-ui": "2.0.3", 7 | "com.unity.purchasing": "2.0.3", 8 | "com.unity.textmeshpro": "1.3.0", 9 | "com.unity.modules.ai": "1.0.0", 10 | "com.unity.modules.animation": "1.0.0", 11 | "com.unity.modules.assetbundle": "1.0.0", 12 | "com.unity.modules.audio": "1.0.0", 13 | "com.unity.modules.cloth": "1.0.0", 14 | "com.unity.modules.director": "1.0.0", 15 | "com.unity.modules.imageconversion": "1.0.0", 16 | "com.unity.modules.imgui": "1.0.0", 17 | "com.unity.modules.jsonserialize": "1.0.0", 18 | "com.unity.modules.particlesystem": "1.0.0", 19 | "com.unity.modules.physics": "1.0.0", 20 | "com.unity.modules.physics2d": "1.0.0", 21 | "com.unity.modules.screencapture": "1.0.0", 22 | "com.unity.modules.terrain": "1.0.0", 23 | "com.unity.modules.terrainphysics": "1.0.0", 24 | "com.unity.modules.tilemap": "1.0.0", 25 | "com.unity.modules.ui": "1.0.0", 26 | "com.unity.modules.uielements": "1.0.0", 27 | "com.unity.modules.umbra": "1.0.0", 28 | "com.unity.modules.unityanalytics": "1.0.0", 29 | "com.unity.modules.unitywebrequest": "1.0.0", 30 | "com.unity.modules.unitywebrequestassetbundle": "1.0.0", 31 | "com.unity.modules.unitywebrequestaudio": "1.0.0", 32 | "com.unity.modules.unitywebrequesttexture": "1.0.0", 33 | "com.unity.modules.unitywebrequestwww": "1.0.0", 34 | "com.unity.modules.vehicles": "1.0.0", 35 | "com.unity.modules.video": "1.0.0", 36 | "com.unity.modules.vr": "1.0.0", 37 | "com.unity.modules.wind": "1.0.0", 38 | "com.unity.modules.xr": "1.0.0" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Assets/Math/LMathExtension2.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | 3 | namespace Lockstep.Math { 4 | public static partial class LMathExtension { 5 | public static LVector2 ToLVector2(this LVector2Int vec){ 6 | return new LVector2(true, vec.x * LFloat.Precision, vec.y * LFloat.Precision); 7 | } 8 | 9 | public static LVector3 ToLVector3(this LVector3Int vec){ 10 | return new LVector3(true, vec.x * LFloat.Precision, vec.y * LFloat.Precision, vec.z * LFloat.Precision); 11 | } 12 | 13 | public static LVector2Int ToLVector2Int(this LVector2 vec){ 14 | return new LVector2Int(vec.x.ToInt(), vec.y.ToInt()); 15 | } 16 | 17 | public static LVector3Int ToLVector3Int(this LVector3 vec){ 18 | return new LVector3Int(vec.x.ToInt(), vec.y.ToInt(), vec.z.ToInt()); 19 | } 20 | } 21 | 22 | public static partial class LMathExtension { 23 | public static LFloat ToLFloat(this float v){ 24 | return LMath.ToLFloat(v); 25 | } 26 | 27 | public static LFloat ToLFloat(this int v){ 28 | return LMath.ToLFloat(v); 29 | } 30 | 31 | public static LFloat ToLFloat(this long v){ 32 | return LMath.ToLFloat(v); 33 | } 34 | } 35 | 36 | public static partial class LMathExtension { 37 | public static LVector2Int Floor(this LVector2 vec){ 38 | return new LVector2Int(LMath.FloorToInt(vec.x), LMath.FloorToInt(vec.y)); 39 | } 40 | 41 | public static LVector3Int Floor(this LVector3 vec){ 42 | return new LVector3Int( 43 | LMath.FloorToInt(vec.x), 44 | LMath.FloorToInt(vec.y), 45 | LMath.FloorToInt(vec.z) 46 | ); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!126 &1 4 | NavMeshProjectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | areas: 8 | - name: Walkable 9 | cost: 1 10 | - name: Not Walkable 11 | cost: 1 12 | - name: Jump 13 | cost: 2 14 | - name: 15 | cost: 1 16 | - name: 17 | cost: 1 18 | - name: 19 | cost: 1 20 | - name: 21 | cost: 1 22 | - name: 23 | cost: 1 24 | - name: 25 | cost: 1 26 | - name: 27 | cost: 1 28 | - name: 29 | cost: 1 30 | - name: 31 | cost: 1 32 | - name: 33 | cost: 1 34 | - name: 35 | cost: 1 36 | - name: 37 | cost: 1 38 | - name: 39 | cost: 1 40 | - name: 41 | cost: 1 42 | - name: 43 | cost: 1 44 | - name: 45 | cost: 1 46 | - name: 47 | cost: 1 48 | - name: 49 | cost: 1 50 | - name: 51 | cost: 1 52 | - name: 53 | cost: 1 54 | - name: 55 | cost: 1 56 | - name: 57 | cost: 1 58 | - name: 59 | cost: 1 60 | - name: 61 | cost: 1 62 | - name: 63 | cost: 1 64 | - name: 65 | cost: 1 66 | - name: 67 | cost: 1 68 | - name: 69 | cost: 1 70 | - name: 71 | cost: 1 72 | m_LastAgentTypeID: -887442657 73 | m_Settings: 74 | - serializedVersion: 2 75 | agentTypeID: 0 76 | agentRadius: 0.5 77 | agentHeight: 2 78 | agentSlope: 45 79 | agentClimb: 0.75 80 | ledgeDropHeight: 0 81 | maxJumpAcrossDistance: 0 82 | minRegionArea: 2 83 | manualCellSize: 0 84 | cellSize: 0.16666667 85 | manualTileSize: 0 86 | tileSize: 256 87 | accuratePlacement: 0 88 | debug: 89 | m_Flags: 0 90 | m_SettingNames: 91 | - Humanoid 92 | -------------------------------------------------------------------------------- /Assets/Collision/UnityWarp/DebugDraw/EditorBaseShape.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | #if UNITY_EDITOR 3 | using UnityEditor; 4 | #endif 5 | using Lockstep.Math; 6 | 7 | /* 8 | */ 9 | namespace Lockstep.Collision 10 | { 11 | public partial class BaseShape 12 | { 13 | public virtual void OnDrawGizmos(bool isGizmo,Color color) 14 | { 15 | } 16 | } 17 | 18 | public partial class AABB 19 | { 20 | public override void OnDrawGizmos(bool isGizmo,Color color) 21 | { 22 | #if UNITY_EDITOR 23 | DebugExtension.DebugLocalCube(Matrix4x4.TRS(c.ToVector3(),Quaternion.identity, Vector3.one),r.ToVector3(), color); 24 | #endif 25 | } 26 | } 27 | 28 | public partial class OBB 29 | { 30 | public override void OnDrawGizmos(bool isGizmo,Color color) 31 | { 32 | #if UNITY_EDITOR 33 | DebugExtension.DebugLocalCube(Matrix4x4.TRS( 34 | c.ToVector3(), 35 | Quaternion.LookRotation(u.z.ToVector3(), u.y.ToVector3()), 36 | Vector3.one), 37 | e.ToVector3() * 2, color); 38 | #endif 39 | } 40 | } 41 | 42 | public partial class Sphere 43 | { 44 | public override void OnDrawGizmos(bool isGizmo,Color color) 45 | { 46 | #if UNITY_EDITOR 47 | DebugExtension.DebugWireSphere(c.ToVector3(), color,r.ToFloat()); 48 | #endif 49 | } 50 | } 51 | 52 | public partial class Capsule 53 | { 54 | public override void OnDrawGizmos(bool isGizmo,Color color) 55 | { 56 | #if UNITY_EDITOR 57 | DebugExtension.DrawCapsule( 58 | a.ToVector3() - (_hDir.normalized.ToVector3() * r.ToFloat()) , 59 | b.ToVector3() + (_hDir.normalized.ToVector3() * r.ToFloat()) , 60 | color, 61 | r.ToFloat()); 62 | #endif 63 | } 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /Assets/Math/BaseType/LAxis3D.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | using static Lockstep.Math.LVector3; 3 | 4 | namespace Lockstep.Math 5 | { 6 | public struct LAxis3D 7 | { 8 | public LVector3 x; 9 | public LVector3 y; 10 | public LVector3 z; 11 | public static readonly LAxis3D identity = new LAxis3D(LVector3.right, LVector3.up, LVector3.forward); 12 | 13 | public LAxis3D(LVector3 right, LVector3 up, LVector3 forward) 14 | { 15 | this.x = right; 16 | this.y = up; 17 | this.z = forward; 18 | } 19 | 20 | public LVector3 WorldToLocal(LVector3 vec) 21 | { 22 | var _x = Dot(x, vec); 23 | var _y = Dot(y, vec); 24 | var _z = Dot(z, vec); 25 | return new LVector3(_x, _y, _z); 26 | } 27 | public LVector3 LocalToWorld(LVector3 vec) 28 | { 29 | return x * vec.x + y * vec.y + z * vec.z; 30 | } 31 | 32 | public LVector3 this[int index] 33 | { 34 | get 35 | { 36 | switch (index) 37 | { 38 | case 0: return x; 39 | case 1: return y; 40 | case 2: return z; 41 | default: throw new System.IndexOutOfRangeException("vector idx invalid" + index); 42 | } 43 | } 44 | 45 | set 46 | { 47 | switch (index) 48 | { 49 | case 0: 50 | x = value; 51 | break; 52 | case 1: 53 | y = value; 54 | break; 55 | case 2: 56 | z = value; 57 | break; 58 | default: throw new System.IndexOutOfRangeException("vector idx invalid" + index); 59 | } 60 | } 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/CollisionTest.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Collision2D; 2 | using Lockstep.Math; 3 | 4 | namespace Lockstep.UnsafeCollision2D { 5 | public class CollisionTest { 6 | private static LFloat[] _distances = new LFloat[6]; 7 | 8 | public static bool TestAABBAABB(LVector2 posA, LFloat rA, LVector2 sizeA, LVector2 posB, LFloat rB, 9 | LVector2 sizeB){ 10 | var diff = posA - posB; 11 | var allRadius = rA + rB; 12 | //circle 判定 13 | if (diff.sqrMagnitude > allRadius * allRadius) { 14 | return false; 15 | } 16 | 17 | var absX = LMath.Abs(diff.x); 18 | var absY = LMath.Abs(diff.y); 19 | 20 | //AABB and AABB 21 | var allSize = sizeA + sizeB; 22 | if (absX > allSize.x) return false; 23 | if (absY > allSize.y) return false; 24 | return true; 25 | } 26 | 27 | public static bool TestAABB(LVector3 min0, LVector3 max0, LVector3 min1, LVector3 max1, 28 | ref CollisionResult result, 29 | bool twod = true){ 30 | _distances[0] = max1[0] - min0[0]; 31 | _distances[1] = max0[0] - min1[0]; 32 | _distances[2] = max1[2] - min0[2]; 33 | _distances[3] = max0[2] - min1[2]; 34 | 35 | var iter = 4; 36 | 37 | // test y if 3d 38 | if (!twod) { 39 | _distances[4] = max1[1] - min0[1]; 40 | _distances[5] = max0[1] - min1[1]; 41 | iter = 6; 42 | } 43 | 44 | for (int i = 0; i < iter; i++) { 45 | if (_distances[i] < LFloat.zero) 46 | return false; 47 | 48 | if ((i == 0) || _distances[i] < result.Penetration) { 49 | result.Penetration = _distances[i]; 50 | //result.Normal = _aabbNormals[i]; 51 | } 52 | } 53 | 54 | return true; 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /Assets/Collision/Geometry/Triangle.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | using Lockstep.Math; 3 | using UnityEditor.Experimental.UIElements.GraphView; 4 | using static Lockstep.Math.LMath; 5 | using Point2D = Lockstep.Math.LVector2; 6 | 7 | namespace Lockstep.Collision { 8 | [System.Serializable] 9 | public partial class Triangle : BaseShape { 10 | public LVector3 a; 11 | public LVector3 b; 12 | public LVector3 c; 13 | 14 | //所在平面 15 | public LVector3 n; 16 | public LFloat d; 17 | 18 | /// 19 | /// Collision Type 20 | /// 21 | public override EColType ColType { 22 | get { return EColType.Triangle; } 23 | } 24 | } 25 | 26 | 27 | public class SAABB { 28 | public LVector3 min; 29 | public LVector3 max; 30 | } 31 | 32 | /// 33 | /// 结构体 方便 内存紧凑 34 | /// 35 | public struct STriangle { 36 | public LVector3 a; 37 | public LVector3 b; 38 | public LVector3 c; 39 | 40 | public STriangle(LVector3 a, LVector3 b, LVector3 c){ 41 | this.a = a; 42 | this.b = b; 43 | this.c = c; 44 | this.n = Cross(b - a, c - a).normalized; 45 | this.d = Dot(n, a); 46 | this.min = a; 47 | this.max = a; 48 | for (int i = 0; i < 3; i++) { 49 | LFloat minv = a[i]; 50 | LFloat maxv = a[i]; 51 | var _b = b[i]; 52 | var _c = c[i]; 53 | if (_b < minv) minv = _b; 54 | if (_c < minv) minv = _c; 55 | if (_b > maxv) maxv = _b; 56 | if (_c > maxv) maxv = _c; 57 | min[i] = minv; 58 | max[i] = maxv; 59 | } 60 | } 61 | 62 | //所在平面 63 | public LVector3 n; 64 | public LFloat d; 65 | 66 | //bound box 67 | public LVector3 min; 68 | public LVector3 max; 69 | } 70 | } -------------------------------------------------------------------------------- /Assets/Collision/Geometry/Ray.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | 3 | namespace Lockstep.Collision 4 | { 5 | [System.Serializable] 6 | public partial class Ray : BaseShape 7 | { 8 | /// 9 | /// Collision Type 10 | /// 11 | public override EColType ColType 12 | { 13 | get { return EColType.Ray; } 14 | } 15 | 16 | /// 17 | /// orgin point 18 | /// 19 | public LVector3 o; 20 | 21 | /// 22 | /// dir 23 | /// 24 | public LVector3 d; 25 | 26 | public Ray() 27 | { 28 | } 29 | 30 | public Ray(LVector3 o, LVector3 d) 31 | { 32 | this.o = o; 33 | this.d = d; 34 | } 35 | 36 | public override bool TestWithShape(BaseShape shape) 37 | { 38 | return shape.TestWith(this); 39 | } 40 | 41 | public override bool TestWith(Sphere sphere) 42 | { 43 | return Utils.IntersectRaySphere(o, d, sphere, out LFloat t, out LVector3 p); 44 | } 45 | 46 | public override bool TestWith(AABB aabb) 47 | { 48 | return Utils.IntersectRayAABB(o, d, aabb, out LFloat t, out LVector3 p); 49 | } 50 | 51 | public override bool TestWith(Capsule capsule) 52 | { 53 | return Utils.IntersectRayCapsule(o, d, capsule.a, capsule.b, capsule.r, out LFloat t); 54 | } 55 | 56 | public override bool TestWith(OBB obb) 57 | { 58 | return Utils.IntersectRayOBB(o, d, obb, out LFloat t, out LVector3 p); 59 | } 60 | 61 | public override bool TestWith(Plane plane) 62 | { 63 | return Utils.IntersectRayPlane(o, d, plane, out LFloat t, out LVector3 p); 64 | } 65 | 66 | public override bool TestWith(Ray ray) 67 | { 68 | throw new System.NotImplementedException(GetType() + " not implement this TestWithRay"); 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /Assets/Collision/Geometry/Sphere.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | using static Lockstep.Math.LMath; 3 | using Point2D = Lockstep.Math.LVector2; 4 | 5 | namespace Lockstep.Collision 6 | { 7 | [System.Serializable] 8 | public partial class Sphere : BaseShape 9 | { 10 | /// 11 | /// Collision Type 12 | /// 13 | public override EColType ColType{get { return EColType.Sphere;}} 14 | 15 | /// 16 | /// // Sphere center 17 | /// 18 | public LVector3 c; 19 | 20 | /// 21 | /// Sphere radius 22 | /// 23 | public LFloat r; 24 | 25 | public Sphere(LVector3 c, LFloat r) 26 | { 27 | this.c = c; 28 | this.r = r; 29 | } 30 | 31 | public Sphere() 32 | { 33 | } 34 | public override Sphere GetBoundSphere() 35 | { 36 | return this; 37 | } 38 | 39 | public override bool TestWithShape(BaseShape shape) 40 | { 41 | return shape.TestWith(this); 42 | } 43 | 44 | public override bool TestWith(Sphere sphere) 45 | { 46 | return Utils.TestSphereSphere(sphere, this); 47 | } 48 | public override bool TestWith(AABB aabb) 49 | { 50 | return Utils.TestSphereAABB(this,aabb); 51 | } 52 | public override bool TestWith(Capsule capsule) 53 | { 54 | return Utils.TestSphereCapsule(this, capsule); 55 | } 56 | 57 | public override bool TestWith(OBB obb) 58 | { 59 | return Utils.TestSphereOBB( this,obb,out LVector3 p); 60 | } 61 | 62 | public override bool TestWith(Plane plane) 63 | { 64 | return Utils.TestSpherePlane(this, plane); 65 | } 66 | 67 | public override bool TestWith(Ray ray) 68 | { 69 | return Utils.IntersectRaySphere(ray.o, ray.d,this, out LFloat t,out LVector3 p); 70 | } 71 | }; 72 | } -------------------------------------------------------------------------------- /Assets/TestRotation.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_5_3_OR_NEWER 2 | using UnityEngine; 3 | 4 | public class TestRotation : MonoBehaviour 5 | { 6 | // Update is called once per frame 7 | void Update() 8 | { 9 | var _temp = quaternion2Euler(transform.rotation, RotSeq.yxz) * Mathf.Rad2Deg; 10 | convertResult = new Vector3(_temp.y,_temp.z,_temp.x); 11 | myret = operatorMul(q1,q2); 12 | unityret = q1 * q2; 13 | } 14 | 15 | public Vector3 convertResult; 16 | public RotSeq rotseq; 17 | 18 | public enum RotSeq 19 | { 20 | zyx, zyz, zxy, zxz, yxz, yxy, yzx, yzy, xyz, xyx, xzy,xzx 21 | }; 22 | 23 | //yxz 24 | Vector3 threeaxisrot(float r11, float r12, float r21, float r31, float r32){ 25 | Vector3 ret = new Vector3(); 26 | ret.x = Mathf.Atan2( r31, r32 ); 27 | ret.y = Mathf.Asin ( r21 ); 28 | ret.z = Mathf.Atan2( r11, r12 ); 29 | return ret; 30 | } 31 | 32 | public Quaternion q1; 33 | public Quaternion q2; 34 | public Quaternion myret; 35 | public Quaternion unityret; 36 | Quaternion operatorMul(Quaternion q1, Quaternion q2){ 37 | Quaternion q; 38 | q.w = q1.w*q2.w - q1.x*q2.x - q1.y*q2.y - q1.z*q2.z; 39 | q.x = q1.w*q2.x + q1.x*q2.w + q1.y*q2.z - q1.z*q2.y; 40 | q.y = q1.w*q2.y - q1.x*q2.z + q1.y*q2.w + q1.z*q2.x; 41 | q.z = q1.w*q2.z + q1.x*q2.y - q1.y*q2.x + q1.z*q2.w; 42 | return q; 43 | } 44 | 45 | Vector3 quaternion2Euler(Quaternion q, RotSeq rotSeq) 46 | { 47 | switch(rotSeq){ 48 | 49 | case RotSeq.yxz: 50 | return threeaxisrot( 2*(q.x*q.z + q.w*q.y), 51 | q.w*q.w - q.x*q.x - q.y*q.y + q.z*q.z, 52 | -2*(q.y*q.z - q.w*q.x), 53 | 2*(q.x*q.y + q.w*q.z), 54 | q.w*q.w - q.x*q.x + q.y*q.y - q.z*q.z); 55 | 56 | 57 | default: 58 | Debug.LogError("No good sequence"); 59 | return Vector3.zero; 60 | 61 | } 62 | 63 | } 64 | } 65 | #endif 66 | -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/Utils/UnsafeUtils.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | using Lockstep.UnsafeCollision2D; 3 | using UnityEngine; 4 | namespace Lockstep.Collision2D { 5 | 6 | public static unsafe partial class Utils { 7 | public static bool TestCollision(Circle* a, OBB2D* b){ 8 | return TestCircleOBB(a->pos, a->radius 9 | , b->pos, b->radius, b->size, b->up 10 | ); 11 | } 12 | 13 | public static bool TestCollision(AABB2D* a, OBB2D* b){ 14 | return TestAABBOBB(a->pos, a->radius, a->size 15 | , b->pos, b->radius, b->size, b->up 16 | ); 17 | } 18 | 19 | public static bool TestCollision(OBB2D* a, OBB2D* b){ 20 | return TestOBBOBB(a->pos, a->radius, a->size, a->up 21 | , b->pos, b->radius, b->size, b->up 22 | ); 23 | } 24 | 25 | //Circle* & Circle 26 | public static bool TestCollision(Circle* a, Circle* b){ 27 | var diff = a->pos - b->pos; 28 | var allRadius = a->radius + b->radius; 29 | return diff.sqrMagnitude <= allRadius * allRadius; 30 | } 31 | 32 | //Circle* & AABB 33 | public static bool TestCollision(Circle* a, AABB2D* b){ 34 | return TestCircleAABB(a->pos, a->radius, b->pos, b->radius, b->size); 35 | } 36 | 37 | //AABB & AABB 38 | public static bool TestCollision(AABB2D* a, AABB2D* b){ 39 | return TestAABBAABB(a->pos, a->radius, a->size, b->pos, b->radius, b->size); 40 | } 41 | 42 | //AABB & Tile 43 | public static bool TestCollision(AABB2D* a, Vector2Int tilePos){ 44 | return TestAABBAABB( 45 | a->pos, a->radius, a->size, //AABB1 46 | tilePos.ToLVector2() + LVector2.half, new LFloat(true, 707), LVector2.half //AABB2 47 | ); 48 | } 49 | 50 | public static bool TestCollision(Circle* a, Vector2Int tilePos){ 51 | return TestCircleAABB( 52 | a->pos, a->radius, //Circle1 53 | tilePos.ToLVector2() + LVector2.half, new LFloat(true, 707), LVector2.half //AABB2 54 | ); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /Assets/Collision/Geometry/Plane.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | 3 | using static Lockstep.Math.LMath; 4 | using Point2D = Lockstep.Math.LVector2; 5 | 6 | namespace Lockstep.Collision 7 | { 8 | [System.Serializable] 9 | public partial class Plane :BaseShape 10 | { 11 | /// 12 | /// Collision Type 13 | /// 14 | public override EColType ColType{get { return EColType.Plane;}} 15 | 16 | /// 17 | /// Plane normal. Points x on the plane satisfy Dot(n,x) = d 18 | /// 19 | public LVector3 n; 20 | 21 | /// 22 | /// d = dot(n,p) for a given point p on the plane 23 | /// 24 | public LFloat d; 25 | 26 | public Plane() 27 | { 28 | } 29 | 30 | public Plane(LVector3 n, LFloat d) 31 | { 32 | this.n = n; 33 | this.d = d; 34 | } 35 | 36 | public Plane(LVector3 a, LVector3 b, LVector3 c) 37 | { 38 | n = Cross(b - a, c - a).normalized; 39 | d = Dot(n, a); 40 | } 41 | public override bool TestWithShape(BaseShape shape) 42 | { 43 | return shape.TestWith(this); 44 | } 45 | 46 | public override bool TestWith(Sphere sphere) 47 | { 48 | return Utils.TestSpherePlane(sphere, this); 49 | } 50 | public override bool TestWith(AABB aabb) 51 | { 52 | return Utils.TestAABBPlane(aabb,this); 53 | } 54 | public override bool TestWith(Capsule capsule) 55 | { 56 | return Utils.TestCapsulePlane(capsule,this); 57 | } 58 | 59 | public override bool TestWith(OBB obb) 60 | { 61 | return Utils.TestOBBPlane( obb, this); 62 | } 63 | 64 | public override bool TestWith(Plane plane) 65 | { 66 | throw new System.NotImplementedException(GetType() + " not implement this TestWithRay"); 67 | } 68 | 69 | public override bool TestWith(Ray ray) 70 | { 71 | return Utils.IntersectRayPlane(ray.o, ray.d, this, out LFloat t, out LVector3 p); 72 | } 73 | }; 74 | } -------------------------------------------------------------------------------- /Assets/Collision/UnityWarp/Editor/EditorColliderProxy.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_5_3_OR_NEWER 2 | using UnityEngine; 3 | using UnityEditor; 4 | 5 | [CustomEditor(typeof(DebugUnityColliderProxy))] 6 | public class EditorColliderProxy : Editor 7 | { 8 | private DebugUnityColliderProxy owner; 9 | 10 | Vector3 posOffset = new Vector3(0, 0, 0); 11 | float GizmoSize = 0.4f; 12 | Transform _goParent; 13 | 14 | public override void OnInspectorGUI() 15 | { 16 | base.OnInspectorGUI(); 17 | owner = (DebugUnityColliderProxy) target; 18 | 19 | } 20 | 21 | 22 | void OnSceneGUI() 23 | { 24 | 25 | owner = (DebugUnityColliderProxy) target; 26 | //DrawPathHeap(); 27 | } 28 | 29 | /// 30 | /// 绘制寻路堆栈 31 | /// 32 | void DrawPathHeap() 33 | { 34 | foreach (var col in owner.allCollider) 35 | { 36 | var _colType = col.ColType; 37 | switch (_colType) 38 | { 39 | // case EColType. Sphere: {var _col = col as AABB; Handles.DrawSphere(_col.c.ToVector3(), _col.r.ToVector3* GizmoSize * 10f);break;} 40 | // case EColType. AABB: {var _col = col as AABB; Handles.DrawWireCube(_col.c.ToVector3(), _col.r.ToVector3* GizmoSize * 10f);break;} 41 | // case EColType. Capsule: {var _col = col as AABB; Handles.DrawWireCube(_col.c.ToVector3(), _col.r.ToVector3* GizmoSize * 10f);break;} 42 | // case EColType. OBB: {var _col = col as AABB; Handles.DrawWireCube(_col.c.ToVector3(), _col.r.ToVector3* GizmoSize * 10f);break;} 43 | // case EColType. Plane: {var _col = col as AABB; Handles.DrawWireCube(_col.c.ToVector3(), _col.r.ToVector3* GizmoSize * 10f);break;} 44 | // case EColType. Rect: {var _col = col as AABB; Handles.DrawWireCube(_col.c.ToVector3(), _col.r.ToVector3* GizmoSize * 10f);break;} 45 | // case EColType. Segment: {var _col = col as AABB; Handles.DrawWireCube(_col.c.ToVector3(), _col.r.ToVector3* GizmoSize * 10f);break;} 46 | // case EColType. Polygon: {var _col = col as AABB; Handles.DrawWireCube(_col.c.ToVector3(), _col.r.ToVector3* GizmoSize * 10f);break;} 47 | } 48 | } 49 | //Gizmos.DrawCube(); 50 | } 51 | } 52 | #endif -------------------------------------------------------------------------------- /Assets/NativeUtil/Buffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | namespace Lockstep { 6 | public class Buffer : IDisposable, IEnumerable, IEnumerable where T : struct { 7 | private static Stack> _pool = new Stack>(); 8 | private bool _inited; 9 | public T[] Items; 10 | public int Count; 11 | 12 | public T this[int index] { 13 | get { 14 | if (index >= 0 && index < this.Count) 15 | return this.Items[index]; 16 | throw new ArgumentOutOfRangeException(nameof(index)); 17 | } 18 | } 19 | 20 | public static Buffer Alloc(int size){ 21 | lock (Buffer._pool) { 22 | while (Buffer._pool.Count > 0) { 23 | Buffer buffer = Buffer._pool.Pop(); 24 | if (buffer._inited) { 25 | if (buffer.Items.Length < size) 26 | buffer.Items = new T[size]; 27 | buffer._inited = false; 28 | return buffer; 29 | } 30 | } 31 | } 32 | 33 | return new Buffer(size); 34 | } 35 | 36 | private Buffer(int size){ 37 | this.Items = new T[size]; 38 | } 39 | 40 | public void Add(T item){ 41 | this.Items[this.Count++] = item; 42 | } 43 | 44 | public void Dispose(){ 45 | if (this._inited) 46 | return; 47 | this.Count = 0; 48 | this._inited = true; 49 | lock (Buffer._pool) 50 | Buffer._pool.Push(this); 51 | } 52 | 53 | public IEnumerator GetEnumerator(){ 54 | if (this._inited) 55 | throw new Exception("Buffer has been pooled"); 56 | for (int i = 0; i < this.Count; ++i) { 57 | if (this._inited) 58 | throw new Exception("Buffer has been pooled"); 59 | yield return this.Items[i]; 60 | } 61 | } 62 | 63 | IEnumerator IEnumerable.GetEnumerator(){ 64 | return (IEnumerator) this.GetEnumerator(); 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/PhysicsBody.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Xml.Linq; 3 | using Lockstep.Collision2D; 4 | using Lockstep.Math; 5 | using UnityEngine; 6 | using Random = UnityEngine.Random; 7 | 8 | namespace Lockstep.UnsafeCollision2D { 9 | public unsafe class PhysicsBody : MonoBehaviour, ICollisionBody { 10 | public ColliderConfig ColliderConfig; 11 | private Color _gizmoColor = Color.green; 12 | public Circle* ColPtr { get; set; } 13 | public int RefId { get; set; } 14 | public LFloat Y { get; set; } 15 | public LVector2 Pos { get; set; } 16 | public LVector2 PreCenter { get; set; } 17 | 18 | public bool IsUpdateFromUnity = true; 19 | public bool Sleeping => false; 20 | 21 | public LVector2 Position => new LVector2(transform.position.x.ToLFloat(), transform.position.z.ToLFloat()); 22 | 23 | public bool QuadTreeIgnore => false; 24 | 25 | static float moveSpd = 5; 26 | public bool isDebug = false; 27 | 28 | private void Awake(){ 29 | Pos = transform.position.ToLVector2XZ(); 30 | Y = transform.position.y.ToLFloat(); 31 | } 32 | 33 | 34 | 35 | private void Update(){ 36 | if (IsUpdateFromUnity) { 37 | var pos = transform.position; 38 | Pos = pos.ToLVector2XZ(); 39 | Y = pos.y.ToLFloat(); 40 | } 41 | 42 | if (Pos != PreCenter) { 43 | CollisionSystem.MarkDirty(this); 44 | } 45 | PreCenter = Pos; 46 | if (ColPtr != null) { 47 | ColPtr->pos = Pos; 48 | } 49 | } 50 | 51 | 52 | public virtual void OnCollision(CollisionResult result, ICollisionBody other){ 53 | _gizmoColor = result.Type == ECollisionEvent.Exit ? Color.green : Color.red; 54 | if (isDebug && result.Type == ECollisionEvent.Enter) { 55 | Debug.LogError("Enter Collision"); 56 | } 57 | } 58 | private void OnDrawGizmos(){ 59 | Gizmos.color = _gizmoColor; 60 | Gizmos.DrawWireCube(transform.position, Vector3.one * 1.25f); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /Assets/Math/Editor/EditorCreateLUT.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.IO; 3 | using System.Net; 4 | using System.Net.Mime; 5 | using System.Text; 6 | using UnityEditor; 7 | using UnityEngine; 8 | 9 | namespace Lockstep.Math 10 | { 11 | public static class EditorCreateLUT 12 | { 13 | [MenuItem("Lockstep.Math/CreateLUTAsin")] 14 | static void CreateLUTAsin() 15 | { 16 | string fileName = Application.dataPath + "/Lockstep.Math/LUT/LUTAsin.cs"; 17 | const int count = 1024; 18 | const int percision = 10000; 19 | string content = @"using System; 20 | using Lockstep.Math; 21 | namespace Lockstep.Math 22 | { 23 | public static class LUTAsin 24 | { 25 | public static readonly int COUNT; 26 | public static readonly int HALF_COUNT; 27 | public static readonly int[] table; 28 | static LUTAsin() 29 | { 30 | COUNT = $COUNT_VAL; 31 | HALF_COUNT = COUNT >> 1; 32 | table = new int[] 33 | { 34 | $ALL_VALUES 35 | }; 36 | } 37 | } 38 | }"; 39 | 40 | //public static LFloat LMath.Asin(LFloat val) 41 | //{ 42 | // int num = (int) (val._val * (long) LUTAsin.HALF_COUNT / LFloat.Precision) + 43 | // LUTAsin.HALF_COUNT; 44 | // num = Mathf.Clamp(num, 0, LUTAsin.COUNT); 45 | // return new LFloat(true,(long) LUTAsin.table[num] / 10); 46 | //} 47 | StringBuilder sb = new StringBuilder(); 48 | // 49 | string prefix = "\t\t\t\t"; 50 | var step = 2.0f / count; 51 | for (int i = 0; i <= count; i++) 52 | { 53 | //-1~1 54 | int val = (int) (Mathf.Asin(Mathf.Clamp(-1.0f + step * i,-1f,1f)) * percision); 55 | if (i == count) 56 | { 57 | sb.Append(prefix + val.ToString()); 58 | } 59 | else 60 | { 61 | sb.AppendLine(prefix + val + ","); 62 | } 63 | } 64 | 65 | content = content.Replace("$COUNT_VAL",count.ToString()) 66 | .Replace("$ALL_VALUES", sb.ToString()); 67 | //save to files 68 | File.WriteAllText(fileName,content); 69 | AssetDatabase.Refresh(); 70 | } 71 | } 72 | } 73 | #endif -------------------------------------------------------------------------------- /Assets/Math/LRandom.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Lockstep.Math; 3 | using UnityEngine; 4 | using Random = UnityEngine.Random; 5 | 6 | namespace Lockstep.Math { 7 | public partial class Random { 8 | public ulong randSeed = 1; 9 | public Random(uint seed = 17){ 10 | randSeed = seed; 11 | } 12 | public LFloat value => new LFloat(true, Range(0, 1000)); 13 | 14 | public uint Next(){ 15 | randSeed = randSeed * 1103515245 + 36153; 16 | return (uint) (randSeed / 65536); 17 | } 18 | // range:[0 ~(max-1)] 19 | public uint Next(uint max){ 20 | return Next() % max; 21 | } 22 | public int Next(int max){ 23 | return (int) (Next() % max); 24 | } 25 | // range:[min~(max-1)] 26 | public uint Range(uint min, uint max){ 27 | if (min > max) 28 | throw new ArgumentOutOfRangeException("minValue", 29 | string.Format("'{0}' cannot be greater than {1}.", min, max)); 30 | 31 | uint num = max - min; 32 | return this.Next(num) + min; 33 | } 34 | public int Range(int min, int max){ 35 | if (min >= max - 1) 36 | return min; 37 | int num = max - min; 38 | 39 | return this.Next(num) + min; 40 | } 41 | 42 | public LFloat Range(LFloat min, LFloat max){ 43 | if (min > max) 44 | throw new ArgumentOutOfRangeException("minValue", 45 | string.Format("'{0}' cannot be greater than {1}.", min, max)); 46 | 47 | uint num = (uint) (max._val - min._val); 48 | return new LFloat(true, Next(num) + min._val); 49 | } 50 | } 51 | #if false 52 | public class LRandom { 53 | private static Random _i = new Random(3274); 54 | public static LFloat value => _i.value; 55 | public static uint Next(){return _i.Next();} 56 | public static uint Next(uint max){return _i.Next(max);} 57 | public static int Next(int max){return _i.Next(max);} 58 | public static uint Range(uint min, uint max){return _i.Range(min, max);} 59 | public static int Range(int min, int max){return _i.Range(min, max);} 60 | public static LFloat Range(LFloat min, LFloat max){return _i.Range(min, max);} 61 | } 62 | #endif 63 | } -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/UnityWarp/New Material.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_CorrespondingSourceObject: {fileID: 0} 8 | m_PrefabInstance: {fileID: 0} 9 | m_PrefabAsset: {fileID: 0} 10 | m_Name: New Material 11 | m_Shader: {fileID: 10755, guid: 0000000000000000f000000000000000, type: 0} 12 | m_ShaderKeywords: 13 | m_LightmapFlags: 4 14 | m_EnableInstancingVariants: 0 15 | m_DoubleSidedGI: 0 16 | m_CustomRenderQueue: -1 17 | stringTagMap: {} 18 | disabledShaderPasses: [] 19 | m_SavedProperties: 20 | serializedVersion: 3 21 | m_TexEnvs: 22 | - _BumpMap: 23 | m_Texture: {fileID: 0} 24 | m_Scale: {x: 1, y: 1} 25 | m_Offset: {x: 0, y: 0} 26 | - _DetailAlbedoMap: 27 | m_Texture: {fileID: 0} 28 | m_Scale: {x: 1, y: 1} 29 | m_Offset: {x: 0, y: 0} 30 | - _DetailMask: 31 | m_Texture: {fileID: 0} 32 | m_Scale: {x: 1, y: 1} 33 | m_Offset: {x: 0, y: 0} 34 | - _DetailNormalMap: 35 | m_Texture: {fileID: 0} 36 | m_Scale: {x: 1, y: 1} 37 | m_Offset: {x: 0, y: 0} 38 | - _EmissionMap: 39 | m_Texture: {fileID: 0} 40 | m_Scale: {x: 1, y: 1} 41 | m_Offset: {x: 0, y: 0} 42 | - _MainTex: 43 | m_Texture: {fileID: 0} 44 | m_Scale: {x: 1, y: 1} 45 | m_Offset: {x: 0, y: 0} 46 | - _MetallicGlossMap: 47 | m_Texture: {fileID: 0} 48 | m_Scale: {x: 1, y: 1} 49 | m_Offset: {x: 0, y: 0} 50 | - _OcclusionMap: 51 | m_Texture: {fileID: 0} 52 | m_Scale: {x: 1, y: 1} 53 | m_Offset: {x: 0, y: 0} 54 | - _ParallaxMap: 55 | m_Texture: {fileID: 0} 56 | m_Scale: {x: 1, y: 1} 57 | m_Offset: {x: 0, y: 0} 58 | m_Floats: 59 | - _BumpScale: 1 60 | - _Cutoff: 0.5 61 | - _DetailNormalMapScale: 1 62 | - _DstBlend: 0 63 | - _GlossMapScale: 1 64 | - _Glossiness: 0.5 65 | - _GlossyReflections: 1 66 | - _Metallic: 0 67 | - _Mode: 0 68 | - _OcclusionStrength: 1 69 | - _Parallax: 0.02 70 | - _SmoothnessTextureChannel: 0 71 | - _SpecularHighlights: 1 72 | - _SrcBlend: 1 73 | - _UVSec: 0 74 | - _ZWrite: 1 75 | m_Colors: 76 | - _Color: {r: 0, g: 0, b: 0, a: 1} 77 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 78 | -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/Shape/OBB2D.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | using Lockstep.Collision2D; 3 | using Lockstep.Math; 4 | 5 | namespace Lockstep.UnsafeCollision2D { 6 | [StructLayout(LayoutKind.Sequential, Pack = NativeHelper.STRUCT_PACK)] 7 | public unsafe struct OBB2D :IShape2D{ 8 | public Circle BoundSphere; 9 | 10 | public int TypeId { 11 | get => BoundSphere.TypeId; 12 | } 13 | 14 | public int Id { 15 | get => BoundSphere.Id; 16 | set => BoundSphere.Id = value; 17 | } 18 | 19 | public LVector2 pos { 20 | get => BoundSphere.pos; 21 | set => BoundSphere.pos = value; 22 | } 23 | 24 | public LFloat radius { 25 | get => BoundSphere.radius; 26 | set => BoundSphere.radius = value; 27 | } 28 | 29 | public LFloat deg; 30 | public LVector2 size; 31 | public LVector2 up; 32 | 33 | public LVector2 right => new LVector2(up.y, -up.x); 34 | 35 | //CCW 旋转角度 36 | public void Rotate(LFloat rdeg){ 37 | deg += rdeg; 38 | if (deg > 360 || deg < -360) { 39 | deg = deg - (deg / 360 * 360); 40 | } 41 | 42 | SetDeg(deg); 43 | } 44 | 45 | public void SetDeg(LFloat rdeg){ 46 | deg = rdeg; 47 | var rad = LMath.Deg2Rad * deg; 48 | var c = LMath.Cos(rad); 49 | var s = LMath.Sin(rad); 50 | up = new LVector2(-s, c); 51 | } 52 | 53 | public OBB2D(int id, LVector2 pos, LVector2 size, LVector2 up){ 54 | BoundSphere = new Circle((int) EShape2D.AABB, id, pos, size.magnitude); 55 | this.size = size; 56 | this.up = up; 57 | this.deg = LMath.Atan2(-up.x, up.y); 58 | } 59 | 60 | public OBB2D(int id, LVector2 pos, LVector2 size, LFloat deg){ 61 | BoundSphere = new Circle((int) EShape2D.AABB, id, pos, size.magnitude); 62 | this.size = size; 63 | this.deg = deg; 64 | var rad = LMath.Deg2Rad * deg; 65 | var c = LMath.Cos(rad); 66 | var s = LMath.Sin(rad); 67 | up = new LVector2(-s, c); 68 | } 69 | public void UpdatePosition(LVector2 pos){this.pos = pos;} 70 | 71 | public void UpdateRotation(LFloat deg){SetDeg(deg);} 72 | } 73 | } -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!30 &1 4 | GraphicsSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 12 7 | m_Deferred: 8 | m_Mode: 1 9 | m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0} 10 | m_DeferredReflections: 11 | m_Mode: 1 12 | m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0} 13 | m_ScreenSpaceShadows: 14 | m_Mode: 1 15 | m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0} 16 | m_LegacyDeferred: 17 | m_Mode: 1 18 | m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0} 19 | m_DepthNormals: 20 | m_Mode: 1 21 | m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0} 22 | m_MotionVectors: 23 | m_Mode: 1 24 | m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0} 25 | m_LightHalo: 26 | m_Mode: 1 27 | m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0} 28 | m_LensFlare: 29 | m_Mode: 1 30 | m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0} 31 | m_AlwaysIncludedShaders: 32 | - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} 33 | - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0} 34 | - {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0} 35 | - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0} 36 | - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} 37 | - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} 38 | - {fileID: 10783, guid: 0000000000000000f000000000000000, type: 0} 39 | m_PreloadedShaders: [] 40 | m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, 41 | type: 0} 42 | m_CustomRenderPipeline: {fileID: 0} 43 | m_TransparencySortMode: 0 44 | m_TransparencySortAxis: {x: 0, y: 0, z: 1} 45 | m_DefaultRenderingPath: 1 46 | m_DefaultMobileRenderingPath: 1 47 | m_TierSettings: [] 48 | m_LightmapStripping: 0 49 | m_FogStripping: 0 50 | m_InstancingStripping: 0 51 | m_LightmapKeepPlain: 1 52 | m_LightmapKeepDirCombined: 1 53 | m_LightmapKeepDynamicPlain: 1 54 | m_LightmapKeepDynamicDirCombined: 1 55 | m_LightmapKeepShadowMask: 1 56 | m_LightmapKeepSubtractive: 1 57 | m_FogKeepLinear: 1 58 | m_FogKeepExp: 1 59 | m_FogKeepExp2: 1 60 | m_AlbedoSwatchInfos: [] 61 | m_LightsUseLinearIntensity: 0 62 | m_LightsUseColorTemperature: 0 63 | -------------------------------------------------------------------------------- /Assets/Math/LMathExtension.cs: -------------------------------------------------------------------------------- 1 | 2 | using Lockstep.Collision2D; 3 | using Lockstep.UnsafeCollision2D; 4 | #if UNITY_5_3_OR_NEWER 5 | using UnityEngine; 6 | #endif 7 | using Lockstep.Math; 8 | 9 | namespace Lockstep.Math { 10 | #if UNITY_5_3_OR_NEWER 11 | public static partial class LMathExtension { 12 | public static LVector2 ToLVector2(this Vector2Int vec){ 13 | return new LVector2(true,vec.x * LFloat.Precision, vec.y * LFloat.Precision); 14 | } 15 | 16 | public static LVector3 ToLVector3(this Vector3Int vec){ 17 | return new LVector3(true,vec.x * LFloat.Precision, vec.y * LFloat.Precision, vec.z * LFloat.Precision); 18 | } 19 | 20 | public static LVector2Int ToLVector2Int(this Vector2Int vec){ 21 | return new LVector2Int(vec.x, vec.y); 22 | } 23 | 24 | public static LVector3Int ToLVector3Int(this Vector3Int vec){ 25 | return new LVector3Int(vec.x, vec.y, vec.z); 26 | } 27 | public static Vector2Int ToVector2Int(this LVector2Int vec){ 28 | return new Vector2Int(vec.x, vec.y); 29 | } 30 | 31 | public static Vector3Int ToVector3Int(this LVector3Int vec){ 32 | return new Vector3Int(vec.x, vec.y, vec.z); 33 | } 34 | public static LVector2 ToLVector2(this Vector2 vec){ 35 | return new LVector2( 36 | LMath.ToLFloat(vec.x), 37 | LMath.ToLFloat(vec.y)); 38 | } 39 | 40 | public static LVector3 ToLVector3(this Vector3 vec){ 41 | return new LVector3( 42 | LMath.ToLFloat(vec.x), 43 | LMath.ToLFloat(vec.y), 44 | LMath.ToLFloat(vec.z)); 45 | } 46 | public static LVector2 ToLVector2XZ(this Vector3 vec){ 47 | return new LVector2( 48 | LMath.ToLFloat(vec.x), 49 | LMath.ToLFloat(vec.z)); 50 | } 51 | public static Vector2 ToVector2(this LVector2 vec){ 52 | return new Vector2(vec.x.ToFloat(), vec.y.ToFloat()); 53 | } 54 | public static Vector3 ToVector3(this LVector2 vec){ 55 | return new Vector3(vec.x.ToFloat(), vec.y.ToFloat(),0); 56 | } 57 | public static Vector3 ToVector3XZ(this LVector2 vec,LFloat y){ 58 | return new Vector3(vec.x.ToFloat(), y.ToFloat(),vec.y.ToFloat()); 59 | } 60 | public static Vector3 ToVector3(this LVector3 vec){ 61 | return new Vector3(vec.x.ToFloat(), vec.y.ToFloat(), vec.z.ToFloat()); 62 | } 63 | public static Rect ToRect(this LRect vec){ 64 | return new Rect(vec.position.ToVector2(),vec.size.ToVector2()); 65 | } 66 | } 67 | #endif 68 | } -------------------------------------------------------------------------------- /Assets/Collision/Geometry/OBB.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | using TMPro; 3 | using UnityEngine; 4 | using static Lockstep.Math.LMath; 5 | using Point2D = Lockstep.Math.LVector2; 6 | 7 | namespace Lockstep.Collision 8 | { 9 | [System.Serializable] 10 | public partial class OBB : BaseShape 11 | 12 | { 13 | /// 14 | /// Collision Type 15 | /// 16 | public override EColType ColType 17 | { 18 | get { return EColType.OBB; } 19 | } 20 | 21 | /// 22 | /// OBB center point 23 | /// 24 | public LVector3 c; 25 | 26 | /// 27 | /// Local x-, y-, and z-axes 28 | /// 29 | public LAxis3D u; 30 | 31 | /// 32 | /// Positive halfwidth extents of OBB along each axis 33 | /// 34 | public LVector3 e; 35 | 36 | public AABB ToAABB() 37 | { 38 | var aabb = new AABB(); 39 | var abse = e.abs; 40 | aabb.min = c - abse; 41 | aabb.max = c + abse; 42 | return aabb; 43 | } 44 | 45 | 46 | public override Sphere GetBoundSphere() 47 | { 48 | return new Sphere(c,e.magnitude); 49 | } 50 | 51 | public override void UpdateRotation(LVector3 forward, LVector3 up){ 52 | u = new LAxis3D(Cross(forward,up),up,forward); 53 | } 54 | 55 | public override void UpdatePosition(LVector3 targetPos){ 56 | c = targetPos; 57 | } 58 | 59 | 60 | public override bool TestWithShape(BaseShape shape) 61 | { 62 | return shape.TestWith(this); 63 | } 64 | 65 | public override bool TestWith(Sphere sphere) 66 | { 67 | return Utils.TestSphereOBB(sphere, this,out LVector3 p); 68 | } 69 | public override bool TestWith(AABB aabb) 70 | { 71 | //TODO 改为更加高效的判定方式 72 | return Utils.TestOBBOBB(this, aabb.ToOBB()); 73 | } 74 | public override bool TestWith(Capsule capsule) 75 | { 76 | return Utils.TestOBBCapsule(this, capsule); 77 | } 78 | 79 | public override bool TestWith(OBB obb) 80 | { 81 | return Utils.TestOBBOBB(obb, this); 82 | } 83 | 84 | public override bool TestWith(Plane plane) 85 | { 86 | return Utils.TestOBBPlane(this, plane); 87 | } 88 | 89 | public override bool TestWith(Ray ray) 90 | { 91 | return Utils.IntersectRayOBB(ray.o, ray.d, this, out LFloat tmin, out LVector3 temp); 92 | } 93 | 94 | }; 95 | } -------------------------------------------------------------------------------- /Assets/NativeUtil/NativePool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Lockstep { 6 | public unsafe class NativeFactory { 7 | static Dictionary pools = new Dictionary(); 8 | 9 | public static long MemSize => pools.Sum((a) => a.Value.MemSize); 10 | 11 | public static NativePool GetPool(int size,bool isAutoPtr = true){ 12 | if (pools.TryGetValue(size, out var pool)) { 13 | return pool; 14 | } 15 | 16 | var tPool = new NativePool(size,isAutoPtr); 17 | pools[size] = tPool; 18 | return tPool; 19 | } 20 | 21 | public static void Clear(){ 22 | foreach (var pair in pools) { 23 | pair.Value.Clear(); 24 | } 25 | } 26 | } 27 | 28 | public unsafe class NativePool { 29 | private List _autoRefPtrs = new List(); 30 | private bool _isAutoPtr; 31 | private Stack _allPtrs = new Stack(); 32 | private int _typeSize = -1; 33 | public int MemSize => _typeSize * _allPtrs.Count; 34 | 35 | 36 | public NativePool(int typeSize, bool isAutoPtr = true){ 37 | this._typeSize = typeSize; 38 | this._isAutoPtr = isAutoPtr; 39 | if (isAutoPtr) { 40 | _autoRefPtrs = new List(); 41 | } 42 | } 43 | 44 | public void Return(void* ptr){ 45 | if (ptr == null) NativeHelper.NullPointer(); 46 | _allPtrs.Push((long) ptr); 47 | } 48 | 49 | public void* Get(){ 50 | if (_allPtrs.Count == 0) return null; 51 | var ptr = (byte*) _allPtrs.Pop(); 52 | NativeHelper.Zero(ptr, _typeSize); 53 | return ptr; 54 | } 55 | 56 | public void* ForceGet(){ 57 | var ptr = Get(); 58 | if (ptr == null) { 59 | ptr = NativeHelper.AllocAndZero(_typeSize); 60 | if (_isAutoPtr) { 61 | _autoRefPtrs.Add((long) ptr); 62 | } 63 | } 64 | 65 | return ptr; 66 | } 67 | 68 | public void Clear(){ 69 | if (_isAutoPtr) { 70 | foreach (var ptr in _autoRefPtrs) { 71 | NativeHelper.Free((IntPtr) ptr); 72 | } 73 | _autoRefPtrs.Clear(); 74 | _allPtrs.Clear(); 75 | } 76 | else { 77 | while (_allPtrs.Count > 0) { 78 | var ptr = _allPtrs.Pop(); 79 | NativeHelper.Free((IntPtr) ptr); 80 | } 81 | } 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/UnityWarp/GizmosHelper.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Collision2D; 2 | using Lockstep.Math; 3 | using UnityEngine; 4 | 5 | namespace Lockstep.UnsafeCollision2D { 6 | public class GizmosHelper { 7 | public static unsafe void DrawGizmos(ShapeWrap shapeWrap, Color color){ 8 | var shapeType = (EShape2D) shapeWrap.TypeId; 9 | switch (shapeType) { 10 | case EShape2D.Circle: 11 | DrawCircle(((ShapeWrapCircle) shapeWrap).shape, color); 12 | break; 13 | case EShape2D.AABB: 14 | DrawAABB(((ShapeWrapAABB) shapeWrap).shape, color); 15 | break; 16 | case EShape2D.OBB: 17 | DrawOBB(((ShapeWrapOBB) shapeWrap).shape, color); 18 | break; 19 | } 20 | } 21 | 22 | public static unsafe void DrawGizmos(EShape2D shapeType, Circle* shape, Color color){ 23 | switch (shapeType) { 24 | case EShape2D.Circle: 25 | DrawCircle(*(Circle*) shape, color); 26 | break; 27 | case EShape2D.AABB: 28 | DrawAABB(*(AABB2D*) shape, color); 29 | break; 30 | case EShape2D.OBB: 31 | DrawOBB(*(OBB2D*) shape, color); 32 | break; 33 | } 34 | } 35 | 36 | public static void DrawCircle(Circle circle, Color color){ 37 | DebugExtension.DebugCircle(circle.pos.ToVector2(), Vector3.back, color, circle.radius.ToFloat()); 38 | } 39 | 40 | public static void DrawAABB(AABB2D aabb, Color color){ 41 | var right = aabb.size.x * LVector2.right; 42 | var up = aabb.size.y * LVector2.up; 43 | var lb = aabb.pos - up - right; 44 | var lt = aabb.pos + up - right; 45 | var rt = aabb.pos + up + right; 46 | var rb = aabb.pos - up + right; 47 | Debug.DrawLine(lb.ToVector2(), lt.ToVector2(), color); 48 | Debug.DrawLine(lt.ToVector2(), rt.ToVector2(), color); 49 | Debug.DrawLine(rt.ToVector2(), rb.ToVector2(), color); 50 | Debug.DrawLine(rb.ToVector2(), lb.ToVector2(), color); 51 | } 52 | 53 | public static void DrawOBB(OBB2D obb, Color color){ 54 | var right = obb.size.x * obb.right; 55 | var up = obb.size.y * obb.up; 56 | var lb = obb.pos - up - right; 57 | var lt = obb.pos + up - right; 58 | var rt = obb.pos + up + right; 59 | var rb = obb.pos - up + right; 60 | Debug.DrawLine(lb.ToVector2(), lt.ToVector2(), color); 61 | Debug.DrawLine(lt.ToVector2(), rt.ToVector2(), color); 62 | Debug.DrawLine(rt.ToVector2(), rb.ToVector2(), color); 63 | Debug.DrawLine(rb.ToVector2(), lb.ToVector2(), color); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /Assets/Collision2D/Test/ColliderProxyMono.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.UnsafeCollision2D; 2 | using Lockstep.Math; 3 | using UnityEngine; 4 | 5 | namespace Lockstep.Collision2D { 6 | public class ColliderProxyMono : MonoBehaviour { 7 | public ColliderProxy proxy; 8 | 9 | public Vector2 prePos; 10 | public float preDeg; 11 | public bool hasInit = false; 12 | 13 | private Material mat; 14 | private bool hasCollided = false; 15 | public Color rawColor = Color.yellow; 16 | private Renderer render; 17 | private Material rawmat; 18 | public static bool IsReplaceNullMat; 19 | 20 | private void Start(){ 21 | render = GetComponent(); 22 | if (render == null) { 23 | render = GetComponentInChildren(); 24 | } 25 | 26 | if (render == null) { 27 | render = GetComponent(); 28 | if (render == null) { 29 | render = GetComponentInChildren(); 30 | } 31 | } 32 | 33 | if (render != null) { 34 | rawmat = render.material; 35 | mat = new Material(render.material); 36 | render.material = mat; 37 | } 38 | 39 | preDeg = 0; 40 | } 41 | 42 | public void Update(){ 43 | if (proxy == null) return; 44 | if (!hasInit) { 45 | hasInit = true; 46 | proxy.OnTriggerEvent += OnTriggerEvent; 47 | prePos = (transform.position - Vector3.up).ToVector2XZ(); 48 | } 49 | 50 | var curPos = transform.position.ToVector2XZ(); 51 | if (prePos != curPos) { 52 | prePos = curPos; 53 | proxy.pos = curPos.ToLVector2(); 54 | } 55 | 56 | var curDeg = transform.localRotation.eulerAngles.y; 57 | if (Mathf.Abs(curDeg - preDeg) > 0.1f) { 58 | preDeg = curDeg; 59 | proxy.deg = curDeg.ToLFloat(); 60 | } 61 | 62 | if (IsDebug) { 63 | int i = 0; 64 | } 65 | 66 | if (mat != null) { 67 | mat.color = hasCollided ? rawColor * 0.2f : rawColor; 68 | if (IsReplaceNullMat) { 69 | render.material = hasCollided ? null : rawmat; 70 | } 71 | } 72 | 73 | if (hasCollided) { 74 | hasCollided = false; 75 | } 76 | } 77 | 78 | public bool IsDebug = false; 79 | 80 | void OnTriggerEvent(ColliderProxy other, ECollisionEvent type){ 81 | hasCollided = true; 82 | if (IsDebug) { 83 | if (type != ECollisionEvent.Stay) { 84 | Debug.Log(type); 85 | } 86 | } 87 | 88 | if (proxy.IsStatic) { 89 | int i = 0; 90 | } 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/PtrList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Lockstep.Math; 3 | 4 | namespace Lockstep.UnsafeCollision2D { 5 | public unsafe class PtrList { 6 | private const int AlignSize = 64; 7 | protected int count; 8 | protected int capacity; 9 | protected byte* _dirtyBits; 10 | protected void** _ptrs; 11 | Dictionary _ptr2Pos = new Dictionary(); 12 | 13 | public void* GetShapePtr(int idx){ 14 | if (idx < 0 || idx >= count) { 15 | NativeHelper.ArrayOutOfRange(); 16 | } 17 | 18 | return _ptrs[idx]; 19 | } 20 | 21 | public PtrList(int initSize = AlignSize){ 22 | initSize = LMath.Max(AlignSize, initSize); 23 | if (initSize % AlignSize != 0) { 24 | initSize = (initSize % AlignSize + 1) * AlignSize; 25 | } 26 | 27 | capacity = initSize; 28 | count = 0; 29 | _ptrs = (void**) NativeHelper.AllocAndZero(sizeof(void*) * initSize); 30 | _dirtyBits = (byte*) NativeHelper.AllocAndZero(initSize / 8); 31 | } 32 | 33 | void CheckAndResize(){ 34 | if (count == capacity) { 35 | _ptrs = (void**) NativeHelper.Resize(_ptrs, sizeof(void*) * capacity, 36 | sizeof(void*) * capacity * 2); 37 | _dirtyBits = (byte*) NativeHelper.Resize(_dirtyBits, capacity * 8 / AlignSize, 38 | capacity * 8 / AlignSize * 2); 39 | capacity *= 2; 40 | } 41 | } 42 | 43 | public void AddPtr(void* ptr){ 44 | CheckAndResize(); 45 | var ptrVal = (long) ptr; 46 | if (!_ptr2Pos.ContainsKey(ptrVal)) { 47 | _ptrs[count] = ptr; 48 | //_ptr2Pos[ptrVal] = count; 49 | count++; 50 | } 51 | } 52 | 53 | public void RemovePtr(void* ptr){ 54 | var ptrVal = (long) ptr; 55 | if (_ptr2Pos.TryGetValue(ptrVal, out var id)) { 56 | _ptrs[id] = null; 57 | _ptr2Pos.Remove(ptrVal); 58 | } 59 | } 60 | 61 | public Iterator GetEnumerator(){ 62 | return new Iterator(_ptrs,count); 63 | } 64 | 65 | public unsafe partial struct Iterator { 66 | private int _count; 67 | private void** _ptrs; 68 | private int _index; 69 | public void* Current; 70 | 71 | public Iterator(void** ptrs, int count){ 72 | _ptrs = ptrs; 73 | _count = count; 74 | Current = null; 75 | _index = -1; 76 | } 77 | 78 | public bool Next(){ 79 | while (++_index < _count) { 80 | if (_ptrs[_index] != null) { 81 | Current = _ptrs[_index]; 82 | return true; 83 | } 84 | } 85 | 86 | Current = null; 87 | return false; 88 | } 89 | } 90 | } 91 | } -------------------------------------------------------------------------------- /Assets/Collision/Geometry/Capsule.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | using LockStepLMath; 3 | using static Lockstep.Math.LMath; 4 | using Point2D = Lockstep.Math.LVector2; 5 | 6 | namespace Lockstep.Collision { 7 | [System.Serializable] 8 | public partial class Capsule : BaseShape { 9 | public override EColType ColType => EColType.Capsule; 10 | 11 | public Capsule(LVector3 c, LVector3 hDir, LFloat r) : base(){ 12 | this.c = c; 13 | this.hDir = hDir; 14 | this.r = r; 15 | } 16 | 17 | /// 18 | /// Medial line segment start point 19 | /// 20 | public LVector3 a => c - _hDir; 21 | 22 | /// 23 | /// Medial line segment end point 24 | /// 25 | public LVector3 b => c + _hDir; 26 | 27 | 28 | private LFloat _hLen; 29 | 30 | public LFloat hLen { 31 | get => _hLen; 32 | set { 33 | _hLen = value; 34 | _hDir = value * _hDir.normalized; 35 | } 36 | } 37 | 38 | private LVector3 _hDir; 39 | 40 | public LVector3 hDir { 41 | get => _hDir; 42 | set { 43 | _hDir = value; 44 | _hLen = value.magnitude; 45 | } 46 | } 47 | 48 | /// 49 | /// Center 50 | /// 51 | public LVector3 c; 52 | 53 | /// 54 | /// Radius 55 | /// 56 | public LFloat r; 57 | 58 | public LFloat GetBoundsSphereRadius(){ 59 | return _hLen + r; 60 | } 61 | 62 | public LVector3 GetBoundSphereCenter(){ 63 | return c; 64 | } 65 | 66 | public override Sphere GetBoundSphere(){ 67 | return new Sphere(c, _hLen + r); 68 | } 69 | 70 | public override void UpdateRotation(LVector3 forward, LVector3 up){ 71 | _hDir = up * _hLen; 72 | } 73 | 74 | public override void UpdatePosition(LVector3 targetPos){ 75 | c = targetPos; 76 | } 77 | 78 | public override bool TestWithShape(BaseShape shape){ 79 | return shape.TestWith(this); 80 | } 81 | 82 | 83 | public override bool TestWith(Sphere sphere){ 84 | return Utils.TestSphereCapsule(sphere, this); 85 | } 86 | 87 | public override bool TestWith(AABB aabb){ 88 | return Utils.TestAABBCapsule(aabb, this); 89 | } 90 | 91 | public override bool TestWith(Capsule capsule){ 92 | return Utils.TestCapsuleCapsule(this, capsule); 93 | } 94 | 95 | public override bool TestWith(OBB obb){ 96 | return Utils.TestOBBCapsule(obb, this); 97 | } 98 | 99 | public override bool TestWith(Plane plane){ 100 | return Utils.TestCapsulePlane(this, plane); 101 | } 102 | 103 | public override bool TestWith(Ray ray){ 104 | return Utils.IntersectRayCapsule(ray.o, ray.d, a, b, r, out LFloat t); 105 | } 106 | }; 107 | } -------------------------------------------------------------------------------- /Assets/Collision2D/ColliderProxy.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.UnsafeCollision2D; 2 | using Lockstep.Math; 3 | using UnityEngine; 4 | 5 | namespace Lockstep.Collision2D { 6 | public delegate void FuncOnTriggerEvent(ColliderProxy other, ECollisionEvent type); 7 | 8 | public class ColliderProxy :ILPCollisionEventHandler,ILPTriggerEventHandler{ 9 | #if UNITY_EDITOR 10 | public Transform UnityTransform; 11 | #endif 12 | public int Id; 13 | public int LayerType { get; set; } 14 | public ColliderPrefab Prefab; 15 | public CTransform2D Transform2D; 16 | public LFloat Height; 17 | public bool IsTrigger = true; 18 | public bool IsStatic = false; 19 | 20 | 21 | private LRect _bound; 22 | 23 | public FuncOnTriggerEvent OnTriggerEvent; 24 | 25 | private BoundsQuadTree _quadTree; 26 | 27 | private static int autoIncId = 0; 28 | 29 | public void Init(ColliderPrefab prefab, LVector2 pos, LFloat y){ 30 | Init(prefab, pos, y, LFloat.zero); 31 | } 32 | 33 | public void Init(ColliderPrefab prefab, LVector2 pos){ 34 | Init(prefab, pos, LFloat.zero, LFloat.zero); 35 | } 36 | 37 | public void Init(ColliderPrefab prefab, LVector2 pos, LFloat y, LFloat deg){ 38 | this.Prefab = prefab; 39 | _bound = prefab.GetBounds(); 40 | Transform2D = new CTransform2D(pos, y, deg); 41 | unchecked { 42 | Id = autoIncId++; 43 | } 44 | } 45 | 46 | public bool _isMoved = true; 47 | 48 | public LVector2 pos { 49 | get => Transform2D.pos; 50 | set { 51 | _isMoved = true; 52 | Transform2D.pos = value; 53 | } 54 | } 55 | 56 | public LFloat y { 57 | get => Transform2D.y; 58 | set { 59 | _isMoved = true; 60 | Transform2D.y = value; 61 | } 62 | } 63 | 64 | public LFloat deg { 65 | get => Transform2D.deg; 66 | set { 67 | _isMoved = true; 68 | Transform2D.deg = value; 69 | } 70 | } 71 | 72 | 73 | public LRect GetBounds(){ 74 | return new LRect(_bound.position + pos, _bound.size); 75 | } 76 | 77 | public virtual void OnLPTriggerEnter(ColliderProxy other){ } 78 | public virtual void OnLPTriggerStay(ColliderProxy other){ } 79 | public virtual void OnLPTriggerExit(ColliderProxy other){ } 80 | public virtual void OnLPCollisionEnter(ColliderProxy other){ } 81 | public virtual void OnLPCollisionStay(ColliderProxy other){ } 82 | public virtual void OnLPCollisionExit(ColliderProxy other){ } 83 | } 84 | public interface ILPCollisionEventHandler { 85 | void OnLPTriggerEnter(ColliderProxy other); 86 | void OnLPTriggerStay(ColliderProxy other); 87 | void OnLPTriggerExit(ColliderProxy other); 88 | } 89 | public interface ILPTriggerEventHandler { 90 | void OnLPTriggerEnter(ColliderProxy other); 91 | void OnLPTriggerStay(ColliderProxy other); 92 | void OnLPTriggerExit(ColliderProxy other); 93 | } 94 | } -------------------------------------------------------------------------------- /Assets/Collision/SpacePartition/Algorithm.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | 4 | namespace LockStep { 5 | public static class Algorithm { 6 | public static void Swap(List data, int a, int b){ 7 | var temp = data[a]; 8 | data[a] = data[b]; 9 | data[b] = temp; 10 | } 11 | 12 | public static T Median(T a, T b, T c, Func __comp){ 13 | if (__comp(a, b) < 0) { 14 | if (__comp(b, c) < 0) 15 | return b; 16 | else { 17 | if (__comp(a, c) < 0) 18 | return c; 19 | else 20 | return a; 21 | } 22 | } 23 | else { 24 | //a>b 25 | if (__comp(a, c) < 0) 26 | return a; 27 | else { 28 | if (__comp(b, c) < 0) 29 | return c; 30 | else 31 | return b; 32 | } 33 | } 34 | } 35 | 36 | public static T NthElement(List data, int __first, int __nth, int __last, Func __comp){ 37 | while (__last - __first > 3) { 38 | var _cut = Partition(data, __first, __last, __comp); 39 | if (_cut == __nth) 40 | return data[_cut]; 41 | else if (_cut > __nth) 42 | __first = _cut; 43 | else 44 | __last = _cut; 45 | } 46 | /**/ 47 | 48 | 49 | //__insertion_sort 50 | var n = __last - __first; 51 | for (int i = __first + 1; i < __last; ++i) { 52 | var x = data[i]; 53 | int j = i - 1; 54 | while (__comp(data[j], x) > 0 && j >= __first) { 55 | data[j + 1] = data[j]; 56 | j--; 57 | } 58 | 59 | data[j + 1] = x; 60 | } 61 | 62 | return data[__nth]; 63 | } 64 | 65 | //partition函数 66 | public static int Partition(List data, int __first, int __last, Func __comp){ 67 | var __pivot = Median(data[__first], data[__last], data[(__first + __last) / 2], __comp); 68 | while (true) { 69 | while (__comp(data[__first], __pivot) < 0) 70 | ++__first; 71 | --__last; 72 | while (__comp(__pivot, data[__last]) < 0) 73 | --__last; 74 | if (!(__first < __last)) 75 | return __first; 76 | //swap 77 | Swap(data, __first, __last); 78 | ++__first; 79 | } 80 | } 81 | 82 | public static int Partition(List data, int __first, int __last, Func __comp){ 83 | var _endIdx = __last - 1; 84 | var _beginIdx = __first; 85 | while (true) { 86 | while (__first <= _endIdx && __comp(data[__first])) 87 | ++__first; 88 | --__last; 89 | while (__last >= _beginIdx && __comp(data[__last])) 90 | --__last; 91 | if (!(__first < __last)) 92 | return __first; 93 | //swap 94 | Swap(data, __first, __last); 95 | ++__first; 96 | } 97 | } 98 | } 99 | } -------------------------------------------------------------------------------- /Assets/NativeUtil/NativeHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace Lockstep { 7 | public unsafe class NativeHelper { 8 | public const int STRUCT_PACK = 4; 9 | 10 | #if DEBUG 11 | public static HashSet _allocedPtrs = new HashSet(); 12 | public static Dictionary _prt2Size = new Dictionary(); 13 | #endif 14 | public static long MemSize => _prt2Size.Sum((d) => d.Value); 15 | public static void Free(IntPtr ptr){ 16 | Free(ptr.ToPointer()); 17 | } 18 | public static void Free(void* ptr){ 19 | #if DEBUG 20 | if (!_allocedPtrs.Contains((long) ptr)) { 21 | throw new NullReferenceException("Try to free a block which did not allocated!"); 22 | } 23 | _prt2Size.Remove((long) ptr); 24 | #endif 25 | 26 | if (ptr == null) throw new NullReferenceException(); 27 | Marshal.FreeHGlobal((IntPtr)ptr); 28 | } 29 | 30 | public static IntPtr Alloc(int size){ 31 | var ptr = Marshal.AllocHGlobal(size); 32 | #if DEBUG 33 | _allocedPtrs.Add((long) ptr); 34 | _prt2Size.Add((long) ptr, size); 35 | #endif 36 | return ptr; 37 | } 38 | 39 | public static void* Resize(void* src, int srcSize, int dstSize){ 40 | var newAry = AllocAndZero(dstSize); 41 | Copy(newAry, src, srcSize); 42 | Free(new IntPtr(src)); 43 | return newAry; 44 | } 45 | 46 | public static unsafe void Zero(void* ptr, int size){ 47 | Zero((byte*) ptr, size); 48 | } 49 | 50 | public static unsafe void Zero(byte* ptr, int size){ 51 | for (; size >= 4; size -= 4) { 52 | *(int*) ptr = 0; 53 | ptr += 4; 54 | } 55 | 56 | for (; size > 0; --size) { 57 | *ptr = 0; 58 | } 59 | } 60 | 61 | public static unsafe void Copy(void* dest, void* src, int size){ 62 | Copy((byte*) dest, (byte*) src, size); 63 | } 64 | 65 | public static unsafe void Copy(byte* dest, byte* src, int size){ 66 | for (; size >= 4; size -= 4) { 67 | *(int*) dest = *(int*) src; 68 | dest += 4; 69 | src += 4; 70 | } 71 | 72 | for (; size > 0; --size) { 73 | *dest = *src; 74 | ++dest; 75 | ++src; 76 | } 77 | } 78 | 79 | public static byte* AllocAndZero(int size){ 80 | var ptr = (byte*) (Alloc(size).ToPointer()); 81 | Zero(ptr, size); 82 | return ptr; 83 | } 84 | 85 | public static void NullPointer(){ 86 | throw new NullReferenceException("Method invoked on null pointer."); 87 | } 88 | 89 | public static void ArrayOutOfRange(){ 90 | throw new ArgumentOutOfRangeException("Array index out of range"); 91 | } 92 | 93 | private class BufferSizeMissMatchException : Exception { 94 | public BufferSizeMissMatchException(string info) : base("Buffer Size miss match!! " + info){ } 95 | } 96 | 97 | public static void BufferSizeMissMatch(string info = ""){ 98 | throw new BufferSizeMissMatchException(info); 99 | } 100 | } 101 | } -------------------------------------------------------------------------------- /Assets/Collision/Geometry/BaseShape.cs: -------------------------------------------------------------------------------- 1 | using Lockstep.Math; 2 | using System; 3 | using System.Security.Cryptography.X509Certificates; 4 | using LockStepLMath; 5 | 6 | namespace Lockstep.Collision 7 | { 8 | public enum EColType 9 | { 10 | Sphere, 11 | AABB, 12 | Capsule, 13 | Cylinder, 14 | OBB, 15 | ColMesh, 16 | Triangle, 17 | Plane, 18 | Ray, 19 | Rect, 20 | Segment, 21 | Polygon, 22 | EnumCount, 23 | } 24 | [System.Serializable] 25 | public partial class BaseShape 26 | { 27 | /// 28 | /// 碰撞类型 29 | /// 30 | public virtual EColType ColType 31 | { 32 | get { return EColType.EnumCount; } 33 | } 34 | 35 | public virtual AABB GetBound(){ return null;} 36 | 37 | public virtual Sphere GetBoundSphere() 38 | { 39 | return null; 40 | } 41 | 42 | public virtual void UpdatePosition(LVector3 targetPos) 43 | { 44 | 45 | } 46 | public virtual void UpdateRotation(LVector3 forward, LVector3 up) 47 | { 48 | //throw new NotImplementedException(GetType() + "Can not rotate "); 49 | } 50 | public static bool TestShapeWithShape(BaseShape a, BaseShape b) 51 | { 52 | if (a == null || b == null) 53 | return false; 54 | return a.TestWithShape(b); 55 | } 56 | 57 | #region TestInterfaces 58 | 59 | public virtual bool TestWithShape(BaseShape shape) 60 | { 61 | throw new System.NotImplementedException(GetType() + " not implement this TestWithShape"); 62 | } 63 | 64 | public virtual bool TestWith(Sphere sphere) 65 | { 66 | throw new System.NotImplementedException(GetType() + " not implement this TestWithSphere"); 67 | } 68 | public virtual bool TestWith(AABB aabb) 69 | { 70 | throw new System.NotImplementedException(GetType() + " not implement this TestWithAABB"); 71 | } 72 | public virtual bool TestWith(Capsule capsule) 73 | { 74 | throw new System.NotImplementedException(GetType() + " not implement this TestWithCapsule"); 75 | } 76 | 77 | public virtual bool TestWith(OBB obb) 78 | { 79 | throw new System.NotImplementedException(GetType() + " not implement this TestWithOBB"); 80 | } 81 | 82 | 83 | public virtual bool TestWith(Plane plane) 84 | { 85 | throw new System.NotImplementedException(GetType() + " not implement this TestWithPlane"); 86 | } 87 | 88 | public virtual bool TestWith(Ray ray) 89 | { 90 | throw new System.NotImplementedException(GetType() + " not implement this TestWithRay"); 91 | } 92 | public virtual bool TestWith(Ray ray,ref LFloat tmin) 93 | { 94 | throw new System.NotImplementedException(GetType() + " not implement this TestWithRay"); 95 | } 96 | 97 | 98 | public virtual bool TestWith(Cylinder cylinder) 99 | { 100 | throw new System.NotImplementedException(GetType() + " not implement this TestWithCylinder"); 101 | } 102 | 103 | 104 | public virtual bool TestWith(ColMesh mesh) 105 | { 106 | throw new System.NotImplementedException(GetType() + " not implement this TestWithMesh"); 107 | } 108 | #endregion 109 | } 110 | } -------------------------------------------------------------------------------- /Assets/Math/LMath_Vector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Lockstep.Math; 3 | using static Lockstep.Math.LVector3; 4 | 5 | namespace Lockstep.Math 6 | { 7 | public static partial class LMath 8 | { 9 | public static LVector3 Transform(ref LVector3 point, ref LVector3 axis_x, ref LVector3 axis_y, ref LVector3 axis_z, 10 | ref LVector3 trans) 11 | { 12 | return new LVector3(true, 13 | ((axis_x._x * point._x + axis_y._x * point._y + axis_z._x * point._z) / LFloat.Precision) + trans._x, 14 | ((axis_x._y * point._x + axis_y._y * point._y + axis_z._y * point._z) / LFloat.Precision) + trans._y, 15 | ((axis_x._z * point._x + axis_y._z * point._y + axis_z._z * point._z) / LFloat.Precision) + trans._z); 16 | } 17 | 18 | public static LVector3 Transform(LVector3 point, ref LVector3 axis_x, ref LVector3 axis_y, ref LVector3 axis_z, 19 | ref LVector3 trans) 20 | { 21 | return new LVector3(true, 22 | ((axis_x._x * point._x + axis_y._x * point._y + axis_z._x * point._z) / LFloat.Precision) + trans._x, 23 | ((axis_x._y * point._x + axis_y._y * point._y + axis_z._y * point._z) / LFloat.Precision) + trans._y, 24 | ((axis_x._z * point._x + axis_y._z * point._y + axis_z._z * point._z) / LFloat.Precision) + trans._z); 25 | } 26 | 27 | public static LVector3 Transform(ref LVector3 point, ref LVector3 axis_x, ref LVector3 axis_y, ref LVector3 axis_z, 28 | ref LVector3 trans, ref LVector3 scale) 29 | { 30 | long num = (long) point._x * (long) scale._x; 31 | long num2 = (long) point._y * (long) scale._x; 32 | long num3 = (long) point._z * (long) scale._x; 33 | return new LVector3(true, 34 | (int) (((long) axis_x._x * num + (long) axis_y._x * num2 + (long) axis_z._x * num3) / 1000000L) + 35 | trans._x, 36 | (int) (((long) axis_x._y * num + (long) axis_y._y * num2 + (long) axis_z._y * num3) / 1000000L) + 37 | trans._y, 38 | (int) (((long) axis_x._z * num + (long) axis_y._z * num2 + (long) axis_z._z * num3) / 1000000L) + 39 | trans._z); 40 | } 41 | 42 | public static LVector3 Transform(ref LVector3 point, ref LVector3 forward, ref LVector3 trans) 43 | { 44 | LVector3 up = LVector3.up; 45 | LVector3 vInt = Cross(LVector3.up, forward); 46 | return LMath.Transform(ref point, ref vInt, ref up, ref forward, ref trans); 47 | } 48 | 49 | public static LVector3 Transform(LVector3 point, LVector3 forward, LVector3 trans) 50 | { 51 | LVector3 up = LVector3.up; 52 | LVector3 vInt = Cross(LVector3.up, forward); 53 | return LMath.Transform(ref point, ref vInt, ref up, ref forward, ref trans); 54 | } 55 | 56 | public static LVector3 Transform(LVector3 point, LVector3 forward, LVector3 trans, LVector3 scale) 57 | { 58 | LVector3 up = LVector3.up; 59 | LVector3 vInt = Cross(LVector3.up, forward); 60 | return LMath.Transform(ref point, ref vInt, ref up, ref forward, ref trans, ref scale); 61 | } 62 | 63 | public static LVector3 MoveTowards(LVector3 from, LVector3 to, LFloat dt) 64 | { 65 | if ((to - from).sqrMagnitude <= (dt * dt)) 66 | { 67 | return to; 68 | } 69 | 70 | return from + (to - from).Normalize(dt); 71 | } 72 | 73 | 74 | public static LFloat AngleInt(LVector3 lhs, LVector3 rhs) 75 | { 76 | return LMath.Acos(Dot(lhs, rhs)); 77 | } 78 | 79 | 80 | 81 | } 82 | } -------------------------------------------------------------------------------- /Assets/Collision2D/CollisionHelper.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Lockstep.Collision2D { 3 | public partial class CollisionHelper { 4 | 5 | private static bool CheckSeg_Seg (CSegment col1, CSegment col2,Transform2D trans1,Transform2D trans2){return false;} 6 | private static bool CheckSeg_Ray (CSegment col1, CRay col2,Transform2D trans1,Transform2D trans2){return false;} 7 | private static bool CheckSeg_Circle (CSegment col1, CCircle col2,Transform2D trans1,Transform2D trans2){return false;} 8 | private static bool CheckSeg_AABB (CSegment col1, CAABB col2,Transform2D trans1,Transform2D trans2){return false;} 9 | private static bool CheckSeg_OBB (CSegment col1, COBB col2,Transform2D trans1,Transform2D trans2){return false;} 10 | private static bool CheckSeg_Polygon (CSegment col1, CPolygon col2,Transform2D trans1,Transform2D trans2){return false;} 11 | private static bool CheckRay_Ray (CRay col1, CRay col2,Transform2D trans1,Transform2D trans2){return false;} 12 | private static bool CheckRay_Circle (CRay col1, CCircle col2,Transform2D trans1,Transform2D trans2){return false;} 13 | private static bool CheckRay_AABB (CRay col1, CAABB col2,Transform2D trans1,Transform2D trans2){return false;} 14 | private static bool CheckRay_OBB (CRay col1, COBB col2,Transform2D trans1,Transform2D trans2){return false;} 15 | private static bool CheckRay_Polygon (CRay col1, CPolygon col2,Transform2D trans1,Transform2D trans2){return false;} 16 | 17 | private static bool CheckCircle_Circle(CCircle col1, CCircle col2, Transform2D trans1, Transform2D trans2){ 18 | return Utils.TestCircleCircle( 19 | trans1.pos, col1.radius, 20 | trans2.pos, col2.radius); 21 | } 22 | private static bool CheckCircle_AABB (CCircle col1, CAABB col2,Transform2D trans1,Transform2D trans2){ 23 | return Utils.TestCircleAABB( 24 | trans1.pos, col1.radius, 25 | trans2.pos, col2.radius, col2.size); 26 | 27 | } 28 | private static bool CheckCircle_OBB (CCircle col1, COBB col2,Transform2D trans1,Transform2D trans2){ 29 | return Utils.TestCircleOBB( 30 | trans1.pos, col1.radius, 31 | trans2.pos, col2.radius, col2.size,col2.up);} 32 | private static bool CheckCircle_Polygon (CCircle col1, CPolygon col2,Transform2D trans1,Transform2D trans2){return false;} 33 | 34 | private static bool CheckAABB_AABB(CAABB col1, CAABB col2, Transform2D trans1, Transform2D trans2){ 35 | return Utils.TestAABBAABB( 36 | trans1.pos, col1.radius, col1.size, 37 | trans2.pos, col2.radius, col2.size); 38 | } 39 | 40 | private static bool CheckAABB_OBB(CAABB col1, COBB col2, Transform2D trans1, Transform2D trans2){ 41 | return Utils.TestAABBOBB( 42 | trans1.pos, col1.radius, col1.size, 43 | trans2.pos, col2.radius, col2.size,col2.up); 44 | } 45 | private static bool CheckAABB_Polygon (CAABB col1, CPolygon col2,Transform2D trans1,Transform2D trans2){return false;} 46 | 47 | private static bool CheckOBB_OBB(COBB col1, COBB col2, Transform2D trans1, Transform2D trans2){ 48 | return Utils.TestOBBOBB( 49 | trans1.pos, col1.radius, col1.size,col1.up, 50 | trans2.pos, col2.radius, col2.size,col2.up); 51 | } 52 | private static bool CheckOBB_Polygon (COBB col1, CPolygon col2,Transform2D trans1,Transform2D trans2){return false;} 53 | private static bool CheckPolygon_Polygon(CPolygon col1, CPolygon col2,Transform2D trans1,Transform2D trans2){return false;} 54 | } 55 | } -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/ColliderConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Lockstep.Math; 4 | #if UNITY_5_3_OR_NEWER 5 | using UnityEngine; 6 | #endif 7 | namespace Lockstep.UnsafeCollision2D { 8 | public unsafe class ColliderConfig 9 | #if UNITY_5_3_OR_NEWER 10 | : MonoBehaviour 11 | #endif 12 | { 13 | 14 | #if UNITY_EDITOR 15 | public static Color DebugGizomColor = Color.white; 16 | 17 | public void OnDrawGizmos(){ 18 | var count = allColliders.Count; 19 | for (int i = 0; i < count; i++) { 20 | var shapeWrap = allColliders[i]; 21 | GizmosHelper.DrawGizmos(shapeWrap, DebugGizomColor); 22 | } 23 | } 24 | 25 | 26 | #endif 27 | public LVector2 pos; 28 | public LFloat deg; 29 | public List allOffsets = new List(); 30 | public List allColliders = new List(); 31 | 32 | public ShapeWrap Collider { 33 | get { 34 | if (allColliders.Count == 0) return null; 35 | return allColliders[0]; 36 | } 37 | } 38 | //add 39 | public void AddCircle(LVector2 offset, LVector2 pos, LFloat radius){ 40 | allColliders.Add(new ShapeWrapCircle() { 41 | shape = new Circle(0,pos, radius) 42 | }); 43 | allOffsets.Add(offset); 44 | } 45 | 46 | public void AddAABB(LVector2 offset, LVector2 pos, LVector2 size){ 47 | allColliders.Add(new ShapeWrapAABB() { 48 | shape = new AABB2D(0,pos, size) }); 49 | allOffsets.Add(offset); 50 | } 51 | 52 | public void AddOBB(LVector2 offset, LVector2 pos, LVector2 size, LFloat deg){ 53 | allColliders.Add(new ShapeWrapOBB() { 54 | shape = new OBB2D(0,pos, size, deg) 55 | }); 56 | allOffsets.Add(offset); 57 | } 58 | 59 | //delete 60 | public void Remove(int idx){ 61 | Debug.Assert(idx < allOffsets.Count, "out of range"); 62 | if (idx >= allOffsets.Count) return; 63 | allColliders.RemoveAt(idx); 64 | allOffsets.RemoveAt(idx); 65 | } 66 | 67 | public void Remove(ShapeWrap shape){ 68 | var idx = allColliders.IndexOf(shape); 69 | if (idx != -1) { 70 | Remove(idx); 71 | } 72 | } 73 | 74 | //modify 75 | public void ModifyOffset(int idx, LVector2 offset){ 76 | //Debug.Assert(idx < allOffsets.Count, "out of range"); 77 | if (idx >= allOffsets.Count) return; 78 | allOffsets[idx] = offset; 79 | } 80 | 81 | 82 | public void SetPosition(LVector3 val){ 83 | transform.position = val.ToVector3(); 84 | OnSetPosition(new LVector2(val.x, val.y)); 85 | } 86 | 87 | public void SetRotation(LFloat val){ 88 | transform.rotation = Quaternion.Euler(0, 0, val.ToFloat()); 89 | OnSetRotation(val); 90 | } 91 | 92 | public void Update(){ 93 | var pos = transform.position.ToLVector3(); 94 | var deg = transform.rotation.eulerAngles.z.ToLFloat(); 95 | OnSetPosition(new LVector2(pos.x, pos.y)); 96 | OnSetRotation(deg); 97 | } 98 | 99 | //tranform values 100 | protected void OnSetPosition(LVector2 val){ 101 | if (pos != val) { 102 | pos = val; 103 | var count = allColliders.Count; 104 | for (int i = 0; i < count; i++) { 105 | //allColliders[i].UpdatePosition(pos + allOffsets[i]); 106 | } 107 | } 108 | } 109 | 110 | protected void OnSetRotation(LFloat val){ 111 | if (deg != val) { 112 | deg = val; 113 | var count = allColliders.Count; 114 | for (int i = 0; i < count; i++) { 115 | //allColliders[i].UpdateRotation(deg); 116 | } 117 | } 118 | } 119 | } 120 | } -------------------------------------------------------------------------------- /Assets/Collision/ColliderProxy.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Lockstep.Math; 3 | #if UNITY_5_3_OR_NEWER 4 | using UnityEngine; 5 | 6 | #endif 7 | 8 | namespace Lockstep.Collision { 9 | [System.Serializable] 10 | public struct ColliderLocalInfo { 11 | public LVector3 offset; 12 | public LVector3 rotation; 13 | public static readonly ColliderLocalInfo identity = new ColliderLocalInfo(LVector3.zero, LVector3.zero); 14 | 15 | public ColliderLocalInfo(LVector3 offset, LVector3 rotation){ 16 | this.offset = offset; 17 | this.rotation = rotation; 18 | } 19 | } 20 | 21 | public class ColliderProxy 22 | #if UNITY_5_3_OR_NEWER 23 | : MonoBehaviour { 24 | #else 25 | { 26 | #endif 27 | public List allCollider = new List(); 28 | public List allColliderOffset = new List(); 29 | public Sphere boundSphere; 30 | 31 | public BaseShape Collider => allCollider?[0]; 32 | 33 | /// 34 | /// 获取所有的Shape 的总boundSphere 35 | /// 36 | /// 37 | public virtual Sphere GetBoundSphere(){ 38 | Sphere retS = null; 39 | foreach (var col in allCollider) { 40 | var tempS = col.GetBoundSphere(); 41 | if (retS == null) { 42 | retS = tempS; 43 | } 44 | else { 45 | var rt = (tempS.c - retS.c); 46 | var sqrCenterDist = rt.sqrMagnitude; 47 | var rDist = retS.r + tempS.r; 48 | if (rDist * rDist <= sqrCenterDist) //separatie 49 | { 50 | var centerDist = LMath.Sqrt(sqrCenterDist); 51 | var r = (centerDist + rDist) * LFloat.half; 52 | var c = retS.c + rt.normalized * (r - retS.r); 53 | retS.c = c; 54 | retS.r = r; 55 | } 56 | else { 57 | var rdiff = LMath.Abs(retS.r - tempS.r); 58 | if (rdiff <= sqrCenterDist) //one contains another 59 | { 60 | if (retS.r < tempS.r) { 61 | retS.c = tempS.c; 62 | retS.r = tempS.r; 63 | } 64 | } 65 | else //intersect 66 | { 67 | var centerDist = LMath.Sqrt(sqrCenterDist); 68 | var r = (centerDist + rDist) * LFloat.half; 69 | var c = retS.c + rt.normalized * (r - retS.r); 70 | retS.c = c; 71 | retS.r = r; 72 | } 73 | } 74 | } 75 | } 76 | 77 | return retS; 78 | } 79 | 80 | public void UpdatePosition(LVector3 pos){ 81 | boundSphere.c = pos; 82 | foreach (var col in allCollider) { 83 | col.UpdatePosition(pos); 84 | } 85 | } 86 | 87 | public void UpdateRotation(LVector3 forward, LVector3 up){ 88 | foreach (var col in allCollider) { 89 | col.UpdateRotation(forward, up); 90 | } 91 | } 92 | 93 | public void AddCollider(BaseShape shape, ColliderLocalInfo localInfo){ 94 | allCollider.Add(shape); 95 | allColliderOffset.Add(localInfo); 96 | boundSphere = GetBoundSphere(); 97 | } 98 | 99 | public static bool TestColliderProxy(ColliderProxy a, ColliderProxy b){ 100 | //TODO use better ways 101 | var isCollided = Utils.TestSphereSphere(a.boundSphere, b.boundSphere); 102 | if (isCollided) { 103 | foreach (var cCola in a.allCollider) { 104 | foreach (var cColb in b.allCollider) { 105 | if (BaseShape.TestShapeWithShape(cCola, cColb)) { 106 | return true; 107 | } 108 | } 109 | } 110 | } 111 | return false; 112 | } 113 | } 114 | } -------------------------------------------------------------------------------- /Assets/Collision/Geometry/AABB.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | using System.Runtime.CompilerServices; 3 | using Lockstep.Math; 4 | using UnityEditor; 5 | using static Lockstep.Math.LMath; 6 | using Point2D = Lockstep.Math.LVector2; 7 | 8 | namespace Lockstep.Collision { 9 | [System.Serializable] 10 | public partial class AABB : BaseShape { 11 | public override EColType ColType { 12 | get { return EColType.AABB; } 13 | } 14 | 15 | public LVector3 min; 16 | public LVector3 max; 17 | 18 | /// 19 | /// center point of AABB 20 | /// 21 | public LVector3 c { 22 | get { return (max + min) * LFloat.half; } 23 | } 24 | 25 | /// 26 | /// radius or halfwidth extents 27 | /// 28 | public LVector3 r { 29 | get { return (max - min) * LFloat.half; } 30 | } 31 | 32 | public AABB(LVector3 min, LVector3 max){ 33 | this.min = min; 34 | this.max = max; 35 | } 36 | 37 | public AABB(AABB o){ 38 | this.min = o.min; 39 | this.max = o.max; 40 | } 41 | 42 | 43 | public AABB(){ } 44 | 45 | public static AABB FromOBB(OBB obb){ 46 | var aabb = new AABB(); 47 | var abse = obb.e.abs; 48 | aabb.min = obb.c - abse; 49 | aabb.max = obb.c + abse; 50 | return aabb; 51 | } 52 | 53 | public OBB ToOBB(){ 54 | var obb = new OBB(); 55 | obb.c = c; 56 | obb.e = r; 57 | obb.u = LAxis3D.identity; 58 | return obb; 59 | } 60 | 61 | public LFloat SurfaceArea(){ 62 | LVector3 d = min - min; 63 | return (d.x * d.y + d.x * d.z + d.y * d.z) * 2; 64 | } 65 | 66 | public int MaximumExtent(){ 67 | var diag = min - min; 68 | if (diag.x > diag.y && diag.x > diag.z) 69 | return 0; 70 | else if (diag.y > diag.z) 71 | return 1; 72 | else 73 | return 2; 74 | } 75 | 76 | public LVector3 this[int index] { 77 | get { 78 | if (index == 0) return min; 79 | else return max; 80 | } 81 | set { 82 | if (index == 0) min = value; 83 | else max = value; 84 | } 85 | } 86 | 87 | public override void UpdatePosition(LVector3 targetPos){ 88 | var oldR = r; 89 | min = targetPos - oldR; 90 | max = targetPos + oldR; 91 | } 92 | // Transform AABB a by the matrix m and translation t, 93 | // find maximum extents, and store result into AABB b. 94 | public void UpdateAABB(LMatrix33 m, LVector3 t){ 95 | LVector3 _c = c + t; 96 | LVector3 _r = r; 97 | min = max = _c; 98 | // For all three axes 99 | for (int i = 0; i < 3; i++) { 100 | // Form extent by summing smaller and larger terms respectively 101 | for (int j = 0; j < 3; j++) { 102 | LFloat e = m[i, j] * _r[j]; 103 | if (e < LFloat.zero) { 104 | min[i] += e; 105 | max[i] -= e; 106 | } 107 | else { 108 | min[i] -= e; 109 | max[i] += e; 110 | } 111 | } 112 | } 113 | } 114 | 115 | public override Sphere GetBoundSphere(){ 116 | return new Sphere(c, (max - min).magnitude * LFloat.half); 117 | } 118 | 119 | public override bool TestWithShape(BaseShape shape){ 120 | return shape.TestWith(this); 121 | } 122 | 123 | 124 | public override bool TestWith(Sphere sphere){ 125 | return Utils.TestSphereAABB(sphere, this); 126 | } 127 | 128 | public override bool TestWith(AABB aabb){ 129 | return Utils.TestAABBAABB(aabb, this); 130 | } 131 | 132 | public override bool TestWith(Capsule capsule){ 133 | return Utils.TestAABBCapsule(this, capsule); 134 | } 135 | 136 | public override bool TestWith(OBB obb){ 137 | return Utils.TestOBBOBB(obb, this.ToOBB()); 138 | } 139 | 140 | public override bool TestWith(Plane plane){ 141 | return Utils.TestAABBPlane(this, plane); 142 | } 143 | 144 | public override bool TestWith(Ray ray){ 145 | return Utils.IntersectRayAABB(ray.o, ray.d, this, out LFloat tmin, out LVector3 temp); 146 | } 147 | } 148 | } -------------------------------------------------------------------------------- /Assets/Octree/TestOCTree.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Drawing; 5 | using UnityEngine; 6 | using UnityEngine.Profiling; 7 | using Color = UnityEngine.Color; 8 | using Random = UnityEngine.Random; 9 | 10 | namespace UnityOctree { 11 | public class TestOCTree : MonoBehaviour { 12 | public Vector3 pos; 13 | 14 | // Initial size (metres), initial centre position, minimum node size (metres), looseness 15 | BoundsOctree boundsTree; 16 | 17 | public List objs = new List(); 18 | public List mats = new List(); 19 | 20 | public float worldSize = 150; 21 | public float minNodeSize = 1; 22 | public float loosenessval = 1.25f; 23 | 24 | private void Start(){ 25 | // Initial size (metres), initial centre position, minimum node size (metres), looseness 26 | boundsTree = new BoundsOctree(worldSize, pos, minNodeSize, loosenessval); 27 | // Initial size (metres), initial centre position, minimum node size (metres) 28 | //pointTree = new PointOctree(150, .pos, 1); 29 | for (int i = 0; i < count; i++) { 30 | var obj = GameObject.CreatePrimitive(PrimitiveType.Cube).GetComponent(); 31 | obj.transform.SetParent(transform, false); 32 | obj.transform.position = new Vector3(Random.Range(0, worldSize), 0, Random.Range(0, worldSize)); 33 | obj.transform.localScale = new Vector3(Random.Range(1, 4), Random.Range(1, 4), Random.Range(1, 4)); 34 | 35 | var mat = new Material(obj.GetComponent().material); 36 | obj.GetComponent().material = mat; 37 | if (i % Mathf.CeilToInt(1 / percent) == 0) { 38 | StartCoroutine(RandomMove(obj, () => { 39 | boundsTree.Remove(obj); 40 | boundsTree.Add(obj, obj.bounds); 41 | })); 42 | } 43 | else if (i % Mathf.CeilToInt(1 / percent) == 1) { 44 | objs.Add(obj); 45 | mats.Add(mat); 46 | isCollide.Add(false); 47 | StartCoroutine(RandomMove(obj, null)); 48 | } 49 | else { 50 | boundsTree.Add(obj, obj.bounds); 51 | } 52 | } 53 | 54 | testObj = GameObject.CreatePrimitive(PrimitiveType.Cube).transform; 55 | mat = new Material(testObj.GetComponent().material); 56 | testObj.GetComponent().material = mat; 57 | } 58 | 59 | public Transform testObj; 60 | public Material mat; 61 | public Bounds bound; 62 | public float percent = 0.1f; 63 | public int count = 100; 64 | 65 | private void Update(){ 66 | Profiler.BeginSample("CheckCollision"); 67 | CheckCollision(); 68 | Profiler.EndSample(); 69 | for (int i = 0; i < objs.Count; i++) { 70 | mats[i].color = isCollide[i] ? Color.red : Color.green; 71 | } 72 | } 73 | 74 | private List isCollide = new List(); 75 | 76 | private void CheckCollision(){ 77 | for (int i = 0; i < objs.Count; i++) { 78 | var obj = objs[i]; 79 | isCollide[i] = boundsTree.IsColliding(obj.bounds); 80 | } 81 | 82 | } 83 | 84 | public IEnumerator RandomMove(Collider obj, Action func){ 85 | float timer = 0; 86 | Vector3 targetPos = new Vector3(); 87 | float spd = 3; 88 | 89 | while (true) { 90 | timer += Time.deltaTime; 91 | if (timer > 2) { 92 | timer = 0; 93 | targetPos = new Vector3(Random.Range(0, worldSize), 0, Random.Range(0, worldSize)); 94 | } 95 | 96 | yield return null; 97 | obj.transform.position += (targetPos - obj.transform.position).normalized * Time.deltaTime * spd; 98 | func?.Invoke(); 99 | } 100 | } 101 | 102 | void OnDrawGizmos(){ 103 | if (boundsTree == null) return; 104 | 105 | boundsTree.DrawAllBounds(); // Draw node boundaries 106 | boundsTree.DrawAllObjects(); // Draw object boundaries 107 | boundsTree.DrawCollisionChecks(); // Draw the last *numCollisionsToSave* collision check boundaries 108 | 109 | // pointTree.DrawAllBounds(); // Draw node boundaries 110 | // pointTree.DrawAllObjects(); // Mark object positions 111 | } 112 | } 113 | } -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/UnityWarp/Editor/EditorCollider2DMono.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections.Generic; 3 | using Lockstep.Collision2D; 4 | using UnityEditor; 5 | using Lockstep.Math; 6 | 7 | namespace Lockstep.UnsafeCollision2D { 8 | [CustomEditor(typeof(ColliderConfig))] 9 | public class EditorCollider2DMono : Editor { 10 | public ColliderConfig owner; 11 | 12 | private int removeIdx = 0; 13 | private int addTypeID = 0; 14 | 15 | public override void OnInspectorGUI(){ 16 | base.OnInspectorGUI(); 17 | owner = (ColliderConfig) target; 18 | { 19 | GUILayout.BeginHorizontal(); 20 | GUILayout.Label("Type:"); 21 | if (int.TryParse(GUILayout.TextField(addTypeID.ToString()), out int idx)) { 22 | addTypeID = idx; 23 | addTypeID = Mathf.Clamp(addTypeID, 0, 2); 24 | } 25 | 26 | GUILayout.Label("removeIdx:"); 27 | if (int.TryParse(GUILayout.TextField(removeIdx.ToString()), out int _idx)) { 28 | removeIdx = Mathf.Clamp(_idx, 0, owner.allOffsets.Count - 1); 29 | } 30 | 31 | GUILayout.EndHorizontal(); 32 | } 33 | { 34 | GUILayout.BeginHorizontal(); 35 | if (GUILayout.Button("+")) { 36 | IShape2D shape = null; 37 | var type = (EShape2D) addTypeID; 38 | if (type == EShape2D.Circle) { 39 | owner.AddCircle(LVector2.zero, owner.transform.position.ToLVector3(), 1.ToLFloat()); 40 | } 41 | else if (type == EShape2D.AABB) { 42 | owner.AddAABB(LVector2.zero, owner.transform.position.ToLVector3(), LVector2.one); 43 | } 44 | else if (type == EShape2D.OBB) { 45 | owner.AddOBB(LVector2.zero, owner.transform.position.ToLVector3(), LVector2.one, 01.ToLFloat()); 46 | } 47 | } 48 | 49 | if (GUILayout.Button("-")) { 50 | if (removeIdx >= owner.allOffsets.Count) 51 | return; 52 | owner.Remove(removeIdx); 53 | } 54 | 55 | GUILayout.EndHorizontal(); 56 | } 57 | //Draw Property 58 | { 59 | var count = owner.allOffsets.Count; 60 | for (int i = 0; i < count; i++) { 61 | var shapeWrap = owner.allColliders[i]; 62 | var shapeType = (EShape2D) shapeWrap.TypeId; 63 | switch (shapeType) { 64 | case EShape2D.Circle: 65 | ShowShape(ref ((ShapeWrapCircle) shapeWrap).shape, i); 66 | break; 67 | case EShape2D.AABB: 68 | ShowShape(ref ((ShapeWrapAABB) shapeWrap).shape, i); 69 | break; 70 | case EShape2D.OBB: 71 | ShowShape(ref ((ShapeWrapOBB) shapeWrap).shape, i); 72 | break; 73 | } 74 | } 75 | } 76 | } 77 | 78 | 79 | void ShowShape(ref Circle circle, int idx){ 80 | ShowShape(ref circle, idx, DrawProperty); 81 | } 82 | 83 | void ShowShape(ref AABB2D aabb, int idx){ 84 | ShowShape(ref aabb, idx, DrawProperty); 85 | } 86 | 87 | void ShowShape(ref OBB2D obb, int idx){ 88 | ShowShape(ref obb, idx, DrawProperty); 89 | } 90 | 91 | public static void DrawProperty(ref Circle shape){ 92 | shape.radius = EditorGUILayoutExt.FloatField("Radius", shape.radius); 93 | } 94 | 95 | public static void DrawProperty(ref AABB2D shape){ 96 | shape.size = EditorGUILayoutExt.Vector2Field("Size", shape.size); 97 | } 98 | 99 | public static void DrawProperty(ref OBB2D shape){ 100 | shape.size = EditorGUILayoutExt.Vector2Field("Size", shape.size); 101 | var deg = EditorGUILayoutExt.FloatField("Deg", shape.deg); 102 | if (deg != shape.deg) { 103 | shape.SetDeg(deg); 104 | } 105 | } 106 | 107 | delegate void FuncDrawProperty(ref T shape) where T : IShape2D; 108 | 109 | void ShowShape(ref T circle, int idx, FuncDrawProperty _Func) where T : IShape2D{ 110 | GUILayout.BeginVertical(); 111 | var offset = EditorGUILayoutExt.Vector2Field("Offset", owner.allOffsets[idx]); 112 | owner.allOffsets[idx] = offset; 113 | circle.UpdatePosition(owner.pos + offset); 114 | { 115 | GUILayout.BeginHorizontal(); 116 | _Func(ref circle); 117 | GUILayout.EndHorizontal(); 118 | } 119 | GUILayout.EndVertical(); 120 | } 121 | } 122 | } -------------------------------------------------------------------------------- /Assets/Collision2D/QuadTree/QuadTreeExt.cs: -------------------------------------------------------------------------------- 1 | #define SHOW_TREE_NODES//层级显示所有节点 2 | #if SHOW_TREE_NODES && UNITY_EDITOR 3 | #define SHOW_NODES 4 | #endif 5 | 6 | using System; 7 | using System.Collections.Generic; 8 | using Lockstep.Math; 9 | using Lockstep.UnsafeCollision2D; 10 | using UnityEngine; 11 | using Object = UnityEngine.Object; 12 | using Plane = UnityEngine.Plane; 13 | using Ray = UnityEngine.Ray; 14 | 15 | namespace Lockstep.Collision2D { 16 | // A node in a BoundsOctree 17 | // Copyright 2014 Nition, BSD licence (see LICENCE file). www.momentstudio.co.nz 18 | public partial class BoundsQuadTreeNode { 19 | /// 20 | /// Draws node boundaries visually for debugging. 21 | /// Must be called from OnDrawGizmos externally. See also: DrawAllObjects. 22 | /// 23 | /// Used for recurcive calls to this method. 24 | public void DrawBoundQuadTreeNode(float depth = 0){ 25 | float tintVal = depth / 7; // Will eventually get values > 1. Color rounds to 1 automatically 26 | Gizmos.color = new Color(tintVal, 0, 1.0f - tintVal); 27 | 28 | LRect thisBounds = CreateLRect(Center, new LVector2(adjLength, adjLength)); 29 | Gizmos.DrawWireCube(thisBounds.center.ToLVector3().ToVector3(), thisBounds.size.ToLVector3().ToVector3()); 30 | 31 | if (children != null) { 32 | depth++; 33 | for (int i = 0; i < NUM_CHILDREN; i++) { 34 | children[i].DrawBoundQuadTreeNode(depth); 35 | } 36 | } 37 | 38 | Gizmos.color = Color.white; 39 | } 40 | 41 | /// 42 | /// Draws the bounds of all objects in the tree visually for debugging. 43 | /// Must be called from OnDrawGizmos externally. See also: DrawAllBounds. 44 | /// 45 | public void DrawAllObjects(){ 46 | float tintVal = (BaseLength / 20).ToFloat(); 47 | Gizmos.color = new Color(0, 1.0f - tintVal, tintVal, 0.25f); 48 | 49 | foreach (OctreeObject obj in objects) { 50 | Gizmos.DrawCube(obj.Bounds.center.ToLVector3().ToVector3(), obj.Bounds.size.ToLVector3().ToVector3()); 51 | } 52 | 53 | if (children != null) { 54 | for (int i = 0; i < NUM_CHILDREN; i++) { 55 | children[i].DrawAllObjects(); 56 | } 57 | } 58 | 59 | Gizmos.color = Color.white; 60 | } 61 | } 62 | 63 | public partial class BoundsQuadTree { 64 | // Intended for debugging. Must be called from OnDrawGizmos externally 65 | // See also DrawAllBounds and DrawAllObjects 66 | /// 67 | /// Visualises collision checks from IsColliding and GetColliding. 68 | /// Collision visualisation code is automatically removed from builds so that collision checks aren't slowed down. 69 | /// 70 | #if UNITY_EDITOR 71 | public void DrawCollisionChecks(){ 72 | int count = 0; 73 | foreach (LRect collisionCheck in lastBoundsCollisionChecks) { 74 | Gizmos.color = new Color(1.0f, 1.0f - ((float) count / numCollisionsToSave), 1.0f); 75 | Gizmos.DrawCube(collisionCheck.center.ToLVector3().ToVector3(), collisionCheck.size.ToLVector3().ToVector3()); 76 | count++; 77 | } 78 | 79 | foreach (Ray collisionCheck in lastRayCollisionChecks) { 80 | Gizmos.color = new Color(1.0f, 1.0f - ((float) count / numCollisionsToSave), 1.0f); 81 | Gizmos.DrawRay(collisionCheck.origin, collisionCheck.direction); 82 | count++; 83 | } 84 | 85 | Gizmos.color = Color.white; 86 | } 87 | #endif 88 | 89 | // #### PRIVATE METHODS #### 90 | 91 | /// 92 | /// Used for visualising collision checks with DrawCollisionChecks. 93 | /// Automatically removed from builds so that collision checks aren't slowed down. 94 | /// 95 | /// bounds that were passed in to check for collisions. 96 | #if UNITY_EDITOR 97 | void AddCollisionCheck(LRect checkBounds){ 98 | lastBoundsCollisionChecks.Enqueue(checkBounds); 99 | if (lastBoundsCollisionChecks.Count > numCollisionsToSave) { 100 | lastBoundsCollisionChecks.Dequeue(); 101 | } 102 | } 103 | #endif 104 | 105 | /// 106 | /// Used for visualising collision checks with DrawCollisionChecks. 107 | /// Automatically removed from builds so that collision checks aren't slowed down. 108 | /// 109 | /// ray that was passed in to check for collisions. 110 | 111 | #if UNITY_EDITOR 112 | void AddCollisionCheck(Ray checkRay){ 113 | lastRayCollisionChecks.Enqueue(checkRay); 114 | if (lastRayCollisionChecks.Count > numCollisionsToSave) { 115 | lastRayCollisionChecks.Dequeue(); 116 | } 117 | } 118 | #endif 119 | } 120 | 121 | public static partial class LRectExt { 122 | public static Vector2 ToVector2XZ(this Vector3 vec){ 123 | return new Vector2(vec.x, vec.z); 124 | } 125 | 126 | public static Vector3 ToVector3(this Vector2 vec, int y = 1){ 127 | return new Vector3(vec.x, y, vec.y); 128 | } 129 | 130 | } 131 | 132 | } -------------------------------------------------------------------------------- /Assets/Collision2D_Unsafe/QuadTree/LDemoScript.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Lockstep.Collision2D; 4 | using Lockstep.Math; 5 | using UnityEngine; 6 | using UnityEngine.Profiling; 7 | using Random = UnityEngine.Random; 8 | 9 | namespace Lockstep.UnsafeCollision2D { 10 | public unsafe class LDemoScript : MonoBehaviour { 11 | public enum CollisionSystemType { 12 | Brute, 13 | QuadTree 14 | } 15 | 16 | public PhysicsBody DemoPhysicsBody; 17 | [Header("CollisionSystem Settings")] public CollisionSystemType CSType; 18 | public int MaxBodies = 500; 19 | 20 | [Header("QuadTree Settings")] public Vector2 WorldSize = new Vector2(200, 200); 21 | public int BodiesPerNode = 6; 22 | public int MaxSplits = 6; 23 | 24 | public QuadTree* _quadTree; 25 | private CollisionSystemQuadTree _collisionSystem; 26 | 27 | private void Start(){ 28 | OnStart(); 29 | } 30 | 31 | private void Update(){ 32 | //raw 5.91~7.0ms 33 | //LMath 13.06ms 14.02ms 12.9ms 34 | //Unsafe LMath 7.0~7.5ms 35 | //LRect Simple 5.3~6.4ms 36 | //QuadTree MarkDirty 2.4ms 37 | Profiler.BeginSample("QuadTreeUpdate"); 38 | OnUpdate(); 39 | Profiler.EndSample(); 40 | } 41 | 42 | private void OnDestroy(){ 43 | Debug.Log("Collision Quit :OnDestroy"); 44 | if (_quadTree != null) { 45 | _quadTree->Clear(); 46 | QuadTreeFactory.FreeQuadTree(_quadTree); 47 | _quadTree = null; 48 | } 49 | NativeFactory.Clear(); 50 | Debug.Log($"RemainMemSize: NativeHelper.MemSize {NativeHelper.MemSize}"); 51 | Debug.Assert(NativeHelper.MemSize == 0,$"NativeHelper.MemSize {NativeHelper.MemSize}"); 52 | } 53 | 54 | public static System.Random random; 55 | public float RandomMovePercent = 0.1f; 56 | private void OnStart(){ 57 | random = new System.Random(0); 58 | _quadTree = QuadTreeFactory.AllocQuadTree(); 59 | *_quadTree = new QuadTree(new LRect(LFloat.zero, LFloat.zero, 60 | WorldSize.x.ToLFloat(), WorldSize.y.ToLFloat()), BodiesPerNode, MaxSplits); 61 | _collisionSystem = new CollisionSystemQuadTree(_quadTree); 62 | var tempLst = new List(); 63 | RandomMove.border = WorldSize; 64 | for (int i = 0; i < MaxBodies; i++) { 65 | var body = GameObject.Instantiate(DemoPhysicsBody); 66 | body.transform.position = new Vector3( 67 | random.Next(0, (int) (WorldSize.x * 1000)) * 0.001f, 0, 68 | random.Next(0, (int) (WorldSize.y * 1000)) * 0.001f); 69 | if (i % (int)(1/RandomMovePercent) == 0) { 70 | body.gameObject.AddComponent(); 71 | } 72 | 73 | tempLst.Add(body); 74 | } 75 | 76 | GameObject.Destroy(DemoPhysicsBody.gameObject); 77 | //raw 35.43ms 38.52ms 39.05ms 78 | //LMath 40.7ms 38.9ms 79 | //UnsafeLMath 8.6ms 8.7ms 80 | Profiler.BeginSample("QuadInit"); 81 | foreach (var body in tempLst) { 82 | var config = body.ColliderConfig; 83 | foreach (var collider in config.allColliders) { 84 | var type = (EShape2D)collider.TypeId; 85 | switch (type) { 86 | case EShape2D.AABB: { 87 | AABB2D* boxPtr = CollisionFactory.AllocAABB(); 88 | var shape = ((ShapeWrapAABB) collider).shape; 89 | body.RefId = _collisionSystem.AddBody(body, boxPtr, shape.pos, shape.size); 90 | body.ColPtr = (Circle*) boxPtr; 91 | _quadTree->AddBody(boxPtr); // add body to QuadTree 92 | break; 93 | } 94 | } 95 | } 96 | } 97 | 98 | Profiler.EndSample(); 99 | } 100 | 101 | private void OnUpdate(){ 102 | NativeFactoryMemSize = NativeFactory.MemSize; 103 | NativeHelperMemSize = NativeHelper.MemSize; 104 | _collisionSystem.Step(); 105 | countDetectBodyVsBody = _collisionSystem.countDetectBodyVsBody; 106 | Profiler.BeginSample("Recalc QuadTree"); 107 | addBodyCount = CollisionSystem.dirtyBodys.Count; 108 | foreach (var body in CollisionSystem.dirtyBodys) { 109 | if (body.ColPtr == null) throw new Exception("CollisionBody have no unsafe CollisionProxy"); 110 | QuadTree.RemoveNode(body.ColPtr); 111 | _quadTree->AddBody(body.ColPtr); 112 | } 113 | 114 | CollisionSystem.CleanDirtyBodies(); 115 | Profiler.EndSample(); 116 | } 117 | 118 | public int addBodyCount = 0; 119 | public int countDetectBodyVsBody; 120 | 121 | public long NativeFactoryMemSize; 122 | public long NativeHelperMemSize; 123 | private void OnDrawGizmos(){ 124 | if (_quadTree == null) return; 125 | _quadTree->DrawGizmos(); 126 | } 127 | } 128 | } --------------------------------------------------------------------------------