Lua的table 表格式
local myParams = {
animation = {
duration = 10.0;
time_function = "ease-in";
delay = 0;
islocal = true;
};
keyframes = {
[0] = {pos = {x = -85,y = -143,z = 0}, alpha = 1, scale = {x = 1,y=1,z=1}, rotate = {x=0,y=0,z=0}, color = {x = 255,y = 255,z = 255},};
[50] = {pos = {x = 0,y = 0,z = 0}, alpha = 0.4, scale = {x = 2,y=2,z=2}, rotate = {x=180,y=180,z=0}, color = {x = 255,y = 0,z = 0},};
[100] = {pos = {x = 100,y = -143,z = 0}, alpha = 1, scale = {x = 1,y=1,z=1}, rotate = {x=0,y=0,z=0}, color = {x= 255,y = 255, z = 10},};
};
};
将之转换为HashTable格式
private int Lua_FlyAction(ILuaState lua)
{
LuaObject luaObj = LuaObject.GetLuaObject(lua, 2);
if (luaObj == null)
return 0;
if (lua.Type(3) != LuaType.LUA_TTABLE)
{
return 0;
}
Hashtable hashTable = MoveControllerAdaptHasHTable(lua);
moveController.DoFlyEffect(luaObj.transform, hashTable);
return 0;
}
// zsy add
private Hashtable MoveControllerAdaptHasHTable(ILuaState lua)
{
LuaObjWithCallFun callBackFun = new LuaObjWithCallFun();
//print("*********** state len" + lua.GetTop());
Hashtable hashTable = new Hashtable();
lua.PushValue(3);
lua.PushNil();
while (lua.Next(-2))
{
string key = lua.L_CheckString(-2);
switch (key)
{
case "animation":
{
Hashtable animation = new Hashtable();
lua.PushValue(-1);
lua.PushNil();
float value = 0;
string strtype = "ease";
bool blean = true;
while (lua.Next(-2))
{
string childkey = lua.L_CheckString(-2);
switch (lua.Type(-1))
{
case LuaType.LUA_TNUMBER:
value = (float)lua.L_CheckNumber(-1);
animation.Add(childkey, value);
break;
case LuaType.LUA_TBOOLEAN :
blean = lua.ToBoolean(-1);
animation.Add(childkey, blean);
break;
case LuaType.LUA_TSTRING:
strtype = lua.L_CheckString(-1);
animation.Add(childkey, strtype);
break;
default:
break;
}
lua.Pop(1);
}
lua.Pop(1);
hashTable.Add(key, animation);
break;
}
case "keyframes":
{
Hashtable keyframes = new Hashtable();
lua.PushValue(-1);
lua.PushNil();
int numkey = -1;
string strkey = "from";
while (lua.Next(-2))
{
Hashtable tempHash = new Hashtable();
if (lua.Type(-1) == LuaType.LUA_TTABLE)
{
lua.PushValue(-1);
lua.PushNil();
while (lua.Next(-2))
{
string child2key = lua.L_CheckString(-2);
switch (child2key)
{
case "pos":
case "scale":
case "rotate":
case "color":
Vector3 vecValue = GetVector3(lua, -1);
tempHash.Add(child2key, vecValue);
break;
case "alpha":
float alpha = (float)lua.L_CheckNumber(-1);
tempHash.Add(child2key, alpha);
break;
default:
break;
}
lua.Pop(1);
}
lua.Pop(1);
}
if (lua.Type(-2) == LuaType.LUA_TSTRING)
{
strkey = lua.L_CheckString(-2);
keyframes.Add(strkey, tempHash);
}
else if (lua.Type(-2) == LuaType.LUA_TNUMBER)
{
numkey = (int)lua.L_CheckInteger(-2);
keyframes.Add(numkey, tempHash);
}
lua.Pop(1);
}
lua.Pop(1);
hashTable.Add(key, keyframes);
break;
}
default:
break;
}
lua.Pop(1);
}
lua.Pop(1);
//print("***********AAAAAAA state len" + lua.GetTop());
return hashTable;
}