Skip to content

Commit 91d4767

Browse files
committed
Update ver 1.0
1 parent a7b6770 commit 91d4767

File tree

108 files changed

+323
-362
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+323
-362
lines changed

.vs/UnityPathGenerator/v16/.suo

256 KB
Binary file not shown.

Assembly-CSharp.csproj

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<ProductVersion>10.0.20506</ProductVersion>
1010
<SchemaVersion>2.0</SchemaVersion>
1111
<RootNamespace></RootNamespace>
12-
<ProjectGuid>{3FE15C33-C38F-BFFA-DC82-D98C3E23D3F2}</ProjectGuid>
12+
<ProjectGuid>{09434EEF-816A-E7B0-91C2-3ABE8AD3BEF0}</ProjectGuid>
1313
<OutputType>Library</OutputType>
1414
<AppDesignerFolder>Properties</AppDesignerFolder>
1515
<AssemblyName>Assembly-CSharp</AssemblyName>
@@ -595,31 +595,31 @@
595595
<HintPath>C:/Program Files/Unity/Hub/Editor/2019.4.2f1/Editor/Data/NetStandard/compat/2.0.0/shims/netfx/System.Xml.Serialization.dll</HintPath>
596596
</Reference>
597597
<Reference Include="Unity.Timeline.Editor">
598-
<HintPath>C:/Users/movie/Desktop/AutoPathGenerator/Library/ScriptAssemblies/Unity.Timeline.Editor.dll</HintPath>
598+
<HintPath>C:/src/UnityPathGenerator/Library/ScriptAssemblies/Unity.Timeline.Editor.dll</HintPath>
599599
</Reference>
600600
<Reference Include="Unity.VSCode.Editor">
601-
<HintPath>C:/Users/movie/Desktop/AutoPathGenerator/Library/ScriptAssemblies/Unity.VSCode.Editor.dll</HintPath>
601+
<HintPath>C:/src/UnityPathGenerator/Library/ScriptAssemblies/Unity.VSCode.Editor.dll</HintPath>
602602
</Reference>
603603
<Reference Include="Unity.TextMeshPro.Editor">
604-
<HintPath>C:/Users/movie/Desktop/AutoPathGenerator/Library/ScriptAssemblies/Unity.TextMeshPro.Editor.dll</HintPath>
604+
<HintPath>C:/src/UnityPathGenerator/Library/ScriptAssemblies/Unity.TextMeshPro.Editor.dll</HintPath>
605605
</Reference>
606606
<Reference Include="UnityEngine.UI">
607-
<HintPath>C:/Users/movie/Desktop/AutoPathGenerator/Library/ScriptAssemblies/UnityEngine.UI.dll</HintPath>
607+
<HintPath>C:/src/UnityPathGenerator/Library/ScriptAssemblies/UnityEngine.UI.dll</HintPath>
608608
</Reference>
609609
<Reference Include="Unity.Timeline">
610-
<HintPath>C:/Users/movie/Desktop/AutoPathGenerator/Library/ScriptAssemblies/Unity.Timeline.dll</HintPath>
610+
<HintPath>C:/src/UnityPathGenerator/Library/ScriptAssemblies/Unity.Timeline.dll</HintPath>
611611
</Reference>
612612
<Reference Include="Unity.CollabProxy.Editor">
613-
<HintPath>C:/Users/movie/Desktop/AutoPathGenerator/Library/ScriptAssemblies/Unity.CollabProxy.Editor.dll</HintPath>
613+
<HintPath>C:/src/UnityPathGenerator/Library/ScriptAssemblies/Unity.CollabProxy.Editor.dll</HintPath>
614614
</Reference>
615615
<Reference Include="Unity.Rider.Editor">
616-
<HintPath>C:/Users/movie/Desktop/AutoPathGenerator/Library/ScriptAssemblies/Unity.Rider.Editor.dll</HintPath>
616+
<HintPath>C:/src/UnityPathGenerator/Library/ScriptAssemblies/Unity.Rider.Editor.dll</HintPath>
617617
</Reference>
618618
<Reference Include="Unity.TextMeshPro">
619-
<HintPath>C:/Users/movie/Desktop/AutoPathGenerator/Library/ScriptAssemblies/Unity.TextMeshPro.dll</HintPath>
619+
<HintPath>C:/src/UnityPathGenerator/Library/ScriptAssemblies/Unity.TextMeshPro.dll</HintPath>
620620
</Reference>
621621
<Reference Include="UnityEditor.UI">
622-
<HintPath>C:/Users/movie/Desktop/AutoPathGenerator/Library/ScriptAssemblies/UnityEditor.UI.dll</HintPath>
622+
<HintPath>C:/src/UnityPathGenerator/Library/ScriptAssemblies/UnityEditor.UI.dll</HintPath>
623623
</Reference>
624624
</ItemGroup>
625625
<ItemGroup></ItemGroup>

