本文整理汇总了C#中ICodeBlock.Function方法的典型用法代码示例。如果您正苦于以下问题:C# ICodeBlock.Function方法的具体用法?C# ICodeBlock.Function怎么用?C# ICodeBlock.Function使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICodeBlock
的用法示例。
在下文中一共展示了ICodeBlock.Function方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateInitializeLevel
private void GenerateInitializeLevel(ICodeBlock codeBlock, IElement element)
{
#region /////////////////////////////////Early out////////////////////////////////
bool shouldGenerate = GetIfShouldGenerate(element);
if (!shouldGenerate)
{
return;
}
///////////////////////////////End early out/////////////////////////////
#endregion
codeBlock.Line("FlatRedBall.TileGraphics.LayeredTileMap CurrentTileMap;");
var function = codeBlock.Function("void", "InitializeLevel", "string levelName");
GenerateInitializeLevelObjects(function);
GenerateInitializeCamera(function);
GenerateAddCollisionAndEntities(function);
GenerateInitializeAnimations(function);
}
示例2: GenerateAdditionalMethods
public override ICodeBlock GenerateAdditionalMethods(ICodeBlock codeBlock, IElement element)
{
EntitySave entitySave = element as EntitySave;
if (entitySave == null || (!entitySave.ImplementsIClickable && !entitySave.ImplementsIWindow))
{
return codeBlock;
}
if (entitySave.ImplementsIWindow)
{
bool inheritsFromIWindow = entitySave.GetInheritsFromIWindow();
// Add all the code that never changes if this is the base IWindow (doesn't have a parent IWindow)
if (!inheritsFromIWindow)
{
GenerateEnabledVariable(codeBlock, element);
}
}
IWindowCodeGenerator.WriteCodeForHasCursorOver(
entitySave, codeBlock, entitySave.GetInheritsFromIWindowOrIClickable());
var isVirtual = string.IsNullOrEmpty(entitySave.BaseEntity) || entitySave.GetInheritsFromIWindowOrIClickable() == false;
codeBlock
.Function("WasClickedThisFrame", "FlatRedBall.Gui.Cursor cursor", Public: true, Virtual: isVirtual, Override: !isVirtual, Type: "bool")
.Line("return cursor.PrimaryClick && HasCursorOver(cursor);")
.End();
return codeBlock;
}
示例3: GenerateHandleFileChanged
private void GenerateHandleFileChanged(ICodeBlock codeBlock)
{
var method = codeBlock.Function("private static void", "HandleFileChanged", "object sender, System.IO.FileSystemEventArgs e");
{
var tryBlock = method.Try();
tryBlock.Line("System.Threading.Thread.Sleep(500);");
tryBlock.Line("var fullFileName = e.FullPath;");
tryBlock.Line("var relativeFileName = FlatRedBall.IO.FileManager.MakeRelative(FlatRedBall.IO.FileManager.Standardize(fullFileName));");
foreach(var rfs in GlueState.Self.CurrentGlueProject.GlobalFiles)
{
bool shouldGenerate = rfs.LoadedAtRuntime && rfs.IsDatabaseForLocalizing == false;
if(shouldGenerate)
{
var fileName = ProjectBase.AccessContentDirectory + rfs.Name.ToLower().Replace("\\", "/");
var instanceName = rfs.GetInstanceName();
var ifStatement = tryBlock.If($"relativeFileName == \"{fileName}\"");
{
ifStatement.Line($"Reload({instanceName});");
}
}
}
var catchBlock = tryBlock.End().Line("catch{}");
}
}
示例4: 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();
}
}
示例5: 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;");
}
}
}
示例6: GenerateInitialize
private static void GenerateInitialize(ICodeBlock codeBlock)
{
var initializeMethod = codeBlock.Function("private static void", "InitializeFileWatch", "");
{
initializeMethod.Line("string globalContent = FlatRedBall.IO.FileManager.RelativeDirectory + \"content/globalcontent/\";");
var ifBlock = initializeMethod.If("System.IO.Directory.Exists(globalContent)");
{
ifBlock.Line("watcher = new System.IO.FileSystemWatcher();");
ifBlock.Line("watcher.Path = globalContent;");
ifBlock.Line("watcher.NotifyFilter = System.IO.NotifyFilters.LastWrite;");
ifBlock.Line("watcher.Filter = \"*.*\";");
ifBlock.Line("watcher.Changed += HandleFileChanged;");
ifBlock.Line("watcher.EnableRaisingEvents = true;");
}
}
}
示例7: 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;
}
示例8: 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;
}
示例9: GetFactoryInitializeMethod
private static ICodeBlock GetFactoryInitializeMethod(ICodeBlock codeBlock, string factoryClassName, int numberToPreAllocate)
{
string entityClassName = factoryClassName.Substring(0, factoryClassName.Length - "Factory".Length);
codeBlock
.Function("private static void", "FactoryInitialize", "")
.Line("const int numberToPreAllocate = " + numberToPreAllocate + ";")
.For("int i = 0; i < numberToPreAllocate; i++")
.Line(string.Format("{0} instance = new {0}(mContentManagerName, false);", entityClassName))
.Line("mPool.AddToPool(instance);")
.End()
.End();
return codeBlock;
}
示例10: WriteCodeForHasCursorOver
private static void WriteCodeForHasCursorOver(EntitySave entitySave, ICodeBlock codeBlock, bool doesParentHaveCursorOverMethod)
{
ICodeBlock func;
#region Write the method header
if (doesParentHaveCursorOverMethod)
{
func = codeBlock.Function("public override bool", "HasCursorOver", "FlatRedBall.Gui.Cursor cursor");
func.If("base.HasCursorOver(cursor)")
.Line("return true;");
}
else
{
func = codeBlock.Function("public virtual bool", "HasCursorOver", "FlatRedBall.Gui.Cursor cursor");
}
#endregion
// Even if this has a base Entity, it should check to see
// if it is paused, invisible, or on an invisible layer.
// The reason is if we rely on the base to
// tell us that, the base will return false if it's paused but
// we'll still end up checking the clickable objects in this.
#region Make sure the Entity isn't paused
func.If("mIsPaused")
.Line("return false;");
#endregion
#region If IVisible, then check to make sure the object is visible
if (entitySave.ImplementsIVisible)
{
func.If("!AbsoluteVisible")
.Line("return false;");
}
#endregion
#region Check to make sure the layer this is on is visible
func.If("LayerProvidedByContainer != null && LayerProvidedByContainer.Visible == false")
.Line("return false;");
#endregion
#region Make sure cursor is on the layer
func.If("!cursor.IsOn(LayerProvidedByContainer)")
.Line("return false;");
#endregion
AddCodeForIsOn(func, entitySave.NamedObjects);
func.Line("return false;");
}
示例11: GetInitializeFactoryMethod
private static ICodeBlock GetInitializeFactoryMethod(ICodeBlock codeBlock, string className, bool poolObjects, string listToAssign)
{
codeBlock = codeBlock
.Function("public static void", "Initialize", string.Format("FlatRedBall.Math.PositionedObjectList<{0}> listFromScreen, string contentManager", className))
.Line("mContentManagerName = contentManager;")
.Line(listToAssign + " = listFromScreen;");
if (poolObjects)
{
codeBlock.Line("FactoryInitialize();");
}
codeBlock = codeBlock.End();
return codeBlock;
}
示例12: GetDestroyFactoryMethod
private static ICodeBlock GetDestroyFactoryMethod(ICodeBlock codeBlock, string className)
{
className = className.Substring(0, className.Length - "Factory".Length);
codeBlock
.Function("public static void", "Destroy", "")
.Line("mContentManagerName = null;")
.Line("mScreenListReference = null;")
.Line("mPool.Clear();")
.Line("EntitySpawned = null;")
.End();
return codeBlock;
}
示例13: GenerateAssignCustomVariables
private static void GenerateAssignCustomVariables(ICodeBlock codeBlock, IElement element)
{
bool inherits = !string.IsNullOrEmpty(element.BaseElement) && !element.InheritsFromFrbType();
if (inherits)
{
codeBlock = codeBlock.Function("public override void", "AssignCustomVariables", "bool callOnContainedElements");
codeBlock.Line("base.AssignCustomVariables(callOnContainedElements);");
}
else
{
codeBlock = codeBlock.Function("public virtual void", "AssignCustomVariables", "bool callOnContainedElements");
}
// call AssignCustomVariables on all contained objects before assigning custom variables on "this"
var ifCallOnContainedElements = codeBlock.If("callOnContainedElements");
var listOfItems = element.NamedObjects.Where(item=>
item.IsFullyDefined &&
!item.IsDisabled &&
item.Instantiate &&
!item.SetByContainer &&
!item.SetByDerived
).ToList();
GenerateAssignmentForListOfObjects(codeBlock, element, ifCallOnContainedElements, listOfItems);
foreach (CustomVariable customVariable in element.CustomVariables)
{
CustomVariableCodeGenerator.AppendAssignmentForCustomVariableInElement(codeBlock, customVariable, element);
}
EventCodeGenerator.GenerateAddToManagersBottomUp(codeBlock, element);
}
示例14: FillWithGeneratedEventCode
public static ICodeBlock FillWithGeneratedEventCode(ICodeBlock currentBlock, EventResponseSave ers, IElement element)
{
EventSave eventSave = ers.GetEventSave();
string args = ers.GetArgsForMethod(element);
if (!string.IsNullOrEmpty(ers.SourceObject) && !string.IsNullOrEmpty(ers.SourceObjectEvent))
{
currentBlock = currentBlock
.Function("void", "On" + ers.EventName + "Tunnel", args);
string reducedArgs = StripTypesFromArguments(args);
currentBlock.If("this." + ers.EventName + " != null")
.Line(ers.EventName + "(" + reducedArgs + ");")
.End();
currentBlock = currentBlock.End();
}
return currentBlock;
}
示例15: 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;
}