本文整理汇总了C#中ICodeBlock.ForEach方法的典型用法代码示例。如果您正苦于以下问题:C# ICodeBlock.ForEach方法的具体用法?C# ICodeBlock.ForEach怎么用?C# ICodeBlock.ForEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICodeBlock
的用法示例。
在下文中一共展示了ICodeBlock.ForEach方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateAnimateForCategory
private void GenerateAnimateForCategory(ICodeBlock currentBlock, string categoryName, List<Gum.DataTypes.Variables.StateSave> states)
{
string propertyToAssign;
if (categoryName == "VariableState")
{
propertyToAssign = "this.CurrentVariableState";
}
else
{
propertyToAssign = "this.Current" + categoryName + "State";
}
currentBlock = currentBlock.Function("public void", "Animate",
"System.Collections.Generic.IEnumerable<FlatRedBall.Gum.Keyframe<" + categoryName + ">> keyframes");
{
currentBlock.Line("bool isFirst = true;");
currentBlock.Line("FlatRedBall.Gum.Keyframe<" + categoryName + "> lastKeyframe = null;");
var foreachBlock = currentBlock.ForEach("var frame in keyframes");
{
var ifBlock = foreachBlock.If("isFirst");
{
ifBlock.Line("isFirst = false;");
ifBlock.Line(propertyToAssign + " = frame.State;");
}
var elseBlock = ifBlock.End().Else();
{
elseBlock.Line("float timeToTake = frame.Time - lastKeyframe.Time;");
elseBlock.Line("var fromState = lastKeyframe.State;");
elseBlock.Line("var toState = frame.State;");
elseBlock.Line("var interpolationType = lastKeyframe.InterpolationType;");
elseBlock.Line("var easing = lastKeyframe.Easing;");
elseBlock.Line(
"System.Action action = () => this.InterpolateTo(fromState, toState, timeToTake, interpolationType, easing, {});");
elseBlock.Line(
"FlatRedBall.Instructions.DelegateInstruction instruction = new FlatRedBall.Instructions.DelegateInstruction(action);");
elseBlock.Line("instruction.Target = this;");
elseBlock.Line("instruction.TimeToExecute = FlatRedBall.TimeManager.CurrentTime + lastKeyframe.Time;");
elseBlock.Line("FlatRedBall.Instructions.InstructionManager.Instructions.Add(instruction);");
}
foreachBlock.Line("lastKeyframe = frame;");
}
}
}
示例2: GenerateInitializeAnimations
private static void GenerateInitializeAnimations(ICodeBlock function)
{
function.Line("// initialize the animations:");
function.Line("Dictionary<string, FlatRedBall.Graphics.Animation.AnimationChain> animationDictionary = new Dictionary<string, FlatRedBall.Graphics.Animation.AnimationChain>();");
var outerForEach = function.ForEach("var item in levelInfoObject as System.Collections.Generic.List<DataTypes.TileMapInfo>");
{
var ifBlock = outerForEach.If("item.EmbeddedAnimation != null && item.EmbeddedAnimation.Count != 0");
{
ifBlock.Line("FlatRedBall.Graphics.Animation.AnimationChain newChain = new FlatRedBall.Graphics.Animation.AnimationChain();");
ifBlock.Line("newChain.Name = item.Name + \"Animation\";");
ifBlock.Line("animationDictionary.Add(item.Name, newChain);");
var innerForEach = ifBlock.ForEach("var frameSave in item.EmbeddedAnimation");
{
innerForEach.Line("var frame = new FlatRedBall.Graphics.Animation.AnimationFrame();");
innerForEach.Line("int index = 0;");
innerForEach.Line("int.TryParse(frameSave.TextureName, out index);");
innerForEach.Line("frame.Texture = CurrentTileMap.MapLayers[index].Texture;");
innerForEach.Line("frame.FrameLength = frameSave.FrameLength;");
innerForEach.Line("// We use pixel coords in the Save:");
innerForEach.Line("frame.LeftCoordinate = frameSave.LeftCoordinate / frame.Texture.Width;");
innerForEach.Line("frame.RightCoordinate = frameSave.RightCoordinate / frame.Texture.Width;");
innerForEach.Line("frame.TopCoordinate = frameSave.TopCoordinate / frame.Texture.Height;");
innerForEach.Line("frame.BottomCoordinate = frameSave.BottomCoordinate / frame.Texture.Height;");
innerForEach.Line("// finish others");
innerForEach.Line("newChain.Add(frame);");
}
}
}
function.Line("CurrentTileMap.Animation = new FlatRedBall.TileGraphics.LayeredTileMapAnimation(animationDictionary);");
}