检查动作列表中的参数

Checking the parameter inside a Action List

我想知道是否可以在列表中引用参数,例如

if ( listOfActions[index].SecondParameter == x ){
    do stuff
}

老实说,我无法理解 Action Documentation 中的大部分内容,但到目前为止我得到的是:

List<Action> musicSequence = new List<Action>();
...
void addBulletToList (string direction, float time){
    musicSequence.Add ( ()=>musicControl.spawnBullet(direction, time) );
}

void spawnBullet(string direction, float time){
    go = (GameObject)Instantiate(Resources.Load(direction));
}
//And in my main function it would be something like this
if ( CurrentMusicTime equals the time parameter in musicSequence[index] ){
    execute musicSequence[index]
    next index
}

如果每个动作 float time 是唯一的,您可以考虑使用 Dictionary<float, Action> 来存储相应的动作,因为您当前尝试的是不可能的。

Dictionary<float, Action> musicSequence = new Dictionary<float, Action>();

void addBulletToList (string direction, float time){
    musicSequence.Add(time, () => musicControl.spawnBullet(direction, time));
}

void spawnBullet(string direction, float time){
    go = (GameObject)Instantiate(Resources.Load(direction));
}

if (musicSequence.Keys.Contains(CurrentMusicTime)){
    musicSequence[CurrentMusicTime]();
    next index
}