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


C# IElement.GetCustomVariable方法代码示例

本文整理汇总了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" });
            }

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

示例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;
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:50,代码来源:StateCodeGenerator.Interpolation.cs

示例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;
        }
开发者ID:GorillaOne,项目名称:FlatRedBall,代码行数:22,代码来源:LevelCodeGenerator.cs

示例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");
//.........这里部分代码省略.........
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:101,代码来源:StateCodeGenerator.cs

示例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++)
            {
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:67,代码来源:BehaviorSaveExtensionMethods.cs

示例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;
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:61,代码来源:StateCodeGenerator.Interpolation.cs

示例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 + ";");
                            }
                        }
                    }
                }
            }
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:83,代码来源:StateCodeGenerator.Interpolation.cs

示例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;
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:56,代码来源:StateCodeGenerator.Interpolation.cs


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