Пример #1
0
        /// アセットファイルタイプを指定したファイル追加処理.拡張子なし=UnitObject扱いになってしまう対策. 2018/08/20. yoshida.
        AssetFileBase AddSub(string path, AssetFileType assetFileType, IAssetFileSettingData settingData)
        {
            AssetFileBase file;

            //管理テーブルにあるなら、そこから
            if (!fileTbl.TryGetValue(path, out file))
            {
                if (path.Contains(" "))
                {
                    Debug.LogWarning("[" + path + "] contains white space");
                }
                AssetBundleInfo assetBundleInfo = AssetBundleInfoManager.FindAssetBundleInfo(path);
                AssetFileInfo   fileInfo        = new AssetFileInfo(path, settings, assetFileType, assetBundleInfo);

                //staticなアセットにあるなら、そこから
                file = StaticAssetManager.FindAssetFile(this, fileInfo, settingData);
                if (file == null)
                {
                    //カスタムロードなアセットにあるなら、そこから
                    file = CustomLoadManager.Find(this, fileInfo, settingData);
                    if (file == null)
                    {
                        //宴形式の通常ファイルロード
                        file = new AssetFileUtage(this, fileInfo, settingData);
                    }
                }
                fileTbl.Add(path, file);
            }
            return(file);
        }
Пример #2
0
 /// AssetFileTypeを指定してSettingを設定できるようにしたタイプのコンストラクタ.拡張子なし=UnitObject扱いになってしまう対策. 2018/08/20. yoshida.
 public AssetFileInfo(string path, AssetFileManagerSettings settings, AssetFileType assetFileType, AssetBundleInfo assetBundleInfo)
 {
     this.FileName        = path;
     this.Setting         = settings.Find(assetFileType);
     this.AssetBundleInfo = assetBundleInfo;
     this.StrageType      = ParseStrageType();
 }
        //リソースをアウトプット
        void OutputResources(string srcDir, string destDir)
        {
            int count = 0;

            string[] assets = AssetDatabase.FindAssets("", new[] { srcDir });
            foreach (string assetId in assets)
            {
                string        assetPath = AssetDatabase.GUIDToAssetPath(assetId);
                AssetFileType fileType  = fileManager.PraseFileType(assetPath);
                switch (fileType)
                {
                case AssetFileType.UnityObject:
                    MakeAssetBundle(assetPath, destDir);
                    break;

                default:
                    if (CopyFile(assetPath, assetPath.Replace(srcDir, destDir)))
                    {
                        ++count;
                    }
                    break;
                }
            }
            Debug.Log("" + count + " files copied");
            if (count > 0)
            {
                AssetDatabase.Refresh();
            }
        }
Пример #4
0
        //各アセットタイプに対応する拡張子を追加
        internal void AddAssetFileTypeExtensionsSub(AssetFileType type, string[] extensions)
        {
            switch (type)
            {
            case AssetFileType.Text:
                textExtArray = UtageToolKit.AddArrayUnique <string>(textExtArray, extensions);
                break;

            case AssetFileType.Bytes:
                binaryExtArray = UtageToolKit.AddArrayUnique <string>(binaryExtArray, extensions);
                break;

            case AssetFileType.Texture:
                textureExtArray = UtageToolKit.AddArrayUnique <string>(textureExtArray, extensions);
                break;

            case AssetFileType.Sound:
                soundExtArray = UtageToolKit.AddArrayUnique <string>(soundExtArray, extensions);
                break;

            case AssetFileType.Csv:
                csvExtArray = UtageToolKit.AddArrayUnique <string>(csvExtArray, extensions);
                break;

            case AssetFileType.UnityObject:
            default:
                break;
            }
        }
 public void ConstructorParameters()
 {
     _ = new AssetFileType(".foo");
     Assert.Throws <ArgumentNullException>(() => new AssetFileType(null));
     Assert.Throws <ArgumentException>(() => new AssetFileType(string.Empty));
     Assert.Throws <ArgumentException>(() => new AssetFileType(" "));
     Assert.Throws <ArgumentException>(() => new AssetFileType("foo"));
 }
