Exemple #1
0
 /// <summary>
 /// 使っていないか(アンロード可能か)チェック
 /// </summary>
 /// <returns>使っていないならtrue。まだ使っているならfalse</returns>
 public bool CheckUnuse()
 {
     if (referenceSet.RemoveWhere(s => s == null) > 0)
     {
         Debug.LogError(LanguageErrorMsg.LocalizeTextFormat(ErrorMsg.FileReferecedIsNull));
     }
     if (status == STAUS.USING)
     {
         if (referenceSet.Count <= 0)
         {
             status       = STAUS.UNUSED;
             unusedSortID = sCommonUnusedSortID;
             ++sCommonUnusedSortID;
         }
     }
     else if (status == STAUS.UNUSED)
     {
         if (referenceSet.Count > 0)
         {
             status       = STAUS.USING;
             unusedSortID = 0;
             Debug.LogError(LanguageErrorMsg.LocalizeTextFormat(ErrorMsg.MemoryLeak));
         }
     }
     return(status == STAUS.UNUSED);
 }
Exemple #2
0
        /// <summary>
        /// ロードの準備開始
        /// </summary>
        /// <param name="loadPriority">ロードの優先順</param>
        /// <param name="referenceObj">ファイルを参照するオブジェクト</param>
        /// <returns></returns>
        public bool ReadyToLoad(AssetFileLoadPriority loadPriority, System.Object referenceObj)
        {
            //ロードプライオリティの反映
            if (loadPriority < this.Priority)
            {
                this.Priority = loadPriority;
            }

            Use(referenceObj);
            unusedSortID = Int32.MaxValue;

            //通常ロード
            switch (status)
            {
            case STAUS.LOAD_WAIT:
                status = STAUS.LOADING;
                return(false);

            case STAUS.LOADING:
            case STAUS.LOAD_END:
                return(true);

            case STAUS.USING:
            case STAUS.UNUSED:
            default:
                status = STAUS.USING;
                return(true);
            }
        }
Exemple #3
0
 /// <summary>
 /// リソースをアンロードして、メモリを解放
 /// </summary>
 public void Unload()
 {
     if (FileInfo.StrageType == AssetFileStrageType.Resources)
     {
         UnloadResources();
     }
     else
     {
         if (FileInfo.IsAssetBundle)
         {
             UnloadAssetBundle();
         }
         else
         {
             UnloadWWW();
         }
     }
     foreach (AssetFile subFile in SubFiles.Values)
     {
         subFile.Unuse(this);
     }
     SubFiles.Clear();
     memSize  = 0;
     Priority = AssetFileLoadPriority.DownloadOnly;
     status   = STAUS.LOAD_WAIT;
 }
Exemple #4
0
//		AudioClip WriteCacheFileSound { get; }

//		byte[] CacheWriteBytes { get; }

        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="info">ファイル情報</param>
        /// <param name="fileIO">ファイルのIO管理クラス</param>
        public AssetFileWork(AssetFileInfo info, FileIOManagerBase fileIO)
        {
            this.FileName = info.Key;
            this.FileInfo = info;
            this.fileIO   = fileIO;
            this.status   = STAUS.LOAD_WAIT;
            this.Priority = AssetFileLoadPriority.DownloadOnly;
            this.SubFiles = new Dictionary <string, AssetFile>();
        }
Exemple #5
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="info">ファイル情報</param>
 /// <param name="fileIO">ファイルのIO管理クラス</param>
 internal AssetFileUtage(AssetFileUtageManager manager, AssetFileInfo info, StringGridRow rowData, FileIOManagerBase fileIO)
 {
     this.manager  = manager;
     this.fileIO   = fileIO;
     this.FileName = info.Key;
     this.FileInfo = info;
     this.status   = STAUS.LOAD_WAIT;
     this.Priority = AssetFileLoadPriority.DownloadOnly;
     this.SubFiles = new Dictionary <string, AssetFile>();
     this.RowData  = rowData;
 }
Exemple #6
0
 /// <summary>
 /// そのオブジェクトで使用する(参照を設定する)
 /// </summary>
 /// <param name="referenceObj">ファイルを参照するオブジェクト</param>
 public void Use(System.Object referenceObj)
 {
     if (null != referenceObj)
     {
         referenceSet.Add(referenceObj);
         if (status == STAUS.UNUSED)
         {
             status = STAUS.USING;
         }
     }
 }
Exemple #7
0
        /// <summary>
        /// ロードの完了処理
        /// </summary>
        public void LoadComplete()
        {
            //新たにキャッシュファイル書きこむ必要がある場合
            if (FileInfo.IsWriteNewCache)
            {
                //ロード成功
                this.manager.WriteNewVersion(this);
            }

            cacheWriteBytes = null;
            if (IsDownloadOnly)
            {
                if (OnLoadSubFiles != null)
                {
                    status = STAUS.USING;
                    if (OnLoadComplete != null)
                    {
                        OnLoadComplete(this);
                    }
                    if (OnLoadSubFiles != null)
                    {
                        OnLoadSubFiles(this);
                    }
                    Unload();
                }
                else
                {
                    status = STAUS.LOAD_WAIT;
                }
            }
            else
            {
                //			status = STAUS.LOAD_END;
                status = STAUS.USING;
                //メモリサイズを計算
                if (!IsLoadRetry)
                {
                    InitMemsSize();
                    if (OnLoadComplete != null)
                    {
                        OnLoadComplete(this);
                    }
                    if (OnLoadSubFiles != null)
                    {
                        OnLoadSubFiles(this);
                    }
                }
                streamingStatus = LOAD_STREAMING_STAUS.LOADEND;
            }
        }
