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
7c42f50b
Commit
7c42f50b
authored
Jul 14, 2019
by
18김민수
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Main Development Initiation - path rendering update
parent
8dfd1a8d
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
220 additions
and
2404 deletions
+220
-2404
SampleScene.unity
Assets/Scenes/SampleScene.unity
+186
-2235
FlatLandObject.cs
Assets/Scripts/FlatLandObject.cs
+0
-1
Square.cs
Assets/Scripts/Square.cs
+34
-124
UIManager.cs
Assets/Scripts/UIManager.cs
+0
-33
UIManager.cs.meta
Assets/Scripts/UIManager.cs.meta
+0
-11
No files found.
Assets/Scenes/SampleScene.unity
View file @
7c42f50b
This diff is collapsed.
Click to expand it.
Assets/Scripts/FlatLandObject.cs
View file @
7c42f50b
...
...
@@ -11,6 +11,5 @@ public class FlatLandObject : MonoBehaviour
void
Awake
()
{
square
.
allObjects
.
Add
(
this
);
}
}
Assets/Scripts/Square.cs
View file @
7c42f50b
...
...
@@ -8,149 +8,59 @@ public class Square : FlatLandObject
{
public
LineRenderer
pathRenderer
;
// About drawing paths.
public
List
<
Vector
2
>
pathList
=
new
List
<
Vector2
>();
p
ublic
UIManager
uiManager
;
public
List
<
Vector
3
>
pathList
=
new
List
<
Vector3
>();
p
rivate
float
_zPosition
=>
transform
.
position
.
z
;
public
List
<
FlatLandObject
>
allObjects
=
new
List
<
FlatLandObject
>();
// Evety FlatLandObject is automatically added with Awake().
public
FlatLandObject
attatchedObject
=
null
;
private
Vector2
_currentPathEnd
;
// Start is called before the first frame update
void
Start
()
private
void
Awake
()
{
_ResetPaths
();
}
// Update is called once per frame
public
void
Update
()
private
void
Update
()
{
if
(
Input
.
GetMouseButtonDown
(
1
))
// If right mouse button is clicked
if
(
Input
.
GetMouseButtonDown
(
1
))
{
Ray
ray
=
Camera
.
main
.
ScreenPointToRay
(
Input
.
mousePosition
);
if
(
Physics
.
Raycast
(
ray
,
out
RaycastHit
hit
))
// If the click was on the background
RaycastHit
hit
;
var
ray
=
Camera
.
main
.
ScreenPointToRay
(
Input
.
mousePosition
);
if
(
Physics
.
Raycast
(
ray
,
out
hit
))
{
if
(
Input
.
GetKey
(
KeyCode
.
LeftShift
)
&&
pathRenderer
.
GetPosition
(
1
)
!=
Vector3
.
zero
)
// If shift is clicked and path is already exists
AddPath
(
hit
.
point
);
if
(
Input
.
GetKey
(
KeyCode
.
LeftShift
))
{
Debug
.
Log
(
"asdf"
);
_DrawMorePath
(
hit
.
point
);
}
else
CreatePath
(
hit
.
point
);
{
_DrawOnePath
(
hit
.
point
);
}
}
}
if
(
Input
.
GetKeyDown
(
KeyCode
.
G
))
Grab
();
if
(
Input
.
GetKeyDown
(
KeyCode
.
H
))
Detach
();
}
p
ublic
IEnumerator
MoveSquare
(
Vector2
destination
)
p
rivate
void
_DrawOnePath
(
Vector3
point
)
{
speedVector
=
destination
-
(
Vector2
)
transform
.
position
;
Vector3
scaledVector
=
speedVector
*
Time
.
deltaTime
;
while
(
speedVector
.
x
*
(
destination
.
x
-
transform
.
position
.
x
)
>
0
||
speedVector
.
y
*
(
destination
.
y
-
transform
.
position
.
y
)
>
0
)
{
transform
.
position
+=
scaledVector
;
if
(
attatchedObject
!=
null
)
attatchedObject
.
gameObject
.
transform
.
position
+=
scaledVector
;
yield
return
null
;
}
}
public
void
CreatePath
(
Vector3
point
)
// Creates the fitst path, and updates Proper Time UI.
{
pathRenderer
.
positionCount
=
2
;
pathRenderer
.
SetPositions
(
new
Vector3
[]
{
transform
.
position
,
point
});
uiManager
.
UpdateUI
();
}
public
void
AddPath
(
Vector3
point
)
// Adds new path to current path, and updates Proper Time UI.
{
pathRenderer
.
positionCount
++;
pathRenderer
.
SetPosition
(
pathRenderer
.
positionCount
-
1
,
point
);
uiManager
.
UpdateUI
();
}
public
void
Move
()
{
StartCoroutine
(
_StartMovingPath
());
}
public
IEnumerator
_StartMovingPath
()
{
Vector3
[]
tomoveList
=
new
Vector3
[
pathRenderer
.
positionCount
];
pathRenderer
.
GetPositions
(
tomoveList
);
for
(
int
i
=
1
;
i
<
pathRenderer
.
positionCount
;
i
++)
{
yield
return
StartCoroutine
(
MoveSquare
(
tomoveList
[
i
]));
}
AddTimes
();
ResetPaths
();
uiManager
.
UpdateUI
();
uiManager
.
CheckVictory
();
_ResetPaths
();
point
.
z
=
_zPosition
;
pathList
[
0
]
=
transform
.
position
;
pathList
[
1
]
=
point
;
pathRenderer
.
SetPositions
(
pathList
.
ToArray
());
}
p
ublic
void
ResetPaths
()
p
rivate
void
_
ResetPaths
()
{
pathRenderer
.
positionCount
=
2
;
pathRenderer
.
SetPositions
(
new
Vector3
[]
{
Vector3
.
zero
,
Vector3
.
zero
});
pathList
.
Clear
();
pathList
.
Add
(
transform
.
position
);
pathList
.
Add
(
new
Vector3
(
0
,
0
,
_zPosition
));
pathRenderer
.
SetPositions
(
pathList
.
ToArray
());
}
p
ublic
Vector2
getNthPath
(
int
n
)
// returns movement vector stored in path renderer by index.
p
rivate
void
_DrawMorePath
(
Vector3
point
)
{
if
(
n
>=
pathRenderer
.
positionCount
)
throw
new
InvalidOperationException
(
n
+
"th path is not stored."
);
return
pathRenderer
.
GetPosition
(
n
+
1
)
-
pathRenderer
.
GetPosition
(
n
);
}
public
double
MovingTime
(
Vector2
v
)
// How long it takes to move given vector with current speed.
{
return
v
.
sqrMagnitude
/
gameSpeed
;
}
public
double
CalculateEntireMovingTime
()
// How long it takes to move current path all the way.
{
double
result
=
0
;
for
(
int
i
=
0
;
i
<
pathRenderer
.
positionCount
-
1
;
i
++)
result
+=
MovingTime
(
getNthPath
(
i
));
return
result
/
gameSpeed
;
}
public
void
ModifySpeed
(
float
d
)
{
if
(
gameSpeed
+
d
<=
Constants
.
c
&&
gameSpeed
+
d
>=
0
)
gameSpeed
+=
d
;
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
));
point
.
z
=
_zPosition
;
pathList
.
Add
(
point
);
pathRenderer
.
positionCount
=
pathList
.
Count
();
pathRenderer
.
SetPositions
(
pathList
.
ToArray
());
}
}
Assets/Scripts/UIManager.cs
deleted
100644 → 0
View file @
8dfd1a8d
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
using
UnityEngine.UI
;
public
class
UIManager
:
MonoBehaviour
{
public
Text
properTime
;
public
Text
currentSpeed
;
public
Text
clockText
;
public
Square
square
;
public
FlatLandObject
clock1
,
clock2
;
public
GameObject
victoryScreen
;
public
void
UpdateUI
()
// it just updates UI.
{
string
newPropertime
,
prevPropertime
;
currentSpeed
.
text
=
"Current Speed : "
+
(
square
.
gameSpeed
/
Constants
.
c
).
ToString
(
"F2"
)
+
"c"
;
prevPropertime
=
square
.
CalculateEntireMovingTime
().
ToString
();
newPropertime
=
(
square
.
CalculateEntireMovingTime
()
/
Constants
.
Gamma
(
square
.
gameSpeed
)).
ToString
();
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
);
}
}
Assets/Scripts/UIManager.cs.meta
deleted
100644 → 0
View file @
8dfd1a8d
fileFormatVersion: 2
guid: 2c85c5f34b599bd47bda7810cd6b95a6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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