Assets/Scenes/SampleScene.unity

+15-1
Original file line numberDiff line numberDiff line change
@@ -737,10 +737,24 @@ MonoBehaviour:
737737
m_Script: {fileID: 11500000, guid: 539089cfe4dd8c149854dff36789b0b4, type: 3}
738738
m_Name:
739739
m_EditorClassIdentifier:
740+
endEvent:
741+
m_PersistentCalls:
742+
m_Calls:
743+
- m_Target: {fileID: 1506752710}
744+
m_MethodName: SetActive
745+
m_Mode: 6
746+
m_Arguments:
747+
m_ObjectArgument: {fileID: 0}
748+
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
749+
m_IntArgument: 0
750+
m_FloatArgument: 0
751+
m_StringArgument:
752+
m_BoolArgument: 0
753+
m_CallState: 2
740754
path: {fileID: 195522643}
741755
speed: 300
742756
turningSpeed: 10
743-
isLoop: 1
757+
isLoop: 0
744758
isMove: 1
745759
--- !u!54 &1506752712
746760
Rigidbody:

Assets/Scripts/PathFollower.cs

+123-54
Original file line numberDiff line numberDiff line change
@@ -3,98 +3,167 @@
33
using System.Collections.Generic;
44
using UnityEngine;
55

6-
[RequireComponent(typeof(Rigidbody))]
6+
//===================================================================================================
7+
//
8+
// PATH FOLLWER CLASS
9+
//
10+
// Script to follow the path created by "Path Generator" class
11+
// Path Generator가 만든 Path를 따라가는 기능
12+
//
13+
//---------------------------------------------------------------------------------------------------
14+
// 2020.08.30 _ KimYC1223
15+
//===================================================================================================
716

8-
[System.Serializable]
9-
public class EndEvent : UnityEngine.Events.UnityEvent<GameObject> { }
17+
[RequireComponent(typeof(Rigidbody))]
1018

