コード例 #1
0
ファイル: Library.cs プロジェクト: YuriSukhorukov/Drawing
        public Library()
        {
            string repositoryJSON = File.ReadAllText(URLManager.LocalPageRepository);

            pages.FromJSON(repositoryJSON);

            repositoryJSON = File.ReadAllText(URLManager.LocalBookRepository);
            books.FromJSON(repositoryJSON);

            repositoryJSON = File.ReadAllText(URLManager.LocalTextureRepository);
            textures.FromJSON(repositoryJSON);
        }
コード例 #2
0
        private static void export()
        {
            System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();

            TextureRepository texturesRepository = new TextureRepository();

            texturesRepository.FromJSON(File.ReadAllText(
                                            URLManager.CombinePath(
                                                Application.streamingAssetsPath,
                                                AssetPath.DEFAULT_REPOSITORY_IN_SA,
                                                URLManager.DEFAULT_TEXTURE_REPOSITORY_FILENAME)
                                            ));

            PageRepository pagesRepository = new PageRepository();

            pagesRepository.FromJSON(File.ReadAllText(
                                         URLManager.CombinePath(
                                             Application.streamingAssetsPath,
                                             AssetPath.DEFAULT_REPOSITORY_IN_SA,
                                             URLManager.DEFAULT_PAGE_REPOSITORY_FILENAME)
                                         ));

            lastUsedAssetPath =
                AssetPath.CreateAssetPath(AssetPath.DEFAULT_RESOURCES_PATH, wizard.Folder) + "/" +
                PAGE_PREFIX + wizard.Name + ".asset";
            ImageData data = exportMeshData();

            AssetDatabase.CreateAsset(data, lastUsedAssetPath);
            AssetImporter asset = AssetImporter.GetAtPath(lastUsedAssetPath);

            string bundleName = wizard.Folder + ".unity3d";

            asset.SetAssetBundleNameAndVariant(bundleName, "");

            AssetDatabase.SaveAssets();

            // Модификация реестра страниц
            string previewPath = AssetDatabase.GetAssetPath(wizard.PreviewTexture);

            uint textureID = texturesRepository.Find(t => t.Location.ResourceName == previewPath).ID;

            List <uint> allPagesIDs = pagesRepository.FindAll(p => true).Select(p => p.ID).ToList();
            uint        maxPageID   = 0;

            allPagesIDs.ForEach(id => maxPageID = (id > maxPageID) ? id : maxPageID);

            Page oldPage = pagesRepository.Find(p => p.Location.ResourceName == lastUsedAssetPath);

            if (oldPage == null)
            {
                pagesRepository.Add(new Page(
                                        maxPageID + 1,
                                        lastUsedAssetPath,
                                        bundleName,
                                        textureID
                                        ));
            }
            else
            {
                pagesRepository.Storage[oldPage.ID].TextureID = textureID;
//                    = new Page(
//                    oldPage.ID,
//                    oldPage.Location.ResourceName,
//                    bundleName,
//                    textureID
//                );
            }

            File.WriteAllText(URLManager.CombinePath(
                                  Application.streamingAssetsPath,
                                  AssetPath.DEFAULT_REPOSITORY_IN_SA,
                                  URLManager.DEFAULT_PAGE_REPOSITORY_FILENAME),
                              pagesRepository.ToJSON());

            sw.Stop();
            Debug.Log(string.Format("Import completed. Time elapsed: {0}ms", sw.ElapsedMilliseconds));
        }