Пример #6
0
            public string path;        //资源文件全路径

            public AssetFileInfo(AssetFileType t, string n, string a, string abs, string pa)
            {
                type    = t;
                name    = n;
                alias   = a;
                absName = abs;
                path    = pa;
            }
Пример #7
0
 public AssetFile AddLoadFile(string path, AssetFileType assetFileType, IAssetFileSettingData settingData)
 {
     if (IsEntityType)
     {
         return(null);
     }
     return(AddLoadFileSub(AssetFileManager.GetFileCreateIfMissing(path, assetFileType, settingData)));
 }
Пример #8
0
        /// <summary>
        /// ファイル情報を作成
        /// </summary>
        AssetFileInfo CreateFileInfo(string path)
        {
            AssetFileType       fileType   = PraseFileType(path);
            AssetFileStrageType strageType = PraseStrageType(path);
            bool isCrypt = CheckCrypt(fileType, cryptType);

            return(new AssetFileInfo(path, fileType, strageType, isCrypt, this.isAlreadyEncoded && isCrypt));
        }
 /// <summary>
 /// キャッシュデータテーブルをバイナリ読み込み
 /// </summary>
 /// <param name="reader"></param>
 void Read(BinaryReader reader)
 {
     InitKey(reader.ReadString());
     this.fileType     = (AssetFileType)reader.ReadInt32();
     this.cacheVersion = reader.ReadInt32();
     this.cachePath    = reader.ReadString();
     this.cryptType    = (AssetFileCryptType)reader.ReadInt32();
     this.strageType   = AssetFileStrageType.Web;
 }
Пример #10
0
        //符号化するファイルかチェック
        public bool IsAlreadyEncodedFieType(string srcFileName)
        {
            if (!isAlreadyEncoded)
            {
                return(false);
            }
            AssetFileType fileType = PraseFileType(srcFileName);

            return(CheckCrypt(fileType, cryptType));
        }
        public void GetHashCodeFromDefault()
        {
            // Arrange
            AssetFileType assetFileType = default;

            // Act
            int actualHashCode = assetFileType.GetHashCode();

            // Assert
            Assert.AreEqual(string.Empty.GetHashCode(), actualHashCode);
        }
Пример #12
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="path">ファイルパス</param>
 /// <param name="type">ファイルタイプ</param>
 /// <param name="strageType">置き場所のタイプ</param>
 /// <param name="isCrypt">キャッシュ時に暗号化するか</param>
 public AssetFileInfo(string path, AssetFileType type, AssetFileStrageType strageType, bool isCrypt, bool isAlreadyEncoded)
 {
     InitKey(path);
     this.fileType         = type;
     this.strageType       = strageType;
     this.cryptType        = isCrypt ? AssetFileCryptType.Utage : AssetFileCryptType.None;
     this.filePath         = Key;
     this.audioType        = ExtensionUtil.GetAudioType(FilePath);
     this.IsAlreadyEncoded = isAlreadyEncoded;
     CheckCsvLoadFlag();
 }
Пример #13
0
        //获取全部资源
        public static List <AssetFileInfo> UF_GetAllAssets(AssetFileType flag)
        {
            List <AssetFileInfo> list = new List <AssetFileInfo>();

            foreach (AssetFileInfo afi in s_ListAssetsMap)
            {
                if ((afi.type & flag) > 0)
                {
                    list.Add(afi);
                }
            }
            return(list);
        }
Пример #14
0
        public static int UF_GetAssetInfoCount(AssetFileType flag)
        {
            int count = 0;

            foreach (AssetFileInfo afi in s_ListAssetsMap)
            {
                if ((afi.type & flag) > 0)
                {
                    count++;
                }
            }
            return(count);
        }
Пример #15
0
        public AssetFile(string name, string localPath, string url)
        {
            Name      = name;
            Url       = url;
            LocalPath = localPath;

            if (LocalPath.IndexOf(".txt") > 0 || LocalPath.IndexOf(".xml") > 0)
            {
                Type = AssetFileType.TEXT;
            }
            else
            {
                Type = AssetFileType.BYTE;
            }
            IsSaveToFile = !string.IsNullOrEmpty(LocalPath);
        }
