Beispiel #1
0
 private void OnEnable()
 {
     Debug.Log("OnEnable");
     if (controller == null)
     {
         controller = new OpenPackageManagerController();
     }
     repoLocalPath = Path.Combine(cachePath, repositoryLocalFileName);
     if (File.Exists(repoLocalPath))
     {
         // load local repository
         Debug.Log("local repository exists.");
         var data = File.ReadAllText(repoLocalPath);
         controller.ParseRepository(data);
         drawer = new OpenPackageManagerDrawer(controller);
     }
     else
     {
         // download repository from github
         foreach (var link in OpenPackageManagerConfig.RepositoryLinks)
         {
             Debug.Log("local repository does not exist. downloading: " + link);
             EditorCoroutine.start(ConnectionTools.GetData(link, null, (prog) => { Debug.Log("downloading " + prog); }, (data) =>
             {
                 Debug.Log(("Download complete!"));
                 // write file locally
                 File.WriteAllText(repoLocalPath, data);
                 controller.ParseRepository(data);
                 drawer = new OpenPackageManagerDrawer(controller);
             }, (data) => { Debug.Log("download faild: " + data); }));
         }
     }
 }
        public void ParseRepository(string data)
        {
            // parse repository
            repository  = JsonUtility.FromJson <RepositoryItem>(data);
            allPackages = new List <GithubPackage>();
            // allPackages.AddRange(repositoryItem.packages);
            for (int i = 0; i < repository.packages.Count; i++)
            {
                var    packageInfo      = repository.packages[i].Split('/');
                string authorLocalPath  = Application.temporaryCachePath + "/" + packageInfo[0];
                string packageLocalPath = authorLocalPath + "/" + packageInfo[1];
                if (!Directory.Exists(packageLocalPath))
                {
                    Directory.CreateDirectory(packageLocalPath);
                }

                string packageLocalJsonPath = packageLocalPath + "/" + packageInfo[1] + ".json";
                if (File.Exists(packageLocalJsonPath))
                {
                    string packageData = File.ReadAllText(packageLocalJsonPath);
                    ParsePackage(packageData);
                }
                else
                {
                    // https://api.github.com/repos/omid3098/OpenAudio
                    var url = "https://api.github.com/repos/" + repository.packages[i];
                    Debug.Log(url);
                    EditorCoroutine.start(ConnectionTools.GetData(url, "", null, (_data) =>
                    {
                        File.WriteAllText(packageLocalJsonPath, _data);
                        ParsePackage(_data);
                    }, null));
                }
            }
        }