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
1a6a7e32
Commit
1a6a7e32
authored
Feb 23, 2017
by
Luke A Smith
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'borders' into 'master'
Moved setup from Start() to MapEditor button. See merge request
!18
parents
8c23579b
cb83e93d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
12 deletions
+34
-12
Assets/Scripts/MapEditor/MapEditor.cs
Assets/Scripts/MapEditor/MapEditor.cs
+4
-0
Assets/Scripts/Util/Borders.cs
Assets/Scripts/Util/Borders.cs
+30
-12
No files found.
Assets/Scripts/MapEditor/MapEditor.cs
View file @
1a6a7e32
...
...
@@ -146,5 +146,9 @@ public class MapEditorEditor : Editor
// Toggle on field
MapEditor
.
On
=
GUILayout
.
Toggle
(
MapEditor
.
On
,
"ON"
);
// Initialize Borders
if
(
GUILayout
.
Button
(
"Initialize Borders"
))
Borders
.
initializeAll
();
}
}
Assets/Scripts/Util/Borders.cs
View file @
1a6a7e32
...
...
@@ -4,28 +4,37 @@ using UnityEditor;
public
class
Borders
:
MonoBehaviour
{
public
int
top
=
0
,
right
=
0
,
bottom
=
0
,
left
=
0
;
// Border sizes by pixel
public
bool
setup
=
false
;
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
()
/*void Start()
{
SpriteRenderer
sr
=
GetComponent
<
SpriteRenderer
>();
if
(
sr
!=
null
)
if(!setup)
{
Texture2D
texOriginal
=
sr
.
sprite
.
texture
;
Texture2D
tex
=
(
Texture2D
)
Instantiate
(
texOriginal
);
initializeAll();
}
}*/
Color32
[]
pixels
=
tex
.
GetPixels32
();
void
init
()
{
SpriteRenderer
sr
=
GetComponent
<
SpriteRenderer
>();
if
(
sr
!=
null
)
{
Texture2D
texOriginal
=
sr
.
sprite
.
texture
;
Texture2D
tex
=
(
Texture2D
)
Instantiate
(
texOriginal
);
tex
.
SetPixels32
(
setBorders
(
pixels
,
tex
.
width
,
tex
.
height
,
checkAdjacency
()));
tex
.
Apply
(
false
);
Color32
[]
pixels
=
tex
.
GetPixels32
();
sr
.
sprite
=
Sprite
.
Create
(
tex
,
sr
.
sprite
.
rect
,
new
Vector2
(.
5f
,
.
5f
),
sr
.
sprite
.
pixelsPerUnit
);
}
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
);
setup
=
true
;
}
}
Direction
checkAdjacency
()
...
...
@@ -61,7 +70,6 @@ public class Borders : MonoBehaviour
{
if
((
d
&
Direction
.
t
)
>
0
)
// top
{
Debug
.
Log
(
"set top"
);
for
(
int
i
=
left
;
i
<
width
-
right
;
i
++)
{
for
(
int
j
=
height
-
top
*
2
;
j
<
height
-
top
;
j
++)
...
...
@@ -103,4 +111,14 @@ public class Borders : MonoBehaviour
return
pixels
;
}
public
static
void
initializeAll
()
{
Borders
[]
bs
=
GameObject
.
FindObjectsOfType
<
Borders
>();
foreach
(
Borders
b
in
bs
)
{
b
.
init
();
}
}
}
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