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


C# ICodeBlock.For方法代码示例

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


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

示例1: GetDestroyForNamedObject

        public static void GetDestroyForNamedObject(IElement element, NamedObjectSave namedObject, ICodeBlock codeBlock, bool forceRecycle = false)
        {
            #region EARLY OUTS

            if (GetShouldSkipDestroyOn(namedObject))
            {
                return;
            }

            #endregion

            bool shouldRecycle = 
                forceRecycle ||
                (element is EntitySave && (element as EntitySave).CreatedByOtherEntities);


            AddIfConditionalSymbolIfNecesssary(codeBlock, namedObject);

            #region Update dependencies

            // Update April 3, 2011
            // The generated code used
            // to call UpdateDependencies
            // on any contained NamedObjectSave.
            // We did this because we wanted to make
            // sure that all contained NamedObjectSaves
            // were updated so when the Entity is recycled,
            // the contained NamedObjectSaves are in the proper.
            // position...or at least that was how things used to
            // be done.  Now when AddToManagers is called on an Entity,
            // the Entity is moved back to the origin (and unrotated).  This
            // means that we don't need to worry about this anymore:
            //if ( SaveObject is EntitySave && 
            //    (SaveObject as EntitySave).CreatedByOtherEntities && 
            //    (namedObject.AttachToContainer || namedObject.AttachToCamera))
            //{
            //    // Why do we do this?  The reason is because it's possible (and likely) that the Entity that this code
            //    // is being generated for may be moving.  Any attached objects will "lag behind" until the Draw method is
            //    // called which updates dependencies.  But Entities are usually destroyed before this update happens.  If the
            //    // Entity that is destroyed is re-cycled, then all attached objects will be offset slightly.  This can build up
            //    // over time and cause issues.  This should help eliminate a lot of bugs.
            //    if (namedObject.SourceType == SourceType.Entity || 
            //        (namedObject.AssetTypeInfo != null && namedObject.AssetTypeInfo.ShouldAttach))
            //    {
            //        stringBuilder.AppendLine(tabs + namedObject.InstanceName + ".UpdateDependencies(TimeManager.CurrentTime);");
            //    }
            //}

            #endregion

            AssetTypeInfo ati = AvailableAssetTypes.Self.GetAssetTypeFromRuntimeType(namedObject.InstanceType);

            #region If object was added to manager, remove this object from managers

            if (ati != null && namedObject.AddToManagers)
            {
                string removalMethod = null;

                if (shouldRecycle && !string.IsNullOrEmpty(ati.RecycledDestroyMethod))
                {
                    removalMethod = ati.RecycledDestroyMethod.Replace("this", namedObject.InstanceName);
                }
                else
                {
                    if (ati.DestroyMethod != null)
                    {

                        removalMethod = ati.DestroyMethod.Replace("this", namedObject.InstanceName);

                    }
                }

                if (!string.IsNullOrEmpty(removalMethod))
                {
                    codeBlock.If(namedObject.InstanceName + " != null")
                             .Line(removalMethod + ";");
                }
            }

            #endregion

            // TODO:  Do we want to handle this case for pooled objects?  I think so.

            #region If the object is an Entity, destroy the object and unload the static content

            if (namedObject.SourceType == SourceType.Entity)
            {
                var ifBlock = codeBlock.If(namedObject.InstanceName + " != null");
                ifBlock.Line(namedObject.InstanceName + ".Destroy();");

                if(!forceRecycle)
                {
                        // We also detach so that if the object is recycled its Parent will be null
                    ifBlock
                             .Line(namedObject.InstanceName + ".Detach();");
                }
                // Vic says:  We used to manually call UnloadStaticContent on all Entities.  But this
                // doesn't work well with inheritance.  Instead, we now use the ContentManagers UnloadContent method support
                // GenerateStaticDestroyForType(tabs, namedObject.ClassType);
            }
//.........这里部分代码省略.........
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:101,代码来源:NamedObjectSaveCodeGenerator.cs

示例2: GetActivityForNamedObject

        public static void GetActivityForNamedObject(NamedObjectSave namedObjectSave, ICodeBlock codeBlock)
        {
            ///////////////////////////EARLY OUT/////////////////////////////////////////////////
            if (
                (namedObjectSave.SetByContainer && namedObjectSave.GetContainer() is EntitySave)
                ||
                namedObjectSave.IsDisabled || namedObjectSave.CallActivity == false ||
                namedObjectSave.InstantiatedByBase || !namedObjectSave.IsFullyDefined)
            {
                return;
            }
            /////////////////////////END EARLY OUT///////////////////////////////////////////////

            bool setByDerived = namedObjectSave.SetByDerived;

            AddIfConditionalSymbolIfNecesssary(codeBlock, namedObjectSave);

            if (!setByDerived)
            {
                if (namedObjectSave.Instantiate == false)
                {
                    // This may be null or it may be instantiated later by the user, so we should
                    // handle both cases:
                    codeBlock = codeBlock.If(namedObjectSave.InstanceName + " != null");
                }

                if (namedObjectSave.SourceType == SourceType.Entity)
                {
                    // Entities need activity!
                    codeBlock.Line(namedObjectSave.InstanceName + ".Activity();");
                }
                else if (namedObjectSave.SourceType == SourceType.FlatRedBallType &&
                    namedObjectSave.ClassType != null &&
                    namedObjectSave.ClassType.Contains("PositionedObjectList<"))
                {
                    // Now let's see if the object in the list is an entity
                    string genericType = namedObjectSave.SourceClassGenericType;


                    if (genericType.Contains("Entities\\"))
                    {
                        codeBlock.For("int i = " + namedObjectSave.InstanceName + ".Count - 1; i > -1; i--")
                                    .If("i < " + namedObjectSave.InstanceName + ".Count")
                                        .Line("// We do the extra if-check because activity could destroy any number of entities")
                                        .Line(namedObjectSave.InstanceName + "[i].Activity();");
                    }


                }

            }

            // If it's an emitter, call TimedEmit:
            ParticleCodeGenerator.GenerateTimedEmit(codeBlock, namedObjectSave);

            if (!setByDerived)
            {

                if (namedObjectSave.Instantiate == false)
                {
                    // end the if-statement we started above.
                    codeBlock = codeBlock.End();
                }
            }

            AddEndIfIfNecessary(codeBlock, namedObjectSave);
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:67,代码来源:NamedObjectSaveCodeGenerator.cs

示例3: WriteTextInitializationLoopForScene

        private static void WriteTextInitializationLoopForScene(ICodeBlock codeBlock, string sceneName)
        {
            bool useTranslation = ProjectManager.GlueProjectSave.UsesTranslation;

            var forBlock = codeBlock.For(string.Format("int i = 0; i < {0}.Texts.Count; i++", sceneName));

            if (useTranslation)
            {
                forBlock.Line(
                    string.Format(
                        "{0}.Texts[i].DisplayText = FlatRedBall.Localization.LocalizationManager.Translate({0}.Texts[i].DisplayText);", sceneName));
            }
            forBlock.Line(string.Format("{0}.Texts[i].AdjustPositionForPixelPerfectDrawing = true;", sceneName));
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:14,代码来源:NamedObjectSaveCodeGenerator.cs

示例4: GenerateDestroy

        public override ICodeBlock GenerateDestroy(ICodeBlock codeBlock, IElement element)
        {
            if (element is EntitySave)
            {
                EntitySave entitySave = (EntitySave)element;
                if (entitySave.IsScrollableEntityList && !string.IsNullOrEmpty(entitySave.ItemType))
                {
                    string itemTypeWithoutPath = FileManager.RemovePath(entitySave.ItemType);

                    codeBlock
                        .For("int i = mScrollableItems.Count - 1; i > -1; i--")
                            .Line("mScrollableItems[i].Destroy();")
                        .End()

                        .Line("FlatRedBall.SpriteManager.RemovePositionedObject(mScrollableHandle);")
                        .Line("Factories." + itemTypeWithoutPath + "Factory.Destroy();");
                }
            }

            return codeBlock;
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:21,代码来源:ScrollableListCodeGenerator.cs


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