示例#1
0
        public void loadAssetsFromProject(String pathDirToload)
        {
            if (this.MainForm.CurrentProject != null)
            {
                cleanCurrentAssetToSerialize();

                string documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Native-Software";
                if (!Directory.Exists(documentsDirectory))
                {
                    Directory.CreateDirectory(documentsDirectory);
                }

                //Creer d'abord le repertoire du project en cours si il n'existe pas !
                DirectoryInfo dirCurrentProject     = null;
                string        pathDirCurrentProject = documentsDirectory + "\\Asset Manager\\" + this.MainForm.CurrentProject.ProjectName;
                if (!Directory.Exists(pathDirCurrentProject))
                {
                    dirCurrentProject = Directory.CreateDirectory(pathDirCurrentProject);
                }


                //Recuperer les assets du repertoire selectioné
                DirectoryInfo dirProjectSelected = new DirectoryInfo(pathDirToload);
                string        pathFileSerialized = pathDirToload + "\\" + dirProjectSelected.Name.Replace(" ", "_") + ".kres";
                if (File.Exists(pathFileSerialized))
                {
                    FileStream fs = File.OpenRead(pathFileSerialized);
                    if (fs.Length > 0)
                    {
                        MemoryStream ms = new MemoryStream();
                        ms.SetLength(fs.Length);

                        fs.Read(ms.GetBuffer(), 0, (int)ms.Length);

                        assetsToSerialize = new AssetsToSerialize();

                        assetsToSerialize = (AssetsToSerialize)SerializerHelper.DeSerializeBinary(ms);
                        ms.Close();

                        //Remplir la Assets List bx avec la liste
                        loadAssetsListBxFromSerialized(assetsToSerialize);
                    }

                    fs.Close();
                }
                else
                {
                    MessageBox.Show("NO ASSETS FOUND FOR THIS PROJECT !\n You should open the Asset manager to create your assets for this project !",
                                    "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            /* else
             * {
             *   MessageBox.Show("NO PROJECT OPENED!\n Please open or create a project before continuing !",
             *                                                              "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
             * }*/
        }
示例#2
0
        public void updateAssets(List <object> assetsToUpdate)
        {
            //Recuperer tous les repertoires
            string documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Native-Software";

            if (!Directory.Exists(documentsDirectory))
            {
                Directory.CreateDirectory(documentsDirectory);
            }

            if (!Directory.Exists(documentsDirectory + "\\Asset Manager"))
            {
                Directory.CreateDirectory(documentsDirectory + "\\Asset Manager");
            }

            String[] tabString = Directory.GetDirectories(documentsDirectory + "\\Asset Manager\\");

            for (int i = 0; i < tabString.Length; i++)
            {
                string pathDirToload = tabString[i];

                //Recuperer les assets du repertoire selectioné
                DirectoryInfo dirProjectSelected = new DirectoryInfo(pathDirToload);
                string        pathFileSerialized = pathDirToload + "\\" + dirProjectSelected.Name.Replace(" ", "_") + ".kres";
                if (File.Exists(pathFileSerialized))
                {
                    AssetsToSerialize assetsSerialized = null;

                    FileStream fs = File.OpenRead(pathFileSerialized);
                    if (fs.Length > 0)
                    {
                        MemoryStream ms = new MemoryStream();
                        ms.SetLength(fs.Length);

                        fs.Read(ms.GetBuffer(), 0, (int)ms.Length);

                        assetsSerialized = (AssetsToSerialize)SerializerHelper.DeSerializeBinary(ms);
                        ms.Close();
                    }

                    fs.Close();

                    if (assetsSerialized != null)
                    {
                        List <object> assetsUpdated = new List <object>();
                        //Verifier si le projet contient les assets
                        for (int j = 0; j < assetsToUpdate.Count; j++)
                        {
                            object assetOBJ  = assetsToUpdate[j];
                            bool   isUpdated = false;
                            if (assetOBJ is DisplayObject)
                            {
                                DisplayObject assetDisplayObject = assetOBJ as DisplayObject;

                                if (assetDisplayObject.Type.Equals("IMAGE"))
                                {
                                    //Chercher dans le projet d'assets si il contient une image du même nom
                                    for (int k = 0; k < assetsSerialized.ListObjects.Count; k++)
                                    {
                                        DisplayObject serializedDisplayObject = assetsSerialized.ListObjects[k];
                                        if (serializedDisplayObject.Type.Equals("IMAGE"))
                                        {
                                            if (serializedDisplayObject.Name.Equals(assetDisplayObject.OriginalAssetName))
                                            {
                                                //Update the asset
                                                assetDisplayObject.Image = new Bitmap(serializedDisplayObject.Image);
                                                isUpdated = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                                else if (assetDisplayObject.Type.Equals("SPRITE"))
                                {
                                    //Chercher dans le projet d'assets si il contient une image du même nom
                                    for (int k = 0; k < assetsSerialized.ListObjects.Count; k++)
                                    {
                                        DisplayObject serializedDisplayObject = assetsSerialized.ListObjects[k];
                                        if (serializedDisplayObject.Type.Equals("SPRITE"))
                                        {
                                            if (serializedDisplayObject.Name.Equals(assetDisplayObject.OriginalAssetName))
                                            {
                                                //Update the asset
                                                assetDisplayObject.SpriteSet = serializedDisplayObject.SpriteSet;
                                                string currentSeq = assetDisplayObject.CurrentSequence;
                                                assetDisplayObject.CurrentSequence = currentSeq;
                                                int frame = assetDisplayObject.CurrentFrame;
                                                assetDisplayObject.CurrentFrame = frame;

                                                assetDisplayObject.InitialRect = assetDisplayObject.SurfaceRect;

                                                isUpdated = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }

                            if (isUpdated == true)
                            {
                                assetsUpdated.Add(assetOBJ);
                            }
                        }

                        for (int j = 0; j < assetsUpdated.Count; j++)
                        {
                            assetsToUpdate.Remove(assetsUpdated[j]);
                        }
                    }

                    assetsSerialized = null;
                }

                if (assetsToUpdate.Count == 0)
                {
                    return;
                }
            }
        }