コード例 #1
0
        public static AnimationChainList AddAnimationChainList(string fileName)
        {
            AnimationChainList sameNamedList = null;

            foreach (AnimationChainList list in mReferencedAnimationChains)
            {
                if (list.Name == fileName)
                {
                    sameNamedList = list;
                    break;
                }
            }



            if (sameNamedList == null)
            {
                AnimationChainListSave animationChainListSave = AnimationChainListSave.FromFile(fileName);

                AnimationChainList list = animationChainListSave.ToAnimationChainList(SceneContentManager);

                mReferencedAnimationChains.Add(list);

                GuiData.ListWindow.Highlight(list);

                return(list);
            }
            else
            {
                // highlight the list with the same name

                GuiData.ListWindow.Highlight(sameNamedList);
                return(sameNamedList);
            }
        }
コード例 #2
0
        /// <summary>Generates AnimationChainListSave data structure based on input data.</summary>
        /// <param name="frameSize">Size of one sprite sheet cell. All cells in spritesheed have to have uniform size.</param>
        /// <param name="spriteSheetFileName">Only file name of sprite sheet that should be used for generated anim chain. Without path.</param>
        /// <param name="rotations">Number of rotations (sprite sheet rows) for graphic character/object this anim chain is generated for.</param>
        /// <param name="animsDefinitions">List of AnimDefs defining animations for graphic character/object.</param>
        /// <returns>Generated AnimationChainListSave data.</returns>
        public static AnimationChainListSave Generate(
            Size frameSize,
            string spriteSheetFileName,
            ushort rotations,
            Offset <float> allFramesOffset,
            IEnumerable <AnimDef> animsDefinitions
            )
        {
            _FrameSize           = frameSize;
            _SpriteSheetFileName = spriteSheetFileName;
            _Rotations           = rotations;
            _AllFramesOffset     = allFramesOffset;

            AnimationChainListSave animChainListSave = new AnimationChainListSave
            {
                CoordinateType       = FlatRedBall.Graphics.TextureCoordinateType.Pixel,
                FileRelativeTextures = true,
                TimeMeasurementUnit  = FlatRedBall.TimeMeasurementUnit.Second
            };

            foreach (var animDef in animsDefinitions)
            {
                animChainListSave.AnimationChains.AddRange(
                    _GenerateAnimChain(animDef)
                    );
            }

            return(animChainListSave);
        }
コード例 #3
0
        protected void LoadAnimations(string fileName)
        {
            if (animationCache.ContainsKey(fileName))
            {
                animations = animationCache [fileName];
            }
            else
            {
                animations = new List <Animation> ();
                AnimationChainListSave acls = XmlDeserializer.Self.XmlDeserialize <AnimationChainListSave> (fileName);

                foreach (var animationSave in acls.AnimationChains)
                {
                    animations.Add(Animation.FromAnimationSave(animationSave));
                }


                animationCache.Add(fileName, animations);
            }

            // This prevents the sprite from temporarily showing
            // the entire PNG for a split second.
            if (animations != null && animations.Count > 0)
            {
                CurrentAnimation = animations [0];
            }
        }
コード例 #4
0
ファイル: ContentParser.cs プロジェクト: Riva3000/FlatRedBall
        static object GetValueForPropertyOnObject(SpriteSave sprite, string fieldOrProperty)
        {
            if (fieldOrProperty == "Alpha")
            {
                float valueToDivideBy = 255 / GraphicalEnumerations.MaxColorComponentValue;

                return((255 - sprite.Fade) / valueToDivideBy);
            }
            else if (fieldOrProperty == "PixelSize")
            {
                return(sprite.ConstantPixelSize);
            }
            else if (fieldOrProperty == "CurrentChainName")
            {
                // This thing should use an AnimationChain
                string animationChainRelative = sprite.AnimationChainsFile;

                string animationChainFile = FileManager.RelativeDirectory + sprite.AnimationChainsFile;

                AnimationChainListSave acls = AnimationChainListSave.FromFile(animationChainFile);

                int index = sprite.CurrentChain;

                if (index < acls.AnimationChains.Count)
                {
                    return(acls.AnimationChains[index].Name);
                }
                else
                {
                    return(null);
                }
            }

            return(GetValueForPropertyOnObject <SpriteSave>(sprite, fieldOrProperty));
        }
        private void RefreshList()
        {
            AnimationChainListSave acls = null;

            acls = GetAnimationChainListFile(element, referencedNos, stateSave);


            if (acls == null)
            {
                mAvailableChains = new string[0];
            }
            else
            {
                var referencedFile = element.ReferencedFiles.FirstOrDefault(item => ObjectFinder.Self.MakeAbsoluteContent(item.Name) == acls.FileName);

                this.ReferencedFileSave = referencedFile;

                // +1, include empty entry
                mAvailableChains = new string[acls.AnimationChains.Count + 1];

                mAvailableChains[0] = "";

                for (int i = 0; i < acls.AnimationChains.Count; i++)
                {
                    mAvailableChains[i + 1] = acls.AnimationChains[i].Name;
                }
            }
        }
コード例 #6
0
        public static void ConvertToUvCoordinates(this AnimationChainListSave animationList)
        {
            if (animationList.CoordinateType == Graphics.TextureCoordinateType.UV)
            {
                throw new Exception("The animation is already using pixel coordinates");
            }

            animationList.CoordinateType = Graphics.TextureCoordinateType.UV;

            foreach (AnimationChainSave animation in animationList.AnimationChains)
            {
                foreach (var frame in animation.Frames)
                {
                    var texture = WireframeManager.Self.GetTextureForFrame(frame);

                    if (texture != null)
                    {
                        frame.LeftCoordinate  /= texture.Width;
                        frame.RightCoordinate /= texture.Width;

                        frame.TopCoordinate    /= texture.Height;
                        frame.BottomCoordinate /= texture.Height;
                    }
                }
            }
        }
コード例 #7
0
 private void SetAnimationChainOnSprite(Window callingWindow)
 {
     if (mSelectedObject != null)
     {
         mSelectedObject.AnimationChains =
             AnimationChainListSave.FromFile(((FileTextBox)callingWindow).Text).ToAnimationChainList(this.ContentManagerName);
     }
 }
