Here my listing:
Code: Select all
public class StorageHolderLuaWrapper : MonoBehaviour
{
[Header("General settings")]
[SerializeField]
private ItemsDataBase dataBase;
[SerializeField]
private StorageHolder storageHolder;
private void OnEnable()
{
Lua.RegisterFunction($"{nameof(HelloWorld)}", this, SymbolExtensions.GetMethodInfo<string>((message) => HelloWorld(message)));
Lua.RegisterFunction($"{nameof(Contains)}", this, SymbolExtensions.GetMethodInfo<string, bool>((itemID) => Contains(itemID)));
Lua.RegisterFunction($"{nameof(AddItem)}", this, SymbolExtensions.GetMethodInfo<string>((itemID) => AddItem(itemID)));
//Lua.RegisterFunction($"{nameof(AddItemAmount)}", this, SymbolExtensions.GetMethodInfo<string>((message) => AddItemAmount(message)));
Lua.RegisterFunction($"{nameof(AddItemAmount)}", this, SymbolExtensions.GetMethodInfo<string, double>((itemID, amount) => AddItemAmount(itemID, amount)));
Lua.RegisterFunction($"{nameof(RemoveItem)}", this, SymbolExtensions.GetMethodInfo<string>((itemID) => RemoveItem(itemID)));
Lua.RegisterFunction($"{nameof(RemoveItemAmount)}", this, SymbolExtensions.GetMethodInfo<string>((message) => RemoveItemAmount(message)));
}
private void OnDisable()
{
Lua.UnregisterFunction($"{nameof(HelloWorld)}");
Lua.UnregisterFunction($"{nameof(Contains)}");
Lua.UnregisterFunction($"{nameof(AddItem)}");
Lua.UnregisterFunction($"{nameof(AddItemAmount)}");
Lua.UnregisterFunction($"{nameof(RemoveItem)}");
Lua.UnregisterFunction($"{nameof(RemoveItemAmount)}");
}
private void AddItem(string itemID)
{
var itemObject = dataBase[itemID];
storageHolder.Storage.TryToAdd(itemObject, 1, out _);
Debug.Log($"[{nameof(StorageHolderLuaWrapper)}] {name} says: {nameof(AddItem)}: {itemID}");
}
private void AddItemAmount(string message)
{
string[] array = message.Split(';');
if (array.Length == 2)
{
string itemID = array[0];
int.TryParse(array[1], out var amount);
var itemObject = dataBase[itemID];
storageHolder.Storage.TryToAdd(itemObject, amount, out _);
}
else
{
Debug.LogError($"[{nameof(StorageHolderLuaWrapper)}] can't parse message: {message}");
}
Debug.Log($"[{nameof(StorageHolderLuaWrapper)}] {name} says: {nameof(AddItemAmount)}: {message}");
}
private void AddItemAmount(string itemID, double amount)
{
int amountInt = (int)amount;
var itemObject = dataBase[itemID];
storageHolder.Storage.TryToAdd(itemObject, amountInt, out _);
Debug.Log($"[{nameof(StorageHolderLuaWrapper)}] {name} says: {nameof(AddItemAmount)}: {itemID} х {amountInt}");
}
private void RemoveItem(string itemID)
{
var itemObject = dataBase[itemID];
storageHolder.Storage.TryToRemove(itemObject, 1);
Debug.Log($"[{nameof(StorageHolderLuaWrapper)}] {name} says: {nameof(RemoveItem)}: {itemID}");
}
private void RemoveItemAmount(string message)
{
string[] array = message.Split(';');
if (array.Length == 2)
{
string itemID = array[0];
int.TryParse(array[1], out var amount);
var itemObject = dataBase[itemID];
storageHolder.Storage.TryToRemove(itemObject, amount);
}
else
{
Debug.LogError($"[{nameof(StorageHolderLuaWrapper)}] can't parse message: {message}");
}
Debug.Log($"[{nameof(StorageHolderLuaWrapper)}] {name} says: {nameof(RemoveItemAmount)}: {message}");
}
private bool Contains(string itemID)
{
Debug.Log($"[{nameof(StorageHolderLuaWrapper)}] {name} says: {nameof(Contains)}: {itemID}");
var itemObject = dataBase[itemID];
return storageHolder.Storage.Contains(itemObject);
}
private void HelloWorld(string message)
{
Debug.Log($"[{nameof(StorageHolderLuaWrapper)}] {name} says: {message}");
}
Assets\StorageHolderLuaWrapper.cs(35,106): error CS1593: Delegate 'Func<string, double>' does not take 2 arguments
I see your Lua Wizzard allows me to create methods that have multiple parameters. I've double-checked your docs, scene example, script templates, and even this forum, but didn't find any examples for my case. Can you help me?