Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
curvedflats
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
6
Issues
6
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Flatland
curvedflats
Commits
8dfd1a8d
Commit
8dfd1a8d
authored
Jun 26, 2019
by
18김민수
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Proto update
parent
a0f15e00
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
713 additions
and
9 deletions
+713
-9
SampleScene.unity
Assets/Scenes/SampleScene.unity
+651
-3
FlatLandObject.cs
Assets/Scripts/FlatLandObject.cs
+7
-2
Square.cs
Assets/Scripts/Square.cs
+42
-2
UIManager.cs
Assets/Scripts/UIManager.cs
+13
-2
No files found.
Assets/Scenes/SampleScene.unity
View file @
8dfd1a8d
This diff is collapsed.
Click to expand it.
Assets/Scripts/FlatLandObject.cs
View file @
8dfd1a8d
...
@@ -4,8 +4,13 @@ using UnityEngine;
...
@@ -4,8 +4,13 @@ using UnityEngine;
public
class
FlatLandObject
:
MonoBehaviour
public
class
FlatLandObject
:
MonoBehaviour
{
{
public
Square
square
;
public
Vector2
speedVector
=
new
Vector2
(
0
,
0
);
public
Vector2
speedVector
=
new
Vector2
(
0
,
0
);
public
double
gameSpeed
=
2
0
;
public
double
gameSpeed
=
0
;
public
double
properTime
=
0
;
public
double
properTime
=
0
;
void
Awake
()
{
square
.
allObjects
.
Add
(
this
);
}
}
}
Assets/Scripts/Square.cs
View file @
8dfd1a8d
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
UnityEngine
;
using
UnityEngine
;
using
System
;
using
System
;
using
System.Linq
;
public
class
Square
:
FlatLandObject
public
class
Square
:
FlatLandObject
{
{
...
@@ -10,6 +11,9 @@ public class Square : FlatLandObject
...
@@ -10,6 +11,9 @@ public class Square : FlatLandObject
public
List
<
Vector2
>
pathList
=
new
List
<
Vector2
>();
public
List
<
Vector2
>
pathList
=
new
List
<
Vector2
>();
public
UIManager
uiManager
;
public
UIManager
uiManager
;
public
List
<
FlatLandObject
>
allObjects
=
new
List
<
FlatLandObject
>();
// Evety FlatLandObject is automatically added with Awake().
public
FlatLandObject
attatchedObject
=
null
;
private
Vector2
_currentPathEnd
;
private
Vector2
_currentPathEnd
;
// Start is called before the first frame update
// Start is called before the first frame update
...
@@ -22,7 +26,6 @@ public class Square : FlatLandObject
...
@@ -22,7 +26,6 @@ public class Square : FlatLandObject
{
{
if
(
Input
.
GetMouseButtonDown
(
1
))
// If right mouse button is clicked
if
(
Input
.
GetMouseButtonDown
(
1
))
// If right mouse button is clicked
{
{
Debug
.
Log
(
getNthPath
(
0
));
Ray
ray
=
Camera
.
main
.
ScreenPointToRay
(
Input
.
mousePosition
);
Ray
ray
=
Camera
.
main
.
ScreenPointToRay
(
Input
.
mousePosition
);
if
(
Physics
.
Raycast
(
ray
,
out
RaycastHit
hit
))
// If the click was on the background
if
(
Physics
.
Raycast
(
ray
,
out
RaycastHit
hit
))
// If the click was on the background
{
{
...
@@ -32,6 +35,12 @@ public class Square : FlatLandObject
...
@@ -32,6 +35,12 @@ public class Square : FlatLandObject
CreatePath
(
hit
.
point
);
CreatePath
(
hit
.
point
);
}
}
}
}
if
(
Input
.
GetKeyDown
(
KeyCode
.
G
))
Grab
();
if
(
Input
.
GetKeyDown
(
KeyCode
.
H
))
Detach
();
}
}
public
IEnumerator
MoveSquare
(
Vector2
destination
)
public
IEnumerator
MoveSquare
(
Vector2
destination
)
...
@@ -41,6 +50,8 @@ public class Square : FlatLandObject
...
@@ -41,6 +50,8 @@ public class Square : FlatLandObject
while
(
speedVector
.
x
*
(
destination
.
x
-
transform
.
position
.
x
)
>
0
||
speedVector
.
y
*
(
destination
.
y
-
transform
.
position
.
y
)
>
0
)
while
(
speedVector
.
x
*
(
destination
.
x
-
transform
.
position
.
x
)
>
0
||
speedVector
.
y
*
(
destination
.
y
-
transform
.
position
.
y
)
>
0
)
{
{
transform
.
position
+=
scaledVector
;
transform
.
position
+=
scaledVector
;
if
(
attatchedObject
!=
null
)
attatchedObject
.
gameObject
.
transform
.
position
+=
scaledVector
;
yield
return
null
;
yield
return
null
;
}
}
...
@@ -69,14 +80,16 @@ public class Square : FlatLandObject
...
@@ -69,14 +80,16 @@ public class Square : FlatLandObject
public
IEnumerator
_StartMovingPath
()
public
IEnumerator
_StartMovingPath
()
{
{
Vector3
[]
tomoveList
=
new
Vector3
[
pathRenderer
.
positionCount
];
Vector3
[]
tomoveList
=
new
Vector3
[
pathRenderer
.
positionCount
];
Debug
.
Log
(
pathRenderer
.
positionCount
);
pathRenderer
.
GetPositions
(
tomoveList
);
pathRenderer
.
GetPositions
(
tomoveList
);
for
(
int
i
=
1
;
i
<
pathRenderer
.
positionCount
;
i
++)
for
(
int
i
=
1
;
i
<
pathRenderer
.
positionCount
;
i
++)
{
{
yield
return
StartCoroutine
(
MoveSquare
(
tomoveList
[
i
]));
yield
return
StartCoroutine
(
MoveSquare
(
tomoveList
[
i
]));
}
}
AddTimes
();
ResetPaths
();
ResetPaths
();
uiManager
.
UpdateUI
();
uiManager
.
CheckVictory
();
}
}
public
void
ResetPaths
()
public
void
ResetPaths
()
...
@@ -113,4 +126,31 @@ public class Square : FlatLandObject
...
@@ -113,4 +126,31 @@ public class Square : FlatLandObject
gameSpeed
+=
d
;
gameSpeed
+=
d
;
uiManager
.
UpdateUI
();
uiManager
.
UpdateUI
();
}
}
public
void
Grab
()
{
var
lst
=
Physics
.
OverlapSphere
(
transform
.
position
,
10
);
if
(
lst
.
Length
>
0
)
attatchedObject
=
lst
[
0
].
gameObject
.
GetComponent
<
FlatLandObject
>();
}
public
void
Detach
()
{
attatchedObject
=
null
;
}
public
void
AddTimes
()
{
Debug
.
Log
(
CalculateEntireMovingTime
());
foreach
(
var
v
in
allObjects
)
{
Debug
.
Log
(
v
.
gameObject
.
name
);
v
.
properTime
+=
CalculateEntireMovingTime
();
}
square
.
properTime
-=
CalculateEntireMovingTime
()
-
(
square
.
CalculateEntireMovingTime
()
/
Constants
.
Gamma
(
square
.
gameSpeed
));
if
(
attatchedObject
!=
null
)
attatchedObject
.
properTime
-=
CalculateEntireMovingTime
()
-
(
square
.
CalculateEntireMovingTime
()
/
Constants
.
Gamma
(
square
.
gameSpeed
));
}
}
}
Assets/Scripts/UIManager.cs
View file @
8dfd1a8d
...
@@ -6,9 +6,12 @@ public class UIManager : MonoBehaviour
...
@@ -6,9 +6,12 @@ public class UIManager : MonoBehaviour
{
{
public
Text
properTime
;
public
Text
properTime
;
public
Text
currentSpeed
;
public
Text
currentSpeed
;
public
Text
clockText
;
public
Square
square
;
public
Square
square
;
public
FlatLandObject
clock1
,
clock2
;
public
GameObject
victoryScreen
;
public
void
UpdateUI
()
public
void
UpdateUI
()
// it just updates UI.
{
{
string
newPropertime
,
prevPropertime
;
string
newPropertime
,
prevPropertime
;
...
@@ -17,6 +20,14 @@ public class UIManager : MonoBehaviour
...
@@ -17,6 +20,14 @@ public class UIManager : MonoBehaviour
prevPropertime
=
square
.
CalculateEntireMovingTime
().
ToString
();
prevPropertime
=
square
.
CalculateEntireMovingTime
().
ToString
();
newPropertime
=
(
square
.
CalculateEntireMovingTime
()
/
Constants
.
Gamma
(
square
.
gameSpeed
)).
ToString
();
newPropertime
=
(
square
.
CalculateEntireMovingTime
()
/
Constants
.
Gamma
(
square
.
gameSpeed
)).
ToString
();
properTime
.
text
=
"New Proper Time : "
+
newPropertime
+
"\nPrev Proper Time : "
+
prevPropertime
;
properTime
.
text
=
"New Proper Time : +"
+
newPropertime
+
" seconds\nPrev Proper Time : +"
+
prevPropertime
+
" seconds"
;
clockText
.
text
=
"Clock1 : "
+
clock1
.
properTime
+
" second\nClock2 : "
+
clock2
.
properTime
+
" second"
;
}
public
void
CheckVictory
()
{
if
((
clock1
.
transform
.
position
-
clock2
.
transform
.
position
).
sqrMagnitude
<
10
&&
Mathf
.
Abs
((
float
)(
clock1
.
properTime
-
clock2
.
properTime
))
<
1
)
victoryScreen
.
SetActive
(
true
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment