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
11c39c2b
Commit
11c39c2b
authored
2 years ago
by
Robin Halseth Sandvik
Browse files
Options
Downloads
Patches
Plain Diff
Improved commenting and code readability.
parent
17ad2e6d
No related branches found
Branches containing commit
No related tags found
1 merge request
!53
ToolTips, new ability parameter system & misc clean ups.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MrBigsock/Assets/Code/UI/ItemSlot.cs
+36
-27
36 additions, 27 deletions
MrBigsock/Assets/Code/UI/ItemSlot.cs
with
36 additions
and
27 deletions
MrBigsock/Assets/Code/UI/ItemSlot.cs
+
36
−
27
View file @
11c39c2b
...
...
@@ -14,48 +14,57 @@ namespace BigSock.UI
public
ItemPref
item
;
public
Inventory
inventory
;
// Indicates if the special update code has ran yet.
bool
firstRan
=
false
;
public
void
Start
()
{
// Set the change indicator to false.
transform
.
hasChanged
=
false
;
if
(
transform
.
hasChanged
)
{
//Debug.Log($"[ItemSlot.Start({GetInstanceID()})] {transform.position}");
}
}
public
void
Update
()
{
// If it hasn't ran before, and the position has changed, update the ItemPref.
/*
If it hasn't ran before, and the position has changed, update the ItemPref.
- This is to move the item to the item slot when it starts
- This has to be this way because the item slot is hoisted in the corner until this point.
*/
if
(!
firstRan
&&
transform
.
hasChanged
)
{
transform
.
hasChanged
=
false
;
firstRan
=
true
;
if
(
item
!=
null
)
{
//Debug.Log($"[ItemSlot.Update({GetInstanceID()})] Item: {item?.transform?.position}, Slot: {transform.position}");
if
(
item
!=
null
)
item
.
transform
.
position
=
transform
.
position
;
}
}
}
public
void
OnDrop
(
PointerEventData
eventData
)
{
if
(
eventData
.
pointerDrag
!=
null
)
{
var
itemPref
=
eventData
.
pointerDrag
.
GetComponent
<
ItemPref
>();
if
(
itemPref
!=
null
)
{
var
didMove
=
inventory
.
MoveItem
(
itemPref
.
item
,
itemPref
.
itemSlot
.
inventoryType
,
itemPref
.
itemSlot
.
position
,
inventoryType
,
position
);
if
(
didMove
)
{
itemPref
.
itemSlot
.
item
=
null
;
itemPref
.
itemSlot
=
this
;
item
=
itemPref
;
eventData
.
pointerDrag
.
transform
.
position
=
transform
.
position
;
itemPref
.
position
=
null
;
}
}
}
/*
When the user drops an item on this slot, try to move them
*/
public
void
OnDrop
(
PointerEventData
eventData
)
{
// Get the item prefab that was dropped.
var
itemPref
=
eventData
?.
pointerDrag
?.
GetComponent
<
ItemPref
>();
// Cancel if we didn't move an item prefab, or it was empty.
if
(
itemPref
?.
item
==
null
)
return
;
// Try to move the item in the inventory.
var
didMove
=
inventory
.
MoveItem
(
itemPref
.
item
,
itemPref
.
itemSlot
.
inventoryType
,
itemPref
.
itemSlot
.
position
,
inventoryType
,
position
);
// If we successfully moved the item in the inventory: update the gui.
if
(
didMove
)
{
itemPref
.
itemSlot
.
item
=
null
;
// Remove this from the other slot.
itemPref
.
itemSlot
=
this
;
// Make this its new slot.
item
=
itemPref
;
// Make it the item in this slot.
// Place the item centered over this slot.
eventData
.
pointerDrag
.
transform
.
position
=
transform
.
position
;
itemPref
.
position
=
null
;
}
}
}
}
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