コード例 #8
0
        public TextureGrid <FlatRedBall.Graphics.Animation.AnimationChain> ToAnimationChainGrid(string contentManagerName,
                                                                                                float gridSpacing)
        {
            TextureGrid <FlatRedBall.Graphics.Animation.AnimationChain> toReturn = new TextureGrid <FlatRedBall.Graphics.Animation.AnimationChain>();

            toReturn.FirstPaintedX = FirstPaintedX;
            toReturn.LastPaintedX  = new List <float>();

            toReturn.FirstPaintedY = FirstPaintedY;
            toReturn.LastPaintedY  = toReturn.FirstPaintedY + (ReferenceGrid.Length - 1) * gridSpacing;

            toReturn.GridSpacingX = gridSpacing;
            toReturn.GridSpacingY = gridSpacing;

            int yOn = 0;

            toReturn.BaseTexture = null;

            Dictionary <string, FlatRedBall.Graphics.Animation.AnimationChainList> animationChainListCache =
                new Dictionary <string, FlatRedBall.Graphics.Animation.AnimationChainList>();


            foreach (ReferencedAnimationChain[] racArray in ReferenceGrid)
            {
                List <FlatRedBall.Graphics.Animation.AnimationChain> newAnimationChainList =
                    new List <FlatRedBall.Graphics.Animation.AnimationChain>();
                toReturn.Textures.Add(newAnimationChainList);

                toReturn.LastPaintedX.Add(toReturn.FirstPaintedX[yOn] + gridSpacing * (racArray.Length - 1));

                foreach (ReferencedAnimationChain rac in racArray)
                {
                    FlatRedBall.Graphics.Animation.AnimationChainList acl = null;
                    if (!string.IsNullOrEmpty(rac.AnimationChainListFileName) && animationChainListCache.ContainsKey(rac.AnimationChainListFileName) == false)
                    {
                        AnimationChainListSave acls = AnimationChainListSave.FromFile(rac.AnimationChainListFileName);
                        animationChainListCache.Add(rac.AnimationChainListFileName,
                                                    acls.ToAnimationChainList(contentManagerName));
                    }

                    if (string.IsNullOrEmpty(rac.AnimationChainListFileName))
                    {
                        acl = null;
                        newAnimationChainList.Add(null);
                    }
                    else
                    {
                        acl = animationChainListCache[rac.AnimationChainListFileName];
                        newAnimationChainList.Add(acl[rac.AnimationChainName]);
                    }
                }

                yOn++;
            }


            return(toReturn);
        }
コード例 #9
0
        public static SpriteFrame CreateSpriteFrame(string texture, string nameToUse)
        {
            SpriteFrame spriteFrame = SpriteManager.AddSpriteFrame(null, SpriteFrame.BorderSides.All);

            try
            {
                if (texture.EndsWith(".ach") || texture.EndsWith(".achx"))
                {
                    AnimationChainListSave listSave = AnimationChainListSave.FromFile(texture);

                    spriteFrame.AnimationChains = listSave.ToAnimationChainList(SceneContentManager);

                    if (spriteFrame.AnimationChains.Count != 0)
                    {
                        spriteFrame.CurrentChainName = (spriteFrame.AnimationChains[0].Name);
                    }

                    spriteFrame.Animate = true;
                }
                else if (texture.EndsWith(".tga") || texture.EndsWith(".png"))
                {
                    spriteFrame.Texture =
                        FlatRedBallServices.Load <Texture2D>(texture, SceneContentManager);
                }
                else
                {
                    spriteFrame.Texture =
                        FlatRedBallServices.Load <Texture2D>(texture, SceneContentManager);
                }
            }
            catch (Microsoft.DirectX.Direct3D.InvalidDataException)
            {
                throw new Microsoft.DirectX.Direct3D.InvalidDataException();
            }

            if (string.IsNullOrEmpty(nameToUse) == false)
            {
                spriteFrame.Name = nameToUse;
            }
            else
            {
                spriteFrame.Name = FileManager.RemovePath(FileManager.RemoveExtension(texture));
            }

            StringFunctions.MakeNameUnique <SpriteFrame>(spriteFrame, mScene.SpriteFrames);

            spriteFrame.X = Camera.X;
            spriteFrame.Y = Camera.Y;

            mScene.SpriteFrames.Add(spriteFrame);

            return(spriteFrame);
        }
コード例 #10
0
        /// <summary>Saves generated AnimChainList to file and copies it's sprite sheet file to same director if necessary.</summary>
        /// <param name="animChainListSave">AnimationChainListSave data structure generated by GenerateAnimChain()</param>
        /// <param name="achxSavePath">Directory path to where achx file should be saved</param>
        /// <param name="achxFileName">Name of achx output file without extension</param>
        /// <param name="spriteSheetLocation">Directory where sprite sheet image for this cnim chain is located</param>
        public static void SaveAchx(AnimationChainListSave animChainListSave, string achxSavePath, string achxFileName, string spriteSheetLocation)
        {
            if (!File.Exists(Path.Combine(achxSavePath, _SpriteSheetFileName)))
            {
                File.Copy(
                    Path.Combine(spriteSheetLocation, _SpriteSheetFileName),
                    Path.Combine(achxSavePath, _SpriteSheetFileName)
                    );
            }

            animChainListSave.Save(Path.Combine(achxSavePath, achxFileName + ".achx"));
        }
コード例 #11
0
        public void InitateSaveProcess(string oldFileName, MainControl mainControl)
        {
            string fileName = AskUserWhereToSave();

            if (!string.IsNullOrEmpty(fileName))
            {
                // If the directory has changed, we need to ask the user
                // what to do with file references
                string newDirectory     = FileManager.Standardize(FileManager.GetDirectory(fileName));
                string projectFileName  = oldFileName;
                bool   isNewDirectory   = string.IsNullOrEmpty(projectFileName);
                string projectDirectory = null;

                if (!string.IsNullOrEmpty(projectFileName))
                {
                    projectDirectory = FileManager.GetDirectory(projectFileName);

                    projectDirectory = FileManager.Standardize(projectDirectory);

                    isNewDirectory = projectDirectory != newDirectory;
                }

                bool shouldSave = false;

                if (isNewDirectory && !string.IsNullOrEmpty(projectDirectory))
                {
                    AnimationChainListSave achs  = mainControl.AnimationChainList;
                    List <string>          files = GetAllFilesIn(achs, projectDirectory);

                    if (files.Count != 0)
                    {
                        shouldSave = PerformCopyFileRelativeLogic(newDirectory, projectDirectory, shouldSave, achs, files);
                    }
                    else
                    {
                        shouldSave = true;
                    }
                }
                else
                {
                    shouldSave = true;
                }
                if (shouldSave)
                {
                    mainControl.SaveCurrentAnimationChain(fileName);

                    WireframeManager.Self.RefreshAll();
                }
            }
        }
