コード例 #1
0
        private 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
        static void importPictureFiles(PictureFileImporterParam.Mode mode)
        {
            PictureFileImporterParam param = new PictureFileImporterParam();

            string strPath      = EditorUtility.OpenFilePanel("Open File", "", param.strExtensionPng + "," + param.strExtentionTga);
            string strExtension = Path.GetExtension(strPath).ToLower();

            if (strExtension == "." + param.strExtensionPng.ToLower())
            {
                param.strExtension = param.strExtensionPng;
            }
            else if (strExtension == "." + param.strExtentionTga.ToLower())
            {
                param.strExtension = param.strExtentionTga;
            }

            var strFileneWithoutExtention = Path.GetFileNameWithoutExtension(strPath);

            if (!Regex.IsMatch(strFileneWithoutExtention, @"\d+$"))
            {
                Debug.LogError(@"Input doesn't include number.");
                return;
            }



            /// cehck Importing file name
            var regNumbers = new Regex(@"\d+$");
            var matches    = regNumbers.Matches(strFileneWithoutExtention);

            Assert.IsTrue(matches.Count > 0);

            param.match = null;
            foreach (Match match in matches)
            {
                param.match = match;
            }

            Assert.IsTrue(param.match != null);

            var parsed      = int.Parse(param.match.Value);
            int periodIndex = strFileneWithoutExtention.Length;
            int digits      = param.match.Value.Length;

            param.strSrcFolder = Path.GetDirectoryName(strPath);
            var strBaseName = strFileneWithoutExtention.Substring(0, param.match.Index);


            /// create copy destination path


            var strDistFolder = Application.streamingAssetsPath;

            if (mode == PictureFileImporterParam.Mode.SpriteAnimation)
            {
                strDistFolder = Application.dataPath;
            }
            if (!Directory.Exists(strDistFolder))
            {
                Directory.CreateDirectory(strDistFolder);
            }

            param.strAssetName = strBaseName;
            if (param.strAssetName.EndsWith("_") || param.strAssetName.EndsWith("-"))
            {
                param.strAssetName = param.strAssetName.Substring(0, param.strAssetName.Length - 1);
            }

            param.strDstFolder = Path.Combine(strDistFolder, param.strAssetName).Replace("\\", "/");



            /// making list of the files and copy them.
            List <string> strNames = new List <string>();

            for (; ;)
            {
                string strZero     = string.Format("{0:D" + digits + "}", parsed++);
                string strFileName = strBaseName + strZero + "." + param.strExtension;
                strFileName = strFileName.Replace("\\", "/");
                string path = Path.Combine(param.strSrcFolder, strFileName).Replace("\\", "/");
                if (!File.Exists(path))
                {
                    break;
                }
                strNames.Add(strFileName);
            }

            param.files = new string[strNames.Count];
            for (int ii = 0; ii < strNames.Count; ii++)
            {
                param.files[ii] = strNames[ii];
            }
            param.mode = mode;
            PictureFileImportWindow.Init(param);
        }