Пример #16
0
        /// <summary>
        /// Saves the asset file to disk.
        /// Asset previews are automatically resized.
        /// Asset thumbnails are automatically resized and stamped.
        /// </summary>
        public static void SaveAssetFile(Asset asset, BinaryFile file, AssetFileType assetFileType)
        {
            // Check asset
            if (asset == null || asset.IsNull || asset.IsNew)
            {
                throw new InvalidAssetException("Asset is null or new");
            }

            // Check we've got a file
            if (file == null || file.IsEmpty)
            {
                throw new InvalidAssetException("file is empty");
            }

            // Check that we're not trying to save an asset file.  This must be done
            // using a different overload of this method as it has more processes involved.
            if (assetFileType == AssetFileType.AssetFile)
            {
                throw new SystemException("This method cannot be used to save raw asset files; it is designed to save related asset files only");
            }

            // Folder where this file will reside
            string folder = GetFolder(asset.AssetFilePath, assetFileType);

            // Delete the old file
            DeleteFiles(asset.FileReference, folder);

            // Construct path to file to be saved
            string filename = String.Concat(asset.FileReference, ".", file.FileExtension);
            string path     = Path.Combine(folder, filename);

            // Save the file
            SavePostedFile(file, path);

            // Resize previews
            if (AssetTypeChecker.IsImage(file.FileExtension) && assetFileType == AssetFileType.AssetPreview)
            {
                ImageUtils.ResizeImage(path, path, 320, 300, true);
            }

            // Resize thumbnails
            if (AssetTypeChecker.IsImage(file.FileExtension) && assetFileType == AssetFileType.AssetThumbnail)
            {
                ImageUtils.ResizeImageDown(path, 100, 100);
                StampThumbnail(asset);
            }
        }
    static void GetFliter(AssetFileType type, out string fliter, out string defExt)
    {
        fliter = "All Files (*.*)|*.*";
        defExt = "";
        switch (type)
        {
        case AssetFileType.Csv:
            fliter = "配制(*.csv)|*.csv";
            defExt = "csv";    //显示文件的类型
            break;

        case AssetFileType.Movie:
            fliter = "配制(*.avi*.mp4)|*.avi;*.mp4";
            defExt = "mp4";    //显示文件的类型
            break;

        case AssetFileType.Picture:
            fliter = "表格(*.png*.jpg)|*.png;*.jpg";
            defExt = "png";    //显示文件的类型
            break;

        case AssetFileType.Html:
            fliter = "网页(*.html*.htm)|*.html;*.htm";
            defExt = "html";    //显示文件的类型
            break;

        case AssetFileType.Pdf:
            fliter = "信息(*.pdf)|*.pdf";
            defExt = "pdf";    //显示文件的类型
            break;

        case AssetFileType.Excel:
            fliter = "表格(*.xls*.xlsx*.csv)|*.xls;*.xlsx;*.csv;";
            defExt = "xls";    //显示文件的类型
            break;

        case AssetFileType.Exe:
            fliter = "程序(*.exe)|*.exe;";
            defExt = "exe";    //显示文件的类型
            break;

        default:
            break;
        }
        fliter = fliter.Replace("|", "\0") + "\0";
    }
 /// <summary>
 /// ファイル情報取得.AssetFileTypeを指定した生成.拡張子なし=UnitObject扱いになってしまう対策. 2018/08/20. yoshida.
 /// </summary>
 /// <param name="path">ファイルパス</param>
 /// <returns>ファイル情報</returns>
 static public AssetFile GetFileCreateIfMissing(string path, AssetFileType assetFileType, IAssetFileSettingData settingData = null)
 {
     if (!IsEditorErrorCheck)
     {
         AssetFile file = GetInstance().AddSub(path, assetFileType, settingData);
         return(file);
     }
     else
     {
         if (path.Contains(" "))
         {
             Debug.LogWarning("[" + path + "] contains white space");
         }
         //              AssetFileWork dummy = new AssetFileWork();
         return(null);
     }
 }
