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


C# IElement.GetNamedObjectRecursively方法代码示例

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


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

示例1: 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

示例2: GetIsSourceFile

        public static bool GetIsSourceFile(this CustomVariable customVariable, IElement container)
        {
            NamedObjectSave referencedNos = null;
            if(!string.IsNullOrEmpty(customVariable.SourceObject) )
            {
                referencedNos = container.GetNamedObjectRecursively(customVariable.SourceObject);
            }

            return referencedNos != null && customVariable.SourceObjectProperty == "SourceFile" && referencedNos.SourceType == SourceType.FlatRedBallType;


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

示例3: HasAccompanyingVelocityConsideringTunneling

        public static bool HasAccompanyingVelocityConsideringTunneling(this CustomVariable variable, IElement container, int maxDepth = 0)
        {
            if (variable.HasAccompanyingVelocityProperty)
            {
                return true;
            }
            else if (!string.IsNullOrEmpty(variable.SourceObject) && !string.IsNullOrEmpty(variable.SourceObjectProperty) && maxDepth > 0)
            {
                NamedObjectSave nos = container.GetNamedObjectRecursively(variable.SourceObject);

                if (nos != null)
                {
                    // If it's a FRB 
                    if (nos.SourceType == SourceType.FlatRedBallType || nos.SourceType == SourceType.File)
                    {
                        return !string.IsNullOrEmpty(InstructionManager.GetVelocityForState(variable.SourceObjectProperty));
                    }
                    else if(nos.SourceType == SourceType.Entity)
                    {
                        EntitySave entity = ObjectFinder.Self.GetEntitySave(nos.SourceClassType);

                        if (entity != null)
                        {
                            CustomVariable variableInEntity = entity.GetCustomVariable(variable.SourceObjectProperty);

                            if (variableInEntity != null)
                            {
                                if (!string.IsNullOrEmpty(InstructionManager.GetVelocityForState(variableInEntity.Name)))
                                {
                                    return true;
                                }
                                else
                                {

                                    return variableInEntity.HasAccompanyingVelocityConsideringTunneling(entity, maxDepth - 1);
                                }
                            }
                            else
                            {
                                // There's no variable for this, so let's see if it's a variable that has velocity in FRB
                                return !string.IsNullOrEmpty(InstructionManager.GetVelocityForState(variable.SourceObjectProperty));

                            }
                        }
                    }
                }
            }
            return false;

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

示例4: FillPossibleStatesFor

        private static CustomVariable FillPossibleStatesFor(List<string> listToFill, IElement currentElement, CustomVariable customVariable)
        {

            IElement sourceElement = null;

            customVariable = customVariable.GetDefiningCustomVariable();

            if (!string.IsNullOrEmpty(customVariable.SourceObject))
            {
                NamedObjectSave namedObjectSave = currentElement.GetNamedObjectRecursively(customVariable.SourceObject);

                sourceElement = ObjectFinder.Self.GetEntitySave(namedObjectSave.SourceClassType);
                if (sourceElement == null)
                {
                    sourceElement = ObjectFinder.Self.GetScreenSave(namedObjectSave.SourceClassType);
                }
            }
            else
            {
                sourceElement = currentElement;
            }


            IEnumerable<StateSave> whatToLoopThrough = null;

            if (customVariable != null)
            {
                StateSaveCategory category = sourceElement.GetStateCategoryRecursively(customVariable.Type);

                if (category != null)
                {
                    whatToLoopThrough = category.States;
                }
            }

            listToFill.Add("<NONE>");

            if (whatToLoopThrough == null)
            {
                foreach (StateSave state in sourceElement.GetUncategorizedStatesRecursively())
                {
                    listToFill.Add(state.Name);

                }
                foreach (StateSaveCategory ssc in sourceElement.StateCategoryList)
                {
                    if (ssc.SharesVariablesWithOtherCategories == true)
                    {
                        foreach (StateSave stateInCategory in ssc.States)
                        {
                            listToFill.Add(stateInCategory.Name);

                        }
                    }
                }

            }
            else
            {
                // We are looping through a category
                foreach (StateSave stateSave in whatToLoopThrough)
                {
                    listToFill.Add(stateSave.Name);
                }
            }
            return customVariable;
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:67,代码来源:AvailableStates.cs

示例5: AppendPropertyForTunneledVariable

        private static void AppendPropertyForTunneledVariable(IElement saveObject, ICodeBlock codeBlock, CustomVariable customVariable)
        {
            NamedObjectSave referencedNos = saveObject.GetNamedObjectRecursively(customVariable.SourceObject);

            if (referencedNos != null)
            {
                NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, referencedNos); 

                string customVariableType = GetMemberTypeFor(customVariable, saveObject);

                if (customVariable.CreatesEvent)
                {
                    EventCodeGenerator.GenerateEventsForVariable(codeBlock, customVariable.Name);
                }

                if (!string.IsNullOrEmpty(customVariable.OverridingPropertyType))
                {
                    customVariableType = customVariable.OverridingPropertyType;
                }

                ICodeBlock prop = WritePropertyHeader(codeBlock, customVariable, customVariableType);

                bool hasGetter = true;

                string propertyToAssign = customVariable.SourceObjectProperty;


                // later we will want to make this data driven
                if (referencedNos.SourceType == SourceType.File &&
                    FileManager.GetExtension(referencedNos.SourceFile) == "scnx" &&
                    referencedNos.SourceName.StartsWith("Entire File") &&
                    customVariable.SourceObjectProperty == "Visible")
                {
                    hasGetter = false;
                }





                bool isVisibleSetterOnList = referencedNos.IsList &&
                    customVariable.SourceObjectProperty == "Visible";

                if (isVisibleSetterOnList)
                {
                    hasGetter = false;
                }
                if (hasGetter)
                {
                    WriteGetterForProperty(customVariable, saveObject, prop);
                }

                WriteSetterForProperty(saveObject, customVariable, prop, isVisibleSetterOnList);

                NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, referencedNos);

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

示例6: GetRightSideAssignmentValueAsString

        public static string GetRightSideAssignmentValueAsString(IElement element, InstructionSave instruction)
        {
            CustomVariable customVariable = element.GetCustomVariableRecursively(instruction.Member);

            IElement referencedElement = null;

            #region Determine if the assignment is a file

            bool isFile = false;

            if (customVariable != null)
            {
                referencedElement =
                    BaseElementTreeNode.GetElementIfCustomVariableIsVariableState(customVariable, element);

                isFile = customVariable.GetIsFile();

            }

            #endregion

            string valueAsString = "";

            if (referencedElement == null)
            {

                valueAsString = CodeParser.ParseObjectValue(instruction.Value);

                if (isFile)
                {
                    valueAsString = valueAsString.Replace("\"", "");

                    if (valueAsString == "<NONE>")
                    {
                        valueAsString = "null";
                    }
                }
                else if (CustomVariableCodeGenerator.ShouldAssignToCsv(customVariable, valueAsString))
                {
                    valueAsString = CustomVariableCodeGenerator.GetAssignmentToCsvItem(customVariable, element, valueAsString);
                }
                else if (customVariable != null && customVariable.Type == "Color")
                {
                    valueAsString = "Color." + valueAsString.Replace("\"", "");
                }
                if (customVariable != null && !string.IsNullOrEmpty(customVariable.SourceObject) && !isFile)
                {
                    NamedObjectSave namedObject = element.GetNamedObjectRecursively(customVariable.SourceObject);

                    bool isVariableState = customVariable.GetIsVariableState();

                    IElement objectElement = null;

                    if (namedObject != null)
                    {
                        ObjectFinder.Self.GetIElement(namedObject.SourceClassType);
                    }

                    if (objectElement != null)
                    {
                        if (isVariableState)
                        {
                            string typeName = "VariableState";

                            StateSaveCategory category = objectElement.GetStateCategoryRecursively(customVariable.Type);

                            if(category != null && category.SharesVariablesWithOtherCategories == false)
                            {
                                typeName = category.Name;
                            }
                            valueAsString = objectElement.Name.Replace("/", ".").Replace("\\", ".") + "." + typeName + "." + valueAsString.Replace("\"", "");
                        }
                    }

                    valueAsString = CodeWriter.MakeLocalizedIfNecessary(
                        namedObject,
                        instruction.Member,
                        instruction.Value,
                        valueAsString,
                        customVariable);
                }
            }
            else
            {
                string enumValue = (string)instruction.Value;

                if (!string.IsNullOrEmpty(enumValue))
                {
                    string variableType = "VariableState";

                    if (customVariable != null && customVariable.Type.ToLower() != "string")
                    {
                        variableType = customVariable.Type;
                    }
                    valueAsString = FullyQualifyStateValue(referencedElement, enumValue, variableType);
                }

            }
            return valueAsString;
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:100,代码来源:StateCodeGenerator.cs

示例7: GetElementIfCustomVariableIsVariableState

        //public abstract void GenerateCode();



        public static IElement GetElementIfCustomVariableIsVariableState(CustomVariable customVariable, IElement saveObject)
        {

            if (customVariable.GetIsVariableState() && string.IsNullOrEmpty(customVariable.SourceObject))
            {
                return saveObject;
            }
            else
            {

                NamedObjectSave sourceNamedObjectSave = saveObject.GetNamedObjectRecursively(customVariable.SourceObject);

                if (sourceNamedObjectSave != null)
                {
                    EntitySave sourceEntitySave = ObjectFinder.Self.GetEntitySave(sourceNamedObjectSave.SourceClassType);

                    if (sourceEntitySave != null &&
                        ((sourceEntitySave.States.Count != 0 && customVariable.SourceObjectProperty == "CurrentState") ||
                        sourceEntitySave.StateCategoryList.ContainsCategoryName(customVariable.Type))
                        )
                    {
                        return sourceEntitySave;
                    }
                    else if (sourceEntitySave == null)
                    {
                        ScreenSave sourceScreenSave = ObjectFinder.Self.GetScreenSave(sourceNamedObjectSave.SourceClassType);

                        if (sourceScreenSave != null && sourceScreenSave.States.Count != 0 && customVariable.SourceObjectProperty == "CurrentState")
                        {
                            return sourceScreenSave;
                        }

                    }
                }
                return null;
            }
        }
开发者ID:GorillaOne,项目名称:FlatRedBall,代码行数:41,代码来源:BaseElementTreeNode.cs

示例8: IsCustomVariableNameValid

        internal static bool IsCustomVariableNameValid(string variableName, CustomVariable customVariable, IElement containingElement, ref string whyItIsntValid)
        {
            CheckForCommonImproperNames(variableName, ref whyItIsntValid);

            if(string.IsNullOrEmpty(whyItIsntValid))
            {
                if (containingElement.CustomVariables.Any(item=> item.Name == variableName && item != customVariable))
                {
                    string screenOrEntity = "";

                    if (containingElement is ScreenSave)
                    {
                        screenOrEntity = "Screen";
                    }
                    else
                    {
                        screenOrEntity = "Entity";
                    }

                    whyItIsntValid += "This " + screenOrEntity + " already has a variable named " + variableName;
                }
            }

            // This looks like duplicate code compared to what's above.  
            //if (string.IsNullOrEmpty(whyItIsntValid))
            //{
            //    if (containingElement.ContainsCustomVariable(variableName))
            //    {
            //        string screenOrEntity = "";

            //        if (containingElement is ScreenSave)
            //        {
            //            screenOrEntity = "Screen";
            //        }
            //        else
            //        {
            //            screenOrEntity = "Entity";
            //        }

            //        whyItIsntValid += "This " + screenOrEntity + " already has a variable named " + variableName;
            //    }
            //}

            if (string.IsNullOrEmpty(whyItIsntValid))
            {
                if (containingElement.GetNamedObjectRecursively(variableName) != null)
                {
                    string screenOrEntity = "";

                    if (containingElement is ScreenSave)
                    {
                        screenOrEntity = "Screen";
                    }
                    else
                    {
                        screenOrEntity = "Entity";
                    }
                    whyItIsntValid = "This " + screenOrEntity + 
                        " has an object named " + variableName + " so you must choose a different variable name";
                }
            }

            return string.IsNullOrEmpty(whyItIsntValid);

        }
开发者ID:GorillaOne,项目名称:FlatRedBall,代码行数:65,代码来源:NameVerifier.cs

示例9: 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

示例10: 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

示例11: GenerateInterpolateForIndividualStateWithSourceStateVariable

        private static void GenerateInterpolateForIndividualStateWithSourceStateVariable(ICodeBlock codeBlock, CustomVariable variable, IElement container, string value)
        {
            if (string.IsNullOrEmpty(value) == false)
            {
                var nos = container.GetNamedObjectRecursively(variable.SourceObject);



                var sourceElement = ObjectFinder.Self.GetIElement(nos.SourceClassType);
                // InterpolationEntityInstance.InterpolateToState(InterpolationEntity.VariableState.Small, secondsToTake);
                //
                string type = "VariableState";
                if (variable != null && variable.Type.ToLower() != "string")
                {
                    type = variable.Type;
                }


                codeBlock.Line(variable.SourceObject + ".InterpolateToState(" + 
                    sourceElement.GetQualifiedName(ProjectManager.ProjectNamespace) + "." + type + "." + value + ", secondsToTake);");
            }
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:22,代码来源:StateCodeGenerator.Interpolation.cs

示例12: IsVariableTunnelingToDisabledObject

        private static bool IsVariableTunnelingToDisabledObject(CustomVariable customVariable, IElement saveObject)
        {
            if (string.IsNullOrEmpty(customVariable.SourceObject))
            {
                return false;
            }
            else
            {
                NamedObjectSave nos = saveObject.GetNamedObjectRecursively(customVariable.SourceObject);

                return nos != null && nos.IsDisabled;
            }
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:13,代码来源:CustomVariableCodeGenerator.cs

示例13: GetMemberTypeFor

        public static string GetMemberTypeFor(CustomVariable customVariable, IElement element)
        {
            NamedObjectSave referencedNos = element.GetNamedObjectRecursively(customVariable.SourceObject);

            string customVariableType;
            bool isTypeFromCsv = false;
            if (IsTypeFromCsv(customVariable))
            {
                // This is a type defined in a CSV
                ReferencedFileSave rfsForCsv = ObjectFinder.Self.GetAllReferencedFiles().FirstOrDefault(item =>
                    item.IsCsvOrTreatedAsCsv && item.GetTypeForCsvFile() == customVariable.Type);


                if (rfsForCsv != null)
                {
                    customVariableType = rfsForCsv.GetTypeForCsvFile();
                }
                else
                {
                    string unqualifiedType = null;
                    unqualifiedType = FileManager.RemovePath(FileManager.RemoveExtension(customVariable.Type));
                    if (unqualifiedType.EndsWith("File"))
                    {
                        unqualifiedType = unqualifiedType.Substring(0, unqualifiedType.Length - "File".Length);
                    }
                    customVariableType = ProjectManager.ProjectNamespace + ".DataTypes." + unqualifiedType;

                }

                isTypeFromCsv = true;
            }
            else
            {
                customVariableType = customVariable.Type;
            }


            // CSVs may happen to be named the same as base types - like "Resources",
            // so we only want to use the TypeManager if we didn't first find a CSV.
            if (!isTypeFromCsv)
            {

                Type type = null;

                if (!string.IsNullOrEmpty(customVariableType))
                {
                    type = TypeManager.GetTypeFromString(customVariableType);
                }

                if (type != null)
                {
                    // If it's a common type we don't want to make things confusing
                    // by using "System.Single", but we do want to fully-qualify things
                    // like FlatRedBall types to make sure we don't get any kind of naming
                    // conflicts
                    // If a value is defined inside a class (like the Borders enum in SpriteFrame)
                    // then its type will come out with a +.  We need to replace that with a dot.
                    customVariableType = TypeManager.ConvertToCommonType(type.FullName).Replace("+", ".");
                }
            }

            if (customVariable.GetIsVariableState())
            {
                // handle old tunneled variables:  tunneled state variables used to set their type
                // as "string" instead of the variable state type.
                // We now set the type to be the variable type (the enum type) but we want existing projects to continue to work
                if (customVariableType == "string")
                {
                    customVariableType = "VariableState";
                }
                if (customVariable.IsTunneling)
                {
                    IElement namedObjectElement = ObjectFinder.Self.GetIElement(referencedNos.SourceClassType);
                    if (namedObjectElement != null)
                    {
                        customVariableType = namedObjectElement.Name.Replace("\\", ".") + "." + customVariableType;
                    }
                }
                else
                {
                    customVariableType = element.Name.Replace("\\", ".") + "." + customVariableType;
                }
            }

            return customVariableType;
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:86,代码来源:CustomVariableCodeGenerator.cs

示例14: WriteSetterForProperty

        private static void WriteSetterForProperty(IElement saveObject, CustomVariable customVariable, ICodeBlock prop, bool isVisibleSetterOnList)
        {
            var setter = prop.Set();

            if (EventCodeGenerator.ShouldGenerateEventsForVariable(customVariable, saveObject))
            {
                EventCodeGenerator.GenerateEventRaisingCode(setter, BeforeOrAfter.Before, customVariable.Name, saveObject);
            }

            NamedObjectSave nos = saveObject.GetNamedObjectRecursively(customVariable.SourceObject);

            bool addOrRemoveOnValueChange = nos.RemoveFromManagersWhenInvisible && customVariable.SourceObjectProperty == "Visible";

            if (isVisibleSetterOnList)
            {
                setter.Line(customVariable.SourceObject + ".SetVisible(value);");
            }
            else if(customVariable.GetIsSourceFile(saveObject))
            {
                // We need to assign the property here on the NamedObjectSave, as if it's done in code in the AddToManagersBottomUp

                // We need to temporarily make the NOS act as if it's using the argument file as its SourceFile
                var oldSourceType = nos.SourceType;
                var oldSourceFile = nos.SourceFile;
                var oldSourceName = nos.SourceName;
                nos.SourceType = SourceType.File;
                nos.SourceFile = "value";
                nos.SourceName = "Entire File (" + customVariable.Type  + ")";

                
                NamedObjectSaveCodeGenerator.WriteCodeForNamedObjectInitialize(nos, saveObject, setter, "value");//WriteAddToManagersForNamedObject(saveObject, nos, setter);

                bool storeOldValue = nos.RemoveFromManagersWhenInvisible && customVariable.SourceObjectProperty == "Visible";

                bool canBeLayered = false;
                if (nos.GetAssetTypeInfo() != null)
                {
                    canBeLayered = nos.GetAssetTypeInfo().LayeredAddToManagersMethod.Count != 0;
                }


                if (canBeLayered)
                {
                    // This object may be 
                    // added to a Layer.  We
                    // will add it to the NOS's
                    // Layer if there is one.  If 
                    // not, we'll use the object's
                    // Layer
                    string layerName;
                    if (!string.IsNullOrEmpty(nos.LayerOn))
                    {
                        layerName = nos.LayerOn;
                    }
                    else if (saveObject is EntitySave)
                    {
                        layerName = "LayerProvidedByContainer";
                    }
                    else
                    {
                        // I don't remember if Screens
                        // have a Layer that they use by
                        // default.  If so, this has probably
                        // fallen out of style because of Glue.
                        layerName = "null";
                    }

                    // Glue has no way of knowing whether this property will be used or not:
                    setter.Line("#pragma warning disable");
                    setter.Line("");
                    setter.Line("FlatRedBall.Graphics.Layer layerToAddTo = " + layerName + ";");
                    setter.Line("#pragma warning enable");
                    // Wow, so crazy, but the automated
                    // tests revealed that the line following
                    // the #pragma wasn't ever being run on iOS.
                    // I suspect it has to do with line endings after
                    // the #pragma line?  Anyway, putting a new line in
                    // seems to fix the bug.
                    setter.Line("");
                }

                NamedObjectSaveCodeGenerator.WriteAddToManagersForNamedObject(saveObject, nos, setter, true);

                nos.SourceType = oldSourceType;
                nos.SourceFile = oldSourceFile;
                nos.SourceName = oldSourceName;
            }
            else
            {

                string relativeVersionOfProperty = InstructionManager.GetRelativeForAbsolute(customVariable.SourceObjectProperty);
                if (!string.IsNullOrEmpty(relativeVersionOfProperty))
                {
                    setter = setter.If(customVariable.SourceObject + ".Parent == null");
                }

                string value = "value";

                if (!string.IsNullOrEmpty(customVariable.OverridingPropertyType) &&
                    // If the overriding type is the same as the variable type then no conversion can be performed
//.........这里部分代码省略.........
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:101,代码来源:CustomVariableCodeGenerator.cs

示例15: WriteAddToManagersBottomUpForNamedObjectList

        public static void WriteAddToManagersBottomUpForNamedObjectList(List<NamedObjectSave> namedObjectList, ICodeBlock codeBlock, IElement element, List<string[]> reusableEntireFileRfses)
        {
            foreach(var nos in namedObjectList.Where(nos=>nos.SourceType != SourceType.FlatRedBallType || nos.SourceClassType != "Layer"))
            {
                ReferencedFileSave filePullingFrom = null;

                string[] foundPair = null;

                if (nos.SourceType == SourceType.File && nos.SourceName != null)
                {
                    if (nos.IsEntireFile)
                    {
                        filePullingFrom = element.GetReferencedFileSave(nos.SourceFile);
                    }
                    else
                    {
                        foreach (string[] stringPair in reusableEntireFileRfses)
                        {
                            if (stringPair[0] == nos.SourceFile)
                            {
                                foundPair = stringPair;
                                break;
                            }
                        }
                    }
                }

                NamedObjectSave entireFileNos = null;

                if (foundPair != null)
                {
                    entireFileNos = element.GetNamedObjectRecursively(foundPair[1]);
                }

                //mReusableEntireFileRfses

                // We need to add this object if it is not part
                // of an EntireFile object, or if it has a custom
                // Layer.
                // Update September 30, 2012
                // This could also be an object 
                // from a file that is part of a 
                // Screen, therefore it is already
                // added to managers.  If so, we don't
                // want to add it again.
                // Update March 31, 2013
                // If the object is part of a file, but
                // its layer differs from the object that
                // it is a part of, then we need to add it.
                // But we want to remove it from the engine before
                // re-adding so that it isn't part of 2 different if
                // the container is itself on a Layer.
                bool isAlreadyAdded = entireFileNos != null ||
                    (filePullingFrom != null && ReferencedFileSaveCodeGenerator.GetIfShouldAddToManagers(element, filePullingFrom));


                if (!isAlreadyAdded || 
                    (entireFileNos != null && entireFileNos.LayerOn != nos.LayerOn) ||
                    (filePullingFrom != null && !string.IsNullOrEmpty(nos.LayerOn))
                    )
                {
                    if (isAlreadyAdded)
                    {

                        var ati = nos.GetAssetTypeInfo();
                        if (ati != null && !string.IsNullOrEmpty(ati.RecycledDestroyMethod))
                        {
                            string recycleMethod = ati.RecycledDestroyMethod.Replace("this", nos.InstanceName) + ";";
                            codeBlock.Line(recycleMethod);
                        }
                    }
                    NamedObjectSaveCodeGenerator.WriteAddToManagersForNamedObject(element, nos, codeBlock);
                }

                #region Loop through all contained NamedObjects in Lists - and call WriteAddToManagersForNamedObject recursively
                // Loop through all contained NamedObjects
                foreach (NamedObjectSave containedNos in nos.ContainedObjects)
                {
                    WriteAddToManagersForNamedObject(element, containedNos, codeBlock);

                    // 12/14/2010
                    // We used to add
                    // objects which are
                    // part of a list to their
                    // list here, but if that happened,
                    // then variables like Visible wouldn't
                    // work properly.  So this code was moved
                    // into initialize 
                    // stringBuilder.AppendLine("\t\t\t" + namedObject.InstanceName + ".Add(" + containedNos.InstanceName + ");");
                }
                #endregion


            }





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


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