├── .gitignore ├── Assets ├── Line.mat ├── Line.mat.meta ├── LinePolygon.cs ├── LinePolygon.cs.meta ├── LinePolygonRenderer.cs ├── LinePolygonRenderer.cs.meta ├── Main.meta ├── Main.unity ├── Main.unity.meta ├── Main │ ├── LightingData.asset │ ├── LightingData.asset.meta │ ├── ReflectionProbe-0.exr │ └── ReflectionProbe-0.exr.meta ├── New Terrain.asset └── New Terrain.asset.meta ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset └── UnityConnectSettings.asset ├── README.md └── art └── smile.png /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /Assets/AssetStoreTools* 7 | 8 | # Autogenerated VS/MD/Consulo solution and project files 9 | ExportedObj/ 10 | .consulo/ 11 | *.csproj 12 | *.unityproj 13 | *.sln 14 | *.suo 15 | *.tmp 16 | *.user 17 | *.userprefs 18 | *.pidb 19 | *.booproj 20 | *.svd 21 | 22 | 23 | # Unity3D generated meta files 24 | *.pidb.meta 25 | 26 | # Unity3D Generated File On Crash Reports 27 | sysinfo.txt 28 | 29 | # Builds 30 | *.apk 31 | *.unitypackage 32 | 33 | .idea/ 34 | -------------------------------------------------------------------------------- /Assets/Line.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/Assets/Line.mat -------------------------------------------------------------------------------- /Assets/Line.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ad7a02416dba94fa79f68cc8c7530fc4 3 | timeCreated: 1481115028 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/LinePolygon.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using UnityEngine; 3 | 4 | public static class LinePolygon 5 | { 6 | public static Mesh CreateMesh(Vector2[] points, float width) 7 | { 8 | Vector2[] verts = CreateLineVerticies(points, width); 9 | int[] triangles = CreateTriangles(points.Length); 10 | 11 | Mesh mesh = new Mesh(); 12 | mesh.vertices = ConvertVector2ToVector3(verts); 13 | mesh.triangles = triangles; 14 | mesh.RecalculateBounds(); 15 | mesh.RecalculateNormals(); 16 | return mesh; 17 | } 18 | 19 | public static Vector3[] ConvertVector2ToVector3(Vector2[] points) 20 | { 21 | return points.Select(it => new Vector3(it.x, 0, it.y)).ToArray(); 22 | } 23 | 24 | public static Vector2[] CreateLineVerticies(Vector2[] points, float width) 25 | { 26 | if (points.Length < 2) 27 | { 28 | return null; 29 | } 30 | 31 | int verts_length = points.Length << 1; 32 | Vector2[] result = new Vector2[verts_length]; 33 | Vector2[] p1_updown, p2_updown; 34 | float theta, sin_theta, cos_theta; 35 | float theta_previous, sin_theta_previous, cos_theta_previous; 36 | 37 | // 始点を求める 38 | { 39 | theta_previous = Mathf.Atan2(points[1].y - points[0].y, points[1].x - points[0].x); 40 | sin_theta_previous = Mathf.Sin(theta_previous); 41 | cos_theta_previous = Mathf.Cos(theta_previous); 42 | 43 | p1_updown = CalculateUpDownPoints(points[0], sin_theta_previous, cos_theta_previous, width); 44 | result[0] = p1_updown[0]; 45 | result[1] = p1_updown[1]; 46 | } 47 | 48 | // 中点を求める 49 | for (int i = 1; i < points.Length - 1; i++) 50 | { 51 | theta = Mathf.Atan2(points[i + 1].y - points[i].y, points[i + 1].x - points[i].x); 52 | sin_theta = Mathf.Sin(theta); 53 | cos_theta = Mathf.Cos(theta); 54 | 55 | p2_updown = CalculateUpDownPoints(points[i], sin_theta, cos_theta, width); 56 | 57 | Vector2[] medium_points = CalculateMidiumPoint( 58 | p1_updown, 59 | p2_updown, 60 | sin_theta_previous, 61 | cos_theta_previous, 62 | sin_theta, 63 | cos_theta); 64 | 65 | int i2 = i << 1; // i*2 66 | result[i2] = medium_points[0]; 67 | result[i2 + 1] = medium_points[1]; 68 | 69 | sin_theta_previous = sin_theta; 70 | cos_theta_previous = cos_theta; 71 | p1_updown = p2_updown; 72 | } 73 | 74 | // 終点を求める 75 | { 76 | int length = points.Length; 77 | theta = Mathf.Atan2(points[length - 1].y - points[length - 2].y, points[length - 1].x - points[length - 2].x); 78 | sin_theta = Mathf.Sin(theta); 79 | cos_theta = Mathf.Cos(theta); 80 | 81 | p2_updown = CalculateUpDownPoints(points[length - 1], sin_theta, cos_theta, width); 82 | result[verts_length - 2] = p2_updown[0]; 83 | result[verts_length - 1] = p2_updown[1]; 84 | } 85 | 86 | return result; 87 | } 88 | 89 | public static int[] CreateTriangles(int point_count) 90 | { 91 | int[] triangles = new int[(point_count - 1) * 6]; 92 | 93 | for (int i = 0; i < point_count - 1; i++) 94 | { 95 | int triangle_index = i * 6; 96 | int vert_index = i << 1; 97 | triangles[triangle_index] = vert_index; 98 | triangles[triangle_index + 1] = vert_index + 1; 99 | triangles[triangle_index + 2] = vert_index + 2; 100 | triangles[triangle_index + 3] = vert_index + 2; 101 | triangles[triangle_index + 4] = vert_index + 1; 102 | triangles[triangle_index + 5] = vert_index + 3; 103 | } 104 | 105 | return triangles; 106 | } 107 | 108 | public static Vector2[] CalculateUpDownPoints(Vector2 p, float sin_theta, float cos_theta, float width) 109 | { 110 | float width_cos_theta = width * cos_theta; 111 | float width_sin_theta = width * sin_theta; 112 | Vector2 p_up = new Vector2(p.x + width_sin_theta, p.y - width_cos_theta); 113 | Vector2 p_down = new Vector2(p.x - width_sin_theta, p.y + width_cos_theta); 114 | return new Vector2[] {p_up, p_down}; 115 | } 116 | 117 | // Input: p1, p2, p12_theta, p23_theta 118 | // Output: p2', p2'' 119 | public static Vector2[] CalculateMidiumPoint( 120 | Vector2[] p1_updown, 121 | Vector2[] p2_updown, 122 | float sin_theta1, float cos_theta1, float sin_theta2, float cos_theta2) 123 | { 124 | float a1b2_minus_a2b1 = -sin_theta1 * cos_theta2 + sin_theta2 * cos_theta1; 125 | 126 | if (a1b2_minus_a2b1 == 0f) 127 | { 128 | return new Vector2[] 129 | { 130 | (p1_updown[0] + p2_updown[0]) * 0.5f, 131 | (p1_updown[1] + p2_updown[1]) * 0.5f, 132 | }; 133 | } 134 | 135 | Vector2 p1_up = p1_updown[0]; 136 | Vector2 p1_down = p1_updown[1]; 137 | Vector2 p2_up = p2_updown[0]; 138 | Vector2 p2_down = p2_updown[1]; 139 | 140 | float c1b2_c2b1_up = (p1_up.x * sin_theta1 - p1_up.y * cos_theta1) * cos_theta2 - 141 | (p2_up.x * sin_theta2 - p2_up.y * cos_theta2) * cos_theta1; 142 | 143 | float c1a2_c2a1_up = (p1_up.x * sin_theta1 - p1_up.y * cos_theta1) * -sin_theta2 + 144 | (p2_up.x * sin_theta2 - p2_up.y * cos_theta2) * sin_theta1; 145 | 146 | float c1b2_c2b1_down = (p1_down.x * sin_theta1 - p1_down.y * cos_theta1) * cos_theta2 - 147 | (p2_down.x * sin_theta2 - p2_down.y * cos_theta2) * cos_theta1; 148 | float c1a2_c2a1_down = (p1_down.x * sin_theta1 - p1_down.y * cos_theta1) * -sin_theta2 + 149 | (p2_down.x * sin_theta2 - p2_down.y * cos_theta2) * sin_theta1; 150 | 151 | return new Vector2[] 152 | { 153 | new Vector2(c1b2_c2b1_up / -a1b2_minus_a2b1, c1a2_c2a1_up / a1b2_minus_a2b1), 154 | new Vector2(c1b2_c2b1_down / -a1b2_minus_a2b1, c1a2_c2a1_down / a1b2_minus_a2b1), 155 | }; 156 | } 157 | } -------------------------------------------------------------------------------- /Assets/LinePolygon.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 00b5e4741f36f4ee6abdb1f10bab6373 3 | timeCreated: 1481114794 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/LinePolygonRenderer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | public class LinePolygonRenderer : MonoBehaviour 4 | { 5 | public Material Mateiral; 6 | 7 | void Start() 8 | { 9 | CreateLine(new[] 10 | { 11 | new Vector2(-8, 0), 12 | new Vector2(0, -5), 13 | new Vector2(8, 0), 14 | }); 15 | 16 | CreateLine(new[] 17 | { 18 | new Vector2(-10, 5), 19 | new Vector2(-10, 15), 20 | }); 21 | 22 | CreateLine(new[] 23 | { 24 | new Vector2(10, 5), 25 | new Vector2(10, 15), 26 | }); 27 | 28 | CreateLine(new[] 29 | { 30 | new Vector2(20, -5), 31 | new Vector2(25, 5), 32 | new Vector2(20, 15), 33 | }); 34 | 35 | CreateLine(new[] 36 | { 37 | new Vector2(-20, -5), 38 | new Vector2(-25, 5), 39 | new Vector2(-20, 15), 40 | }); 41 | } 42 | 43 | void CreateLine(Vector2[] points) 44 | { 45 | var _object = new GameObject("PolygonLine"); 46 | var meshFilter = _object.AddComponent(); 47 | var meshRenderer = _object.AddComponent(); 48 | 49 | meshFilter.sharedMesh = LinePolygon.CreateMesh(points, 1f); 50 | meshRenderer.material = this.Mateiral; 51 | } 52 | } -------------------------------------------------------------------------------- /Assets/LinePolygonRenderer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 185463a6622d8489da50a36721dc4024 3 | timeCreated: 1481109713 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Main.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 72596a0eff3f54d16b37d82a8a62b876 3 | folderAsset: yes 4 | timeCreated: 1481115321 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Main.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/Assets/Main.unity -------------------------------------------------------------------------------- /Assets/Main.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 381bf21432b9142c8affdd9c8d1fdfb1 3 | timeCreated: 1481109659 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Main/LightingData.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/Assets/Main/LightingData.asset -------------------------------------------------------------------------------- /Assets/Main/LightingData.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 12fe2efe5d44445d2a7f760f2bb7a7c2 3 | timeCreated: 1481115338 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Main/ReflectionProbe-0.exr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/Assets/Main/ReflectionProbe-0.exr -------------------------------------------------------------------------------- /Assets/Main/ReflectionProbe-0.exr.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c32ef3e37fa6f48c5b812742a6efd844 3 | timeCreated: 1481115338 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: 7 | 8900000: generatedCubemap 8 | serializedVersion: 4 9 | mipmaps: 10 | mipMapMode: 0 11 | enableMipMap: 1 12 | sRGBTexture: 1 13 | linearTexture: 0 14 | fadeOut: 0 15 | borderMipMap: 0 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | grayScaleToAlpha: 0 25 | generateCubemap: 6 26 | cubemapConvolution: 1 27 | seamlessCubemap: 1 28 | textureFormat: 1 29 | maxTextureSize: 2048 30 | textureSettings: 31 | filterMode: 2 32 | aniso: 0 33 | mipBias: 0 34 | wrapMode: 1 35 | nPOTScale: 1 36 | lightmap: 0 37 | compressionQuality: 50 38 | spriteMode: 0 39 | spriteExtrude: 1 40 | spriteMeshType: 1 41 | alignment: 0 42 | spritePivot: {x: 0.5, y: 0.5} 43 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 44 | spritePixelsToUnits: 100 45 | alphaUsage: 1 46 | alphaIsTransparency: 0 47 | spriteTessellationDetail: -1 48 | textureType: 0 49 | textureShape: 2 50 | maxTextureSizeSet: 0 51 | compressionQualitySet: 0 52 | textureFormatSet: 0 53 | platformSettings: 54 | - buildTarget: DefaultTexturePlatform 55 | maxTextureSize: 2048 56 | textureFormat: -1 57 | textureCompression: 1 58 | compressionQuality: 100 59 | crunchedCompression: 0 60 | allowsAlphaSplitting: 0 61 | overridden: 0 62 | spriteSheet: 63 | serializedVersion: 2 64 | sprites: [] 65 | outline: [] 66 | spritePackingTag: 67 | userData: 68 | assetBundleName: 69 | assetBundleVariant: 70 | -------------------------------------------------------------------------------- /Assets/New Terrain.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/Assets/New Terrain.asset -------------------------------------------------------------------------------- /Assets/New Terrain.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 30c41c9e56f10411cac08b08c0846be8 3 | timeCreated: 1481109636 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.5.0f3 2 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LINE SAMPLE 2 | 3 | Unity Line draw sample without using LineRenderer. 4 | It creates polygon and draws line. 5 | 6 | ![art](./art/smile.png) 7 | -------------------------------------------------------------------------------- /art/smile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/LineSample/983ae73167032da12c66dccf2a282ebd357e08d2/art/smile.png --------------------------------------------------------------------------------