예제 #1
0
        private bool PrepareDownload(PolyAsset asset, out string baseName, out string downloadLocalPath)
        {
            assetsBeingDownloaded.Remove(asset);
            PtDebug.LogFormat("ABM: Preparing to download {0}", asset);

            // basePath is something like Assets/Poly/Sources.
            string baseLocalPath = PtUtils.NormalizeLocalPath(PtSettings.Instance.assetSourcesPath);

            if (!baseLocalPath.StartsWith("Assets/"))
            {
                Debug.LogErrorFormat("Invalid asset sources folder {0}. Must be under Assets folder.");
                baseName = downloadLocalPath = null;
                return(false);
            }

            // basePathAbs is something like C:\Users\foo\bar\MyUnityProject\Assets\Poly\Sources
            string baseFullPath = PtUtils.ToAbsolutePath(baseLocalPath);

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

            baseName = PtUtils.GetPtAssetBaseName(asset);
            PtDebug.LogFormat("Import name: {0}", baseName);

            // downloadLocalPath is something like Assets/Poly/Sources/assetTitle_assetId
            downloadLocalPath = baseLocalPath + "/" + baseName;
            string downloadFullPath = PtUtils.ToAbsolutePath(downloadLocalPath);

            if (Directory.Exists(downloadFullPath))
            {
                if (PtSettings.Instance.warnOnSourceOverwrite &&
                    !EditorUtility.DisplayDialog("Warning: Overwriting asset source folder",
                                                 string.Format("The asset source folder '{0}' will be deleted and created again. " +
                                                               "This should be safe *unless* you have manually made changes to its contents, " +
                                                               "in which case you will lose those changes.\n\n" +
                                                               "(You can silence this warning in Poly Toolkit settings)",
                                                               asset.displayName, downloadLocalPath), "OK", "Cancel"))
                {
                    return(false);
                }
                Directory.Delete(downloadFullPath, /* recursive */ true);
            }

            // Create the download folder.
            // Something like C:\Users\foo\bar\MyUnityProject\Assets\Poly\Sources\assetTitle_assetId
            Directory.CreateDirectory(downloadFullPath);
            return(true);
        }