コード例 #12
0
        private static List <string> GetAllFilesIn(AnimationChainListSave achs, string directoryToMakeRelativeTo)
        {
            List <string> files = new List <string>();

            foreach (var animationChain in achs.AnimationChains)
            {
                foreach (var animationFrame in animationChain.Frames)
                {
                    if (FileManager.IsRelative(animationFrame.TextureName))
                    {
                        files.Add(directoryToMakeRelativeTo + animationFrame.TextureName);
                    }
                }
            }
            return(files);
        }
        private static AnimationChainListSave GetReferencedAclsThroughSetVariables(IElement element, NamedObjectSave referencedNos, StateSave stateSave)
        {
            AnimationChainListSave foundAcls = null;

            // Give states the priority
            if (stateSave != null)
            {
                foreach (var item in stateSave.InstructionSaves)
                {
                    var customVariable = element.CustomVariables.FirstOrDefault(variable => variable.Name == item.Member);

                    if (customVariable != null && customVariable.SourceObject == referencedNos.InstanceName && customVariable.SourceObjectProperty == "AnimationChains")
                    {
                        string value = (string)item.Value;

                        foundAcls = LoadAnimationChainListSave(element, value);
                    }
                }
            }

            if (foundAcls == null)
            {
                // Does this have a set AnimationChainList?
                foreach (CustomVariable customVariable in element.CustomVariables)
                {
                    if (customVariable.SourceObject == referencedNos.InstanceName && customVariable.SourceObjectProperty == "AnimationChains")
                    {
                        string value = (string)customVariable.DefaultValue;

                        foundAcls = LoadAnimationChainListSave(element, value);
                    }
                }
            }

            // If the acls is null that means that it hasn't been set by custom variables, but the NOS itself may have a value set right on the Sprite for the current AnimationChain
            if (foundAcls == null)
            {
                var instruction = referencedNos.GetInstructionFromMember("AnimationChains");
                if (instruction != null)
                {
                    foundAcls = LoadAnimationChainListSave(element, (string)instruction.Value);
                }
            }


            return(foundAcls);
        }
        private static AnimationChainListSave LoadAnimationChainListSave(IElement element, string rfsName)
        {
            AnimationChainListSave acls = null;

            ReferencedFileSave rfs = element.GetReferencedFileSaveByInstanceNameRecursively(rfsName);

            if (rfs != null)
            {
                string fullFileName = Facades.FacadeContainer.Self.ProjectValues.ContentDirectory + rfs.Name;

                if (System.IO.File.Exists(fullFileName))
                {
                    acls = AnimationChainListSave.FromFile(
                        fullFileName);
                }
            }
            return(acls);
        }
コード例 #15
0
        internal void LoadAnimationChain(string fileName)
        {
            // Reset all textures
            LoaderManager.Self.CacheTextures = false;
            LoaderManager.Self.CacheTextures = true;

            AnimationChainListSave acls = AnimationChainListSave.FromFile(fileName);


            AnimationChainListSave = acls;

            FileName = fileName;

            //Now just convert back to pixel when saving out
            if (acls.CoordinateType == Graphics.TextureCoordinateType.Pixel)
            {
                acls.ConvertToUvCoordinates();
            }
        }
コード例 #16
0
        public void AdjustAnimationToResize(AnimationChainListSave acls, int oldWidth, int oldHeight, int newWidth, int newHeight, string absoluteTextureFileName, List <AnimationFrameSave> adjustedFrames)
        {
            string aclsDirectory = FileManager.GetDirectory(acls.FileName);

            absoluteTextureFileName = FileManager.Standardize(absoluteTextureFileName, null, false);

            foreach (var animationChain in acls.AnimationChains)
            {
                foreach (var frame in animationChain.Frames)
                {
                    string fullFrameTextureName = FileManager.Standardize(aclsDirectory + frame.TextureName, null, false);

                    if (fullFrameTextureName == absoluteTextureFileName)
                    {
                        AdjustFrameToResize(frame, oldWidth, oldHeight, newWidth, newHeight);
                        adjustedFrames.Add(frame);
                    }
                }
            }
        }
        private AnimationChainListSave GetAnimationChainListFromScnxReference(NamedObjectSave referencedNos)
        {
            string sourceFileName = ContentDirectory + referencedNos.SourceFile;

            string sourceFileDirectory = FlatRedBall.IO.FileManager.GetDirectory(sourceFileName);

            AnimationChainListSave acls = null;

            SpriteEditorScene ses;

            if (System.IO.File.Exists(sourceFileName))
            {
                ses = SpriteEditorScene.FromFile(sourceFileName);
                string truncatedName = referencedNos.SourceName.Substring(0, referencedNos.SourceName.LastIndexOf('(') - 1);



                SpriteSave spriteSave = ses.FindSpriteByName(truncatedName);

                if (spriteSave != null && !string.IsNullOrEmpty(spriteSave.AnimationChainsFile))
                {
                    acls = AnimationChainListSave.FromFile(
                        sourceFileDirectory + spriteSave.AnimationChainsFile);
                }

                if (acls == null)
                {
                    SpriteFrameSave sfs = ses.FindSpriteFrameSaveByName(truncatedName);

                    if (sfs != null)
                    {
                        acls = AnimationChainListSave.FromFile(
                            sourceFileDirectory + sfs.ParentSprite.AnimationChainsFile);
                    }
                }
            }



            return(acls);
        }
コード例 #18
0
        public static void AddSprite(string textureOrAnimationFile)
        {
            Sprite newSprite = null;

            if (FileManager.GetExtension(textureOrAnimationFile) == "achx")
            {
                AnimationChainListSave achs = AnimationChainListSave.FromFile(textureOrAnimationFile);

                newSprite = SpriteManager.AddSprite(
                    achs.ToAnimationChainList(ContentManagerName));
                mBlockingScene.Sprites.Add(newSprite);

                newSprite.Name = FileManager.RemovePath(FileManager.RemoveExtension(textureOrAnimationFile));
            }
            else
            {
                newSprite = SpriteManager.AddSprite(textureOrAnimationFile, ContentManagerName);
                mBlockingScene.Sprites.Add(newSprite);

                newSprite.Name = FileManager.RemovePath(FileManager.RemoveExtension(textureOrAnimationFile));
            }

            SetNewlyCreatedSpriteProperties(newSprite);
        }
        private AnimationChainListSave GetAnimationChainListFile(IElement element, NamedObjectSave referencedNos, StateSave stateSave)
        {
            AnimationChainListSave acls = null;

            if (referencedNos != null)
            {
                if (referencedNos.SourceType == SourceType.File &&
                    !string.IsNullOrEmpty(referencedNos.SourceFile) &&
                    !string.IsNullOrEmpty(referencedNos.SourceName) &&
                    referencedNos.SourceFile.EndsWith(".scnx"))
                {
                    // This is the AnimationChainListSave
                    // referenced by the file...
                    acls = GetAnimationChainListFromScnxReference(referencedNos);

                    // ... but the user may be overriding that
                    // through variables, so let's check if that's
                    // the case
                    AnimationChainListSave foundAcls = GetReferencedAclsThroughSetVariables(element, referencedNos, stateSave);
                    if (foundAcls != null)
                    {
                        acls = foundAcls;
                    }
                }
                else if (referencedNos.SourceType == SourceType.FlatRedBallType &&
                         (referencedNos.SourceClassType == "Sprite" || referencedNos.SourceClassType == "SpriteFrame" ||
                          referencedNos.SourceClassType == "FlatRedBall.Sprite" || referencedNos.SourceClassType == "FlatRedBall.ManagedSpriteGroups.SpriteFrame"
                         ))
                {
                    AnimationChainListSave foundAcls = GetReferencedAclsThroughSetVariables(element, referencedNos, stateSave);

                    acls = foundAcls;
                }
            }
            return(acls);
        }
