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


C# ICodeBlock.Block方法代码示例

本文整理汇总了C#中ICodeBlock.Block方法的典型用法代码示例。如果您正苦于以下问题:C# ICodeBlock.Block方法的具体用法?C# ICodeBlock.Block怎么用?C# ICodeBlock.Block使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICodeBlock的用法示例。


在下文中一共展示了ICodeBlock.Block方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleWriteInstanceVariableAssignment

        public static void HandleWriteInstanceVariableAssignment(NamedObjectSave instance, ICodeBlock code, InstructionSave variable)
        {
            var shouldHandle = variable.Member == "AtlasedTexture" && instance.SourceClassType == "Sprite";

            if(shouldHandle)
            {
                var memberName = instance.InstanceName;

                // The code should look something like:
                // 
                // SpriteInstance.AtlasedTexture = FlatRedBall.Graphics.Texture.AtlasLoader.LoadAtlasedTexture("asdf");
                //
                // But I still need to make the AtlasLoader keep track of all loaded assets, and I need to have a "priority" system

                code = code.Block();
                {
                    // eventually this might exist
                    //var atlas = instance.GetInstructionFromMember("");
                    // for now we assume that the texture packer project is in global content
                    var rfs = GlueState.Self.CurrentGlueProject.GlobalFiles.FirstOrDefault(item =>
                    {
                        var ati = item.GetAssetTypeInfo();
                        if(ati != null)
                        {
                            return ati == AtiManager.Self.TextureAtlasAti;
                        }

                        return false;
                    });

                    if (rfs != null)
                    {
                        var atlas = $"{GlueState.Self.ProjectNamespace}.GlobalContent.{rfs.GetInstanceName()}";
                        code.Line($"var atlas = {atlas};");

                        code.Line($"{memberName}.AtlasedTexture = atlas.Sprite(\"{variable.Value}\");");
                    }
                }
            }
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:40,代码来源:VariableAssignmentCodeGenerator.cs

示例2: GeneratePreloadStateContentForStateType

        private static ICodeBlock GeneratePreloadStateContentForStateType(ICodeBlock codeBlock, IElement element, List<StateSave> list, string variableType)
        {
            if (list.Count != 0)
            {

                codeBlock = codeBlock.Function("public static void", "PreloadStateContent", variableType + " state, string contentManagerName");
                codeBlock.Line("ContentManagerName = contentManagerName;");

                codeBlock = codeBlock.Switch("state");

                // Loop through states here and access properties that need the values
                foreach (StateSave state in list)
                {
                    codeBlock = codeBlock.Case(variableType + "." + state.Name);
                    foreach (InstructionSave instruction in state.InstructionSaves)
                    {
                        if (instruction.Value != null && instruction.Value is string)
                        {
                            // We insert a block so that object throwaway is not redefined in the switch scope.
                            // We do this instead of making an object throwaway above the switch so that we don't
                            // get warnings if is nothing to load
                            codeBlock.Block().Line("object throwaway = " + GetRightSideAssignmentValueAsString(element, instruction) + ";");
                        }
                    }
                    codeBlock = codeBlock.End();

                }

                codeBlock = codeBlock.End();

                codeBlock = codeBlock.End();
            }
            return codeBlock;
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:34,代码来源:StateCodeGenerator.cs

示例3: CreateInstructionForInterpolationRelative

        private void CreateInstructionForInterpolationRelative(StateCodeGeneratorContext context, ICodeBlock currentBlock, AnimatedStateSave previousState, AnimatedStateSave currentState)
        {
            if(previousState != null)
            {
                currentBlock.Line("var toReturn = new FlatRedBall.Instructions.DelegateInstruction(() =>");
                {
                    currentBlock = currentBlock.Block();

                    // Is the start clone necessary?
                    currentBlock.Line("var relativeStart = ElementSave.AllStates.FirstOrDefault(item => item.Name == \"" + previousState.StateName + "\").Clone();");
                    currentBlock.Line("var relativeEnd = ElementSave.AllStates.FirstOrDefault(item => item.Name == \"" + currentState.StateName + "\").Clone();");
                    currentBlock.Line("Gum.DataTypes.Variables.StateSaveExtensionMethods.SubtractFromThis(relativeEnd, relativeStart);");
                    currentBlock.Line("var difference = relativeEnd;");

                    string categoryName = "VariableState";
                    var category = context.Element.Categories.FirstOrDefault(item => item.States.Any(stateCandidate => stateCandidate.Name == currentState.StateName));

                    string enumValue = currentState.StateName;

                    if(currentState.StateName.Contains('/'))
                    {
                        var split = currentState.StateName.Split('/');

                        category = context.Element.Categories.FirstOrDefault(item => item.Name == split[0]);
                        enumValue = split[1];
                    }

                    if(category != null)
                    {
                        categoryName = category.Name;
                    }
                    currentBlock.Line("Gum.DataTypes.Variables.StateSave first = GetCurrentValuesOnState(" + categoryName + "." + enumValue + ");");

                    currentBlock.Line("Gum.DataTypes.Variables.StateSave second = first.Clone();");
                    currentBlock.Line("Gum.DataTypes.Variables.StateSaveExtensionMethods.AddIntoThis(second, difference);");


                    string interpolationTime = ToFloatString(currentState.Time - previousState.Time);

                    string easing = "FlatRedBall.Glue.StateInterpolation.Easing." + previousState.Easing;
                    string interpolationType = "FlatRedBall.Glue.StateInterpolation.InterpolationType." + previousState.InterpolationType;


                    currentBlock.Line(
                        string.Format("FlatRedBall.Glue.StateInterpolation.Tweener tweener = new FlatRedBall.Glue.StateInterpolation.Tweener(from: 0, to: 1, duration: {0}, type: {1}, easing: {2});",
                        interpolationTime,
                        interpolationType,
                        easing));

                    currentBlock.Line("tweener.Owner = this;");

                    currentBlock.Line("tweener.PositionChanged = newPosition => this.InterpolateBetween(first, second, newPosition);");
                    currentBlock.Line("tweener.Start();");
                    currentBlock.Line("StateInterpolationPlugin.TweenerManager.Self.Add(tweener);");


                    currentBlock = currentBlock.End();
                }
                currentBlock.Line(");");
                string previousStateTime = ToFloatString(previousState.Time);

                currentBlock.Line("toReturn.TimeToExecute = FlatRedBall.TimeManager.CurrentTime + " + previousStateTime + ";");
                currentBlock.Line("yield return toReturn;");
                
            }
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:66,代码来源:StateCodeGenerator.Animation.cs

示例4: CreateInstructionForInterpolation

        private void CreateInstructionForInterpolation(StateCodeGeneratorContext context, ICodeBlock currentBlock, string animationType, AnimatedStateSave previousState, AnimatedStateSave currentState, AbsoluteOrRelative absoluteOrRelative, string animationName)
        {

            currentBlock = currentBlock.Block();

            if (absoluteOrRelative == AbsoluteOrRelative.Absolute)
            {

                CreateInstructionForInterpolationAbsolute(context, currentBlock, animationType, previousState, currentState, animationName);
            }
            else
            {
                CreateInstructionForInterpolationRelative(context,currentBlock,  previousState, currentState);
            }
            currentBlock = currentBlock.End();
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:16,代码来源:StateCodeGenerator.Animation.cs

示例5: CreateInstructionForSubAnimation

        private static void CreateInstructionForSubAnimation(ICodeBlock currentBlock, AnimationReferenceSave animationReferenceSave, AbsoluteOrRelative absoluteOrRelative, AnimationSave parentAnimation)
        {
            currentBlock = currentBlock.Block();

            //var instruction = new FlatRedBall.Instructions.DelegateInstruction(() =>
            //FlatRedBall.Instructions.InstructionManager.Instructions.AddRange(ClickableBushInstance.GrowAnimation));
            //instruction.TimeToExecute = FlatRedBall.TimeManager.CurrentTime + asdf;
            //yield return instruction;

            string animationName = animationReferenceSave.PropertyNameInCode();
                //animationReferenceSave. FlatRedBall.IO.FileManager.RemovePath(animationReferenceSave.Name) + "Animation";
            if(absoluteOrRelative == AbsoluteOrRelative.Relative)
            {
                animationName += "Relative";
            }

            currentBlock.Line($"var instruction = new FlatRedBall.Instructions.DelegateInstruction(()=>{animationName}.Play({parentAnimation.PropertyNameInCode()}));");
            currentBlock.Line("instruction.TimeToExecute = FlatRedBall.TimeManager.CurrentTime + " + ToFloatString(animationReferenceSave.Time) + ";");


            currentBlock.Line("yield return instruction;");
            currentBlock = currentBlock.End();
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:23,代码来源:StateCodeGenerator.Animation.cs

示例6: GenerateEnumerableFor

        private void GenerateEnumerableFor(StateCodeGeneratorContext context, ICodeBlock currentBlock, AnimationSave animation, AbsoluteOrRelative absoluteOrRelative)
        {
            string animationType = "VariableState";

            string animationName = animation.PropertyNameInCode();

            if(absoluteOrRelative == AbsoluteOrRelative.Relative)
            {
                animationName += "Relative";
            }

            string propertyName = animationName + "Instructions";

            // Instructions used to be public - the user would grab them and add them to the InstructionManager,
            // but now everything is encased in an Animation object which handles stopping itself and provides a simple
            // Play method.
            if (animation.States.Count == 0 && animation.Animations.Count == 0)
            {
                currentBlock = currentBlock.Property("private System.Collections.Generic.IEnumerable<FlatRedBall.Instructions.Instruction>", propertyName).Get();

                currentBlock.Line("yield break;");

            }
            else if(absoluteOrRelative == AbsoluteOrRelative.Relative && animation.States.Count < 2 && animation.Animations.Count == 0)
            {

                currentBlock = currentBlock.Property("private System.Collections.Generic.IEnumerable<FlatRedBall.Instructions.Instruction>", propertyName).Get();

                currentBlock.Line("yield break;");
            }
            else
            {
                if (animation.States.Count != 0)
                {
                    var firstState = context.Element.AllStates.FirstOrDefault(item => item.Name == animation.States.First().StateName);

                    var category = context.Element.Categories.FirstOrDefault(item => item.States.Contains(firstState));

                    if (category != null)
                    {
                        animationType = category.Name;
                    }
                }

                currentBlock = currentBlock.Property("private System.Collections.Generic.IEnumerable<FlatRedBall.Instructions.Instruction>", propertyName).Get();

                GenerateOrderedStateAndSubAnimationCode(context, currentBlock, animation, animationType, absoluteOrRelative);

                if(animation.Loops)
                {
                    currentBlock = currentBlock.Block();

                    currentBlock.Line("var toReturn = new FlatRedBall.Instructions.DelegateInstruction(  " + 
                        "() => FlatRedBall.Instructions.InstructionManager.Instructions.AddRange(this." + propertyName + "));");
                    string executionTime = "0.0f";

                    if(animation.States.Count != 0)
                    {
                        executionTime = ToFloatString( animation.States.Last().Time);
                    }

                    currentBlock.Line("toReturn.TimeToExecute = FlatRedBall.TimeManager.CurrentTime + " + executionTime + ";");

                    currentBlock.Line("yield return toReturn;");
                    currentBlock = currentBlock.End();

                }
            }
            
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:70,代码来源:StateCodeGenerator.Animation.cs

示例7: GenerateCsvDeserializationCode

        private static void GenerateCsvDeserializationCode(ReferencedFileSave referencedFile, ICodeBlock codeBlock,  string variableName, string fileName, LoadType loadType)
        {
            #region Get the typeName (type as a string)

            string typeName;

            if (FileManager.GetExtension(fileName) == "csv" || referencedFile.TreatAsCsv)
            {
                // The CustomClass interface keeps a name just as it appears in Glue, so we want to use
                // the referencedFile.Name instead of the fileName because fileName will have "Content/" on it
                // and this shouldn't be the case for XNA 4 games
                typeName = CsvCodeGenerator.GetEntireGenericTypeForCsvFile(referencedFile);
            }

            else
            {
                typeName = "System.Collections.Generic.List<" + FileManager.RemovePath(FileManager.RemoveExtension(fileName)) + ">";
            }

            if (typeName.ToLower().EndsWith("file"))
            {
                typeName = typeName.Substring(0, typeName.Length - "file".Length);
            }
            #endregion

            #region Apply the delimiter change

            // Use the delimiter specified in Glue

            var block = codeBlock.Block();
            block.Line("// We put the { and } to limit the scope of oldDelimiter");
            block.Line("char oldDelimiter = FlatRedBall.IO.Csv.CsvFileManager.Delimiter;");

            char delimiterAsChar = referencedFile.CsvDelimiter.ToChar();

            block.Line(@"FlatRedBall.IO.Csv.CsvFileManager.Delimiter = '" + delimiterAsChar + "';");

            #endregion

            string whatToLoadInto;
            if (loadType == LoadType.CompleteLoad)
            {
                whatToLoadInto = "temporaryCsvObject";
                block.Line(string.Format("{0} {1} = new {0}();", typeName, whatToLoadInto));
            }
            else
            {
                whatToLoadInto = referencedFile.GetInstanceName();
                block.Line(string.Format("{0}.Clear();", whatToLoadInto));
            }

            #region Call CsvFileManager.CsvDeserializeList/Dictionary

            if (referencedFile.CreatesDictionary)
            {
                string keyType;
                string valueType;

                CsvCodeGenerator.GetDictionaryTypes(referencedFile, out keyType, out valueType);

                if (keyType == null)
                {
                    System.Windows.Forms.MessageBox.Show("Could not find the key type for:\n\n" + referencedFile.Name + "\n\nYou need to mark one of the headers as required or not load this file as a dictionary.");
                    keyType = "UNKNOWN_TYPE";

                }
                // CsvFileManager.CsvDeserializeDictionary<string, CarData>("Content/CarData.csv", carDataDictionary);
                block.Line(string.Format("FlatRedBall.IO.Csv.CsvFileManager.CsvDeserializeDictionary<{2}, {3}>(\"{0}\", {1});", ProjectBase.AccessContentDirectory + fileName,
                                  whatToLoadInto, keyType, valueType));
            }
            else
            {
                string elementType = referencedFile.GetTypeForCsvFile();

                block.Line(string.Format("FlatRedBall.IO.Csv.CsvFileManager.CsvDeserializeList(typeof({0}), \"{1}\", {2});",
                                         elementType, ProjectBase.AccessContentDirectory + fileName, whatToLoadInto));
            }

            #endregion

            block.Line("FlatRedBall.IO.Csv.CsvFileManager.Delimiter = oldDelimiter;");

            if (loadType == LoadType.CompleteLoad)
            {
                block.Line(string.Format("{0} = temporaryCsvObject;", variableName));
            }
        }
开发者ID:gitter-badger,项目名称:FlatRedBall,代码行数:87,代码来源:ReferencedFileSaveCodeGenerator.cs


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