当前位置: 首页>>代码示例>>C#>>正文


C# ICodeBlock.ForEach方法代码示例

本文整理汇总了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;");
                }
            }
        }
开发者ID:GorillaOne,项目名称:FlatRedBall,代码行数:48,代码来源:StateCodeGenerator.Animation.cs

示例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);");
        }
开发者ID:GorillaOne,项目名称:FlatRedBall,代码行数:42,代码来源:LevelCodeGenerator.cs


注:本文中的ICodeBlock.ForEach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。