コード例 #20
0
        private void HandleForceSaveAll(object sender, EventArgs e)
        {
            foreach (var rfs in FlatRedBall.Glue.Elements.ObjectFinder.Self.GetAllReferencedFiles()
                     .Where(item => FileManager.GetExtension(item.Name) == "achx"))
            {
                string fullFileName = FlatRedBall.Glue.ProjectManager.MakeAbsolute(rfs.Name);

                if (System.IO.File.Exists(fullFileName))
                {
                    try
                    {
                        AnimationChainListSave acls = AnimationChainListSave.FromFile(fullFileName);

                        acls.Save(fullFileName);

                        PluginManager.ReceiveOutput("Re-saved " + rfs.ToString());
                    }
                    catch (Exception exc)
                    {
                        PluginManager.ReceiveError(exc.ToString());
                    }
                }
            }
        }
コード例 #21
0
ファイル: ResizeMethods.cs プロジェクト: vchelaru/FlatRedBall
        public void AdjustAnimationToResize(AnimationChainListSave acls, int oldWidth, int oldHeight, int newWidth, int newHeight, string absoluteTextureFileName, List<AnimationFrameSave> adjustedFrames)
        {
            string aclsDirectory = FileManager.GetDirectory(acls.FileName);

            absoluteTextureFileName = FileManager.Standardize(absoluteTextureFileName, null, false);

            foreach (var animationChain in acls.AnimationChains)
            {
                foreach (var frame in animationChain.Frames)
                {
                    string fullFrameTextureName = FileManager.Standardize(aclsDirectory + frame.TextureName, null, false);

                    if (fullFrameTextureName == absoluteTextureFileName)
                    {
                        AdjustFrameToResize(frame, oldWidth, oldHeight, newWidth, newHeight);
                        adjustedFrames.Add(frame);
                    }
                }
            }
        }
コード例 #22
0
        //public void SetSprite(TextureAtlas textureAtlas, Sprite sprite)
        //{
        //    SetSprite("", sprite);

        //    if (!string.IsNullOrEmpty(this.Texture))
        //    {
        //        var entry = textureAtlas.GetEntryFor(this.Texture);

        //        if (entry != null)
        //        {
        //            float left;
        //            float right;
        //            float top;
        //            float bottom;


        //            entry.FullToReduced(sprite.LeftTextureCoordinate, sprite.RightTextureCoordinate,
        //                sprite.TopTextureCoordinate, sprite.BottomTextureCoordinate,
        //                out left, out right, out top, out bottom);

        //            sprite.LeftTextureCoordinate = left;
        //            sprite.RightTextureCoordinate = right;
        //            sprite.TopTextureCoordinate = top;
        //            sprite.BottomTextureCoordinate = bottom;

        //            sprite.Texture = textureAtlas.Texture;

        //        }
        //    }

        //    if (!string.IsNullOrEmpty(this.AnimationChainsFile))
        //    {

        //        if (string.IsNullOrEmpty(this.AnimationChainsFile) == false)
        //        {
        //            //AnimationChains = FlatRedBall.Content.AnimationChain.AnimationChainListSave.FromFile(AnimationChainsFile);
        //            AnimationChainListSave acls = AnimationChainListSave.FromFile(this.AnimationChainsFile);
        //            sprite.AnimationChains = acls.ToAnimationChainList(textureAtlas);
        //        }

        //        if (CurrentChain != -1)
        //        {
        //            // Now using the CurrentChainName property so it works with IAnimationChainAnimatable
        //            sprite.CurrentChainName = sprite.AnimationChains[CurrentChain].Name;
        //            //sprite.SetAnimationChain();
        //        }
        //    }


        //}

        internal static void SetRuntimeAnimationChain(string contentManagerName, IAnimationChainAnimatable sprite,
                                                      AnimationChainList animationChainListInstance, int currentChain, AnimationChainListSave animationChains,
                                                      string animationChainsFile
                                                      )
        {
            if (animationChainListInstance != null)
            {
                if (animationChainListInstance != null)
                {
                    sprite.AnimationChains = animationChainListInstance;;
                }

                if (currentChain != -1)
                {
                    // Now using the CurrentChainName property so it works with IAnimationChainAnimatable
                    sprite.CurrentChainName = sprite.AnimationChains[currentChain].Name;
                    //sprite.SetAnimationChain(sprite.AnimationChains[CurrentChain]);
                }
            }
            else if (animationChains != null || string.IsNullOrEmpty(animationChainsFile) == false)
            {
                if (animationChains != null && animationChains.FileName != null && animationChains.FileName != "")
                {
                    // load the AnimationChainArray here
                    //                    AnimationChains = new AnimationChainList(saveToSetFrom.animationChains.Name);
                    sprite.AnimationChains      = animationChains.ToAnimationChainList(contentManagerName);
                    sprite.AnimationChains.Name = FlatRedBall.IO.FileManager.Standardize(animationChains.FileName);
                }
                else if (string.IsNullOrEmpty(animationChainsFile) == false)
                {
                    //AnimationChains = FlatRedBall.Content.AnimationChain.AnimationChainListSave.FromFile(AnimationChainsFile);
                    sprite.AnimationChains = FlatRedBallServices.Load <AnimationChainList>(
                        animationChainsFile, contentManagerName);
                }

                if (currentChain != -1)
                {
                    // Now using the CurrentChainName property so it works with IAnimationChainAnimatable
                    sprite.CurrentChainName = sprite.AnimationChains[currentChain].Name;
                    //sprite.SetAnimationChain();
                }
            }
        }