Пример #19
0
        public void AddUpdateFileContents(int assetId, string filename, AssetFileType assetFileType, ByteArray byteArray, bool forceAdd)
        {
            IDbCommand command = CreateCommand();

            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "usp_AddUpdateAssetFile";

            // Add AssetId Parameter
            IDbDataParameter assetIdParameter = m_factory.CreateParameter("@AssetId", assetId);

            assetIdParameter.DbType = DbType.Int32;
            command.Parameters.Add(assetIdParameter);

            // Add ContentBytes Parameter
            IDbDataParameter contentBytesParameter = m_factory.CreateParameter("@FileContent", byteArray.ContentBytes);

            contentBytesParameter.DbType = DbType.Binary;
            command.Parameters.Add(contentBytesParameter);

            // Add Filename parameter
            IDbDataParameter fileNameParameter = m_factory.CreateParameter("@FileName", filename);

            fileNameParameter.DbType = DbType.String;
            command.Parameters.Add(fileNameParameter);

            // Add FileExtension parameter
            IDbDataParameter fileExtensionParameter = m_factory.CreateParameter("@FileExtension", (Path.GetExtension(filename) ?? string.Empty).ToLower());

            fileExtensionParameter.DbType = DbType.String;
            command.Parameters.Add(fileExtensionParameter);

            // Add AssetFileType parameter
            IDbDataParameter fileTypeParameter = m_factory.CreateParameter("@AssetFileTypeId", Convert.ToInt32(assetFileType));

            fileTypeParameter.DbType = DbType.Int32;
            command.Parameters.Add(fileTypeParameter);

            // Add ForceAdd parameter
            IDbDataParameter forceAddParameter = m_factory.CreateParameter("@ForceAdd", (forceAdd) ? 1 : 0);

            fileTypeParameter.DbType = DbType.Int32;
            command.Parameters.Add(forceAddParameter);

            ExecuteCommand(command);
        }
Пример #20
0
        //符号化して書き込み
        public bool WriteEncode(string path, string srcFileName, byte[] bytes)
        {
            AssetFileType fileType = PraseFileType(srcFileName);

            bool ret;

            switch (fileType)
            {
            case AssetFileType.Texture:
                ret = FileIOManger.WriteEncodeNoCompress(path, bytes);
                break;

            default:
                ret = FileIOManger.WriteEncode(path, bytes);
                break;
            }
            return(ret);
        }
Пример #21
0
        //暗号化するかのチェック
        bool CheckCrypt(AssetFileType type, CryptAssetType cryptType)
        {
            switch (type)
            {
            case AssetFileType.Bytes:
                return((cryptType & CryptAssetType.Binary) == CryptAssetType.Binary);

            case AssetFileType.Text:
            case AssetFileType.Csv:
                return((cryptType & CryptAssetType.Text) == CryptAssetType.Text);

            case AssetFileType.Texture:
                return((cryptType & CryptAssetType.Texture) == CryptAssetType.Texture);

            default:
                return(false);
            }
        }
    public static string SaveFileDialog(AssetFileType fileType, string windowTitle = "保存文件", string initPath = null)
    {
        OpenFileName ofn = InitDialogCommon(windowTitle, initPath);

        GetFliter(fileType, out ofn.filter, out ofn.defExt);
        ofn.flags = (int)(
            OpenFileNameFlags.OFN_EXPLORER
            | OpenFileNameFlags.OFN_FILEMUSTEXIST
            | OpenFileNameFlags.OFN_PATHMUSTEXIST
            | OpenFileNameFlags.OFN_NOCHANGEDIR
            );
        if (WindowDll.GetSaveFileName(ofn))
        {
            IntPtr filePointer = ofn.file;
            string file        = Marshal.PtrToStringAuto(filePointer);
            return(file);
        }
        return(null);
    }
