本文整理汇总了C#中ICodeBlock.If方法的典型用法代码示例。如果您正苦于以下问题:C# ICodeBlock.If方法的具体用法?C# ICodeBlock.If怎么用?C# ICodeBlock.If使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICodeBlock
的用法示例。
在下文中一共展示了ICodeBlock.If方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateActivity
public override ICodeBlock GenerateActivity(ICodeBlock codeBlock, IElement element)
{
bool shouldGenerate = GetIfShouldGenerate(element);
if (shouldGenerate)
{
var ifBlock = codeBlock.If("CurrentTileMap != null");
ifBlock.Line("CurrentTileMap.AnimateSelf();");
}
return codeBlock;
}
示例2: GeneratePauseForNos
private void GeneratePauseForNos(NamedObjectSave nos, ICodeBlock codeBlock)
{
// eventually I may want to move this to AssetTypeInfo....
if (nos.InstanceType == "SoundEffectInstance")
{
var instanceName = nos.InstanceName;
var ifBlock = codeBlock.If(instanceName + ".State == Microsoft.Xna.Framework.Audio.SoundState.Playing");
{
ifBlock.Line(instanceName + ".Pause();");
ifBlock.Line("instructions.Add(new FlatRedBall.Instructions.DelegateInstruction(() => " + instanceName + ".Resume()));");
}
ifBlock.End();
}
}
示例3: GenerateInterpolateBetween
private void GenerateInterpolateBetween(ElementSave elementSave, ICodeBlock currentBlock,
string enumType, IEnumerable<StateSave> states)
{
// We used to only generate these if there was were any states in this category, but
// since Gum generated code supports dynamic states, there could be states in a category
// even if they're not defined in Gum.
//if (states.Count() > 0)
{
currentBlock = currentBlock.Function("public void",
"InterpolateBetween", enumType + " firstState, " + enumType + " secondState, float interpolationValue");
GenerateDebugCheckForInterpolationValueNaN(currentBlock);
Dictionary<VariableSave, InterpolationCharacteristic> interpolationCharacteristics =
new Dictionary<VariableSave, InterpolationCharacteristic>();
CreateStartingValueVariables(elementSave, states, currentBlock, interpolationCharacteristics);
currentBlock = currentBlock.Switch("firstState");
currentBlock = SetInterpolateBetweenValuesForStates(elementSave, enumType, states, currentBlock,
interpolationCharacteristics, FirstValue);
currentBlock = currentBlock.End();
currentBlock = currentBlock.Switch("secondState");
currentBlock = SetInterpolateBetweenValuesForStates(elementSave, enumType, states, currentBlock,
interpolationCharacteristics, SecondValue);
currentBlock = currentBlock.End();
currentBlock = AssignValuesUsingStartingValues(elementSave, currentBlock, interpolationCharacteristics);
currentBlock = currentBlock.If("interpolationValue < 1");
string fieldToAssign;
if (enumType == "VariableState")
{
fieldToAssign = "mCurrentVariableState";
}
else
{
fieldToAssign = "mCurrent" + enumType + "State";
}
currentBlock.Line(fieldToAssign + " = firstState;");
currentBlock = currentBlock.End().Else();
currentBlock.Line(fieldToAssign + " = secondState;");
currentBlock = currentBlock.End();
}
}
示例4: GenerateAdditionalMethods
public override ICodeBlock GenerateAdditionalMethods(ICodeBlock codeBlock, FlatRedBall.Glue.SaveClasses.IElement element)
{
//////////////////////////EARLY OUT//////////////////////////////////////
if (element is ScreenSave)
{
return codeBlock;
}
///////////////////////END EARLY OUT/////////////////////////////////////
codeBlock = codeBlock.Function("public void", "MoveToLayer", "Layer layerToMoveTo");
foreach (NamedObjectSave nos in element.NamedObjects)
{
if (!nos.IsDisabled)
{
if (nos.GetAssetTypeInfo() != null && !string.IsNullOrEmpty(nos.GetAssetTypeInfo().RemoveFromLayerMethod))
{
NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, nos);
bool shouldSkip = GetShouldSkip(nos);
if (!shouldSkip)
{
codeBlock.If("LayerProvidedByContainer != null")
.Line(nos.GetAssetTypeInfo().RemoveFromLayerMethod.Replace("this", nos.InstanceName).Replace("mLayer", "LayerProvidedByContainer") + ";")
.End();
codeBlock.Line(nos.GetAssetTypeInfo().LayeredAddToManagersMethod[0].Replace("this", nos.InstanceName).Replace("mLayer", "layerToMoveTo") + ";");
}
NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, nos);
}
else if (nos.SourceType == SourceType.Entity && !string.IsNullOrEmpty(nos.SourceClassType))
{
NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, nos);
codeBlock.Line(nos.InstanceName + ".MoveToLayer(layerToMoveTo);");
NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, nos);
}
}
}
codeBlock.Line("LayerProvidedByContainer = layerToMoveTo;");
codeBlock = codeBlock.End();
return codeBlock;
}
示例5: GenerateLoadStaticContent
public override ICodeBlock GenerateLoadStaticContent(ICodeBlock codeBlock, SaveClasses.IElement element)
{
#region For debugging record if we're using a global content manager
codeBlock.Line("#if DEBUG");
codeBlock.If("contentManagerName == FlatRedBall.FlatRedBallServices.GlobalContentManager")
.Line("HasBeenLoadedWithGlobalContentManager = true;");
codeBlock.ElseIf("HasBeenLoadedWithGlobalContentManager")
.Line("throw new System.Exception(\"This type has been loaded with a Global content manager, then loaded with a non-global. This can lead to a lot of bugs\");");
codeBlock.Line("#endif");
#endregion
return codeBlock;
}
示例6: AddCodeForIsOn
private static void AddCodeForIsOn(ICodeBlock codeBlock, NamedObjectSave nos)
{
string condition = null;
AssetTypeInfo ati = nos.GetAssetTypeInfo();
if (ati != null && ati.HasCursorIsOn)
{
bool shouldConsiderVisible =
ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Sprite" ||
ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.ManagedSpriteGroups.SpriteFrame" ||
ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Graphics.Text";
bool shouldConsiderAlpha =
ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Sprite" ||
ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.ManagedSpriteGroups.SpriteFrame" ||
ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Graphics.Text";
string whatToFormat;
if (shouldConsiderVisible)
{
whatToFormat = "{0}.AbsoluteVisible && cursor.IsOn3D({0}, LayerProvidedByContainer)";
}
else if (ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Scene")
{
whatToFormat = "cursor.IsOn3D({0}, LayerProvidedByContainer, false)";
}
else
{
whatToFormat = "cursor.IsOn3D({0}, LayerProvidedByContainer)";
}
if (shouldConsiderAlpha)
{
whatToFormat = "{0}.Alpha != 0 && " + whatToFormat;
}
condition = string.Format(whatToFormat, nos.InstanceName);
}
else if (nos.SourceType == SourceType.Entity)
{
EntitySave entitySave = ObjectFinder.Self.GetEntitySave(nos.SourceClassType);
if (entitySave != null)
{
// This happens if:
// The user has an Entity which is IWindow
// The user adds a new object
// The user sets the object to Entity - this will cause a code regeneration and this will be null;
if (entitySave.ImplementsIWindow || entitySave.ImplementsIClickable)
{
condition = string.Format("{0}.HasCursorOver(cursor)", nos.InstanceName);
}
}
}
if (condition != null)
{
codeBlock.If(condition)
.Line("return true;");
}
}
示例7: GenerateInterpolateToStateAdvanced
private ICodeBlock GenerateInterpolateToStateAdvanced(ICodeBlock codeBlock, string enumName)
{
codeBlock = codeBlock.Function("public void", "InterpolateToState",
enumName + " fromState, " + enumName + " toState, double secondsToTake, FlatRedBall.Glue.StateInterpolation.InterpolationType interpolationType, FlatRedBall.Glue.StateInterpolation.Easing easing");
string variableName;
if (enumName == "VariableState")
{
variableName = "CurrentState";
}
else
{
variableName = "Current" + enumName + "State";
}
codeBlock = codeBlock.If("secondsToTake <= 0");
codeBlock.Line(variableName + " = toState;");
codeBlock = codeBlock.End().Else();
// Immediately set the state to the from state:
codeBlock.Line(variableName + " = fromState;");
codeBlock.Line("mFrom" + enumName + "Tween = fromState;");
codeBlock.Line("mTo" + enumName + "Tween = toState;");
codeBlock.Line(
TweenerNameFor(enumName) + ".Start(0, 1, (float)secondsToTake, FlatRedBall.Glue.StateInterpolation.Tweener.GetInterpolationFunction(interpolationType, easing));");
codeBlock = codeBlock.End();// else
codeBlock = codeBlock.End();
return codeBlock;
}
示例8: WriteConvertToManuallyUpdated
public static void WriteConvertToManuallyUpdated(ICodeBlock codeBlock, IElement element, List<string[]> reusableEntireFileRfses)
{
foreach (NamedObjectSave nos in element.NamedObjects)
{
if ((nos.IsList || nos.AddToManagers) && !nos.IsDisabled && !nos.InstantiatedByBase && nos.IsFullyDefined && nos.IsContainer == false)
{
AddIfConditionalSymbolIfNecesssary(codeBlock, nos);
bool shouldHaveIfNullCheck = nos.Instantiate == false || nos.SetByDerived;
if (shouldHaveIfNullCheck)
{
codeBlock = codeBlock.If(nos.InstanceName + " != null");
}
#region The NOS is an Entity
if (nos.SourceType == SourceType.Entity)
{
codeBlock.Line(nos.InstanceName + ".ConvertToManuallyUpdated();");
}
#endregion
#region The NOS is a PositionedObjectList
else if (nos.IsList && !string.IsNullOrEmpty(nos.SourceClassGenericType))
{
WriteConvertToManuallyUpdatedForListNos(codeBlock, nos);
}
#endregion
else
{
AssetTypeInfo ati = nos.GetAssetTypeInfo();
bool alreadyHandledByEntireFileObject = false;
if (nos.SourceType == SourceType.File &&
!string.IsNullOrEmpty(nos.SourceFile) &&
!string.IsNullOrEmpty(nos.SourceName) &&
!nos.SourceName.StartsWith("Entire File ("))
{
foreach (string[] stringPair in reusableEntireFileRfses)
{
if (stringPair[0] == nos.SourceFile)
{
alreadyHandledByEntireFileObject = true;
break;
}
}
}
if (!alreadyHandledByEntireFileObject && ati != null && !string.IsNullOrEmpty(ati.MakeManuallyUpdatedMethod))
{
codeBlock.Line(ati.MakeManuallyUpdatedMethod.Replace("this", nos.InstanceName) + ";");
}
}
if (shouldHaveIfNullCheck)
{
codeBlock = codeBlock.End();
}
AddEndIfIfNecessary(codeBlock, nos);
}
}
}
示例9: AddTextSpecificAddToManagersCode
private static void AddTextSpecificAddToManagersCode(NamedObjectSave namedObject, ICodeBlock codeBlock, string objectName, string layerName)
{
// April 1, 2012
// Text that is added
// through TextManager.AddText("Hello")
// will automatically scale itself to be
// pixel-perfect for the default Camera, or
// to the Layer that it's added on. This behavior
// is very handy but is a little more difficult to reproduce
// with generated code. The reason for that is because generated
// code adds Text objects to the Camera *after* variables are set on
// the Text object (if they happen to be tunneled). Therefore, we need
// to only set pixel perfect if the user has marked the text as being pixel
// perfect.
if (namedObject.SourceType == SourceType.FlatRedBallType && namedObject.SourceClassType == "Text" && namedObject.IsPixelPerfect)
{
codeBlock.If(objectName + ".Font != null")
.Line(objectName + ".SetPixelPerfectScale(" + layerName + ");");
}
}
示例10: AddLayerSpecificAddToManagersCode
private static void AddLayerSpecificAddToManagersCode(NamedObjectSave namedObject, ICodeBlock codeBlock, string objectName)
{
if (namedObject.IsLayer &&
namedObject.IndependentOfCamera)
{
if (namedObject.Is2D)
{
codeBlock.Line(objectName + ".UsePixelCoordinates();");
if (namedObject.DestinationRectangle != null)
{
float leftDestination = namedObject.DestinationRectangle.Value.X;
float topDestination = namedObject.DestinationRectangle.Value.Y;
float rightDestination = (namedObject.DestinationRectangle.Value.X + namedObject.DestinationRectangle.Value.Width);
float bottomDestination = bottomDestination = (namedObject.DestinationRectangle.Value.Y + namedObject.DestinationRectangle.Value.Height);
if (namedObject.LayerCoordinateUnit == LayerCoordinateUnit.Pixel)
{
codeBlock.Line(objectName + ".LayerCameraSettings.LeftDestination = " + FlatRedBall.Math.MathFunctions.RoundToInt( leftDestination ) + ";");
codeBlock.Line(objectName + ".LayerCameraSettings.TopDestination = " + FlatRedBall.Math.MathFunctions.RoundToInt(topDestination ) + ";");
codeBlock.Line(objectName + ".LayerCameraSettings.RightDestination = " + FlatRedBall.Math.MathFunctions.RoundToInt(rightDestination ) + ";");
codeBlock.Line(objectName + ".LayerCameraSettings.BottomDestination = " + FlatRedBall.Math.MathFunctions.RoundToInt(bottomDestination ) + ";");
codeBlock.Line(objectName + ".LayerCameraSettings.OrthogonalWidth = " + FlatRedBall.Math.MathFunctions.RoundToInt(namedObject.DestinationRectangle.Value.Width ) + ";");
codeBlock.Line(objectName + ".LayerCameraSettings.OrthogonalHeight = " + FlatRedBall.Math.MathFunctions.RoundToInt(namedObject.DestinationRectangle.Value.Height ) + ";");
}
else
{
codeBlock.Line(objectName +
".LayerCameraSettings.LeftDestination = " +
"FlatRedBall.Math.MathFunctions.RoundToInt(FlatRedBall.SpriteManager.Camera.DestinationRectangle.Right * " + (.01 * leftDestination) + ");");
codeBlock.Line(objectName +
".LayerCameraSettings.TopDestination = " +
"FlatRedBall.Math.MathFunctions.RoundToInt(FlatRedBall.SpriteManager.Camera.DestinationRectangle.Bottom * " + (.01 * topDestination) + ");");
codeBlock.Line(objectName +
".LayerCameraSettings.BottomDestination = " +
"FlatRedBall.Math.MathFunctions.RoundToInt(FlatRedBall.SpriteManager.Camera.DestinationRectangle.Bottom * " + (.01 * bottomDestination) + ");");
codeBlock.Line(objectName +
".LayerCameraSettings.RightDestination = " +
"FlatRedBall.Math.MathFunctions.RoundToInt(FlatRedBall.SpriteManager.Camera.DestinationRectangle.Right * " + (.01 * rightDestination) + ");");
codeBlock.Line(objectName + ".LayerCameraSettings.OrthogonalWidth = " +
"FlatRedBall.SpriteManager.Camera.OrthogonalWidth * (float)(" + (.01 * (rightDestination - leftDestination)) + ");");
codeBlock.Line(objectName + ".LayerCameraSettings.OrthogonalHeight = " +
"FlatRedBall.SpriteManager.Camera.OrthogonalHeight * (float)(" + (.01 * (bottomDestination - topDestination)) + ");");
}
}
else if (namedObject.LayerCoordinateType == LayerCoordinateType.MatchCamera)
{
codeBlock = codeBlock.If("FlatRedBall.SpriteManager.Camera.Orthogonal");
codeBlock.Line(objectName + ".LayerCameraSettings.OrthogonalWidth = FlatRedBall.SpriteManager.Camera.OrthogonalWidth;");
codeBlock.Line(objectName + ".LayerCameraSettings.OrthogonalHeight = FlatRedBall.SpriteManager.Camera.OrthogonalHeight;");
codeBlock = codeBlock.End();
}
}
else
{
codeBlock.Line(objectName + ".LayerCameraSettings = new FlatRedBall.Graphics.LayerCameraSettings();");
codeBlock.Line(objectName + ".LayerCameraSettings.Orthogonal = false;");
}
}
}
示例11: GenerateAdditionalMethods
public override ICodeBlock GenerateAdditionalMethods(ICodeBlock codeBlock, FlatRedBall.Glue.SaveClasses.IElement element)
{
//////////////////////////EARLY OUT//////////////////////////////////////
if (element is ScreenSave)
{
return codeBlock;
}
///////////////////////END EARLY OUT/////////////////////////////////////
bool isInDerived = element.InheritsFromElement();
if (isInDerived)
{
codeBlock = codeBlock.Function("public override void", "MoveToLayer", "FlatRedBall.Graphics.Layer layerToMoveTo");
codeBlock.Line("base.MoveToLayer(layerToMoveTo);");
}
else
{
codeBlock = codeBlock.Function("public virtual void", "MoveToLayer", "FlatRedBall.Graphics.Layer layerToMoveTo");
}
if (element.InheritsFromFrbType())
{
AssetTypeInfo ati = AvailableAssetTypes.Self.GetAssetTypeFromRuntimeType(element.BaseElement);
if (ati != null )
{
if (ati.RemoveFromLayerMethod != null)
{
codeBlock.If("LayerProvidedByContainer != null")
.Line(ati.RemoveFromLayerMethod.Replace("mLayer", "LayerProvidedByContainer") + ";")
.End();
}
if (ati.LayeredAddToManagersMethod.Count != 0)
{
codeBlock.Line(ati.LayeredAddToManagersMethod[0].Replace("mLayer", "layerToMoveTo") + ";");
}
}
}
foreach (NamedObjectSave nos in element.NamedObjects)
{
if (!nos.IsDisabled && !nos.IsContainer)
{
bool shouldCheckForNull = nos.Instantiate == false;
if (nos.GetAssetTypeInfo() != null && !string.IsNullOrEmpty(nos.GetAssetTypeInfo().RemoveFromLayerMethod))
{
NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, nos);
bool shouldSkip = GetShouldSkip(nos);
if (!shouldSkip)
{
if (shouldCheckForNull)
{
codeBlock = codeBlock.If(nos.InstanceName + " != null");
}
codeBlock.If("LayerProvidedByContainer != null")
.Line(nos.GetAssetTypeInfo().RemoveFromLayerMethod.Replace("this", nos.InstanceName).Replace("mLayer", "LayerProvidedByContainer") + ";")
.End();
codeBlock.Line(nos.GetAssetTypeInfo().LayeredAddToManagersMethod[0].Replace("this", nos.InstanceName).Replace("mLayer", "layerToMoveTo") + ";");
if (shouldCheckForNull)
{
codeBlock = codeBlock.End();
}
}
NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, nos);
}
else if (nos.SourceType == SourceType.Entity && !string.IsNullOrEmpty(nos.SourceClassType))
{
if (shouldCheckForNull)
{
codeBlock = codeBlock.If(nos.InstanceName + " != null");
}
NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, nos);
codeBlock.Line(nos.InstanceName + ".MoveToLayer(layerToMoveTo);");
NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, nos);
if (shouldCheckForNull)
{
codeBlock = codeBlock.End();
}
}
}
}
codeBlock.Line("LayerProvidedByContainer = layerToMoveTo;");
//.........这里部分代码省略.........
示例12: GenerateInitializationForCsvRfs
private static void GenerateInitializationForCsvRfs(ReferencedFileSave referencedFile, ICodeBlock codeBlock, string variableName, string fileName, LoadType loadType)
{
var curBlock = codeBlock;
// If it's not
// a complete reload
// then we don't care
// about whether it's null
// or not.
if (referencedFile.IsSharedStatic && loadType == LoadType.CompleteLoad)
{
// Modify this line of code to use mVariable name if it's a global content and if we're doing async loading.
// The reason is we can't query the property, because that would result in the property waiting until the content
// is done loading - which would lock the game.
// Update March 29, 2014
// Global content will now feed the variable name with 'm' prefixed
// so we don't have to branch here anymore:
//if (referencedFile.GetContainerType() == ContainerType.None && ProjectManager.GlueProjectSave.GlobalContentSettingsSave.LoadAsynchronously)
//{
// curBlock = codeBlock.If(string.Format("{0} == null", variableName));
//}
//else
//{
// curBlock = codeBlock.If(string.Format("{0} == null", variableName));
//}
curBlock = codeBlock.If(string.Format("{0} == null", variableName));
}
GenerateCsvDeserializationCode(referencedFile, curBlock, variableName, fileName, loadType);
}
示例13: AssignValuesUsingStartingValues
private ICodeBlock AssignValuesUsingStartingValues(ElementSave element, ICodeBlock curBlock, Dictionary<VariableSave, InterpolationCharacteristic> mInterpolationCharacteristics)
{
foreach (KeyValuePair<VariableSave, InterpolationCharacteristic> kvp in mInterpolationCharacteristics)
{
var variable = kvp.Key;
if (kvp.Value != InterpolationCharacteristic.CantInterpolate)
{
string stringSuffix = variable.MemberNameInCode(element, mVariableNamesToReplaceForStates).Replace(".", "");
curBlock = curBlock.If("set" + stringSuffix + FirstValue + " && set" + stringSuffix + SecondValue);
AddAssignmentForInterpolationForVariable(curBlock, variable, element);
curBlock = curBlock.End();
}
}
return curBlock;
}
示例14: GenerateUnloadStaticContent
public override ICodeBlock GenerateUnloadStaticContent(ICodeBlock codeBlock, IElement element)
{
// We'll assume that we want to get rid of the last one
// The user may have loaded content from an Entity without calling LoadStaticContent - like if the
// Entity is a LoadedOnlyWhenReferenced container. In that case, we need to make sure we account for
// that by only removing if there are actually loaded content managers
codeBlock = codeBlock.If("LoadedContentManagers.Count != 0");
codeBlock.Line("LoadedContentManagers.RemoveAt(0);");
codeBlock.Line("mRegisteredUnloads.RemoveAt(0);");
codeBlock = codeBlock.End();
codeBlock = codeBlock.If("LoadedContentManagers.Count == 0");
for (int i = 0; i < element.ReferencedFiles.Count; i++)
{
if (element.ReferencedFiles[i].IsSharedStatic && element.ReferencedFiles[i].GetGeneratesMember())
{
ReferencedFileSave rfs = element.ReferencedFiles[i];
AddIfConditionalSymbolIfNecesssary(codeBlock, rfs);
string variableName = rfs.GetInstanceName();
string fieldName = variableName;
if (rfs.LoadedOnlyWhenReferenced)
{
fieldName = "m" + variableName;
}
AssetTypeInfo ati = rfs.GetAssetTypeInfo();
codeBlock = codeBlock
.If(fieldName + " != null");
// Vic says - since now static referenced file saves just represent the last-loaded, we don't
// want them to be removed anymore.
//stringBuilder.AppendLine(string.Format("{0}{1};", tabs, ati.DestroyMethod.Replace("this", variableName)));
//stringBuilder.AppendLine(string.Format("{0}{1} = null;", tabs, fieldName));
// But we do want to null them out if they are loaded only when referenced
// Update on May 2, 2011
// This is actually a problem with Entities because
// you can move from Screen to Screen and accumulate
// static references to objects which don't get removed
// which can cause some pretty nasty accumulation errors.
// Therefore, I really do think we should always call Destroy and remove the object.
// I can't think of why we wouldn't, actually. Perhaps the comment above was written
// before we had a very advanced pattern in place.
//if (rfs.LoadedOnlyWhenReferenced)
{
// We want to call destroy on the object,
// but some types, like the AnimationChainList,
// don't have destroy methods. Therefore, we should
// check if destroy exists and append a destroy call if
// so.
// Files like .CSV may
// be part of an Entity
// but these will not have
// an AssetTypeInfo, so we need
// to check for that.
if (ati != null && !string.IsNullOrEmpty(ati.DestroyMethod))
{
codeBlock.Line(ati.DestroyMethod.Replace("this", fieldName) + ";");
}
codeBlock.Line(fieldName + "= null;");
}
codeBlock = codeBlock.End();
AddEndIfIfNecessary(codeBlock, rfs);
}
}
codeBlock = codeBlock.End();
return codeBlock;
}
示例15: WriteLoadedOnlyWhenReferencedPropertyBody
private static void WriteLoadedOnlyWhenReferencedPropertyBody(ReferencedFileSave referencedFile, string containerName, IElement element,
string contentManagerName, AssetTypeInfo ati, string variableName, string lastContentManagerVariableName, ICodeBlock getBlock)
{
string referencedFileName = GetFileToLoadForRfs(referencedFile, ati);
string mThenVariableName = "m" + variableName;
ICodeBlock ifBlock = null;
if (element == null)
{
ifBlock = getBlock.If(mThenVariableName + " == null");
}
else
{
string contentManagerToCompareAgainst;
if (element is ScreenSave)
{
contentManagerToCompareAgainst = "\"" + FileManager.RemovePath(element.Name) + "\"";
}
else
{
contentManagerToCompareAgainst = "ContentManagerName";
}
string conditionContents =
mThenVariableName + " == null || " + lastContentManagerVariableName + " != " + contentManagerToCompareAgainst;
bool isDisposable = referencedFile.RuntimeType == "Texture2D" ||
referencedFile.RuntimeType == "Microsoft.Xna.Framework.Graphics.Texture2D";
if (isDisposable)
{
conditionContents += " || " + mThenVariableName + ".IsDisposed";
}
ifBlock = getBlock.If(conditionContents);
ifBlock.Line(lastContentManagerVariableName + " = " + contentManagerToCompareAgainst + ";");
}
if (containerName != ContentLoadWriter.GlobalContentContainerName)
{
GenerateExceptionForPostInitializeLoads(getBlock);
}
PerformancePluginCodeGenerator.CodeBlock = ifBlock;
PerformancePluginCodeGenerator.SaveObject = element;
PerformancePluginCodeGenerator.GenerateStart(" Get " + variableName);
if (ati != null && !referencedFile.IsCsvOrTreatedAsCsv)
{
GetLoadCallForAtiFile(referencedFile,
ati, mThenVariableName, contentManagerName,
ProjectBase.AccessContentDirectory + referencedFileName, ifBlock);
}
else if (referencedFile.IsCsvOrTreatedAsCsv)
{
GenerateCsvDeserializationCode(referencedFile, ifBlock, mThenVariableName,
referencedFileName, LoadType.CompleteLoad);
}
if (element != null && element is EntitySave)
{
AppendAddUnloadMethod(ifBlock, containerName);
}
PerformancePluginCodeGenerator.GenerateEnd();
getBlock.Line("return " + mThenVariableName + ";");
}