Esempio n. 1
0
        public void Save(string projectPath, string[] folderPaths, AssetItem[] assetItems, PersistentObject[] persistentObjects, ProjectInfo projectInfo, StorageEventHandler callback)
        {
            if (assetItems.Length != persistentObjects.Length || persistentObjects.Length != folderPaths.Length)
            {
                throw new ArgumentException("assetItems");
            }

            projectPath = FullPath(projectPath);
            string      projectInfoPath = projectPath + "/Project.rtmeta";
            ISerializer serializer      = IOC.Resolve <ISerializer>();
            Error       error           = new Error(Error.OK);

            for (int i = 0; i < assetItems.Length; ++i)
            {
                string           folderPath       = folderPaths[i];
                AssetItem        assetItem        = assetItems[i];
                PersistentObject persistentObject = persistentObjects[i];
                try
                {
                    string path = projectPath + folderPath;
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    string previewPath = path + "/" + assetItem.NameExt + PreviewExt;
                    if (assetItem.Preview == null)
                    {
                        File.Delete(previewPath);
                    }
                    else
                    {
                        using (FileStream fs = File.OpenWrite(previewPath))
                        {
                            serializer.Serialize(assetItem.Preview, fs);
                        }
                    }

                    using (FileStream fs = File.OpenWrite(path + "/" + assetItem.NameExt + MetaExt))
                    {
                        serializer.Serialize(assetItem, fs);
                    }
                    using (FileStream fs = File.OpenWrite(path + "/" + assetItem.NameExt))
                    {
                        serializer.Serialize(persistentObject, fs);
                    }
                    using (FileStream fs = File.OpenWrite(projectInfoPath))
                    {
                        serializer.Serialize(projectInfo, fs);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogErrorFormat("Unable to create asset: {0} -> got exception: {1} ", assetItem.NameExt, e.ToString());
                    error.ErrorCode = Error.E_Exception;
                    error.ErrorText = e.ToString();
                    break;
                }
            }

            callback(error);
        }
Esempio n. 2
0
        public void Save(string projectPath, string folderPath, AssetItem assetItem, PersistentObject persistentObject, ProjectInfo projectInfo, StorageEventHandler callback)
        {
            projectPath = FullPath(projectPath);
            string      projectInfoPath = projectPath + "/Project.rtmeta";
            ISerializer serializer      = IOC.Resolve <ISerializer>();
            Error       error           = new Error(Error.OK);

            try
            {
                string path        = projectPath + folderPath;
                string previewPath = path + "/" + assetItem.NameExt + PreviewExt;
                if (assetItem.Preview == null)
                {
                    File.Delete(previewPath);
                }
                else
                {
                    using (FileStream fs = File.OpenWrite(previewPath))
                    {
                        serializer.Serialize(assetItem.Preview, fs);
                    }
                }

                using (FileStream fs = File.OpenWrite(path + "/" + assetItem.NameExt + MetaExt))
                {
                    serializer.Serialize(assetItem, fs);
                }
                using (FileStream fs = File.OpenWrite(path + "/" + assetItem.NameExt))
                {
                    serializer.Serialize(persistentObject, fs);
                }
                using (FileStream fs = File.OpenWrite(projectInfoPath))
                {
                    serializer.Serialize(projectInfo, fs);
                }
            }
            catch (Exception e)
            {
                Debug.LogErrorFormat("Unable to create asset: {0} -> got exception: {1} ", assetItem.NameExt, e.ToString());
                error.ErrorCode = Error.E_Exception;
                error.ErrorText = e.ToString();
            }

            callback(error);
        }