コード例 #23
0
        private static bool PerformCopyFileRelativeLogic(string newDirectory, string projectDirectory, bool shouldSave, AnimationChainListSave achs, List <string> files)
        {
            MultiButtonMessageBox mbmb = new MultiButtonMessageBox();

            mbmb.MessageText = "What would you like to do with files referenced by the .achx?";

            mbmb.AddButton("Copy them relative", DialogResult.Yes);
            mbmb.AddButton("Leave them where they are (make relative references)", DialogResult.No);

            DialogResult result = mbmb.ShowDialog();


            AnimationChainListSave cloned = FileManager.CloneObject(achs);



            foreach (var animationChain in achs.AnimationChains)
            {
                foreach (var animationFrame in animationChain.Frames)
                {
                    if (FileManager.IsRelative(animationFrame.TextureName))
                    {
                        animationFrame.TextureName = projectDirectory + animationFrame.TextureName;
                    }
                }
            }

            StringFunctions.RemoveDuplicates(files);

            if (result == DialogResult.Yes)
            {
                // Copy these all over, then make all files relative
                foreach (string file in files)
                {
                    if (System.IO.File.Exists(file))
                    {
                        string destination = newDirectory + FileManager.RemovePath(file);
                        System.IO.File.Copy(file, destination, true);
                    }
                }
                foreach (var animationChain in achs.AnimationChains)
                {
                    foreach (var animationFrame in animationChain.Frames)
                    {
                        animationFrame.TextureName = FileManager.RemovePath(animationFrame.TextureName);
                    }
                }
                shouldSave = true;
            }
            else if (result == DialogResult.No)
            {
                foreach (var animationChain in achs.AnimationChains)
                {
                    foreach (var animationFrame in animationChain.Frames)
                    {
                        animationFrame.TextureName = FileManager.MakeRelative(animationFrame.TextureName, newDirectory);
                    }
                }
                shouldSave = true;
            }
            else if (result == DialogResult.Cancel)
            {
                for (int animationIndex = 0; animationIndex < cloned.AnimationChains.Count; animationIndex++)
                {
                    for (int frameIndex = 0; frameIndex < cloned.AnimationChains[animationIndex].Frames.Count; animationIndex++)
                    {
                        ProjectManager.Self.AnimationChainListSave.AnimationChains[animationIndex].Frames[frameIndex].TextureName =
                            cloned.AnimationChains[animationIndex].Frames[frameIndex].TextureName;
                    }
                }
            }
            return(shouldSave);
        }
コード例 #24
0
        protected override AnimationChainList Read(ContentReader input, AnimationChainList existingInstance)
        {
            if (existingInstance != null)
            {
                return(existingInstance);
            }

            AnimationChainListSave acls = null;

            if (ObjectReader.UseReflection)
            {
                acls = ObjectReader.ReadObject <AnimationChainListSave>(input);
            }
            else
            {
                acls = ReadAnimationChainListSave(input);
            }
            acls.FileName = input.AssetName;

            return(acls.ToAnimationChainList(""));

            /*
             * //read list of animation chains
             * TimeMeasurementUnit timeMeasurement = (TimeMeasurementUnit)input.ReadInt32();
             * float divisor = timeMeasurement == TimeMeasurementUnit.Millisecond ? 1000 : 1;
             *
             * int chainsCount = input.ReadInt32();
             * existingInstance = new AnimationChainList(chainsCount);
             * existingInstance.TimeMeasurementUnit = timeMeasurement;
             *
             * existingInstance.Name = input.AssetName;
             *
             * for (int i = 0; i < chainsCount; i++)
             * {
             * //read list of Frames
             * int frameCount = input.ReadInt32();
             * FlatRedBall.Graphics.Animation.AnimationChain ach =
             * new FlatRedBall.Graphics.Animation.AnimationChain(frameCount);
             *
             * ach.Name = input.ReadString();
             *
             * for (int j = 0; j < frameCount; j++)
             * {
             * AnimationFrame frame = new AnimationFrame(
             * input.ReadExternalReference<Texture2D>(),
             * input.ReadSingle());
             * frame.FrameLength /= divisor;
             * frame.FlipHorizontal = input.ReadBoolean();
             * frame.FlipVertical = input.ReadBoolean();
             *
             * frame.LeftCoordinate = input.ReadSingle();
             * frame.RightCoordinate = input.ReadSingle();
             * frame.TopCoordinate = input.ReadSingle();
             * frame.BottomCoordinate = input.ReadSingle();
             *
             * frame.RelativeX = input.ReadSingle();
             * frame.RelativeY = input.ReadSingle();
             *
             * ach.Add(frame);
             * }
             * existingInstance.Add(ach);
             * }
             *
             * return existingInstance;
             */
        }