Пример #23
0
        /// <summary>
        /// Gets the absolute folder where files of the specified type should be saved for the specified asset
        /// </summary>
        internal static string GetFolder(AssetFilePath path, AssetFileType fileType)
        {
            if (GeneralUtils.ValueIsInList(fileType, AssetFileType.AssetFile, AssetFileType.AssetPreview, AssetFileType.AssetThumbnail))
            {
                return(Path.Combine(path.Path, fileType + "s"));
            }

            if (GeneralUtils.ValueIsInList(fileType, AssetFileType.AssetFileZipped))
            {
                return(Path.Combine(path.Path, "AssetFilesZipped"));
            }

            if (GeneralUtils.ValueIsInList(fileType, AssetFileType.AttachedFile))
            {
                throw new SystemException("Attached files are not stored on disk");
            }

            throw new SystemException("Unknown file type: " + fileType);
        }
Пример #24
0
        public async Task BadFileType(AssetFileType ft, bool passes)
        {
            bool exceptedWithUnsupportedFileType = !passes;

            try
            {
                ObjectAnchorsConversionClient client = new ObjectAnchorsConversionClient(Guid.NewGuid(), "eastus2.azure.com", new AccessToken("dummykey", new DateTimeOffset(new DateTime(3000, 1, 1))));
                await client.StartAssetConversionAsync(new AssetConversionOptions(new Uri(anyWorkingUriString), new AssetFileType(".exe"), new AssetConversionConfiguration(new System.Numerics.Vector3(0, 0, 1), 1)));
            }
            catch (AssetFileTypeNotSupportedException)
            {
                exceptedWithUnsupportedFileType = true;
            }
            catch (Exception)
            {
                // This is fine
            }

            Assert.True(exceptedWithUnsupportedFileType);
        }
Пример #25
0
        //	指定タイプのキャッシュファイルを全て削除
        void DeleteCacheFileAllSub(AssetFileType type)
        {
            List <string> removeFile = new List <string>();

            foreach (string key in fileInfoTbl.Keys)
            {
                AssetFileInfo fileInfo = fileInfoTbl.GetValue(key);
                if (fileInfo.FileType == type)
                {
                    removeFile.Add(key);
                }
            }
            foreach (string key in removeFile)
            {
                AssetFileInfo fileInfo = fileInfoTbl.GetValue(key);
                //キャッシュファイル削除
                fileInfo.DeleteCache();
                fileInfoTbl.Remove(key);
            }
            WriteCacheTbl();
        }
Пример #26
0
 public void AddExtensions(AssetFileType type, string[] extensions)
 {
     this.Find(type).AddExtensions(extensions);
 }
		//各アセットタイプに対応する拡張子を追加
		internal void AddAssetFileTypeExtensionsSub(AssetFileType type, string[] extensions)
		{
			switch (type)
			{
				case AssetFileType.Text:
					textExtArray = UtageToolKit.AddArrayUnique<string>(textExtArray, extensions);
					break;
				case AssetFileType.Bytes:
					binaryExtArray = UtageToolKit.AddArrayUnique<string>(binaryExtArray, extensions);
					break;
				case AssetFileType.Texture:
					textureExtArray = UtageToolKit.AddArrayUnique<string>(textureExtArray, extensions);
					break;
				case AssetFileType.Sound:
					soundExtArray = UtageToolKit.AddArrayUnique<string>(soundExtArray, extensions);
					break;
				case AssetFileType.Csv:
					csvExtArray = UtageToolKit.AddArrayUnique<string>(csvExtArray, extensions);
					break;
				case AssetFileType.UnityObject:
				default:
					break;
			}
		}
Пример #28
0
 //拡張子を追加
 internal static void AddAssetFileTypeExtensions(AssetFileType type, string[] extensions)
 {
     GetInstance().AddAssetFileTypeExtensionsSub(type, extensions);
 }
