本文整理汇总了C#中IElement.GetCustomVariable方法的典型用法代码示例。如果您正苦于以下问题:C# IElement.GetCustomVariable方法的具体用法?C# IElement.GetCustomVariable怎么用?C# IElement.GetCustomVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IElement
的用法示例。
在下文中一共展示了IElement.GetCustomVariable方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddCustomVariables
private void AddCustomVariables(IElement glueElement)
{
if (glueElement.GetCustomVariable("X") == null)
{
glueElement.CustomVariables.Add(new CustomVariable(){ Type="float", DefaultValue = 0.0f, Name = "X"});
}
if (glueElement.GetCustomVariable("Y") == null)
{
glueElement.CustomVariables.Add(new CustomVariable() { Type = "float", DefaultValue = 0.0f, Name = "Y" });
}
}
示例2: GenerateInterpolateForIndividualState
private static ICodeBlock GenerateInterpolateForIndividualState(IElement element, ICodeBlock codeBlock, ICodeBlock otherBlock, StateSave stateSave, string enumType)
{
codeBlock = codeBlock.Case(enumType + "." + stateSave.Name);
otherBlock = otherBlock.Case(enumType + "." + stateSave.Name);
foreach (InstructionSave instruction in stateSave.InstructionSaves)
{
CustomVariable customVariable = null;
customVariable = element.GetCustomVariable(instruction.Member);
string valueAsString = CodeParser.ParseObjectValue(instruction.Value);
if (customVariable != null && !string.IsNullOrEmpty(valueAsString))
{
NamedObjectSave sourceNamedObjectSave = element.GetNamedObjectRecursively(customVariable.SourceObject);
if (sourceNamedObjectSave == null || sourceNamedObjectSave.IsDisabled == false)
{
if (sourceNamedObjectSave != null)
{
NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, sourceNamedObjectSave);
NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(otherBlock, sourceNamedObjectSave);
}
string timeCastString = "";
if (instruction.Value is float)
{
timeCastString = "(float)";
}
if (string.IsNullOrEmpty(customVariable.SourceObject))
{
GenerateInterpolateForIndividualStateNoSource(ref codeBlock, element, ref otherBlock, instruction, customVariable, valueAsString, timeCastString);
}
else
{
GenerateInterpolateForIndividualStateWithSource(ref codeBlock, element, ref otherBlock, customVariable, valueAsString, sourceNamedObjectSave, timeCastString);
}
if (sourceNamedObjectSave != null)
{
NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, sourceNamedObjectSave);
NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(otherBlock, sourceNamedObjectSave);
}
}
}
}
return codeBlock;
}
示例3: GetIfShouldGenerate
private static bool GetIfShouldGenerate(IElement element)
{
bool shouldContinue = true;
bool isScreen = element is ScreenSave;
if (!isScreen)
{
shouldContinue = false;
}
if (shouldContinue)
{
var variable = element.GetCustomVariable(AddLevelController.UsesTmxLevelFilesVariableName);
if (variable == null || variable.DefaultValue == null || (variable.DefaultValue is bool) == false || (bool)(variable.DefaultValue) == false)
{
shouldContinue = false;
}
}
return shouldContinue;
}
示例4: GenerateCurrentStateProperty
private static ICodeBlock GenerateCurrentStateProperty(IElement element, ICodeBlock codeBlock, string enumType, List<StateSave> states)
{
var createField = false;
if (enumType == "VariableState" && !DoesBaseHaveUncategorizedStates(element)) //Uncategorized and not base
{
createField = true;
}
else if (enumType != "VariableState") //Check if this state category exists in a parent entity
{
if (element.BaseElement != null)
{
var categories = GetAllStateCategoryNames(ObjectFinder.Self.GetIElement(element.BaseElement), true);
if (!categories.Any(category => category == enumType))
{
createField = true;
}
}else
{
createField = true;
}
}
string variableNameModifier = enumType;
if (enumType == "VariableState")
{
variableNameModifier = "";
}
string qualifiedEnumType = element.Name.Replace("\\", ".").Replace("/", ".") + "." + enumType;
if (states.Count != 0)
{
string variableToLookFor = "Current" + variableNameModifier + "State";
CustomVariable customVariable = element.GetCustomVariable(variableToLookFor);
bool hasEvent = customVariable != null && customVariable.CreatesEvent;
#region Header and Getter stuff - simple stuff with no logic
if (createField)
{
codeBlock
.Line(string.Format("protected int mCurrent{0}State = 0;", variableNameModifier));
}
string publicWithOptionalNew = "public";
if (ShouldUseNewKeyword(element, enumType))
{
publicWithOptionalNew += " new";
}
var setBlock = codeBlock
.Property(publicWithOptionalNew + " " + qualifiedEnumType, "Current" + variableNameModifier + "State")
.Get()
.If(string.Format("System.Enum.IsDefined(typeof({0}), mCurrent{1}State)", enumType, variableNameModifier))
.Line(string.Format("return ({0})mCurrent{1}State;", enumType, variableNameModifier))
.End()
.Else()
.Line(string.Format("return {0}.Unknown;", enumType))
.End()
.End()
.Set();
#endregion
#region Set the state value and call an event if necessary
bool stillNeedsToAssignValue = true;
if (element is EntitySave)
{
EntitySave asEntitySave = element as EntitySave;
//if (!string.IsNullOrEmpty(asEntitySave.CurrentStateChange))
//{
// setBlock
// .If("value != mCurrent" + variableNameModifier + "State")
// .Line("mCurrent" + variableNameModifier + "State = value;")
// .Line(asEntitySave.CurrentStateChange + "(this, null);");
// stillNeedsToAssignValue = false;
//}
}
if (hasEvent)
{
EventCodeGenerator.GenerateEventRaisingCode(setBlock, BeforeOrAfter.Before, variableToLookFor, element);
}
if (stillNeedsToAssignValue)
{
setBlock.Line("mCurrent" + variableNameModifier + "State = (int)value;");
}
#endregion
var switchBlock = setBlock.Switch("Current" + variableNameModifier + "State");
switchBlock.Case(enumType + ".Uninitialized");
switchBlock.Case(enumType + ".Unknown");
//.........这里部分代码省略.........
示例5: UpdateCustomVariablesFromBaseType
//.........这里部分代码省略.........
public static void UpdateCustomVariablesFromBaseType(IElement behaviorContainer)
{
IElement baseElement = null;
if (behaviorContainer is ScreenSave)
{
baseElement = ObjectFinder.Self.GetScreenSave(behaviorContainer.BaseObject);
}
else
{
baseElement = ObjectFinder.Self.GetEntitySave(behaviorContainer.BaseObject);
}
List<CustomVariable> customVariablesBeforeUpdate = new List<CustomVariable>();
for (int i = 0; i < behaviorContainer.CustomVariables.Count; i++)
{
if (behaviorContainer.CustomVariables[i].DefinedByBase)
{
customVariablesBeforeUpdate.Add(behaviorContainer.CustomVariables[i]);
}
}
List<CustomVariable> newCustomVariables = null;
//EntitySave entity = ProjectManager.GetEntitySave(mBaseEntity);
if (baseElement != null)
{
newCustomVariables = baseElement.GetCustomVariablesToBeSetByDerived();
}
else
{
newCustomVariables = new List<CustomVariable>();
}
// See if there are any objects to be removed.
for (int i = customVariablesBeforeUpdate.Count - 1; i > -1; i--)
{
bool contains = false;
for (int j = 0; j < newCustomVariables.Count; j++)
{
if (customVariablesBeforeUpdate[i].Name == newCustomVariables[j].Name &&
customVariablesBeforeUpdate[i].DefinedByBase)
{
contains = true;
break;
}
}
if (!contains)
{
// We got a NamedObject we should remove
behaviorContainer.CustomVariables.Remove(customVariablesBeforeUpdate[i]);
customVariablesBeforeUpdate.RemoveAt(i);
}
}
// Next, see if there are any objects to be added
for (int i = 0; i < newCustomVariables.Count; i++)
{
示例6: SetInterpolateBetweenValuesForStates
private static ICodeBlock SetInterpolateBetweenValuesForStates(IElement element, string enumType, List<StateSave> states, ICodeBlock curBlock, Dictionary<InstructionSave, InterpolationCharacteristic> mInterpolationCharacteristics, string firstOrSecondValue)
{
foreach (StateSave state in states)
{
curBlock = curBlock.Case(enumType + "." + state.Name);
foreach (InstructionSave instructionSave in state.InstructionSaves)
{
var customVariable = element.GetCustomVariable(instructionSave.Member);
NamedObjectSave sourceNamedObjectSave = null;
if (customVariable != null)
{
sourceNamedObjectSave = element.GetNamedObjectRecursively(customVariable.SourceObject);
}
if(sourceNamedObjectSave != null)
{
NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(curBlock, sourceNamedObjectSave);
}
if (GetValue(mInterpolationCharacteristics, instructionSave.Member) != InterpolationCharacteristic.CantInterpolate)
{
if (instructionSave.Value == null)
{
curBlock.Line("set" + instructionSave.Member + " = false;");
}
else
{
string valueToWrite = GetRightSideAssignmentValueAsString(element, instructionSave);
curBlock.Line(instructionSave.Member + firstOrSecondValue + " = " + valueToWrite + ";");
}
}
else // This value can't be interpolated, but if the user has set a value of 0 or 1, then it should be set
{
ICodeBlock ifBlock;
// value will come from the first state unless the interpolationValue is 1.
// This makes the code behave the same as InterpolateTo which uses instructions.
if (firstOrSecondValue == FirstValue)
{
ifBlock = curBlock.If("interpolationValue < 1");
}
else
{
ifBlock = curBlock.If("interpolationValue >= 1");
}
string valueToWrite = GetRightSideAssignmentValueAsString(element, instructionSave);
ifBlock.Line("this." + instructionSave.Member + " = " + valueToWrite + ";");
}
if (sourceNamedObjectSave != null)
{
NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(curBlock, sourceNamedObjectSave);
}
}
curBlock = curBlock.End();
}
return curBlock;
}
示例7: CreateStartingValueVariables
private static void CreateStartingValueVariables(IElement element, List<StateSave> states, ICodeBlock curBlock, Dictionary<InstructionSave, InterpolationCharacteristic> interpolationCharacteristics)
{
foreach (StateSave state in states)
{
foreach (InstructionSave instructionSave in state.InstructionSaves)
{
string member = instructionSave.Member;
if (!ContainsKey(interpolationCharacteristics, member))
{
CustomVariable customVariable = element.GetCustomVariable(member);
NamedObjectSave nos = null;
if (customVariable != null)
{
nos = element.GetNamedObjectRecursively(customVariable.SourceObject);
}
if (nos == null || nos.IsDisabled == false)
{
InterpolationCharacteristic interpolationCharacteristic =
CustomVariableHelper.GetInterpolationCharacteristic(customVariable, element);
interpolationCharacteristics.Add(instructionSave, interpolationCharacteristic);
if (interpolationCharacteristic != InterpolationCharacteristic.CantInterpolate)
{
curBlock.Line("bool set" + instructionSave.Member + " = true;");
string defaultStartingValue = "";
try
{
if (customVariable.GetIsVariableState())
{
IElement stateContainingEntity = null;
if (nos != null)
{
stateContainingEntity = ObjectFinder.Self.GetIElement(nos.SourceClassType);
}
else if (string.IsNullOrEmpty(customVariable.SourceObject))
{
stateContainingEntity = element;
}
if (stateContainingEntity != null)
{
string stateType = "VariableState";
if (customVariable != null && customVariable.Type.ToLower() != "string")
{
stateType = customVariable.Type;
}
defaultStartingValue = StateCodeGenerator.FullyQualifiedDefaultStateValue(stateContainingEntity, stateType);
}
}
else
{
defaultStartingValue = TypeManager.GetDefaultForType(instructionSave.Type);
}
}
catch
{
throw new Exception("Could not get a default value for " + instructionSave.Member + " of type " + instructionSave.Type);
}
string type = CustomVariableCodeGenerator.GetMemberTypeFor(customVariable, element);
curBlock.Line(type + " " + member + FirstValue + "= " + defaultStartingValue + ";");
curBlock.Line(type + " " + member + SecondValue + "= " + defaultStartingValue + ";");
}
}
}
}
}
}
示例8: AssignValuesUsingStartingValues
private static ICodeBlock AssignValuesUsingStartingValues(IElement element, ICodeBlock curBlock, Dictionary<InstructionSave, InterpolationCharacteristic> mInterpolationCharacteristics)
{
foreach (KeyValuePair<InstructionSave, InterpolationCharacteristic> kvp in mInterpolationCharacteristics)
{
if (kvp.Value != InterpolationCharacteristic.CantInterpolate)
{
curBlock = curBlock.If("set" + kvp.Key.Member);
CustomVariable variable = element.GetCustomVariable(kvp.Key.Member);
var nos = element.GetNamedObjectRecursively(variable.SourceObject);
if(nos != null)
{
NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(curBlock, nos);
}
string relativeValue = InstructionManager.GetRelativeForAbsolute(kvp.Key.Member);
string variableToAssign = kvp.Key.Member;
string leftSideOfEqualsWithRelative = GetLeftSideOfEquals(element, variable, kvp.Key, true);
if (!string.IsNullOrEmpty(leftSideOfEqualsWithRelative) && leftSideOfEqualsWithRelative != kvp.Key.Member)
{
string beforeDotParent = variable.SourceObject;
if (string.IsNullOrEmpty(variable.SourceObject))
{
beforeDotParent = "this";
}
curBlock = curBlock.If(beforeDotParent + ".Parent != null");
AddAssignmentForInterpolationForVariable(curBlock, variable, variableToAssign, leftSideOfEqualsWithRelative);
curBlock = curBlock.End().Else();
}
AddAssignmentForInterpolationForVariable(curBlock, variable, variableToAssign, variableToAssign);
if (!string.IsNullOrEmpty(relativeValue))
{
curBlock = curBlock.End(); // end the else
}
curBlock = curBlock.End();
if (nos != null)
{
NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(curBlock, nos);
}
}
}
return curBlock;
}