internal static void InitWindow()
        {
            Rect rect = new Rect(160, 160, 0, 0);
            PictureFileImportWindow window = ScriptableObject.CreateInstance <PictureFileImportWindow>(); // GetWindow<PictureFileImportWindow>();

            //      PictureFileImportWindow window = GetWindow<PictureFileImportWindow>();
            window.ShowAsDropDown(rect, new Vector2(640, 480));
        }
예제 #2
0
        /// <param name="importerMode"> Importer mode: StreamingAssets or SpriteAnimation</param>
        /// <param name="path"> Can be a directory path or a file path</param>
        public static void ImportPictureFiles(PictureFileImporterParam.Mode importerMode, string path,
                                              StreamingImageSequencePlayableAsset targetAsset)
        {
            Assert.IsFalse(string.IsNullOrEmpty(path));

            //Convert path to folder here
            string         folder = path;
            FileAttributes attr   = File.GetAttributes(path);

            if (!attr.HasFlag(FileAttributes.Directory))
            {
                folder = Path.GetDirectoryName(folder);
            }
            string fullSrcPath    = Path.GetFullPath(folder).Replace("\\", "/");
            Uri    fullSrcPathUri = new Uri(fullSrcPath + "/");


            if (string.IsNullOrEmpty(folder))
            {
                Debug.LogError(@"Folder is empty. Path: " + path);
                return;
            }

            //Enumerate all files with the supported extensions and sort
            List <string> relFilePaths = new List <string>();

            string[] extensions =
            {
                "*." + PictureFileImporter.PNG_EXTENSION,
                "*." + PictureFileImporter.TGA_EXTENSION,
            };
            foreach (string ext in extensions)
            {
                IEnumerable <string> files = Directory.EnumerateFiles(fullSrcPath, ext, SearchOption.AllDirectories);
                foreach (string filePath in files)
                {
                    Uri curPathUri = new Uri(filePath.Replace("\\", "/"));
                    Uri diff       = fullSrcPathUri.MakeRelativeUri(curPathUri);
                    relFilePaths.Add(diff.OriginalString);
                }
            }
            if (relFilePaths.Count <= 0)
            {
                EditorUtility.DisplayDialog(StreamingImageSequenceConstants.DIALOG_HEADER, @"No files in folder:: " + folder, "OK");
                return;
            }
            relFilePaths.Sort(FileNameComparer);

            //Estimate the asset name. Use the filename without numbers at the end
            string assetName = EstimateAssetName(relFilePaths[0]);

            // set dest folder
            string rootDestFolder = Application.streamingAssetsPath;

            if (importerMode == PictureFileImporterParam.Mode.SpriteAnimation)
            {
                rootDestFolder = Application.dataPath;
            }

            //Set importer param
            PictureFileImporterParam importerParam = new PictureFileImporterParam {
                strAssetName      = assetName,
                strSrcFolder      = folder,
                RelativeFilePaths = relFilePaths,
                mode        = importerMode,
                DoNotCopy   = false,
                TargetAsset = targetAsset
            };


            if (fullSrcPath.StartsWith(rootDestFolder))
            {
                //Import immediately if the assets are already under Unity
                importerParam.strDstFolder = importerParam.strSrcFolder;
                importerParam.DoNotCopy    = true;
                PictureFileImporter.Import(importerParam);
            }
            else
            {
                importerParam.strDstFolder = Path.Combine(rootDestFolder, assetName).Replace("\\", "/");
                PictureFileImportWindow.SetParam(importerParam);
                PictureFileImportWindow.InitWindow();
            }
        }