コード例 #25
0
        public static List <string> GetNamedObjectsIn(string fileName)
        {
            string        extension    = FileManager.GetExtension(fileName);
            List <string> listToReturn = new List <string>();

            switch (extension)
            {
                #region case Scene (scnx)
            case "scnx":

                SpriteEditorScene ses = SpriteEditorScene.FromFile(fileName);

                for (int i = 0; i < ses.PositionedModelSaveList.Count; i++)
                {
                    listToReturn.Add(ses.PositionedModelSaveList[i].Name + " (PositionedModel)");
                }

                for (int i = 0; i < ses.SpriteFrameSaveList.Count; i++)
                {
                    listToReturn.Add(ses.SpriteFrameSaveList[i].ParentSprite.Name + " (SpriteFrame)");
                }

                for (int i = 0; i < ses.SpriteGridList.Count; i++)
                {
                    listToReturn.Add(ses.SpriteGridList[i].Name + " (SpriteGrid)");
                }

                for (int i = 0; i < ses.SpriteList.Count; i++)
                {
                    listToReturn.Add(ses.SpriteList[i].Name + " (Sprite)");
                }

                for (int i = 0; i < ses.TextSaveList.Count; i++)
                {
                    listToReturn.Add(ses.TextSaveList[i].Name + " (Text)");
                }
                break;
                #endregion

                #region case ShapeCollection (shcx)

            case "shcx":
                ShapeCollectionSave scs = ShapeCollectionSave.FromFile(fileName);

                for (int i = 0; i < scs.AxisAlignedCubeSaves.Count; i++)
                {
                    listToReturn.Add(scs.AxisAlignedCubeSaves[i].Name + " (AxisAlignedCube)");
                }
                for (int i = 0; i < scs.AxisAlignedRectangleSaves.Count; i++)
                {
                    listToReturn.Add(scs.AxisAlignedRectangleSaves[i].Name + " (AxisAlignedRectangle)");
                }
                for (int i = 0; i < scs.CircleSaves.Count; i++)
                {
                    listToReturn.Add(scs.CircleSaves[i].Name + " (Circle)");
                }
                for (int i = 0; i < scs.PolygonSaves.Count; i++)
                {
                    listToReturn.Add(scs.PolygonSaves[i].Name + " (Polygon)");
                }
                for (int i = 0; i < scs.SphereSaves.Count; i++)
                {
                    listToReturn.Add(scs.SphereSaves[i].Name + " (Sphere)");
                }
                break;

                #endregion

                #region NodeNetwork (nntx)
            case "nntx":
                NodeNetworkSave nns = NodeNetworkSave.FromFile(fileName);

                for (int i = 0; i < nns.PositionedNodes.Count; i++)
                {
                    listToReturn.Add(nns.PositionedNodes[i].Name + " (PositionedNode)");
                }

                break;
                #endregion

                #region EmitterList (emix)
            case "emix":
                EmitterSaveList esl = EmitterSaveList.FromFile(fileName);

                for (int i = 0; i < esl.emitters.Count; i++)
                {
                    listToReturn.Add(esl.emitters[i].Name + " (Emitter)");
                }

                break;

                #endregion

                #region Case AnimationChainList (achx)

            case "achx":
                AnimationChainListSave acls = AnimationChainListSave.FromFile(fileName);

                for (int i = 0; i < acls.AnimationChains.Count; i++)
                {
                    listToReturn.Add(acls.AnimationChains[i].Name + " (AnimationChain)");
                }
                break;
                #endregion

                #region Case SplineList (splx)
            case "splx":
                SplineSaveList ssl = SplineSaveList.FromFile(fileName);

                for (int i = 0; i < ssl.Splines.Count; i++)
                {
                    listToReturn.Add(ssl.Splines[i].Name + " (Spline)");
                }

                break;

                #endregion
            }

            return(listToReturn);
        }
コード例 #26
0
        public static List <string> GetFilesReferencedByAsset(string file, bool readRecursively)
        {
            string fileExtension = FileManager.GetExtension(file);

            List <string> referencedFiles = null;           // = new List<string>();

            switch (fileExtension)
            {
                #region Scene (.scnx)

            case "scnx":

                SpriteEditorScene ses = SpriteEditorScene.FromFile(file);
                referencedFiles = ses.GetReferencedFiles(RelativeType.Absolute);
                break;

                #endregion

                #region Emitter List (.emix)

            case "emix":
                EmitterSaveList esl = EmitterSaveList.FromFile(file);
                referencedFiles = esl.GetReferencedFiles(RelativeType.Absolute);
                break;

                #endregion

                #region SpriteRig (.srgx)

            case "srgx":
                SpriteRigSave srs = SpriteRigSave.FromFile(file);
                referencedFiles = srs.GetReferencedFiles(RelativeType.Absolute);
                break;

                #endregion

                #region AnimationChain List

            case "achx":
                AnimationChainListSave acls = AnimationChainListSave.FromFile(file);
                referencedFiles = acls.GetReferencedFiles(RelativeType.Absolute);
                break;

                #endregion

                #region Bitmap Font Generator Config File (.bmfc)

            case "bmfc":

                referencedFiles = new List <string>();

                // These are only referenced IF they actually exist
                string referencedFileToAdd = FileManager.RemoveExtension(file) + ".png";
                if (FileManager.FileExists(referencedFileToAdd))
                {
                    referencedFiles.Add(referencedFileToAdd);
                }

                referencedFileToAdd = FileManager.RemoveExtension(file) + ".fnt";
                if (FileManager.FileExists(referencedFileToAdd))
                {
                    referencedFiles.Add(referencedFileToAdd);
                }
                break;

                #endregion

                #region X File (.x)

            case "x":
                referencedFiles = GetTextureReferencesInX(file);
                break;

                #endregion

                #region WME File (.wme)
            case "wme":
                referencedFiles = new List <string>();
                WMELoader.GetReferencedFiles(file, referencedFiles, RelativeType.Absolute);

                break;

                #endregion

                #region Spline List (.slpx) - falls to default

            case "splx":

                #endregion
            default:
                referencedFiles = new List <string>();
                break;
            }

            if (readRecursively)
            {
                for (int i = referencedFiles.Count - 1; i > -1; i--)
                {
                    referencedFiles.AddRange(GetFilesReferencedByAsset(referencedFiles[i], true));
                }
            }

            // Files may include "../", so let's get rid of that stuff
            for (int i = 0; i < referencedFiles.Count; i++)
            {
                referencedFiles[i] = FileManager.Standardize(referencedFiles[i], "", false);
            }


            return(referencedFiles);
        }
