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

RefreshNamedObjectPositionedObjectValues() private method

private RefreshNamedObjectPositionedObjectValues ( ) : void
return void
        private void RefreshNamedObjectPositionedObjectValues()
        {
            for (int i = 0; i < ContainedElements.Count; i++)
            {
                RefreshFromFileValues(ContainedElements[i]);
            }
            for (int i = 0; i < this.mElementsInList.Count; i++)
            {
                RefreshFromFileValues(mElementsInList[i]);
            }
        }

Usage Example

Esempio n. 1
0
        void RefreshFromFileValues(ElementRuntime elementRuntime)
        {
            if (elementRuntime.mAssociatedNamedObjectSave != null &&
                elementRuntime.mAssociatedNamedObjectSave.SourceType == SourceType.File &&
                !string.IsNullOrEmpty(elementRuntime.mAssociatedNamedObjectSave.SourceFile) &&
                !string.IsNullOrEmpty(elementRuntime.mAssociatedNamedObjectSave.SourceName))
            {
                Scene scene = null;
                string fileNameToFind =
                    FileManager.Standardize(ContentDirectory + elementRuntime.mAssociatedNamedObjectSave.SourceFile);
                foreach (Scene loadedScene in mReferencedFileRuntimeList.LoadedScenes)
                {
                    if (loadedScene.Name == fileNameToFind)
                    {
                        scene = loadedScene;
                        break;
                    }
                }

                if (scene != null)
                {

                    INameable nameable = scene.FindByName(elementRuntime.mAssociatedNamedObjectSave.SourceNameWithoutParenthesis);

                    // It's valid if this is null.  This may happen if the NamedObjectSave references
                    // the entire file.
                    if (nameable != null)
                    {
                        Type typeOfObject = nameable.GetType();

                        bool wasFound = false;
                        BindingFlags bindingFlags = BindingFlags.Default;

                        if (typeOfObject.GetProperty("X") != null)
                        {
                            wasFound = true;
                            bindingFlags = BindingFlags.GetProperty;
                        }

                        //if(typeOfObject.GetField("X") != null)
                        //{
                        //    wasFound = true;
                        //    bindingFlags = BindingFlags.GetField;
                        //}


                        if (wasFound)
                        {
                            Binder binder = null;
                            object[] args = null;

                            // I think this can't be attached to a camera, but we should throw an exception if so


                            PositionedObject asPositionedObject = elementRuntime.mDirectObjectReference as PositionedObject;

                            if (asPositionedObject.Parent != null)
                            {

                                asPositionedObject.RelativeX = (float)typeOfObject.InvokeMember("X",
                                       bindingFlags, binder, nameable, args);

                                asPositionedObject.RelativeY = (float)typeOfObject.InvokeMember("Y",
                                    bindingFlags, binder, nameable, args);

                                asPositionedObject.RelativeZ = (float)typeOfObject.InvokeMember("Z",
                                    bindingFlags, binder, nameable, args);

                                asPositionedObject.RelativeRotationX = (float)typeOfObject.InvokeMember("RotationX",
                                    bindingFlags, binder, nameable, args);

                                asPositionedObject.RelativeRotationY = (float)typeOfObject.InvokeMember("RotationY",
                                    bindingFlags, binder, nameable, args);

                                asPositionedObject.RelativeRotationZ = (float)typeOfObject.InvokeMember("RotationZ",
                                    bindingFlags, binder, nameable, args);
                                asPositionedObject.ForceUpdateDependencies();
                            }
                            else
                            {

                                asPositionedObject.X = (float)typeOfObject.InvokeMember("X",
                                       bindingFlags, binder, nameable, args);

                                asPositionedObject.Y = (float)typeOfObject.InvokeMember("Y",
                                    bindingFlags, binder, nameable, args);

                                asPositionedObject.Z = (float)typeOfObject.InvokeMember("Z",
                                    bindingFlags, binder, nameable, args);

                                asPositionedObject.RotationX = (float)typeOfObject.InvokeMember("RotationX",
                                    bindingFlags, binder, nameable, args);

                                asPositionedObject.RotationY = (float)typeOfObject.InvokeMember("RotationY",
                                    bindingFlags, binder, nameable, args);

                                asPositionedObject.RotationZ = (float)typeOfObject.InvokeMember("RotationZ",
                                    bindingFlags, binder, nameable, args);
                            }
                        }
                    }
                }
            }

            elementRuntime.RefreshNamedObjectPositionedObjectValues();
        }