1119
public class PathFollower : MonoBehaviour
1220
{
13-
public EventArgs endEvent;
14-
public PathGenerator path;
15-
public float speed = 100f;
16-
public float turningSpeed = 10f;
17-
public bool isLoop = false;
18-
public bool isMove = true;
21+
[System.Serializable]
22+
public class EndEvent : UnityEngine.Events.UnityEvent { }
23+
24+
[SerializeField]
25+
public EndEvent endEvent; // method to run when this is done moving
1926

20-
private Rigidbody TargetRigidbody;
21-
private GameObject Target;
22-
private GameObject NextAngle;
23-
private int AngleStep = 1;
27+
public PathGenerator path; // choose the path to move
28+
public float speed = 100f; // move speed
29+
public float turningSpeed = 10f; // rotation speed
30+
public bool isLoop = false; // does it move repeatedly?
31+
public bool isMove = true; // is this moving now?
2432

25-
33+
private Rigidbody targetRigidbody; // the rigidbody of the object to move
34+
private GameObject target; // object to move;
35+
private GameObject nextPath; // the direction the obejct will move
36+
private int pathIndex = 1; // the path index the object will move
37+
private float distanceThreshold = 0.2f; // distance threshold
2638

39+
//===============================================================================================
40+
// Start method
41+
//-----------------------------------------------------------------------------------------------
42+
// init variable & position
43+
// 각종 변수와 position 초기화
44+
//===============================================================================================
2745
void Start()
2846
{
29-
TargetRigidbody = GetComponent<Rigidbody>();
30-
if (path == null) {
31-
Debug.LogError("경로가 없음");
32-
}
33-
Target = this.gameObject;
34-
NextAngle = path.PathList[1];
47+
targetRigidbody = GetComponent<Rigidbody>();
48+
if (path == null)
49+
Debug.LogError("no path\n경로가 없음");
50+
target = this.gameObject;
51+
nextPath = path.PathList[1];
3552
this.transform.position = path.PathList[0].transform.position;
36-
if (NextAngle == null)
37-
Debug.Log("gg");
3853
}
39-
40-
// Update is called once per frame
54+
55+
//===============================================================================================
56+
// Fixed update method
57+
//-----------------------------------------------------------------------------------------------
58+
// set velocity & direction, and calculate distance
59+
// 속도와 방향 설정 후 거리 계산
60+
//===============================================================================================
4161
void FixedUpdate()
4262
{
63+
//===========================================================================================
64+
// If it is not moving, stop object and return
65+
// 움직이지 않는다면, 물체를 멈추고 종료
66+
//===========================================================================================
4367
if (!isMove) {
44-
TargetRigidbody.velocity = new Vector3(0, 0, 0);
68+
targetRigidbody.velocity = new Vector3(0, 0, 0); // Stop
4569
return;
4670
}
47-
// =====================================================================
48-
// 자동차가 가이드를 바라보게하는 기능
49-
// =====================================================================
50-
Vector3 offset = NextAngle.transform.position - Target.transform.position;
71+
72+
//===========================================================================================
73+
// Function to make objects look at the next path
74+
// 물체가 다음 Path를 바라보게하는 기능
75+
//===========================================================================================
76+
Vector3 offset = nextPath.transform.position - target.transform.position;
5177
offset.Normalize();
5278
Quaternion q = Quaternion.LookRotation(offset);
53-
TargetRigidbody.rotation =
54-
Quaternion.Slerp(TargetRigidbody.rotation,
79+
targetRigidbody.rotation =
80+
Quaternion.Slerp(targetRigidbody.rotation,
5581
q, turningSpeed * Time.deltaTime);
5682

57-
58-
// =====================================================================
59-
// 자동차가 가이드를 따라가게 하는 기능
60-
// =====================================================================
83+
//===========================================================================================
84+
// Function to make objects follow a path
85+
// 물체가 path를 따라가게 하는 기능
86+
//===========================================================================================
6187
offset.Normalize();
62-
TargetRigidbody.velocity = offset * speed * Time.deltaTime;
88+
targetRigidbody.velocity = offset * speed * Time.deltaTime;
89+
90+
// calculate distance between object and next path
91+
// 물체와 next path 경로 사이의 거리 계산
92+
float Distance = Vector3.Distance(nextPath.transform.position,
93+
target.transform.position);
6394

64-
// 두 거리 계산
65-
float Distance = Vector3.Distance(NextAngle.transform.position,
66-
Target.transform.position);
95+
//===========================================================================================
96+
// If it is close enough to the next path
97+
// next path에 충분히 가까워졌을 경우
98+
//===========================================================================================
99+
if (Distance < distanceThreshold) {
67100

68-
// =====================================================================
69-
// 가이드에 가까워 졌을 경우
70-
// =====================================================================
71-
if (Distance < 0.2f) {
72-
73-
if(AngleStep >= path.PathList.Count) {
101+
if (pathIndex < path.PathList.Count) {
102+
//=======================================================================================
103+
// If the end of the path list is not reached, set the next path by increase path Index
104+
// path 리스트의 끝에 도달하지 못했다면, path Index ++ 를 통해 next path 설정
105+
//=======================================================================================
106+
nextPath = path.PathList[pathIndex++];
107+
} else {
108+
//===================================================================================
109+
// If the object reached end of the path list,
110+
// path 리스트 끝에 도달했다면, 즉, 최종 목적지에 도달했을때
111+
//===================================================================================
74112
if (path.isClosed) {
75-
NextAngle = path.PathList[0];
76-
AngleStep = 0;
113+
//===============================================================================
114+
// If current path is closed path, back to zero of the path list
115+
// 현재 path가 닫힌 경로이면, 다시 pathList[0]을 향해 전진
116+
//===============================================================================
117+
nextPath = path.PathList[0];
118+
pathIndex = 0;
77119
} else {
78-
if(isLoop) {
79-
NextAngle = path.PathList[1];
80-
AngleStep = 1;
120+
//===============================================================================
121+
// If current path is open path,
122+
// 현재 path가 열린 경로이면,
123+
//===============================================================================
124+
if (isLoop) {
125+
//===========================================================================
126+
// and object move repeatedly reinit position & value;
127+
// 그리고 물체가 반복적으로 움직인다면, position과 변수 다시 초기화
128+
//===========================================================================
129+
nextPath = path.PathList[1];
130+
pathIndex = 1;
81131
this.transform.position = path.PathList[0].transform.position;
82-
Target.transform.LookAt(path.PathList[1].transform);
132+
target.transform.LookAt(path.PathList[1].transform);
133+
// If endEvent isn't null, run method.
134+
// endEvent가 null이 아니면, method를 실행
135+
if (endEvent != null)
136+
endEvent.Invoke();
83137
} else {
138+
//==========================================================================
139+
// If object move once, Stop move and if endEvent isn't null, run method.
140+
// 물체가 한번만 움직이면 멈추고, endEvent!=null이 아니면, method를 실행
141+
//==========================================================================
84142
StopFollow();
143+
if (endEvent != null)
144+
endEvent.Invoke();
85145
}
86146
}
87-
} else {
88-
NextAngle = path.PathList[AngleStep++];
89147
}
90148
}
91149
}
92150

93-
151+
//===============================================================================================
152+
// Stop Follow method
153+
//-----------------------------------------------------------------------------------------------
154+
// stop move by set isMove false
155+
// 정지
156+
//===============================================================================================
94157
public void StopFollow() {
95158
isMove = false;
96159
}
97160

161+
//===============================================================================================
162+
// Start Follow method
163+
//-----------------------------------------------------------------------------------------------
164+
// Start move by set isMove true
165+
// 움직임
166+
//===============================================================================================
98167
public void StartFollow() {
99168
isMove = true;
100169
}

Assets/Scripts/PathGenerator.cs

+38-14
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,44 @@
33
using UnityEngine;
44
using UnityEngine.UI;
55

6+
//===================================================================================================
7+
//
8+
// PATH PATH GENERATOR CLASS
9+
//
10+
// Script to make followable path the based on Bézier Curve
11+
// Path Generator가 만든 Path를 따라가는 기능
12+
//
13+
//---------------------------------------------------------------------------------------------------
14+
// 2020.08.30 _ KimYC1223
15+
//===================================================================================================
16+
617
public class PathGenerator : MonoBehaviour {
7-
public GameObject Flag;
8-
public GameObject StartFlag;
9-
public GameObject Angle;
10-
public GameObject Guide;
11-
public bool isClosed = true;
12-
public bool isDebugObject = false;
13-
public bool isDebugLine = false;
14-
public int PathDensity = 30;
18+
public GameObject Flag; // Visual maker of stopover
19+
public GameObject StartFlag; // Visual maker of start point
20+
public GameObject Angle; // Visual maker of angle setter
21+
public GameObject Guide; // Visual maker of path guide
22+
public bool isClosed = true; // is this path closed?
23+
public bool isDebugObject = false; // show Flag and Angle objects in play mode?
24+
public bool isDebugLine = false; // show guide objects in play mode?
25+
public int PathDensity = 30; // Density of guide objects between Flags
1526

16-
public List<GameObject> FlagList = new List<GameObject>();
17-
public List<GameObject> AngleList = new List<GameObject>();
18-
internal List<GameObject> PathList = new List<GameObject>();
19-
20-
private Transform Roads;
27+
public List<GameObject> FlagList = new List<GameObject>(); // List of Flag objects
28+
public List<GameObject> AngleList = new List<GameObject>(); // List of Angle objects
29+
internal List<GameObject> PathList = new List<GameObject>(); // List of Path objects
30+
private Transform Roads; // Root object of guide objects
2131

32+
//===============================================================================================
33+
// Awake method
34+
//-----------------------------------------------------------------------------------------------
35+
// init variable & position
36+
// 각종 변수와 position 초기화
37+
//===============================================================================================
2238
public void Awake() {
23-
if(PathDensity < 2) {
39+
//===========================================================================================
40+
// check path density is bigger than 1
41+
// path density가 1보다 큰 지 확인
42+
//===========================================================================================
43+
if (PathDensity < 2) {
2444
#if UNITY_EDITOR
2545
Debug.LogError("Path Density is too small. (must >= 2)");
2646
UnityEditor.EditorApplication.isPlaying = false;
@@ -31,6 +51,10 @@ public void Awake() {
3151
#endif
3252
}
3353

54+
//===========================================================================================
55+
// Get root object of guides for Instantiate guide object
56+
// guide 오브젝트를 Instantiate 하기 위한 부모 객체 가져오기
57+
//===========================================================================================
3458
Transform[] childs = this.transform.GetComponentsInChildren<Transform>();
3559
foreach(Transform t in childs) {
3660
if (t.gameObject.name == "Roads")

Library/ArtifactDB

0 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)