Skip to content

Commit 2b152b6

Browse files
FirstCommit
0 parents  commit 2b152b6

29 files changed

+330
-0
lines changed

Diff for: .gitattributes

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Custom for Visual Studio
5+
*.cs diff=csharp
6+
7+
# Standard to msysgit
8+
*.doc diff=astextplain
9+
*.DOC diff=astextplain
10+
*.docx diff=astextplain
11+
*.DOCX diff=astextplain
12+
*.dot diff=astextplain
13+
*.DOT diff=astextplain
14+
*.pdf diff=astextplain
15+
*.PDF diff=astextplain
16+
*.rtf diff=astextplain
17+
*.RTF diff=astextplain

Diff for: .gitignore

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
[Ll]ibrary/
2+
[Tt]emp/
3+
[Oo]bj/
4+
[Bb]uild/
5+
[Ww]eb/
6+
7+
# Autogenerated VS/MD solution and project files
8+
/*.csproj
9+
/*.unityproj
10+
/*.sln
11+
/*.suo
12+
/*.user
13+
/*.userprefs
14+
/*.pidb
15+
/*.booproj
16+
*.apk
17+
18+
#Unity3D Generated File On Crash Reports
19+
sysinfo.txt
20+
21+
# =========================
22+
# Operating System Files
23+
# =========================
24+
25+
# OSX
26+
# =========================
27+
28+
.DS_Store
29+
.AppleDouble
30+
.LSOverride
31+
32+
# Thumbnails
33+
._*
34+
35+
# Files that might appear on external disk
36+
.Spotlight-V100
37+
.Trashes
38+
39+
# Directories potentially created on remote AFP share
40+
.AppleDB
41+
.AppleDesktop
42+
Network Trash Folder
43+
Temporary Items
44+
.apdisk
45+
46+
# Windows
47+
# =========================
48+
49+
# Windows image file caches
50+
Thumbs.db
51+
ehthumbs.db
52+
53+
# Folder config file
54+
Desktop.ini
55+
56+
# Recycle Bin used on file shares
57+
$RECYCLE.BIN/
58+
59+
# Windows Installer files
60+
*.cab
61+
*.msi
62+
*.msm
63+
*.msp
64+
65+
# Windows shortcuts
66+
*.lnk
67+
TenMinutes/TenMinutes.html
68+
*.apk
69+
TenMinutes/TenMinutes.unity3d

Diff for: Assets/DrawLine.cs

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
using System;
2+
using UnityEngine;
3+
using System.Collections;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using GameUtil;
7+
8+
public class DrawLine : MonoBehaviour
9+
{
10+
[SerializeField] private float width;
11+
[SerializeField] private GameObject linePrefab;
12+
13+
private GameObject targetObject;
14+
private Mesh mesh;
15+
private List<Vector2> l = new List<Vector2>();
16+
17+
private void CreateMesh(Mesh mesh,IEnumerable<Vector2> vlist)
18+
{
19+
mesh.Clear();
20+
var vCnt = vlist.Count();
21+
var vertices = new List<Vector3>();
22+
var indices = new List<int>();
23+
for (int i = 0; i < vCnt; i++)
24+
{
25+
var prevPos = vlist.ElementAt(Mathf.Max(0, i - 1));
26+
var currentPos = vlist.ElementAt(i);
27+
var nextPos = vlist.ElementAt(Mathf.Min(vCnt - 1, i + 1));
28+
//一つ手前と、一つ先のベクトルから、向いている方向を得る
29+
var vec = prevPos - nextPos;
30+
if(vec.magnitude < 0.05f)continue; //あまり頂点の間が空いてないのであればスキップする
31+
var v = vec.normalized * width;
32+
33+
//指定した横幅に広げる
34+
vertices.Add(new Vector3(currentPos.x + v.y,currentPos.y - v.x));
35+
vertices.Add(new Vector3(currentPos.x - v.y,currentPos.y + v.x));
36+
}
37+
38+
for (int index = 0; index < vertices.Count-2; index+=2)
39+
{
40+
indices.Add(index);
41+
indices.Add(index+2);
42+
indices.Add(index+1);
43+
44+
indices.Add(index+1);
45+
indices.Add(index+2);
46+
indices.Add(index+3);
47+
}
48+
49+
mesh.SetVertices(vertices);
50+
mesh.SetIndices(indices.ToArray(),MeshTopology.Triangles,0);
51+
}
52+
53+
public void Update()
54+
{
55+
if (Input.GetMouseButtonDown(0))
56+
{
57+
targetObject = Instantiate(linePrefab);
58+
mesh = null;
59+
l.Clear();
60+
}
61+
if (Input.GetMouseButton(0))
62+
{
63+
Vector3 pos;
64+
MouseUtil.UnprojectMousePositionXY(out pos, Input.mousePosition);
65+
66+
//既にあるオブジェクトに当たりそうならそこで生成を辞める
67+
if (Physics2D.CircleCast(pos, 0.2f, Vector2.zero))
68+
{
69+
Debug.Log("Hit");
70+
}
71+
72+
l.Add(pos);
73+
targetObject.GetComponent<MeshFilter>().mesh = mesh ?? (mesh = new Mesh());
74+
CreateMesh(mesh,l);
75+
}
76+
if (Input.GetMouseButtonUp(0) && targetObject != null)
77+
{
78+
var rigibody = targetObject.AddComponent<Rigidbody2D>();
79+
rigibody.useAutoMass = true;
80+
var polyColliderPos = CreateMeshToPolyCollider(mesh);
81+
var polyCollider = targetObject.AddComponent<PolygonCollider2D>();
82+
polyCollider.SetPath(0,polyColliderPos.ToArray());
83+
}
84+
}
85+
86+
private List<Vector2> CreateMeshToPolyCollider(Mesh mesh)
87+
{
88+
var polyColliderPos = new List<Vector2>();
89+
for (int index = 0; index < mesh.vertices.Length; index+=2)
90+
{
91+
var pos = mesh.vertices[index];
92+
polyColliderPos.Add(pos);
93+
}
94+
for (int index = mesh.vertices.Length-1; index > 0; index-=2)
95+
{
96+
var pos = mesh.vertices[index];
97+
polyColliderPos.Add(pos);
98+
}
99+
return polyColliderPos;
100+
}
101+
}

Diff for: Assets/DrawLine.cs.meta

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Assets/DrawLine.prefab

5.63 KB
Binary file not shown.

Diff for: Assets/DrawLine.prefab.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Assets/MouseUtil.cs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using UnityEngine;
2+
3+
namespace GameUtil
4+
{
5+
public class MouseUtil{
6+
public static bool UnprojectMousePosition(out Vector3 worldPos, Vector2 mousePos,Plane plane) {
7+
float depth;
8+
Camera cam = Camera.main;
9+
if (cam == null) cam = Camera.current;
10+
if (cam == null) {
11+
worldPos = Vector3.zero;
12+
return false;
13+
}
14+
Ray ray = cam.ScreenPointToRay(mousePos);
15+
16+
if (plane.Raycast(ray, out depth)) {
17+
worldPos = ray.origin + ray.direction * depth;
18+
return true;
19+
} else {
20+
worldPos = Vector3.zero;
21+
return false;
22+
}
23+
}
24+
25+
public static bool UnprojectMousePositionXZ(out Vector3 worldPos, Vector2 mousePos)
26+
{
27+
return UnprojectMousePosition(out worldPos, mousePos, new Plane(Vector3.up, new Vector3(0, 0, 0))); //原点の位置にある、無限に広がるXZ平面//
28+
}
29+
30+
public static bool UnprojectMousePositionXY(out Vector3 worldPos, Vector2 mousePos)
31+
{
32+
return UnprojectMousePosition(out worldPos, mousePos, new Plane(Vector3.forward, new Vector3(0, 0, 0))); //原点の位置にある、無限に広がるXY平面//
33+
}
34+
35+
public static Vector3 ClampToScreen(Vector3 worldPos) {
36+
Camera cam = Camera.main;
37+
if (cam == null) cam = Camera.current;
38+
if (cam == null) {
39+
return Vector3.zero;
40+
}
41+
return cam.WorldToViewportPoint(worldPos);
42+
}
43+
}
44+
}

Diff for: Assets/MouseUtil.cs.meta

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Assets/Test.unity

20.3 KB
Binary file not shown.

Diff for: Assets/Test.unity.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Assets/animal_coelacanth.png

384 KB
Loading

Diff for: Assets/animal_coelacanth.png.meta

+57
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ProjectSettings/AudioManager.asset

4.04 KB
Binary file not shown.

Diff for: ProjectSettings/ClusterInputManager.asset

4.01 KB
Binary file not shown.

Diff for: ProjectSettings/DynamicsManager.asset

4.18 KB
Binary file not shown.

Diff for: ProjectSettings/EditorBuildSettings.asset

4.04 KB
Binary file not shown.

Diff for: ProjectSettings/EditorSettings.asset

4.11 KB
Binary file not shown.

Diff for: ProjectSettings/GraphicsSettings.asset

4.16 KB
Binary file not shown.

Diff for: ProjectSettings/InputManager.asset

5.39 KB
Binary file not shown.

Diff for: ProjectSettings/NavMeshAreas.asset

4.28 KB
Binary file not shown.

Diff for: ProjectSettings/NetworkManager.asset

4.02 KB
Binary file not shown.

Diff for: ProjectSettings/Physics2DSettings.asset

4.21 KB
Binary file not shown.

Diff for: ProjectSettings/ProjectSettings.asset

37.1 KB
Binary file not shown.

Diff for: ProjectSettings/ProjectVersion.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
m_EditorVersion: 5.3.4p5
2+
m_StandardAssetsVersion: 0

Diff for: ProjectSettings/QualitySettings.asset

4.94 KB
Binary file not shown.

Diff for: ProjectSettings/TagManager.asset

4.21 KB
Binary file not shown.

Diff for: ProjectSettings/TimeManager.asset

4.02 KB
Binary file not shown.

Diff for: ProjectSettings/UnityAdsSettings.asset

4.02 KB
Binary file not shown.

Diff for: ProjectSettings/UnityConnectSettings.asset

4.02 KB
Binary file not shown.

0 commit comments

Comments
 (0)