コード例 #27
0
ファイル: ContentParser.cs プロジェクト: Riva3000/FlatRedBall
        public static void GetFilesReferencedByAsset(string fileName, TopLevelOrRecursive topLevelOrRecursive, List <string> referencedFiles)
        {
            List <string> newReferencedFiles = new List <string>();

            if (!CanFileReferenceOtherFiles(fileName))
            {
                return;
            }
            else if (!FileManager.FileExists(fileName))
            {
                throw new FileNotFoundException("Could not find file " + fileName, fileName);
            }
            else
            {
                string fileExtension = FileManager.GetExtension(fileName);

                switch (fileExtension)
                {
                    #region Scene (.scnx)

                case "scnx":

                    SceneSave ses = SceneSave.FromFile(fileName);
                    try
                    {
                        newReferencedFiles = ses.GetReferencedFiles(RelativeType.Absolute);
                    }
                    catch (InvalidOperationException e)
                    {
                        MessageBox.Show("There is an invalid file reference in the file\n\n" +
                                        fileName +
                                        "\n\nGlue will skip this file.  You should investigate this file in a text editor " +
                                        "to identify the issue.\n\nAdditional error information:\n\n" + e.ToString());
                    }
                    break;

                    #endregion

                    #region Emitter List (.emix)

                case "emix":
                    EmitterSaveList esl = EmitterSaveList.FromFile(fileName);
                    newReferencedFiles = esl.GetReferencedFiles(RelativeType.Absolute);
                    break;

                    #endregion

                    #region AnimationChain List

                case "achx":
                    AnimationChainListSave acls = AnimationChainListSave.FromFile(fileName);
                    newReferencedFiles = acls.GetReferencedFiles(RelativeType.Absolute);
                    break;

                    #endregion

                    #region X File (.x)

                case "x":
                    newReferencedFiles = GetTextureReferencesInX(fileName);
                    break;

                    #endregion

                    #region Spline List (.slpx) - falls to default

                case "splx":

                    #endregion

                    #region Font File (.fnt)
                case "fnt":
                    newReferencedFiles = GetTextureReferencesInFnt(fileName);

                    break;

                    #endregion
                default:

                    break;
                }

                // We still want to construct as good of a reference structure as possible
                // even if there are missing files.  Therefore, we'll just keep track of errors and report them
                // at the end of the method
                bool   didErrorOccur = false;
                string errorMessage  = "";
                if (topLevelOrRecursive == TopLevelOrRecursive.Recursive)
                {
                    for (int i = newReferencedFiles.Count - 1; i > -1; i--)
                    {
                        // If this file can't reference other files, no need to even do a file check or throw errors.
                        if (CanFileReferenceOtherFiles(newReferencedFiles[i]) == true)
                        {
                            if (File.Exists(newReferencedFiles[i]))
                            {
                                try
                                {
                                    GetFilesReferencedByAsset(newReferencedFiles[i], topLevelOrRecursive, newReferencedFiles);
                                }
                                catch (Exception e)
                                {
                                    didErrorOccur = true;
                                    errorMessage += e.Message;
                                }
                            }
                            else
                            {
                                didErrorOccur = true;
                                errorMessage += "Could not find the file " + newReferencedFiles[i] +
                                                " which is referenced in the file " + fileName + "\n";
                            }
                        }
                    }
                }

                // Files may include "../", so let's get rid of that stuff
                for (int i = 0; i < newReferencedFiles.Count; i++)
                {
                    newReferencedFiles[i] = FileManager.Standardize(newReferencedFiles[i], "", false);
                }

                referencedFiles.AddRange(newReferencedFiles);

                if (didErrorOccur)
                {
                    throw new Exception(errorMessage);
                }
            }
        }