Exemple #8
0
 /// <summary>
 /// ロードの完了処理
 /// </summary>
 public void LoadComplete()
 {
     cacheWriteBytes = null;
     if (IsDownloadOnly)
     {
         status = FileInfo.IsAssetBundle ?  STAUS.LOAD_END : STAUS.LOAD_WAIT;
     }
     else
     {
         //			status = STAUS.LOAD_END;
         status = STAUS.USING;
         //メモリサイズを計算
         if (!IsLoadRetry)
         {
             InitMemsSize();
             if (OnLoadComplete != null)
             {
                 OnLoadComplete(this);
             }
         }
         streamingStatus = LOAD_STREAMING_STAUS.LOADEND;
     }
 }
Exemple #9
0
        /// <summary>
        /// ロード処理
        /// </summary>
        /// <param name="timeOutDownload">ダウンロードのタイムアウトエラー時間</param>
        /// <returns></returns>
        public IEnumerator CoLoadAsync(float timeOutDownload)
        {
            this.status          = STAUS.LOADING;
            this.isLoadRetry     = false;
            this.isLoadError     = false;
            this.streamingStatus = LOAD_STREAMING_STAUS.NONE;
            this.loadingPath     = FileInfo.LoadWWWPath;

            if (FileInfo.StrageType == AssetFileStrageType.Resources)
            {
                LoadResource(loadingPath);
            }
            else
            {
                elapsedTime  = 0.0f;
                lastProgress = 0;

                WWW www;
//				if (FileInfo.IsAssetBundle && FileInfo.StrageType != AssetFileStrageType.StreamingAssets  )
                if (FileInfo.IsAssetBundle)
                {
                    //アセットバンドルのDL
                    www = WWW.LoadFromCacheOrDownload(loadingPath, Version);
                }
                else
                {
                    //その他
                    www = new WWW(loadingPath);
                }
                if (www == null)
                {
                    SetLoadError("Not Found");
                    yield break;
                }

                //WWWでダウンロード
                using (www)
                {
                    //ストリーミング再生でキャッシュへの書き込みが必要ない場合は、先にストリーミング用のサウンドを作成
                    if (FileInfo.IsStreamingType && !FileInfo.IsWriteNewCache)
                    {
                        streamingStatus = LOAD_STREAMING_STAUS.LOADING;
                        sound           = www.GetAudioClip(FileInfo.IsAudio3D, true, FileInfo.AudioType);
                        sound.name      = FileInfo.FilePath;
                    }

                    //ロード待ち
                    while (!www.isDone && string.IsNullOrEmpty(www.error) &&
                           !CheckSoundStreamReady(www) &&
                           !CheckDownloadTimeout(www, timeOutDownload))
                    {
                        UpdateLoadPirority(www);
                        yield return(0);
                    }

                    if (!string.IsNullOrEmpty(www.error))
                    {
                        Debug.Log(loadingPath + " is " + File.Exists(loadingPath));
                        //ロードエラー
                        SetLoadError(www.error);
                    }
                    else if (CheckSoundStreamReady(www))
                    {
                        //ストリーミングのみ独自処理
                        streamingStatus = LOAD_STREAMING_STAUS.READY;

                        //その後のロード待ち
                        while (!www.isDone && string.IsNullOrEmpty(www.error) &&
                               !CheckDownloadTimeout(www, timeOutDownload))
                        {
                            UpdateLoadPirority(www);
                            yield return(0);
                        }
                        if (!string.IsNullOrEmpty(www.error))
                        {
                            //ロードエラー
                            SetLoadError(www.error);
                        }
                        else if (!www.isDone)
                        {
                            //ロードエラー(タイムアウト)
                            SetLoadError("DownLoad TimeOut " + elapsedTime + "sec");
                        }
                        else
                        {
                        }
                    }
                    else if (!www.isDone)
                    {
                        //ロードエラー(タイムアウト)
                        SetLoadError("DownLoad TimeOut " + elapsedTime + "sec");
                    }
                    else
                    {
                        //ロード終了

                        //ストリーミングでも、完全にロードした場合はこっち来る
                        if (streamingStatus != LOAD_STREAMING_STAUS.NONE)
                        {
                            streamingStatus = LOAD_STREAMING_STAUS.DONE;
                        }

                        if (!IsDownloadOnly)
                        {
                            try
                            {
                                switch (FileInfo.EncodeType)
                                {
                                case AssetFileEncodeType.None:
                                    LoadWWWNormal(www);
                                    break;

                                case AssetFileEncodeType.AlreadyEncoded:
                                    LoadWWWCriptFile(www);
                                    break;

                                case AssetFileEncodeType.EncodeOnCache:
                                    if (FileInfo.IsWriteNewCache)
                                    {
                                        LoadWWWNormal(www);
                                    }
                                    else
                                    {
                                        LoadWWWCriptFile(www);
                                    }
                                    break;

                                case AssetFileEncodeType.AssetBundle:
                                    LoadAssetBundle(www);
                                    break;

                                default:
                                    SetLoadError("Load Error " + FileInfo.CachePath);
                                    break;
                                }
                            }
                            catch (Exception e)
                            {
                                SetLoadError("Load Error " + e.Message + "\n" + e.StackTrace);
                            }
                        }
                        //新たにキャッシュファイルとして書き込む必要がある場合は、バイナリを取得しておく
                        if (FileInfo.IsWriteNewCache)
                        {
                            cacheWriteBytes = www.bytes;
                        }
                    }
                }
            }
            yield break;
        }
        /// <summary>
        /// ロード処理
        /// </summary>
        /// <param name="timeOutDownload">ダウンロードのタイムアウトエラー時間</param>
        /// <returns></returns>
        public IEnumerator CoLoadAsync(float timeOutDownload)
        {
            //ロードを無視する
            if (this.IgnoreLoad)
            {
                yield break;
            }

            this.status          = STAUS.LOADING;
            this.isLoadRetry     = false;
            this.isLoadError     = false;
            this.streamingStatus = LOAD_STREAMING_STAUS.NONE;
            this.loadingPath     = FileInfo.LoadWWWPath;

            if (FileInfo.StrageType == AssetFileStrageType.Resources)
            {
                LoadResource(loadingPath);
            }
            else
            {
                elapsedTime  = 0.0f;
                lastProgress = 0;

                WWW www = new WWW(loadingPath);
                if (www == null)
                {
                    SetLoadError("Not Found");
                    yield break;
                }

                //WWWでダウンロード
                using (www)
                {
                    //ストリーミング再生でキャッシュへの書き込みが必要ない場合は、先にストリーミング用のサウンドを作成
                    if (FileInfo.IsStreamingType && !FileInfo.IsWriteNewCache)
                    {
                        streamingStatus = LOAD_STREAMING_STAUS.LOADING;
                        sound           = www.GetAudioClip(FileInfo.IsAudio3D, true, FileInfo.AudioType);
                        sound.name      = FileInfo.FilePath;
                    }

                    //ロード待ち
                    while (!www.isDone && string.IsNullOrEmpty(www.error) &&
                           !CheckSoundStreamReady(www) &&
                           !CheckDownloadTimeout(www, timeOutDownload))
                    {
                        UpdateLoadPirority(www);
                        yield return(0);
                    }

                    if (!string.IsNullOrEmpty(www.error))
                    {
                        //ロードエラー
                        SetLoadError(www.error);
                    }
                    else if (CheckSoundStreamReady(www))
                    {
                        //ストリーミングのみ独自処理
                        streamingStatus = LOAD_STREAMING_STAUS.READY;

                        //その後のロード待ち
                        while (!www.isDone && string.IsNullOrEmpty(www.error) &&
                               !CheckDownloadTimeout(www, timeOutDownload))
                        {
                            UpdateLoadPirority(www);
                            yield return(0);
                        }
                        if (!string.IsNullOrEmpty(www.error))
                        {
                            //ロードエラー
                            SetLoadError(www.error);
                        }
                        else if (!www.isDone)
                        {
                            //ロードエラー(タイムアウト)
                            SetLoadError("DownLoad TimeOut " + elapsedTime + "sec");
                        }
                        else
                        {
                        }
                    }
                    else if (!www.isDone)
                    {
                        //ロードエラー(タイムアウト)
                        SetLoadError("DownLoad TimeOut " + elapsedTime + "sec");
                    }
                    else
                    {
                        //ロード終了

                        //ストリーミングでも、完全にロードした場合はこっち来る
                        if (streamingStatus != LOAD_STREAMING_STAUS.NONE)
                        {
                            streamingStatus = LOAD_STREAMING_STAUS.DONE;
                        }

                        if (IsDownloadOnly)
                        {
                            //ダウンロードするだけでリソースをめもりには読み込まない
                            //ダウンロード = キャッシュファイルに書き込むなので,ここでバイナリを記録しておく
                            cacheWriteBytes = www.bytes;
                        }
                        else if (FileInfo.IsCaching && FileInfo.IsCrypt)
                        {
                            //暗号化されているファイルをキャッシュファイルからロード
                            if (null != www.bytes)
                            {
                                LoadWWWCriptCacheFile(www);
                            }
                            else
                            {
                                SetLoadError("CaecheFile Read Error " + FileInfo.CachePath);
                            }
                        }
                        else
                        {
                            if (FileInfo.IsAlreadyEncoded)
                            {
                                LoadWWWCriptFile(www);
                            }
                            else
                            {
                                //通常のファイルロード
                                LoadWWWNormal(www);
                            }
                        }
                    }
                }
            }
        }