Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mr BigSock
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gard Aleksander Furre
Mr BigSock
Commits
c15f043b
Commit
c15f043b
authored
2 years ago
by
Robin Halseth Sandvik
Browse files
Options
Downloads
Patches
Plain Diff
Made ItemPref use the icon of the item it represents.
parent
282095da
No related branches found
Branches containing commit
No related tags found
1 merge request
!45
Alexander
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
MrBigsock/Assets/Code/PlayerController.cs
+71
-71
71 additions, 71 deletions
MrBigsock/Assets/Code/PlayerController.cs
MrBigsock/Assets/Code/UI/ItemPref.cs
+56
-47
56 additions, 47 deletions
MrBigsock/Assets/Code/UI/ItemPref.cs
with
127 additions
and
118 deletions
MrBigsock/Assets/Code/PlayerController.cs
+
71
−
71
View file @
c15f043b
...
...
@@ -16,33 +16,33 @@ namespace BigSock {
public
partial
class
PlayerController
:
Character
{
public
UtilBar
utilBar
;
public
UtilBar
utilBar
;
public
float
collisionOffset
=
0.05f
;
public
ContactFilter2D
movementFilter
;
public
GameObject
attack
;
public
float
collisionOffset
=
0.05f
;
public
ContactFilter2D
movementFilter
;
public
GameObject
attack
;
Vector2
movementInput
;
SpriteRenderer
spriteRenderer
;
//Rigidbody2D rb;
Animator
animator
;
List
<
RaycastHit2D
>
castCollisions
=
new
List
<
RaycastHit2D
>();
Vector2
movementInput
;
SpriteRenderer
spriteRenderer
;
//Rigidbody2D rb;
Animator
animator
;
List
<
RaycastHit2D
>
castCollisions
=
new
List
<
RaycastHit2D
>();
bool
canMove
=
true
;
bool
canMove
=
true
;
protected
IAttack
_testAttack
;
protected
IAttack
_testAttack2
;
protected
IAbility
_dodge
;
protected
IAttack
_testAttack
;
protected
IAttack
_testAttack2
;
protected
IAbility
_dodge
;
public
DateTime
NextTimeCanAttack
{
get
;
private
set
;
}
=
DateTime
.
Now
;
public
DateTime
NextTimeCanAttack
{
get
;
private
set
;
}
=
DateTime
.
Now
;
public
PlayerController
()
{
{
TryPickUpItem
(
ItemService
.
SINGLETON
.
Get
(
201
));
TryPickUpItem
(
ItemService
.
SINGLETON
.
Get
(
201
));
TryPickUpItem
(
ItemService
.
SINGLETON
.
Get
(
202
));
...
...
@@ -51,70 +51,70 @@ namespace BigSock {
// Start is called before the first frame update
protected
override
void
Start
()
{
base
.
Start
();
{
base
.
Start
();
utilBar
?.
WithXP
((
int
)
xp
,
(
int
)
maxXp
)
?.
WithHealth
(
Convert
.
ToInt32
(
HP
),
Convert
.
ToInt32
(
MaxHP
));
utilBar
?.
WithXP
((
int
)
xp
,
(
int
)
maxXp
)
?.
WithHealth
(
Convert
.
ToInt32
(
HP
),
Convert
.
ToInt32
(
MaxHP
));
animator
=
GetComponent
<
Animator
>();
spriteRenderer
=
GetComponent
<
SpriteRenderer
>();
animator
=
GetComponent
<
Animator
>();
spriteRenderer
=
GetComponent
<
SpriteRenderer
>();
//!! DEBUG: Add item to player at start to test if it works.
/*
TryPickUpItem(ItemService.SINGLETON.Get(201));
TryPickUpItem(ItemService.SINGLETON.Get(201));
TryPickUpItem(ItemService.SINGLETON.Get(202));
TryPickUpItem(ItemService.SINGLETON.Get(101));
*/
//var tmp = PrefabService.SINGLETON;
var
tmp
=
SpriteService
.
SINGLETON
;
//!! DEBUG: Add item to player at start to test if it works.
/*
TryPickUpItem(ItemService.SINGLETON.Get(201));
TryPickUpItem(ItemService.SINGLETON.Get(201));
TryPickUpItem(ItemService.SINGLETON.Get(202));
TryPickUpItem(ItemService.SINGLETON.Get(101));
*/
//var tmp = PrefabService.SINGLETON;
var
tmp
=
SpriteService
.
SINGLETON
;
_testAttack
=
(
IAttack
)
AbilityService
.
SINGLETON
.
Get
(
101
);
_testAttack2
=
(
IAttack
)
AbilityService
.
SINGLETON
.
Get
(
102
);
_dodge
=
AbilityService
.
SINGLETON
.
Get
(
201
);
}
_testAttack
=
(
IAttack
)
AbilityService
.
SINGLETON
.
Get
(
101
);
_testAttack2
=
(
IAttack
)
AbilityService
.
SINGLETON
.
Get
(
102
);
_dodge
=
AbilityService
.
SINGLETON
.
Get
(
201
);
}
private
void
FixedUpdate
()
{
if
(
canMove
)
{
// If movement input is not 0, try to move
if
(
movementInput
!=
Vector2
.
zero
){
bool
success
=
TryMove
(
movementInput
);
if
(!
success
)
{
success
=
TryMove
(
new
Vector2
(
movementInput
.
x
,
0
));
}
if
(!
success
)
{
success
=
TryMove
(
new
Vector2
(
0
,
movementInput
.
y
));
}
animator
.
SetBool
(
"isMoving"
,
success
);
}
else
{
animator
.
SetBool
(
"isMoving"
,
false
);
}
// Set direction of sprite to movement direction
var
mouse
=
Camera
.
main
.
ScreenToWorldPoint
(
Input
.
mousePosition
);
var
pos
=
transform
.
position
;
var
temp
=
(
mouse
-
pos
);
//temp.z = 0;
//direction = temp.normalized;
if
(
temp
.
x
<
0
)
{
spriteRenderer
.
flipX
=
true
;
}
else
if
(
temp
.
x
>
0
)
{
spriteRenderer
.
flipX
=
false
;
}
}
if
(
canMove
)
{
// If movement input is not 0, try to move
if
(
movementInput
!=
Vector2
.
zero
){
bool
success
=
TryMove
(
movementInput
);
if
(!
success
)
{
success
=
TryMove
(
new
Vector2
(
movementInput
.
x
,
0
));
}
if
(!
success
)
{
success
=
TryMove
(
new
Vector2
(
0
,
movementInput
.
y
));
}
animator
.
SetBool
(
"isMoving"
,
success
);
}
else
{
animator
.
SetBool
(
"isMoving"
,
false
);
}
// Set direction of sprite to movement direction
var
mouse
=
Camera
.
main
.
ScreenToWorldPoint
(
Input
.
mousePosition
);
var
pos
=
transform
.
position
;
var
temp
=
(
mouse
-
pos
);
//temp.z = 0;
//direction = temp.normalized;
if
(
temp
.
x
<
0
)
{
spriteRenderer
.
flipX
=
true
;
}
else
if
(
temp
.
x
>
0
)
{
spriteRenderer
.
flipX
=
false
;
}
}
}
...
...
This diff is collapsed.
Click to expand it.
MrBigsock/Assets/Code/UI/ItemPref.cs
+
56
−
47
View file @
c15f043b
...
...
@@ -7,52 +7,61 @@ using BigSock.Item;
namespace
BigSock.UI
{
public
class
ItemPref
:
MonoBehaviour
,
IPointerDownHandler
,
IBeginDragHandler
,
IEndDragHandler
,
IDragHandler
{
public
IItem
item
;
public
ItemSlot
itemSlot
;
private
RectTransform
rectTransform
;
private
CanvasGroup
canvasGroup
;
public
Vector2
?
position
;
private
void
Awake
()
{
rectTransform
=
GetComponent
<
RectTransform
>();
canvasGroup
=
GetComponent
<
CanvasGroup
>();
}
public
void
OnBeginDrag
(
PointerEventData
eventData
)
{
position
=
transform
.
position
;
canvasGroup
.
alpha
=
.
6f
;
canvasGroup
.
blocksRaycasts
=
false
;
}
public
void
OnDrag
(
PointerEventData
eventData
)
{
rectTransform
.
anchoredPosition
+=
eventData
.
delta
;
}
public
void
OnEndDrag
(
PointerEventData
eventData
)
{
if
(
position
!=
null
)
{
transform
.
position
=
position
.
Value
;
}
canvasGroup
.
alpha
=
1f
;
canvasGroup
.
blocksRaycasts
=
true
;
}
public
void
OnPointerDown
(
PointerEventData
eventData
)
{
}
}
public
class
ItemPref
:
MonoBehaviour
,
IPointerDownHandler
,
IBeginDragHandler
,
IEndDragHandler
,
IDragHandler
{
public
IItem
item
;
public
ItemSlot
itemSlot
;
private
RectTransform
rectTransform
;
private
CanvasGroup
canvasGroup
;
public
Vector2
?
position
;
void
Start
()
{
// Change the sprite if the item has one.
var
sprite
=
item
?.
Icon
;
if
(
sprite
!=
null
)
GetComponent
<
UnityEngine
.
UI
.
Image
>().
overrideSprite
=
sprite
;
}
private
void
Awake
()
{
rectTransform
=
GetComponent
<
RectTransform
>();
canvasGroup
=
GetComponent
<
CanvasGroup
>();
}
public
void
OnBeginDrag
(
PointerEventData
eventData
)
{
position
=
transform
.
position
;
canvasGroup
.
alpha
=
.
6f
;
canvasGroup
.
blocksRaycasts
=
false
;
}
public
void
OnDrag
(
PointerEventData
eventData
)
{
rectTransform
.
anchoredPosition
+=
eventData
.
delta
;
}
public
void
OnEndDrag
(
PointerEventData
eventData
)
{
if
(
position
!=
null
)
{
transform
.
position
=
position
.
Value
;
}
canvasGroup
.
alpha
=
1f
;
canvasGroup
.
blocksRaycasts
=
true
;
}
public
void
OnPointerDown
(
PointerEventData
eventData
)
{
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment