@@ -18,6 +18,12 @@ public class InventoryController : MonoBehaviour
18
18
19
19
public List < InventoryItem > initialItems = new List < InventoryItem > ( ) ;
20
20
21
+ [ SerializeField ]
22
+ private AudioClip dropClip ;
23
+
24
+ [ SerializeField ]
25
+ private AudioSource audioSource ;
26
+
21
27
private void Start ( )
22
28
{
23
29
PrepareUI ( ) ;
@@ -60,15 +66,49 @@ private void HandleItemActionRequest(int itemIndex)
60
66
InventoryItem inventoryItem = inventoryData . GetItemAt ( itemIndex ) ;
61
67
if ( inventoryItem . IsEmpty )
62
68
return ;
69
+
63
70
IItemAction itemAction = inventoryItem . item as IItemAction ;
64
71
if ( itemAction != null )
65
72
{
66
- itemAction . PerformAction ( gameObject , null ) ;
73
+
74
+ inventoryUI . ShowItemAction ( itemIndex ) ;
75
+ inventoryUI . AddAction ( itemAction . ActionName , ( ) => PerformAction ( itemIndex ) ) ;
76
+ }
77
+
78
+ IDestroyableItem destroyableItem = inventoryItem . item as IDestroyableItem ;
79
+ if ( destroyableItem != null )
80
+ {
81
+ inventoryUI . AddAction ( "Drop" , ( ) => DropItem ( itemIndex , inventoryItem . quantity ) ) ;
67
82
}
83
+
84
+ }
85
+
86
+ private void DropItem ( int itemIndex , int quantity )
87
+ {
88
+ inventoryData . RemoveItem ( itemIndex , quantity ) ;
89
+ inventoryUI . ResetSelection ( ) ;
90
+ audioSource . PlayOneShot ( dropClip ) ;
91
+ }
92
+
93
+ public void PerformAction ( int itemIndex )
94
+ {
95
+ InventoryItem inventoryItem = inventoryData . GetItemAt ( itemIndex ) ;
96
+ if ( inventoryItem . IsEmpty )
97
+ return ;
98
+
68
99
IDestroyableItem destroyableItem = inventoryItem . item as IDestroyableItem ;
69
- if ( destroyableItem != null )
100
+ if ( destroyableItem != null )
101
+ {
102
+ inventoryData . RemoveItem ( itemIndex , 1 ) ;
103
+ }
104
+
105
+ IItemAction itemAction = inventoryItem . item as IItemAction ;
106
+ if ( itemAction != null )
70
107
{
71
- inventoryData . RemoveItem ( itemIndex , 1 ) ;
108
+ itemAction . PerformAction ( gameObject , inventoryItem . itemState ) ;
109
+ audioSource . PlayOneShot ( itemAction . actionSFX ) ;
110
+ if ( inventoryData . GetItemAt ( itemIndex ) . IsEmpty )
111
+ inventoryUI . ResetSelection ( ) ;
72
112
}
73
113
}
74
114
0 commit comments