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
a0f15e00
Commit
a0f15e00
authored
Jun 25, 2019
by
18김민수
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ProperTime
parent
b2015dec
Changes
8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
1196 additions
and
74 deletions
+1196
-74
New Material.mat
Assets/Resources/New Material.mat
+1
-1
SampleScene.unity
Assets/Scenes/SampleScene.unity
+1131
-37
Constants.cs
Assets/Scripts/Constants.cs
+2
-2
FlatLandObject.cs
Assets/Scripts/FlatLandObject.cs
+2
-5
PathRenderer.cs
Assets/Scripts/PathRenderer.cs
+0
-25
Square.cs
Assets/Scripts/Square.cs
+37
-3
UIManager.cs
Assets/Scripts/UIManager.cs
+22
-0
UIManager.cs.meta
Assets/Scripts/UIManager.cs.meta
+1
-1
No files found.
Assets/Resources/New Material.mat
View file @
a0f15e00
...
...
@@ -73,5 +73,5 @@ Material:
-
_UVSec
:
0
-
_ZWrite
:
1
m_Colors
:
-
_Color
:
{
r
:
0
,
g
:
0
,
b
:
0
,
a
:
1
}
-
_Color
:
{
r
:
1
,
g
:
1
,
b
:
1
,
a
:
1
}
-
_EmissionColor
:
{
r
:
0
,
g
:
0
,
b
:
0
,
a
:
1
}
Assets/Scenes/SampleScene.unity
View file @
a0f15e00
This diff is collapsed.
Click to expand it.
Assets/Scripts/Constants.cs
View file @
a0f15e00
...
...
@@ -4,9 +4,9 @@ using UnityEngine;
public
static
class
Constants
{
public
static
double
C
=>
40
;
// speed of light.
public
static
double
c
=>
40
;
// speed of light.
public
static
double
Gamma
(
double
v
)
{
return
1
/
Mathf
.
Sqrt
((
1
-
(
float
)((
v
/
C
)
*
(
v
/
C
))));
return
1
/
Mathf
.
Sqrt
((
1
-
(
float
)((
v
/
c
)
*
(
v
/
c
))));
}
}
Assets/Scripts/FlatLandObject.cs
View file @
a0f15e00
...
...
@@ -5,10 +5,7 @@ using UnityEngine;
public
class
FlatLandObject
:
MonoBehaviour
{
public
Vector2
speedVector
=
new
Vector2
(
0
,
0
);
public
double
gameSpeed
=
20
;
public
double
properTime
=
0
;
public
virtual
void
Update
()
{
properTime
+=
Time
.
deltaTime
;
}
}
Assets/Scripts/PathRenderer.cs
deleted
100644 → 0
View file @
b2015dec
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
PathRenderer
:
MonoBehaviour
{
LineRenderer
line
;
// Start is called before the first frame update
void
Start
()
{
Vector3
a
=
new
Vector2
(-
30
,
-
30
);
Vector3
b
=
new
Vector2
(
30
,
30
);
Vector3
c
=
new
Vector2
(-
30
,
30
);
line
=
GetComponent
<
LineRenderer
>();
Vector3
[]
lst
=
new
Vector3
[]
{
a
,
b
,
c
};
line
.
positionCount
=
lst
.
Length
;
line
.
SetPositions
(
lst
);
}
// Update is called once per frame
void
Update
()
{
}
}
Assets/Scripts/Square.cs
View file @
a0f15e00
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
using
System
;
public
class
Square
:
FlatLandObject
{
public
LineRenderer
pathRenderer
;
// About drawing paths.
public
List
<
Vector2
>
pathList
=
new
List
<
Vector2
>();
public
UIManager
uiManager
;
private
Vector2
_currentPathEnd
;
...
...
@@ -16,10 +18,11 @@ public class Square : FlatLandObject
}
// Update is called once per frame
public
override
void
Update
()
public
void
Update
()
{
if
(
Input
.
GetMouseButtonDown
(
1
))
// If right mouse button is clicked
{
Debug
.
Log
(
getNthPath
(
0
));
Ray
ray
=
Camera
.
main
.
ScreenPointToRay
(
Input
.
mousePosition
);
if
(
Physics
.
Raycast
(
ray
,
out
RaycastHit
hit
))
// If the click was on the background
{
...
...
@@ -43,16 +46,18 @@ public class Square : FlatLandObject
}
public
void
CreatePath
(
Vector3
point
)
// Creates the fitst path.
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.
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
()
...
...
@@ -79,4 +84,33 @@ public class Square : FlatLandObject
pathRenderer
.
positionCount
=
2
;
pathRenderer
.
SetPositions
(
new
Vector3
[]
{
Vector3
.
zero
,
Vector3
.
zero
});
}
public
Vector2
getNthPath
(
int
n
)
// returns movement vector stored in path renderer by index.
{
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
();
}
}
Assets/Scripts/UIManager.cs
0 → 100644
View file @
a0f15e00
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
using
UnityEngine.UI
;
public
class
UIManager
:
MonoBehaviour
{
public
Text
properTime
;
public
Text
currentSpeed
;
public
Square
square
;
public
void
UpdateUI
()
{
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
+
"\nPrev Proper Time : "
+
prevPropertime
;
}
}
Assets/Scripts/
PathRender
er.cs.meta
→
Assets/Scripts/
UIManag
er.cs.meta
View file @
a0f15e00
fileFormatVersion: 2
guid: 2
386eefa66792304fa006e091f12c04
6
guid: 2
c85c5f34b599bd47bda7810cd6b95a
6
MonoImporter:
externalObjects: {}
serializedVersion: 2
...
...
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