Пример #29
0
 /// <summary>
 /// 指定タイプのキャッシュファイルを全て削除
 /// </summary>
 /// <param name="type">削除するキャッシュファイルのタイプ</param>
 static public void DeleteCacheFileAll(AssetFileType type)
 {
     GetInstance().DeleteCacheFileAllSub(type);
 }
		//暗号化するかのチェック
		bool CheckCrypt(AssetFileType type, CryptAssetType cryptType)
		{
			switch (type)
			{
				case AssetFileType.Bytes:
					return (cryptType & CryptAssetType.Binary) == CryptAssetType.Binary;
				case AssetFileType.Text:
				case AssetFileType.Csv:
					return (cryptType & CryptAssetType.Text) == CryptAssetType.Text;
				case AssetFileType.Texture:
					return (cryptType & CryptAssetType.Texture) == CryptAssetType.Texture;
				default:
					return false;
			}
		}
Пример #31
0
 public AssetFileSetting Find(AssetFileType type)
 {
		//拡張子を追加
		internal static void AddAssetFileTypeExtensions(AssetFileType type, string[] extensions)
		{
			GetInstance().AddAssetFileTypeExtensionsSub(type, extensions);
		}
		//	指定タイプのキャッシュファイルを全て削除
		void DeleteCacheFileAllSub(AssetFileType type)
		{
			List<string> removeFile = new List<string>();
			foreach ( string key in fileInfoTbl.Keys)
			{
				AssetFileInfo fileInfo = fileInfoTbl.GetValue(key);
				if (fileInfo.FileType == type)
				{
					removeFile.Add(key);
				}
			}
			foreach ( string key in removeFile)
			{
				AssetFileInfo fileInfo = fileInfoTbl.GetValue(key);
				//キャッシュファイル削除
				fileInfo.DeleteCache();
				fileInfoTbl.Remove(key);
			}
			WriteCacheTbl();
		}
        public async Task ObserveExistingAssetConversion()
        {
            Recording.DisableIdReuse();

            string  localFilePath = assetLocalFilePath;
            Vector3 assetGravity  = new Vector3(assetGravityX, assetGravityY, assetGravityZ);
            float   scale         = assetScale;

            var clientWithWorkingInternalMethods = CreateClient();
            ObjectAnchorsConversionClient client = InstrumentClient(clientWithWorkingInternalMethods);

            AssetUploadUriResult uploadUriResult = await client.GetAssetUploadUriAsync();

            Uri uploadedInputAssetUri = uploadUriResult.UploadUri;

            BlobClient uploadBlobClient = InstrumentClient(new BlobClient(uploadedInputAssetUri, InstrumentClientOptions(new BlobClientOptions(BlobClientOptions.ServiceVersion.V2019_12_12))));

            using (FileStream fs = File.OpenRead(localFilePath))
            {
                await uploadBlobClient.UploadAsync(fs);
            }

            AssetConversionOptions assetConversionOptions = new AssetConversionOptions(uploadedInputAssetUri, AssetFileType.FromFilePath(localFilePath), assetGravity, scale);

            assetConversionOptions.JobId = Recording.Random.NewGuid();

            Guid jobId = new Guid((await client.StartAssetConversionAsync(assetConversionOptions)).Id);

            AssetConversionOperation operation = new AssetConversionOperation(jobId, clientWithWorkingInternalMethods);

            await operation.WaitForCompletionAsync();

            if (!operation.HasCompletedSuccessfully)
            {
                throw new Exception("The asset conversion operation completed with an unsuccessful status");
            }

            string localFileDownloadPath = modelDownloadLocalFilePath;

            BlobClient downloadBlobClient = InstrumentClient(new BlobClient(operation.Value.OutputModelUri, InstrumentClientOptions(new BlobClientOptions(BlobClientOptions.ServiceVersion.V2019_12_12))));

            BlobDownloadInfo downloadInfo = await downloadBlobClient.DownloadAsync();

            using (FileStream file = File.OpenWrite(localFileDownloadPath))
            {
                await downloadInfo.Content.CopyToAsync(file);

                var fileInfo = new FileInfo(localFileDownloadPath);
                Assert.Greater(fileInfo.Length, 0);
            }
        }
		/// <summary>
		/// 指定タイプのキャッシュファイルを全て削除
		/// </summary>
		/// <param name="type">削除するキャッシュファイルのタイプ</param>
		static public void DeleteCacheFileAll(AssetFileType type)
		{
			GetInstance().DeleteCacheFileAllSub(type);
		}