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
ec6eef23
Commit
ec6eef23
authored
Feb 23, 2017
by
Luke A Smith
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'borders' into 'master'
Borders See merge request
!15
parents
36b87a7e
9d269d1e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
1 deletion
+123
-1
Assets/Scripts/MapEditor/World.cs
Assets/Scripts/MapEditor/World.cs
+6
-1
Assets/Scripts/Util/Borders.cs
Assets/Scripts/Util/Borders.cs
+105
-0
Assets/Scripts/Util/Borders.cs.meta
Assets/Scripts/Util/Borders.cs.meta
+12
-0
No files found.
Assets/Scripts/MapEditor/World.cs
View file @
ec6eef23
...
...
@@ -37,6 +37,11 @@ public static class World
setupWithGOs
();
}
public
static
void
setup
()
{
setup
(
50
,
50
,
3
);
}
private
static
void
instantiateMap
()
{
map
=
new
GameObject
[
width
][][];
...
...
@@ -113,7 +118,7 @@ public static class World
{
if
(
x
<
0
||
y
<
0
||
z
<
0
||
x
>=
width
||
y
>=
height
||
z
>=
depth
)
{
Debug
.
LogWarning
(
"Pos out of bounds!"
);
//
Debug.LogWarning("Pos out of bounds!");
return
false
;
}
return
true
;
...
...
Assets/Scripts/Util/Borders.cs
0 → 100644
View file @
ec6eef23
using
UnityEngine
;
using
UnityEditor
;
public
class
Borders
:
MonoBehaviour
{
public
int
top
=
2
,
right
=
2
,
bottom
=
2
,
left
=
2
;
// Border sizes by pixel
private
enum
Direction
{
none
,
t
,
r
,
rt
,
b
,
bt
,
br
,
brt
,
l
,
lt
,
lr
,
lrt
,
lb
,
lbt
,
lbr
,
lbrt
}
// Binary representation:
// lbrt
// 0000
// Use this for initialization
void
Start
()
{
SpriteRenderer
sr
=
GetComponent
<
SpriteRenderer
>();
if
(
sr
!=
null
)
{
Texture2D
texOriginal
=
sr
.
sprite
.
texture
;
Texture2D
tex
=
(
Texture2D
)
Instantiate
(
texOriginal
);
Color32
[]
pixels
=
tex
.
GetPixels32
();
tex
.
SetPixels32
(
setBorders
(
pixels
,
tex
.
width
,
tex
.
height
,
checkAdjacency
()));
tex
.
Apply
(
false
);
sr
.
sprite
=
Sprite
.
Create
(
tex
,
sr
.
sprite
.
rect
,
new
Vector2
(.
5f
,
.
5f
),
sr
.
sprite
.
pixelsPerUnit
);
}
}
Direction
checkAdjacency
()
{
Direction
d
=
Direction
.
none
;
Vector3
pos
=
transform
.
position
;
if
(!
World
.
Ready
())
{
World
.
setup
();
}
if
(!
World
.
posInBounds
(
pos
+
Vector3
.
up
)
||
World
.
posIsThis
(
pos
+
Vector3
.
up
,
(
GameObject
)
PrefabUtility
.
GetPrefabObject
(
this
)))
{
d
|=
Direction
.
t
;
}
if
(!
World
.
posInBounds
(
pos
+
Vector3
.
left
)
||
World
.
posIsThis
(
pos
+
Vector3
.
left
,
(
GameObject
)
PrefabUtility
.
GetPrefabObject
(
this
)))
{
d
|=
Direction
.
r
;
}
if
(!
World
.
posInBounds
(
pos
+
Vector3
.
down
)
||
World
.
posIsThis
(
pos
+
Vector3
.
down
,
(
GameObject
)
PrefabUtility
.
GetPrefabObject
(
this
)))
{
d
|=
Direction
.
b
;
}
if
(!
World
.
posInBounds
(
pos
+
Vector3
.
right
)
||
World
.
posIsThis
(
pos
+
Vector3
.
right
,
(
GameObject
)
PrefabUtility
.
GetPrefabObject
(
this
)))
{
d
|=
Direction
.
l
;
}
return
d
;
}
Color32
[]
setBorders
(
Color32
[]
pixels
,
int
width
,
int
height
,
Direction
d
)
{
if
((
d
&
Direction
.
t
)
>
0
)
// top
{
for
(
int
i
=
left
;
i
<
width
-
right
;
i
++)
{
for
(
int
j
=
height
-
top
*
2
;
j
<
height
-
top
;
j
++)
{
pixels
[
j
*
width
+
i
]
=
pixels
[(
j
+
top
)*
width
+
i
];
}
}
}
if
((
d
&
Direction
.
r
)
>
0
)
// right
{
for
(
int
j
=
bottom
;
j
<
height
-
top
;
j
++)
{
for
(
int
i
=
left
;
i
<
left
*
2
;
i
++)
{
pixels
[
j
*
width
+
i
]
=
pixels
[
j
*
width
+
(
i
-
left
)];
}
}
}
if
((
d
&
Direction
.
b
)
>
0
)
// bottom
{
for
(
int
i
=
left
;
i
<
width
-
right
;
i
++)
{
for
(
int
j
=
bottom
;
j
<
bottom
*
2
;
j
++)
{
pixels
[
j
*
width
+
i
]
=
pixels
[(
j
-
bottom
)*
width
+
i
];
}
}
}
if
((
d
&
Direction
.
l
)
>
0
)
// left
{
for
(
int
j
=
bottom
;
j
<
height
-
top
;
j
++)
{
for
(
int
i
=
width
-
right
*
2
;
i
<
width
-
right
;
i
++)
{
pixels
[
j
*
width
+
i
]
=
pixels
[
j
*
width
+
(
i
+
right
)];
}
}
}
return
pixels
;
}
}
Assets/Scripts/Util/Borders.cs.meta
0 → 100644
View file @
ec6eef23
fileFormatVersion: 2
guid: 99517dc8d8fd9524a90fa289b59bf635
timeCreated: 1487785654
licenseType: Free
MonoImporter:
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