add project files
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using OHM.UnityToolkit;
|
||||
|
||||
namespace OHM.UnityToolkit.Inventory
|
||||
{
|
||||
[Serializable]
|
||||
public class Inventory<TUType> : SerializableDictionary<TUType, long>
|
||||
{
|
||||
public long GetCount(TUType type)
|
||||
{
|
||||
long count;
|
||||
TryGetValue(type, out count);
|
||||
return count;
|
||||
}
|
||||
|
||||
public void AddReward(TransactionUnit<TUType> tu)
|
||||
{
|
||||
AddReward(tu.type, tu.count);
|
||||
}
|
||||
|
||||
public void AddReward(TUType tuType, long count)
|
||||
{
|
||||
if (ContainsKey(tuType))
|
||||
{
|
||||
base[tuType] = base[tuType] + count;
|
||||
}
|
||||
else
|
||||
{
|
||||
Add(tuType, count);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddRewards<T>(TransactionUnitList<T> rewards)
|
||||
{
|
||||
}
|
||||
|
||||
public void SetCount(TUType type, long count)
|
||||
{
|
||||
base[type] = count;
|
||||
}
|
||||
|
||||
public bool HasCost(TransactionUnit<TUType> tu)
|
||||
{
|
||||
if (tu.count == 0L)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!ContainsKey(tu.type))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return base[tu.type] >= tu.count;
|
||||
}
|
||||
|
||||
public bool PayCost(TransactionUnit<TUType> tu)
|
||||
{
|
||||
if (tu.count == 0L)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!HasCost(tu))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
base[tu.type] = base[tu.type] - tu.count;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e81f91e0ef1433fe7eb4db7e1c223d07
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit.Inventory
|
||||
{
|
||||
public class TUTypeStrId<EnumType>
|
||||
{
|
||||
[SerializeField]
|
||||
public EnumType type;
|
||||
|
||||
[SerializeField]
|
||||
public string id;
|
||||
|
||||
public TUTypeStrId(EnumType type, string id)
|
||||
{
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return new { type, id }.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return Equals(obj as TUTypeStrId<EnumType>);
|
||||
}
|
||||
|
||||
public bool Equals(TUTypeStrId<EnumType> obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!EqualityComparer<EnumType>.Default.Equals(type, obj.type))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return obj.id == id;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db5914e74cbdcc0a236f5d964c4ae678
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit.Inventory
|
||||
{
|
||||
[Serializable]
|
||||
public class TransactionUnitList<TUType>
|
||||
{
|
||||
[SerializeField]
|
||||
public List<TUType> content = new List<TUType>();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64bd80db38c5011668c87a46a676156e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit.Inventory
|
||||
{
|
||||
[Serializable]
|
||||
public class TransactionUnit<TUType>
|
||||
{
|
||||
public TUType type;
|
||||
|
||||
public long count;
|
||||
|
||||
public TransactionUnit(TUType type, long count)
|
||||
{
|
||||
this.type = type;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4cd7a1d785b8f6e443ab5f6821ffc22
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user