コード例 #28
0
        public T LoadFromFile <T>(string assetName)
        {
            string extension = FileManager.GetExtension(assetName);

            if (FileManager.IsRelative(assetName))
            {
                // get the absolute path using the current relative directory
                assetName = FileManager.RelativeDirectory + assetName;
            }



            string fullNameWithType = assetName + typeof(T).Name;


            // get the dictionary by the contentManagerName.  If it doesn't exist, GetDisposableDictionaryByName
            // will create it.

            if (mDisposableDictionary.ContainsKey(fullNameWithType))
            {
#if PROFILE
                mHistory.Add(new ContentLoadHistory(
                                 TimeManager.CurrentTime, typeof(T).Name, fullNameWithType, ContentLoadDetail.Cached));
#endif

                return((T)mDisposableDictionary[fullNameWithType]);
            }
            else if (mNonDisposableDictionary.ContainsKey(fullNameWithType))
            {
                return((T)mNonDisposableDictionary[fullNameWithType]);
            }
            else
            {
#if PROFILE
                mHistory.Add(new ContentLoadHistory(
                                 TimeManager.CurrentTime,
                                 typeof(T).Name,
                                 fullNameWithType,
                                 ContentLoadDetail.HddFromFile));
#endif
#if DEBUG
                // The ThrowExceptionIfFileDoesntExist
                // call used to be done before the checks
                // in the dictionaries.  But whatever is held
                // in there may not really be a file so let's check
                // if the file exists after we check the dictionaries.
                FileManager.ThrowExceptionIfFileDoesntExist(assetName);
#endif

                IDisposable loadedAsset = null;

                if (typeof(T) == typeof(Texture2D) || typeof(T) == typeof(Microsoft.Xna.Framework.Graphics.Texture2D))
                {
                    // for now we'll create it here, eventually have it in a dictionary:
                    loadedAsset = textureContentLoader.Load(assetName);
                }

                #region Scene

                else if (typeof(T) == typeof(FlatRedBall.Scene))
                {
                    FlatRedBall.Scene scene = FlatRedBall.Content.Scene.SceneSave.FromFile(assetName).ToScene(mName);

                    object sceneAsObject = scene;

                    lock (mNonDisposableDictionary)
                    {
                        if (!mNonDisposableDictionary.ContainsKey(fullNameWithType))
                        {
                            mNonDisposableDictionary.Add(fullNameWithType, scene);
                        }
                    }
                    return((T)sceneAsObject);
                }

                #endregion

                #region EmitterList

                else if (typeof(T) == typeof(EmitterList))
                {
                    EmitterList emitterList = EmitterSaveList.FromFile(assetName).ToEmitterList(mName);


                    mNonDisposableDictionary.Add(fullNameWithType, emitterList);


                    return((T)((object)emitterList));
                }

                #endregion

                #region Image
#if !MONOGAME
                else if (typeof(T) == typeof(Image))
                {
                    switch (extension.ToLowerInvariant())
                    {
                    case "gif":
                        Image image = Image.FromFile(assetName);
                        loadedAsset = image;
                        break;
                    }
                }
#endif
                #endregion

                #region BitmapList
#if !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE && !MONOGAME
                else if (typeof(T) == typeof(BitmapList))
                {
                    loadedAsset = BitmapList.FromFile(assetName);
                }
#endif

                #endregion

                #region NodeNetwork
                else if (typeof(T) == typeof(NodeNetwork))
                {
                    NodeNetwork nodeNetwork = NodeNetworkSave.FromFile(assetName).ToNodeNetwork();

                    mNonDisposableDictionary.Add(fullNameWithType, nodeNetwork);

                    return((T)((object)nodeNetwork));
                }
                #endregion

                #region ShapeCollection

                else if (typeof(T) == typeof(ShapeCollection))
                {
                    ShapeCollection shapeCollection =
                        ShapeCollectionSave.FromFile(assetName).ToShapeCollection();

                    mNonDisposableDictionary.Add(fullNameWithType, shapeCollection);

                    return((T)((object)shapeCollection));
                }
                #endregion

                #region PositionedObjectList<Polygon>

                else if (typeof(T) == typeof(PositionedObjectList <FlatRedBall.Math.Geometry.Polygon>))
                {
                    PositionedObjectList <FlatRedBall.Math.Geometry.Polygon> polygons =
                        PolygonSaveList.FromFile(assetName).ToPolygonList();
                    mNonDisposableDictionary.Add(fullNameWithType, polygons);
                    return((T)((object)polygons));
                }

                #endregion

                #region AnimationChainList

                else if (typeof(T) == typeof(AnimationChainList))
                {
                    if (assetName.EndsWith("gif"))
                    {
#if WINDOWS_8 || UWP || DESKTOP_GL
                        throw new NotImplementedException();
#else
                        AnimationChainList acl = new AnimationChainList();
                        acl.Add(FlatRedBall.Graphics.Animation.AnimationChain.FromGif(assetName, this.mName));
                        acl[0].ParentGifFileName = assetName;
                        loadedAsset = acl;
#endif
                    }
                    else
                    {
                        loadedAsset =
                            AnimationChainListSave.FromFile(assetName).ToAnimationChainList(mName);
                    }

                    mNonDisposableDictionary.Add(fullNameWithType, loadedAsset);
                }

                #endregion

                else if (typeof(T) == typeof(Song))
                {
                    var loader = new SongLoader();
                    return((T)(object)loader.Load(assetName));
                }
#if MONOGAME
                else if (typeof(T) == typeof(SoundEffect))
                {
                    T soundEffect;

                    if (assetName.StartsWith(@".\") || assetName.StartsWith(@"./"))
                    {
                        soundEffect = base.Load <T>(assetName.Substring(2));
                    }
                    else
                    {
                        soundEffect = base.Load <T>(assetName);
                    }

                    return(soundEffect);
                }
#endif

                #region RuntimeCsvRepresentation

#if !SILVERLIGHT
                else if (typeof(T) == typeof(RuntimeCsvRepresentation))
                {
#if XBOX360
                    throw new NotImplementedException("Can't load CSV from file.  Try instead to use the content pipeline.");
#else
                    return((T)((object)CsvFileManager.CsvDeserializeToRuntime(assetName)));
#endif
                }
#endif


                #endregion

                #region SplineList

                else if (typeof(T) == typeof(List <Spline>))
                {
                    List <Spline> splineList = SplineSaveList.FromFile(assetName).ToSplineList();
                    mNonDisposableDictionary.Add(fullNameWithType, splineList);
                    object asObject = splineList;

                    return((T)asObject);
                }

                else if (typeof(T) == typeof(SplineList))
                {
                    SplineList splineList = SplineSaveList.FromFile(assetName).ToSplineList();
                    mNonDisposableDictionary.Add(fullNameWithType, splineList);
                    object asObject = splineList;

                    return((T)asObject);
                }

                #endregion

                #region BitmapFont

                else if (typeof(T) == typeof(BitmapFont))
                {
                    // We used to assume the texture is named the same as the font file
                    // But now FRB understands the .fnt file and gets the PNG from the font file
                    //string pngFile = FileManager.RemoveExtension(assetName) + ".png";
                    string fntFile = FileManager.RemoveExtension(assetName) + ".fnt";

                    BitmapFont bitmapFont = new BitmapFont(fntFile, this.mName);

                    object bitmapFontAsObject = bitmapFont;

                    return((T)bitmapFontAsObject);
                }

                #endregion


                #region Text

                else if (typeof(T) == typeof(string))
                {
                    return((T)((object)FileManager.FromFileText(assetName)));
                }

                #endregion

                #region Catch mistakes

#if DEBUG
                else if (typeof(T) == typeof(Spline))
                {
                    throw new Exception("Cannot load Splines.  Try using the List<Spline> type instead.");
                }
                else if (typeof(T) == typeof(Emitter))
                {
                    throw new Exception("Cannot load Emitters.  Try using the EmitterList type instead.");
                }
#endif

                #endregion

                #region else, exception!

                else
                {
                    throw new NotImplementedException("Cannot load content of type " +
                                                      typeof(T).AssemblyQualifiedName + " from file.  If you are loading " +
                                                      "through the content pipeline be sure to remove the extension of the file " +
                                                      "name.");
                }

                #endregion

                if (loadedAsset != null)
                {
                    lock (mDisposableDictionary)
                    {
                        // Multiple threads could try to load this content simultaneously
                        if (!mDisposableDictionary.ContainsKey(fullNameWithType))
                        {
                            mDisposableDictionary.Add(fullNameWithType, loadedAsset);
                        }
                    }
                }

                return((T)loadedAsset);
            }
        }
コード例 #29
0
        public static Sprite AddSprite(string spriteTexture, string nameToUse)
        {
            EditorSprite spriteCreated = new EditorSprite();

            #region Create the spriteCreated depending on the type in spriteTexture
            try
            {
                #region Is the texture null?

                if (string.IsNullOrEmpty(spriteTexture))
                {
                    spriteCreated.Texture        = null;
                    spriteCreated.Red            = GraphicalEnumerations.MaxColorComponentValue;
                    spriteCreated.ColorOperation = Microsoft.DirectX.Direct3D.TextureOperation.SelectArg2;
                }

                #endregion

                #region Create the Sprite with a .achx
                else if (spriteTexture.EndsWith(".ach") || spriteTexture.EndsWith(".achx") ||
                         spriteTexture.EndsWith(".gif"))
                {
                    if (spriteTexture.EndsWith(".gif"))
                    {
                        AnimationChain animationChain = AnimationChain.FromGif(spriteTexture, SceneContentManager);

                        spriteCreated.SetAnimationChain(animationChain);
                    }
                    else
                    {
                        AnimationChainListSave listSave = AnimationChainListSave.FromFile(spriteTexture);

                        spriteCreated.AnimationChains = listSave.ToAnimationChainList(SceneContentManager);
                    }
                    if (spriteCreated.AnimationChains.Count != 0)
                    {
                        spriteCreated.SetAnimationChain(spriteCreated.AnimationChains[0]);
                    }

                    spriteCreated.Animate = true;
                }
                #endregion

                #region Create the Sprite with an image
                else
                {
                    spriteCreated.Texture =
                        FlatRedBallServices.Load <Texture2D>(spriteTexture, SceneContentManager);
                }

                #endregion
            }
            catch (Microsoft.DirectX.Direct3D.InvalidDataException)
            {
                throw new Microsoft.DirectX.Direct3D.InvalidDataException();
            }
            #endregion

            SpriteManager.AddSprite(spriteCreated);



            KeepSpriteNameUnique <Sprite>(spriteCreated, nameToUse, mScene.Sprites);

            spriteCreated.X = Camera.X;
            spriteCreated.Y = Camera.Y;

            // If the camera's in ortho mode then we're likely making a 2D game, so set the PixelSize to .5
            if (SpriteManager.Camera.Orthogonal)
            {
                spriteCreated.PixelSize = .5f;
            }

            SetStoredAddToSE(spriteCreated, EditorProperties.PixelSize);

            return(spriteCreated);
        }