FlatRedBall.Glue.ElementRuntime.SetState C# (CSharp) Method

SetState() public method

public SetState ( StateSave stateToSet, IElement container ) : void
stateToSet FlatRedBall.Glue.SaveClasses.StateSave
container IElement
return void
        public void SetState(StateSave stateToSet, IElement container)
        {
            // Do we need to refresh positioned values?  I don't think so, because it causes bugs and
            // the fact that we set relative values now means we don't need to refresh the povalues anymore...
            //SetState(stateToSet, true, container);
            SetState(stateToSet, false, container);
        }

Same methods

ElementRuntime::SetState ( StateSave stateToSet, bool refreshPositionedObjectValues, IElement container ) : void
ElementRuntime::SetState ( string stateName ) : void
ElementRuntime::SetState ( string stateName, bool refreshPositionedObjectValues ) : void

Usage Example

示例#1
0
        private void SetVariablesForNamedObject(object newlyCreatedElementRuntime, NamedObjectSave n)
        {
            if (newlyCreatedElementRuntime != null)
            {
                ElementRuntime containedElementRuntime = GetContainedElementRuntime(n);

                Type typeOfNewObject = newlyCreatedElementRuntime.GetType();

                // As of June 24, 2012
                // States are set before
                // CustomVariables:
                if (!string.IsNullOrEmpty(n.CurrentState))
                {
                    containedElementRuntime.SetState(n.CurrentState, false);
                }


                // If it's null, this means it's a default value so don't set anything
                foreach (CustomVariableInNamedObject cvino in n.InstructionSaves.Where(cvino => cvino.Value != null))
                {
                    // If there isn't a TypedMember for the variable, that means Glue won't generate code for it, so we shouln't be applying it.
                    if (!ShouldApplyVariableOnRuntime(cvino, n))
                    {
                        continue;
                    }

                    try
                    {
                        // We used to execute
                        // the Instructions right
                        // on the element runtime itself
                        // but I think it's best if we use
                        // the CustomVariable code so that we
                        // get all the benefit of CustomVariables
                        // like loading of files, and calling events.
                        //cvino.ToInstruction(newlyCreatedElementRuntime).Execute();

                        // Update May 25, 2012
                        // We used to get the ElementRuntime
                        // for the NamedObjectSave and have it
                        // set the CustomVariable - however this
                        // doesn't work because it tries to access
                        // files within its own scope, instead of files
                        // that belong to "this".
                        //CustomVariable customVariable = new CustomVariable();
                        //customVariable.Type = cvino.Type;
                        ////customVariable.SourceObject = n.InstanceName;
                        ////customVariable.SourceObjectProperty = cvino.Member;
                        //customVariable.DefaultValue = cvino.Value;
                        //customVariable.Name = cvino.Member;
                        //containedElementRuntime.SetCustomVariable(customVariable, customVariable.DefaultValue, false);

                        CustomVariable customVariable = new CustomVariable();
                        customVariable.Type                 = cvino.Type;
                        customVariable.SourceObject         = n.InstanceName;
                        customVariable.SourceObjectProperty = cvino.Member;
                        customVariable.DefaultValue         = cvino.Value;
                        customVariable.Name                 = cvino.Member;
                        if (cvino.Value is string && customVariable.GetIsFile())
                        {
                            // We want to load the file at this level and pass the result down:
                            ReferencedFileSave rfs         = GetReferencedFileFromName(cvino.Value);
                            object             fileRuntime = null;

                            if (rfs == null)
                            {
                                fileRuntime = null;
                            }
                            else
                            {
                                fileRuntime = LoadReferencedFileSave(rfs, true, this.AssociatedIElement);
                            }

                            customVariable.DefaultValue = fileRuntime;
                        }
                        if (customVariable.DefaultValue is float && customVariable.SourceObjectProperty == "Z" &&
                            newlyCreatedElementRuntime is PositionedObject && ((PositionedObject)newlyCreatedElementRuntime).Parent == Camera.Main)
                        {
                            float value = (float)customVariable.DefaultValue - 40;

                            customVariable.DefaultValue = value;
                        }
                        SetCustomVariable(customVariable, mAssociatedIElement, customVariable.DefaultValue, false);
                    }
                    catch (Exception e)
                    {
                        int m = 3;
                        m++;
                        // for now, do nothing
                    }
                }
            }
        }
All Usage Examples Of FlatRedBall.Glue.ElementRuntime::SetState