├── .github └── FUNDING.yml ├── Assets ├── Graphics │ ├── Cup.png │ ├── Eye.png │ ├── Pen.png │ ├── Circle.png │ ├── BookSquare.png │ ├── FilledSquare.png │ ├── LinesPattern.png │ ├── Cup.png.meta │ ├── Eye.png.meta │ ├── Circle.png.meta │ ├── BookSquare.png.meta │ ├── FilledSquare.png.meta │ ├── LinesPattern.png.meta │ └── Pen.png.meta ├── Scenes │ ├── main.unity │ └── main.unity.meta ├── Prefabs │ ├── Line.prefab │ └── Line.prefab.meta ├── Physics │ ├── bouncy.physicsMaterial2D │ └── bouncy.physicsMaterial2D.meta ├── Graphics.meta ├── Physics.meta ├── Prefabs.meta ├── Scenes.meta ├── Scripts.meta └── Scripts │ ├── Line.cs.meta │ ├── LinesDrawer.cs.meta │ ├── LinesDrawer.cs │ └── Line.cs ├── README.md └── LICENCE /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | custom: ["https://paypal.me/hamzaherbou"] 2 | -------------------------------------------------------------------------------- /Assets/Graphics/Cup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/herbou/Unity_AddPhysicsToLineRenderers/HEAD/Assets/Graphics/Cup.png -------------------------------------------------------------------------------- /Assets/Graphics/Eye.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/herbou/Unity_AddPhysicsToLineRenderers/HEAD/Assets/Graphics/Eye.png -------------------------------------------------------------------------------- /Assets/Graphics/Pen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/herbou/Unity_AddPhysicsToLineRenderers/HEAD/Assets/Graphics/Pen.png -------------------------------------------------------------------------------- /Assets/Scenes/main.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/herbou/Unity_AddPhysicsToLineRenderers/HEAD/Assets/Scenes/main.unity -------------------------------------------------------------------------------- /Assets/Graphics/Circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/herbou/Unity_AddPhysicsToLineRenderers/HEAD/Assets/Graphics/Circle.png -------------------------------------------------------------------------------- /Assets/Prefabs/Line.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/herbou/Unity_AddPhysicsToLineRenderers/HEAD/Assets/Prefabs/Line.prefab -------------------------------------------------------------------------------- /Assets/Graphics/BookSquare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/herbou/Unity_AddPhysicsToLineRenderers/HEAD/Assets/Graphics/BookSquare.png -------------------------------------------------------------------------------- /Assets/Graphics/FilledSquare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/herbou/Unity_AddPhysicsToLineRenderers/HEAD/Assets/Graphics/FilledSquare.png -------------------------------------------------------------------------------- /Assets/Graphics/LinesPattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/herbou/Unity_AddPhysicsToLineRenderers/HEAD/Assets/Graphics/LinesPattern.png -------------------------------------------------------------------------------- /Assets/Physics/bouncy.physicsMaterial2D: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/herbou/Unity_AddPhysicsToLineRenderers/HEAD/Assets/Physics/bouncy.physicsMaterial2D -------------------------------------------------------------------------------- /Assets/Scenes/main.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2af4c5e9c06e1d048b2ac4f4ed0f4000 3 | timeCreated: 1547490437 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Graphics.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b6ef85b498edc644a8bd6d73f91aa8e2 3 | folderAsset: yes 4 | timeCreated: 1594826197 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Physics.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 98459dfa87fe8064fa53330a303a0ed8 3 | folderAsset: yes 4 | timeCreated: 1594827202 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Prefabs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f9b77be91b1d1d142b2a870d83f2359a 3 | folderAsset: yes 4 | timeCreated: 1547490780 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 905b415b617bb2c458b4fad1661eaa9e 3 | folderAsset: yes 4 | timeCreated: 1547490780 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f35d75973c77bb841bc4e61f1ec4f6f8 3 | folderAsset: yes 4 | timeCreated: 1547490780 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Prefabs/Line.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d489242030c18584caa5c64bba0a6082 3 | timeCreated: 1594904902 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 100100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Physics/bouncy.physicsMaterial2D.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c6a7993f8e3c52843ab476fa1651d37f 3 | timeCreated: 1594827213 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 6200000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scripts/Line.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a3c8c27992403e247896d390bcded57a 3 | timeCreated: 1594903536 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/Scripts/LinesDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2c43f9255d2e0f946a81ffca832f61ef 3 | timeCreated: 1594904347 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Draw lines in unity and add Physics to them. 2 | 3 | Click on the image to watch the video tutorial: 4 | [![Tutorial](https://img.youtube.com/vi/KojYeZwEPyQ/0.jpg)](https://www.youtube.com/watch?v=KojYeZwEPyQ) 5 | 6 |

7 |
8 | ## ❤️ Donate 9 | Paypal 10 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 hamza herbou 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Assets/Graphics/Cup.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4ca4eb494c9d926478e9f93b0afddddc 3 | timeCreated: 1594832252 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: 1 34 | nPOTScale: 0 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 1 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 1 46 | spriteTessellationDetail: -1 47 | textureType: 8 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/Graphics/Eye.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9915154cadb5d294484ede8467960764 3 | timeCreated: 1594831073 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: 1 34 | nPOTScale: 0 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 1 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 1 46 | spriteTessellationDetail: -1 47 | textureType: 8 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/Graphics/Circle.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f9d5fd7174a81a148b726e2ac6b9f528 3 | timeCreated: 1594831073 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: 1 34 | nPOTScale: 0 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 1 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 1 46 | spriteTessellationDetail: -1 47 | textureType: 8 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/Scripts/LinesDrawer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | public class LinesDrawer : MonoBehaviour { 4 | 5 | public GameObject linePrefab; 6 | public LayerMask cantDrawOverLayer; 7 | int cantDrawOverLayerIndex; 8 | 9 | [Space ( 30f )] 10 | public Gradient lineColor; 11 | public float linePointsMinDistance; 12 | public float lineWidth; 13 | 14 | Line currentLine; 15 | 16 | Camera cam; 17 | 18 | 19 | void Start ( ) { 20 | cam = Camera.main; 21 | cantDrawOverLayerIndex = LayerMask.NameToLayer ( "CantDrawOver" ); 22 | } 23 | 24 | void Update ( ) { 25 | if ( Input.GetMouseButtonDown ( 0 ) ) 26 | BeginDraw ( ); 27 | 28 | if ( currentLine != null ) 29 | Draw ( ); 30 | 31 | if ( Input.GetMouseButtonUp ( 0 ) ) 32 | EndDraw ( ); 33 | } 34 | 35 | // Begin Draw ---------------------------------------------- 36 | void BeginDraw ( ) { 37 | currentLine = Instantiate ( linePrefab, this.transform ).GetComponent ( ); 38 | 39 | //Set line properties 40 | currentLine.UsePhysics ( false ); 41 | currentLine.SetLineColor ( lineColor ); 42 | currentLine.SetPointsMinDistance ( linePointsMinDistance ); 43 | currentLine.SetLineWidth ( lineWidth ); 44 | 45 | } 46 | // Draw ---------------------------------------------------- 47 | void Draw ( ) { 48 | Vector2 mousePosition = cam.ScreenToWorldPoint ( Input.mousePosition ); 49 | 50 | //Check if mousePos hits any collider with layer "CantDrawOver", if true cut the line by calling EndDraw( ) 51 | RaycastHit2D hit = Physics2D.CircleCast ( mousePosition, lineWidth / 3f, Vector2.zero, 1f, cantDrawOverLayer ); 52 | 53 | if ( hit ) 54 | EndDraw ( ); 55 | else 56 | currentLine.AddPoint ( mousePosition ); 57 | } 58 | // End Draw ------------------------------------------------ 59 | void EndDraw ( ) { 60 | if ( currentLine != null ) { 61 | if ( currentLine.pointsCount < 2 ) { 62 | //If line has one point 63 | Destroy ( currentLine.gameObject ); 64 | } else { 65 | //Add the line to "CantDrawOver" layer 66 | currentLine.gameObject.layer = cantDrawOverLayerIndex; 67 | 68 | //Activate Physics on the line 69 | currentLine.UsePhysics ( true ); 70 | 71 | currentLine = null; 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Assets/Graphics/BookSquare.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 654daf013997bc74aac2a2766537ec08 3 | timeCreated: 1594826186 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: 1 34 | nPOTScale: 0 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 1 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 150 44 | alphaUsage: 1 45 | alphaIsTransparency: 1 46 | spriteTessellationDetail: -1 47 | textureType: 8 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | - buildTarget: Standalone 62 | maxTextureSize: 2048 63 | textureFormat: -1 64 | textureCompression: 1 65 | compressionQuality: 50 66 | crunchedCompression: 0 67 | allowsAlphaSplitting: 0 68 | overridden: 0 69 | - buildTarget: Android 70 | maxTextureSize: 2048 71 | textureFormat: -1 72 | textureCompression: 1 73 | compressionQuality: 50 74 | crunchedCompression: 0 75 | allowsAlphaSplitting: 0 76 | overridden: 0 77 | spriteSheet: 78 | serializedVersion: 2 79 | sprites: [] 80 | outline: [] 81 | spritePackingTag: 82 | userData: 83 | assetBundleName: 84 | assetBundleVariant: 85 | -------------------------------------------------------------------------------- /Assets/Graphics/FilledSquare.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bf5e2fb5bfb87174384af74ab8f64093 3 | timeCreated: 1594826551 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: 1 34 | nPOTScale: 0 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 1 38 | spriteExtrude: 1 39 | spriteMeshType: 0 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 1, y: 1, z: 1, w: 1} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 1 46 | spriteTessellationDetail: -1 47 | textureType: 8 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | - buildTarget: Standalone 62 | maxTextureSize: 2048 63 | textureFormat: -1 64 | textureCompression: 1 65 | compressionQuality: 50 66 | crunchedCompression: 0 67 | allowsAlphaSplitting: 0 68 | overridden: 0 69 | - buildTarget: Android 70 | maxTextureSize: 2048 71 | textureFormat: -1 72 | textureCompression: 1 73 | compressionQuality: 50 74 | crunchedCompression: 0 75 | allowsAlphaSplitting: 0 76 | overridden: 0 77 | spriteSheet: 78 | serializedVersion: 2 79 | sprites: [] 80 | outline: [] 81 | spritePackingTag: 82 | userData: 83 | assetBundleName: 84 | assetBundleVariant: 85 | -------------------------------------------------------------------------------- /Assets/Graphics/LinesPattern.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1515019203e6e4346807a39ccd5d3e5c 3 | timeCreated: 1594831652 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: 1 34 | nPOTScale: 0 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 1 38 | spriteExtrude: 1 39 | spriteMeshType: 0 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 200 44 | alphaUsage: 1 45 | alphaIsTransparency: 1 46 | spriteTessellationDetail: -1 47 | textureType: 8 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | - buildTarget: Standalone 62 | maxTextureSize: 2048 63 | textureFormat: -1 64 | textureCompression: 1 65 | compressionQuality: 50 66 | crunchedCompression: 0 67 | allowsAlphaSplitting: 0 68 | overridden: 0 69 | - buildTarget: Android 70 | maxTextureSize: 2048 71 | textureFormat: -1 72 | textureCompression: 1 73 | compressionQuality: 50 74 | crunchedCompression: 0 75 | allowsAlphaSplitting: 0 76 | overridden: 0 77 | spriteSheet: 78 | serializedVersion: 2 79 | sprites: [] 80 | outline: [] 81 | spritePackingTag: 82 | userData: 83 | assetBundleName: 84 | assetBundleVariant: 85 | -------------------------------------------------------------------------------- /Assets/Scripts/Line.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections.Generic; 3 | 4 | public class Line : MonoBehaviour { 5 | 6 | public LineRenderer lineRenderer; 7 | public EdgeCollider2D edgeCollider; 8 | public Rigidbody2D rigidBody; 9 | 10 | [HideInInspector] public List points = new List ( ); 11 | [HideInInspector] public int pointsCount = 0; 12 | 13 | //The minimum distance between line's points. 14 | float pointsMinDistance = 0.1f; 15 | 16 | //Circle collider added to each line's point 17 | float circleColliderRadius; 18 | 19 | public void AddPoint ( Vector2 newPoint ) { 20 | //If distance between last point and new point is less than pointsMinDistance do nothing (return) 21 | if ( pointsCount >= 1 && Vector2.Distance ( newPoint, GetLastPoint ( ) ) < pointsMinDistance ) 22 | return; 23 | 24 | points.Add ( newPoint ); 25 | pointsCount++; 26 | 27 | //Add Circle Collider to the Point 28 | CircleCollider2D circleCollider = this.gameObject.AddComponent ( ); 29 | circleCollider.offset = newPoint; 30 | circleCollider.radius = circleColliderRadius; 31 | 32 | //Line Renderer 33 | lineRenderer.positionCount = pointsCount; 34 | lineRenderer.SetPosition ( pointsCount - 1, newPoint ); 35 | 36 | //Edge Collider 37 | //Edge colliders accept only 2 points or more (we can't create an edge with one point :D ) 38 | if ( pointsCount > 1 ) 39 | edgeCollider.points = points.ToArray ( ); 40 | } 41 | 42 | public Vector2 GetLastPoint ( ) { 43 | return ( Vector2 )lineRenderer.GetPosition ( pointsCount - 1 ); 44 | } 45 | 46 | public void UsePhysics ( bool usePhysics ) { 47 | // isKinematic = true means that this rigidbody is not affected by Unity's physics engine 48 | rigidBody.isKinematic = !usePhysics; 49 | } 50 | 51 | public void SetLineColor ( Gradient colorGradient ) { 52 | lineRenderer.colorGradient = colorGradient; 53 | } 54 | 55 | public void SetPointsMinDistance ( float distance ) { 56 | pointsMinDistance = distance; 57 | } 58 | 59 | public void SetLineWidth ( float width ) { 60 | lineRenderer.startWidth = width; 61 | lineRenderer.endWidth = width; 62 | 63 | circleColliderRadius = width / 2f; 64 | 65 | edgeCollider.edgeRadius = circleColliderRadius; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /Assets/Graphics/Pen.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f89a688d9f3948243a6c57796af05e7e 3 | timeCreated: 1594893256 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: 7 | 21300000: Pen_0 8 | 21300002: Pen_1 9 | serializedVersion: 4 10 | mipmaps: 11 | mipMapMode: 0 12 | enableMipMap: 0 13 | sRGBTexture: 1 14 | linearTexture: 0 15 | fadeOut: 0 16 | borderMipMap: 0 17 | mipMapFadeDistanceStart: 1 18 | mipMapFadeDistanceEnd: 3 19 | bumpmap: 20 | convertToNormalMap: 0 21 | externalNormalMap: 0 22 | heightScale: 0.25 23 | normalMapFilter: 0 24 | isReadable: 0 25 | grayScaleToAlpha: 0 26 | generateCubemap: 6 27 | cubemapConvolution: 0 28 | seamlessCubemap: 0 29 | textureFormat: 1 30 | maxTextureSize: 2048 31 | textureSettings: 32 | filterMode: -1 33 | aniso: -1 34 | mipBias: -1 35 | wrapMode: 1 36 | nPOTScale: 0 37 | lightmap: 0 38 | compressionQuality: 50 39 | spriteMode: 2 40 | spriteExtrude: 1 41 | spriteMeshType: 1 42 | alignment: 0 43 | spritePivot: {x: 0.5, y: 0.5} 44 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 45 | spritePixelsToUnits: 100 46 | alphaUsage: 1 47 | alphaIsTransparency: 1 48 | spriteTessellationDetail: -1 49 | textureType: 8 50 | textureShape: 1 51 | maxTextureSizeSet: 0 52 | compressionQualitySet: 0 53 | textureFormatSet: 0 54 | platformSettings: 55 | - buildTarget: DefaultTexturePlatform 56 | maxTextureSize: 2048 57 | textureFormat: -1 58 | textureCompression: 1 59 | compressionQuality: 50 60 | crunchedCompression: 0 61 | allowsAlphaSplitting: 0 62 | overridden: 0 63 | - buildTarget: Standalone 64 | maxTextureSize: 2048 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | - buildTarget: Android 72 | maxTextureSize: 2048 73 | textureFormat: -1 74 | textureCompression: 1 75 | compressionQuality: 50 76 | crunchedCompression: 0 77 | allowsAlphaSplitting: 0 78 | overridden: 0 79 | spriteSheet: 80 | serializedVersion: 2 81 | sprites: 82 | - serializedVersion: 2 83 | name: Pen_0 84 | rect: 85 | serializedVersion: 2 86 | x: 0 87 | y: 23 88 | width: 48 89 | height: 177 90 | alignment: 0 91 | pivot: {x: 0, y: 0} 92 | border: {x: 0, y: 0, z: 0, w: 0} 93 | outline: [] 94 | tessellationDetail: 0 95 | - serializedVersion: 2 96 | name: Pen_1 97 | rect: 98 | serializedVersion: 2 99 | x: 12 100 | y: 0 101 | width: 24 102 | height: 20 103 | alignment: 0 104 | pivot: {x: 0, y: 0} 105 | border: {x: 0, y: 0, z: 0, w: 0} 106 | outline: [] 107 | tessellationDetail: 0 108 | outline: [] 109 | spritePackingTag: 110 | userData: 111 | assetBundleName: 112 | assetBundleVariant: 113 | --------------------------------------------------------------------------------