|
|
@ -16,15 +16,17 @@ public class Inventory : ScriptableObject |
|
|
|
|
|
|
|
public System.Action OnItemsUpdated; |
|
|
|
|
|
|
|
public void Add(LogicBlock element,int count = 1, bool isInfinit = false) |
|
|
|
public void Add(LogicBlock element, int count = 1, bool isInfinit = false) |
|
|
|
{ |
|
|
|
|
|
|
|
Data data = new Data { |
|
|
|
Data data = new Data |
|
|
|
{ |
|
|
|
element = element, |
|
|
|
Count = count, |
|
|
|
isInfinit = isInfinit }; |
|
|
|
isInfinit = isInfinit |
|
|
|
}; |
|
|
|
|
|
|
|
Add(data); |
|
|
|
Add(data); |
|
|
|
} |
|
|
|
|
|
|
|
public void Add(Data data) |
|
|
@ -43,26 +45,30 @@ public class Inventory : ScriptableObject |
|
|
|
OnItemsUpdated?.Invoke(); |
|
|
|
} |
|
|
|
|
|
|
|
public void Remove(LogicBlock element) { |
|
|
|
public void Remove(LogicBlock element) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
if (!_bagItems.Exists(p => p.element.isSameType(element))) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Data data = _bagItems.First(p => p.element.isSameType(element)); |
|
|
|
|
|
|
|
if (!data.isInfinit) |
|
|
|
{ |
|
|
|
data.Count--; |
|
|
|
if (data.Count > data.minCount) |
|
|
|
data.Count--; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (data.Count <= 0) |
|
|
|
_bagItems.Remove(data); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OnItemsUpdated?.Invoke(); |
|
|
|
} |
|
|
|
|
|
|
@ -85,7 +91,7 @@ public class Inventory : ScriptableObject |
|
|
|
|
|
|
|
foreach (Data data in copy.BagItems) |
|
|
|
{ |
|
|
|
Data dataCopy = new Data(data.element,data.Count,data.isInfinit); |
|
|
|
Data dataCopy = new Data(data.element, data.Count, data.isInfinit,data.minCount); |
|
|
|
retVal._bagItems.Add(dataCopy); |
|
|
|
} |
|
|
|
|
|
|
@ -98,16 +104,18 @@ public class Inventory : ScriptableObject |
|
|
|
{ |
|
|
|
public LogicBlock element; |
|
|
|
public int Count; |
|
|
|
public int minCount; |
|
|
|
public bool isInfinit = false; |
|
|
|
|
|
|
|
|
|
|
|
public Data() { } |
|
|
|
|
|
|
|
public Data(LogicBlock element, int Count, bool isInfinit) |
|
|
|
{ |
|
|
|
public Data(LogicBlock element, int Count, bool isInfinit, int minCount = 0) |
|
|
|
{ |
|
|
|
this.element = element; |
|
|
|
this.Count = Count; |
|
|
|
this.isInfinit = isInfinit; |
|
|
|
this.minCount = minCount; |
|
|
|
} |
|
|
|
} |
|
|
|
} |