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
4cd68997
Commit
4cd68997
authored
Jul 16, 2019
by
18김민수
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Seperated "Square.cs" and "PathRenderer.cs".
parent
7c42f50b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
55 deletions
+80
-55
PathRenderer.cs
Assets/Scripts/PathRenderer.cs
+69
-0
PathRenderer.cs.meta
Assets/Scripts/PathRenderer.cs.meta
+11
-0
Square.cs
Assets/Scripts/Square.cs
+0
-55
No files found.
Assets/Scripts/PathRenderer.cs
0 → 100644
View file @
4cd68997
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
using
System.Linq
;
public
class
PathRenderer
:
MonoBehaviour
{
[
SerializeField
]
Square
square
;
LineRenderer
_pathRenderer
;
float
_zPosition
=>
square
.
transform
.
position
.
z
;
// Start is called before the first frame update
void
Start
()
{
_pathRenderer
=
GetComponent
<
LineRenderer
>();
_ResetPaths
();
}
// Update is called once per frame
void
Update
()
{
if
(
Input
.
GetMouseButtonDown
(
1
))
{
RaycastHit
hit
;
var
ray
=
Camera
.
main
.
ScreenPointToRay
(
Input
.
mousePosition
);
if
(
Physics
.
Raycast
(
ray
,
out
hit
))
{
if
(
Input
.
GetKey
(
KeyCode
.
LeftShift
))
{
Debug
.
Log
(
"asdf"
);
_DrawMorePath
(
hit
.
point
);
}
else
{
_DrawOnePath
(
hit
.
point
);
}
}
}
}
private
void
_DrawOnePath
(
Vector3
point
)
{
_ResetPaths
();
point
.
z
=
_zPosition
;
square
.
pathList
[
0
]
=
transform
.
position
;
square
.
pathList
[
1
]
=
point
;
_pathRenderer
.
SetPositions
(
square
.
pathList
.
ToArray
());
}
private
void
_ResetPaths
()
{
_pathRenderer
.
positionCount
=
2
;
square
.
pathList
.
Clear
();
square
.
pathList
.
Add
(
transform
.
position
);
square
.
pathList
.
Add
(
new
Vector3
(
0
,
0
,
_zPosition
));
_pathRenderer
.
SetPositions
(
square
.
pathList
.
ToArray
());
}
private
void
_DrawMorePath
(
Vector3
point
)
{
point
.
z
=
_zPosition
;
square
.
pathList
.
Add
(
point
);
_pathRenderer
.
positionCount
=
square
.
pathList
.
Count
();
_pathRenderer
.
SetPositions
(
square
.
pathList
.
ToArray
());
}
}
Assets/Scripts/PathRenderer.cs.meta
0 → 100644
View file @
4cd68997
fileFormatVersion: 2
guid: 8f30fcfb85a9c704291c91129b0b8f0c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/Square.cs
View file @
4cd68997
...
...
@@ -6,61 +6,6 @@ using System.Linq;
public
class
Square
:
FlatLandObject
{
public
LineRenderer
pathRenderer
;
// About drawing paths.
public
List
<
Vector3
>
pathList
=
new
List
<
Vector3
>();
private
float
_zPosition
=>
transform
.
position
.
z
;
private
void
Awake
()
{
_ResetPaths
();
}
private
void
Update
()
{
if
(
Input
.
GetMouseButtonDown
(
1
))
{
RaycastHit
hit
;
var
ray
=
Camera
.
main
.
ScreenPointToRay
(
Input
.
mousePosition
);
if
(
Physics
.
Raycast
(
ray
,
out
hit
))
{
if
(
Input
.
GetKey
(
KeyCode
.
LeftShift
))
{
Debug
.
Log
(
"asdf"
);
_DrawMorePath
(
hit
.
point
);
}
else
{
_DrawOnePath
(
hit
.
point
);
}
}
}
}
private
void
_DrawOnePath
(
Vector3
point
)
{
_ResetPaths
();
point
.
z
=
_zPosition
;
pathList
[
0
]
=
transform
.
position
;
pathList
[
1
]
=
point
;
pathRenderer
.
SetPositions
(
pathList
.
ToArray
());
}
private
void
_ResetPaths
()
{
pathRenderer
.
positionCount
=
2
;
pathList
.
Clear
();
pathList
.
Add
(
transform
.
position
);
pathList
.
Add
(
new
Vector3
(
0
,
0
,
_zPosition
));
pathRenderer
.
SetPositions
(
pathList
.
ToArray
());
}
private
void
_DrawMorePath
(
Vector3
point
)
{
point
.
z
=
_zPosition
;
pathList
.
Add
(
point
);
pathRenderer
.
positionCount
=
pathList
.
Count
();
pathRenderer
.
SetPositions
(
pathList
.
ToArray
());
}
}
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