这是该Itween.MoveTo
功能的直接文档。

oncompleteparams 期望Object
作为参数。这意味着几乎任何数据类型都可以传递给它。例如,string
, bool
, int
, float
, double
, 和object instance
是可以传递给它的数据类型之一。
在回调方面,您使回调函数以 Object 作为参数。在回调函数中,您将Object
参数转换为您传递给它的数据类型的类型。
例子:
"oncomplete", "afterPlayerMove",
"oncompleteparams", 5)
打回来:
public void afterPlayerMove(object cmpParams)
{
Debug.Log("Result" + (int)cmpParams);
}
如您所见,我们将 5 传递给oncompleteparams
函数,而 5 是一个整数。在afterPlayerMove
回调函数中,我们将其转换回整数以获取结果。
在您的示例中,您使用iTween.Hash
了,oncompleteparams
所以您必须转换为,Hashtable
因为 iTween.Hash 返回Hashtable
。之后,要获取 Hashtable 中的值,您也必须转换为该类型。
"oncomplete", "afterPlayerMove",
"oncompleteparams", iTween.Hash("value", _fieldIndex)
打回来:
假设这_fieldIndex
是一个int
.
public void afterPlayerMove(object cmpParams)
{
Hashtable hstbl = (Hashtable)cmpParams;
Debug.Log("Your value " + (int)hstbl["value"]);
}
最后,您的代码不可读。简化此代码,以便其他人下次更容易帮助您。
完整的简化示例:
int _x, _y = 6;
//Parameter
int _fieldIndex = 4;
float floatVal = 2;
string stringVal = "Hello";
bool boolVal = false;
GameObject gObjVal = null;
void Start()
{
Hashtable hashtable = new Hashtable();
hashtable.Add("x", _x);
hashtable.Add("z", _y);
hashtable.Add("time", 2.0f);
hashtable.Add("easetype", iTween.EaseType.easeInExpo);
hashtable.Add("oncomplete", "afterPlayerMove");
//Create oncompleteparams hashtable
Hashtable paramHashtable = new Hashtable();
paramHashtable.Add("value1", _fieldIndex);
paramHashtable.Add("value2", floatVal);
paramHashtable.Add("value3", stringVal);
paramHashtable.Add("value4", boolVal);
paramHashtable.Add("value5", gObjVal);
//Include the oncompleteparams parameter to the hashtable
hashtable.Add("oncompleteparams", paramHashtable);
iTween.MoveTo(gameObject, hashtable);
}
public void afterPlayerMove(object cmpParams)
{
Hashtable hstbl = (Hashtable)cmpParams;
Debug.Log("Your int value " + (int)hstbl["value1"]);
Debug.Log("Your float value " + (float)hstbl["value2"]);
Debug.Log("Your string value " + (string)hstbl["value3"]);
Debug.Log("Your bool value " + (bool)hstbl["value4"]);
Debug.Log("Your GameObject value " + (GameObject)hstbl["value5"]);
}