Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
Birb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gadig
Birb
Commits
b30c4bd7
Commit
b30c4bd7
authored
Apr 07, 2017
by
Luke Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start for drag placement.
parent
6a52a6fb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
152 additions
and
21 deletions
+152
-21
Assets/Scripts/MapEditor/DragPlacement.cs
Assets/Scripts/MapEditor/DragPlacement.cs
+117
-0
Assets/Scripts/MapEditor/MapEditor.cs
Assets/Scripts/MapEditor/MapEditor.cs
+28
-14
Assets/Scripts/MapEditor/World.cs
Assets/Scripts/MapEditor/World.cs
+7
-7
No files found.
Assets/Scripts/MapEditor/DragPlacement.cs
0 → 100644
View file @
b30c4bd7
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
// This script should be attached the the prefab of the left side cap.
// Set mid to the prefab that should be placed between the caps.
// The right cap will be the flipped version of the left cap.
public
class
DragPlacement
:
MonoBehaviour
{
public
GameObject
cap
;
public
GameObject
mid
;
public
static
GameObject
instance
;
// Current instance of this script
public
void
endDrag
(
Vector3
pos
)
{
Vector2
dir
=
pos
-
transform
.
position
;
// Moved further left/right
if
(
Mathf
.
Abs
(
dir
.
x
)
>
Mathf
.
Abs
(
dir
.
y
))
{
placeX
((
int
)
pos
.
x
);
}
// Moved further up/down
else
{
placeY
((
int
)
pos
.
y
);
}
}
private
void
placeX
(
int
x
)
{
// Placeing left
if
(
x
<
transform
.
position
.
x
)
{
// Place start cap and flip
GameObject
go
=
World
.
set
(
transform
.
position
,
cap
);
go
.
transform
.
localScale
=
new
Vector3
(
go
.
transform
.
localScale
.
x
*
-
1
,
go
.
transform
.
localScale
.
y
,
go
.
transform
.
localScale
.
z
);
// Place mid
for
(
int
i
=
(
int
)
transform
.
position
.
x
;
i
>
x
;
i
--)
{
World
.
set
(
i
,
transform
.
position
.
y
,
transform
.
position
.
z
,
mid
);
}
// Place cap
World
.
set
(
x
,
transform
.
position
.
y
,
transform
.
position
.
z
,
cap
);
}
// Placing right
else
{
// Place start cap
World
.
set
(
transform
.
position
,
cap
);
// Place mid
for
(
int
i
=
(
int
)
transform
.
position
.
x
;
i
<
x
;
i
++)
{
World
.
set
(
i
,
transform
.
position
.
y
,
transform
.
position
.
z
,
mid
);
}
// Place cap
GameObject
go
=
World
.
set
(
x
,
transform
.
position
.
y
,
transform
.
position
.
z
,
cap
);
go
.
transform
.
localScale
=
new
Vector3
(
go
.
transform
.
localScale
.
x
*
-
1
,
go
.
transform
.
localScale
.
y
,
go
.
transform
.
localScale
.
z
);
}
}
private
void
placeY
(
int
y
)
{
// Placeing down
if
(
y
<
transform
.
position
.
y
)
{
// Place start cap and flip
GameObject
go
=
World
.
set
(
transform
.
position
,
cap
);
go
.
transform
.
localScale
=
new
Vector3
(
go
.
transform
.
localScale
.
x
,
go
.
transform
.
localScale
.
y
*
-
1
,
go
.
transform
.
localScale
.
z
);
go
.
transform
.
Rotate
(
new
Vector3
(
0
,
0
,
-
90
));
// Place mid
for
(
int
i
=
(
int
)
transform
.
position
.
y
;
i
>
y
;
i
--)
{
go
=
World
.
set
(
transform
.
position
.
x
,
i
,
transform
.
position
.
z
,
mid
);
go
.
transform
.
Rotate
(
new
Vector3
(
0
,
0
,
-
90
));
}
// Place cap
go
=
World
.
set
(
y
,
transform
.
position
.
y
,
transform
.
position
.
z
,
cap
);
go
.
transform
.
Rotate
(
new
Vector3
(
0
,
0
,
-
90
));
}
// Placing up
else
{
// Place start cap and flip
GameObject
go
=
World
.
set
(
transform
.
position
,
cap
);
go
.
transform
.
Rotate
(
new
Vector3
(
0
,
0
,
90
));
// Place mid
for
(
int
i
=
(
int
)
transform
.
position
.
y
;
i
<
y
;
i
++)
{
go
=
World
.
set
(
transform
.
position
.
x
,
i
,
transform
.
position
.
z
,
mid
);
go
.
transform
.
Rotate
(
new
Vector3
(
0
,
0
,
90
));
}
// Place cap
go
=
World
.
set
(
y
,
transform
.
position
.
y
,
transform
.
position
.
z
,
cap
);
go
.
transform
.
localScale
=
new
Vector3
(
go
.
transform
.
localScale
.
x
,
go
.
transform
.
localScale
.
y
*
-
1
,
go
.
transform
.
localScale
.
z
);
go
.
transform
.
Rotate
(
new
Vector3
(
0
,
0
,
90
));
}
}
}
Assets/Scripts/MapEditor/MapEditor.cs
View file @
b30c4bd7
...
...
@@ -81,7 +81,8 @@ public class MapEditor : MonoBehaviour
{
if
(!
World
.
Ready
())
{
Debug
.
LogError
(
"World not initialized! Please set a width, height, and depth in the inspector and click \"Set\"."
);
Debug
.
LogError
(
"World not initialized!\n"
+
"Please set a width, height, and depth in the inspector and click \"Set\"."
);
return
;
}
...
...
@@ -90,27 +91,40 @@ public class MapEditor : MonoBehaviour
if
(
Tiles
==
null
)
GameObject
.
FindObjectOfType
<
MapEditor
>().
setupTilesParent
();
// Placing non-empty tile
if
(
Tile
!=
null
)
{
if
(!
World
.
posIsThis
(
pos
,
Tile
))
// Not a drag place tile
if
(
Tile
.
GetComponent
<
DragPlacement
>()
==
null
)
{
Debug
.
Log
(
"new"
);
GameObject
go
=
(
GameObject
)
GameObject
.
Instantiate
(
Tile
,
new
Vector3
(
pos
.
x
,
pos
.
y
,
Layer
),
Quaternion
.
identity
);
go
=
PrefabUtility
.
ConnectGameObjectToPrefab
(
go
,
Tile
);
go
.
transform
.
position
=
new
Vector3
(
pos
.
x
,
pos
.
y
,
Layer
);
SpriteRenderer
sr
=
go
.
GetComponent
<
SpriteRenderer
>();
if
(
sr
!=
null
)
if
(!
World
.
posIsThis
(
pos
,
Tile
))
{
sr
.
sortingOrder
=
layer
*
-
World
.
SORTING_ORDER_MULT
;
Debug
.
Log
(
"new"
);
GameObject
go
=
(
GameObject
)
GameObject
.
Instantiate
(
Tile
,
new
Vector3
(
pos
.
x
,
pos
.
y
,
Layer
),
Quaternion
.
identity
);
go
=
PrefabUtility
.
ConnectGameObjectToPrefab
(
go
,
Tile
);
go
.
transform
.
position
=
new
Vector3
(
pos
.
x
,
pos
.
y
,
Layer
);
SpriteRenderer
sr
=
go
.
GetComponent
<
SpriteRenderer
>();
if
(
sr
!=
null
)
{
sr
.
sortingOrder
=
layer
*
-
World
.
SORTING_ORDER_MULT
;
}
go
.
transform
.
parent
=
Tiles
;
World
.
set
(
pos
,
layer
,
go
);
}
go
.
transform
.
parent
=
Tiles
;
World
.
set
(
pos
,
layer
,
go
);
}
// Is a drag place tile
else
Debug
.
Log
(
"new"
);
{
if
(
DragPlacement
.
instance
==
null
)
{
// Start new drag placement
// Need to detect when not holding mouse to end drag placement
}
}
}
// Placing empty tile (delete)
else
{
World
.
set
(
pos
,
layer
,
null
);
...
...
Assets/Scripts/MapEditor/World.cs
View file @
b30c4bd7
...
...
@@ -58,19 +58,19 @@ public static class World
public
static
void
giveMap
(
GameObject
[][][]
newMap
)
{
map
=
newMap
;
}
public
static
bool
set
(
Vector3
pos
,
GameObject
go
)
{
return
set
(
pos
.
x
,
pos
.
y
,
pos
.
z
,
go
);
}
public
static
bool
set
(
Vector2
pos
,
float
z
,
GameObject
go
)
{
return
set
(
pos
.
x
,
pos
.
y
,
z
,
go
);
}
public
static
bool
set
(
Vector2
pos
,
int
z
,
GameObject
go
)
{
return
set
((
int
)
pos
.
x
,
(
int
)
pos
.
y
,
z
,
go
);
}
public
static
bool
set
(
float
x
,
float
y
,
float
z
,
GameObject
go
)
{
return
set
((
int
)
x
,
(
int
)
y
,
(
int
)
z
,
go
);
}
public
static
bool
set
(
int
x
,
int
y
,
int
z
,
GameObject
go
)
public
static
GameObject
set
(
Vector3
pos
,
GameObject
go
)
{
return
set
(
pos
.
x
,
pos
.
y
,
pos
.
z
,
go
);
}
public
static
GameObject
set
(
Vector2
pos
,
float
z
,
GameObject
go
)
{
return
set
(
pos
.
x
,
pos
.
y
,
z
,
go
);
}
public
static
GameObject
set
(
Vector2
pos
,
int
z
,
GameObject
go
)
{
return
set
((
int
)
pos
.
x
,
(
int
)
pos
.
y
,
z
,
go
);
}
public
static
GameObject
set
(
float
x
,
float
y
,
float
z
,
GameObject
go
)
{
return
set
((
int
)
x
,
(
int
)
y
,
(
int
)
z
,
go
);
}
public
static
GameObject
set
(
int
x
,
int
y
,
int
z
,
GameObject
go
)
{
if
(!
posInBounds
(
x
,
y
,
z
))
return
false
;
return
null
;
destroyPos
(
x
,
y
,
z
);
map
[
x
][
y
][
z
]
=
go
;
return
true
;
return
go
;
}
...
...
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