private IEnumerator LoadAssetBundle(string assetBundle) { if (_assetBundleList.ContainsKey(assetBundle)) { Debug.LogWarning($"Already loaded asset - {assetBundle}"); ++loadedAssetBundleCount; yield break; } var path = Path.Combine(localAssetBundlePath, assetBundle); var request = AssetBundle.LoadFromFileAsync(path, 0); while (request.isDone == false) { currentAssetBundleProgress = request.progress; yield return(null); } var bundle = request.assetBundle; if (bundle == null) { Debug.LogError($"Failed to load - {assetBundle} is NULL!"); state = STATE.ERROR; yield break; } _assetBundleList.Add(assetBundle, bundle); ++loadedAssetBundleCount; Debug.Log($"Succeeded to load - {assetBundle}"); }
private IEnumerator DownloadAssetBundle(string assetBundleName, uint crc) { var path = $"{downloadUrl}{assetBundleName}"; var hash = _assetBundleManifest.GetAssetBundleHash(assetBundleName); using (var request = UnityWebRequestAssetBundle.GetAssetBundle(path, hash, crc)) { request.SendWebRequest(); while (request.isDone == false) { currentAssetBundleProgress = request.downloadProgress; currentAssetBundleSize = request.downloadedBytes; yield return(null); } if (string.IsNullOrEmpty(request.error) == false) { Debug.LogError($"Network Error! - {assetBundleName} / {crc}\n{request.error}"); state = STATE.ERROR; yield break; } var bundle = DownloadHandlerAssetBundle.GetContent(request); _assetBundleList.Add(assetBundleName, bundle); ++downloadedAssetBundleCount; Debug.Log($"Succeeded to download - {assetBundleName} / {crc}"); } }
private void OnGUI() { if (GUILayout.Button("Application.dataPath")) { Debug.Log(Application.dataPath); EditorUtility.RevealInFinder(Application.dataPath); } if (GUILayout.Button("Application.persistentDataPath")) { Debug.Log(Application.persistentDataPath); EditorUtility.RevealInFinder(Application.persistentDataPath); } if (GUILayout.Button("Application.streamingAssetsPath")) { Debug.Log(Application.streamingAssetsPath); EditorUtility.RevealInFinder(Application.streamingAssetsPath); } if (GUILayout.Button("Application.temporaryCachePath")) { Debug.Log(Application.temporaryCachePath); EditorUtility.RevealInFinder(Application.temporaryCachePath); } }
public static void RemoveDefineSymbol(string symbol) { string defineSymbol = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android); defineSymbol = defineSymbol.Replace($";{symbol}", ""); PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, defineSymbol); PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS, defineSymbol); Debug.Log(defineSymbol); }
public static void SetDefineSymbol(string _symbol) { string defineSymbol = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android); if (defineSymbol.Contains(_symbol) == false) { defineSymbol += ";" + _symbol; PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, defineSymbol); PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS, defineSymbol); Debug.Log(defineSymbol); } }
public static void BuildAndroidAssetBundles() { var path = System.IO.Path.Combine(Application.dataPath, "..", "AssetBundles", "Android"); if (System.IO.Directory.Exists(path) == false) { System.IO.Directory.CreateDirectory(path); } var manifest = BuildPipeline.BuildAssetBundles(path, BuildAssetBundleOptions.None, BuildTarget.Android); Debug.Log(manifest.GetAllAssetBundles()); var args = System.Environment.GetCommandLineArgs(); if (args.Contains("-noRevealInFinder") == false) { EditorUtility.DisplayDialog("Info", $"Completed Android AssetBundles!\nCount: {manifest.GetAllAssetBundles().Length}", "OK"); EditorUtility.RevealInFinder(path); } }
public static void ResetPlayerPrefData() { Debug.Log("reset playerpref data"); UnityEngine.PlayerPrefs.DeleteAll(); }
public IEnumerator PrepareDownload(string url, string manifestName, string assetBundleDirectoryName) { state = STATE.PREPARING; downloadUrl = url; localAssetBundlePath = Path.Combine(Application.persistentDataPath, assetBundleDirectoryName); if (Directory.Exists(localAssetBundlePath) == false) { Directory.CreateDirectory(localAssetBundlePath); } var localManifestRawPath = Path.Combine(localAssetBundlePath, $"{manifestName}.manifest"); var localManifestPath = Path.Combine(localAssetBundlePath, manifestName); string localManifestRaw = string.Empty; string remoteManifestRaw = string.Empty; // NOTE(JJO): 로컬에 저장된 데이터가 없다면 StreamingAssets를 검사하여 모든 StreamingAssets의 AssetBundle을 가져옴 if (File.Exists(localManifestRawPath) == false) { var streamingAssetsPath = Path.Combine(Application.streamingAssetsPath, "Bundle"); if (Directory.Exists(streamingAssetsPath)) { var fileList = Directory.GetFiles(streamingAssetsPath); var fileListCount = fileList.Length; for (int i = 0; i < fileListCount; ++i) { if (fileList[i].Contains(".meta")) { continue; } var fileName = Path.GetFileName(fileList[i]); var destinationPath = Path.Combine(localAssetBundlePath, fileName); File.Copy(fileList[i], destinationPath); Debug.Log($"Copy {fileList[i]} to {destinationPath}"); } } } // NOTE(JJO): 다시 로컬에 있는지 검사하여 가져옴 if (File.Exists(localManifestRawPath)) { localManifestRaw = File.ReadAllText(localManifestRawPath); } var remoteManifestRawPath = downloadUrl.EndsWith("/") == false ? $"{downloadUrl}/{manifestName}.manifest" : $"{downloadUrl}{manifestName}.manifest"; using (var request = UnityWebRequest.Get(remoteManifestRawPath)) { yield return(request.SendWebRequest()); if (string.IsNullOrEmpty(request.error) == false) { Debug.LogError($"Failed to load a manifest from {remoteManifestRawPath}\n{request.error}"); state = STATE.ERROR; yield break; } remoteManifestRaw = request.downloadHandler.text; } if (string.IsNullOrEmpty(localManifestRaw) || localManifestRaw != remoteManifestRaw) { // NOTE(JJO): 먼저 AssetBundleManifest를 받아서 정보를 가져옴. var remoteManifestPath = downloadUrl.EndsWith("/") == false ? $"{downloadUrl}/{manifestName}" : $"{downloadUrl}{manifestName}"; using (var request = UnityWebRequest.Get(remoteManifestPath)) { yield return(request.SendWebRequest()); if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError || string.IsNullOrEmpty(request.error) == false) { Debug.LogError($"Failed to load a manifest from {remoteManifestPath}\n{request.error}"); state = STATE.ERROR; yield break; } _assetBundleManifestObject = AssetBundle.LoadFromMemory(request.downloadHandler.data, 0); File.WriteAllBytes(localManifestPath, request.downloadHandler.data); // NOTE(JJO): Manifest 쓰기가 완료되고 나서 txt도 쓴다. File.WriteAllText(localManifestRawPath, remoteManifestRaw); } } else { _assetBundleManifestObject = AssetBundle.LoadFromFile(localManifestPath); } _assetBundleManifest = _assetBundleManifestObject.LoadAsset <AssetBundleManifest>(MANIFEST_NAME); maximumAssetBundleCount = _assetBundleManifest.GetAllAssetBundles().Length; var localAssetBundleFileNameList = Directory.GetFiles(localAssetBundlePath).ToList(); var assetList = _assetBundleManifest.GetAllAssetBundles(); var listCount = assetList.Length; // NOTE(JJO): 쓰지 않는 AssetBundle 제거 if (localAssetBundleFileNameList.Count > 0) { for (var assetIndex = 0; assetIndex < listCount; ++assetIndex) { var localAssetBundleFileNameListCount = localAssetBundleFileNameList.Count; for (var fileIndex = localAssetBundleFileNameListCount - 1; fileIndex >= 0; --fileIndex) { var fileName = Path.GetFileName(localAssetBundleFileNameList[fileIndex]); if (fileName == manifestName || fileName == $"{manifestName}.manifest" || fileName == assetList[assetIndex] || fileName == $"{assetList[assetIndex]}.manifest") { localAssetBundleFileNameList.RemoveAt(fileIndex); } } } } if (localAssetBundleFileNameList.Count > 0) { var localAssetBundleFileNameListCount = localAssetBundleFileNameList.Count; for (var fileIndex = localAssetBundleFileNameListCount - 1; fileIndex >= 0; --fileIndex) { File.Delete(localAssetBundleFileNameList[fileIndex]); } } // NOTE(JJO): 받아야하는 에셋의 크기를 계산한다! assetBundleTotalSize = 0; for (int i = 0; i < listCount; ++i) { var downloadPath = downloadUrl.EndsWith("/") == false ? $"{downloadUrl}/{assetList[i]}" : $"{downloadUrl}{assetList[i]}"; remoteManifestRawPath = $"{downloadPath}.manifest"; remoteManifestRaw = string.Empty; localManifestRawPath = Path.Combine(localAssetBundlePath, $"{assetList[i]}.manifest"); if (File.Exists(localManifestRawPath)) { localManifestRaw = File.ReadAllText(localManifestRawPath); } else { localManifestRaw = string.Empty; } using (var request = UnityWebRequest.Get(remoteManifestRawPath)) { yield return(request.SendWebRequest()); if (string.IsNullOrEmpty(request.error) == false) { Debug.LogError($"Failed to download a {assetList[i]}.manifest from {remoteManifestRawPath}!\n{request.error}"); state = STATE.ERROR; yield break; } remoteManifestRaw = request.downloadHandler.text; } if (string.IsNullOrEmpty(localManifestRaw) || localManifestRaw != remoteManifestRaw) { // NOTE(JJO): 받아야 하는 에셋의 크기를 구한다. using (var request = UnityWebRequest.Head(downloadPath)) { yield return(request.SendWebRequest()); if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError) { Debug.LogError($"Failed to get size of a {assetList[i]} from {downloadPath}!\n{request.error}"); state = STATE.ERROR; yield break; } ulong assetBundleSize; ulong.TryParse(request.GetResponseHeader(CONTENT_LENGTH), out assetBundleSize); assetBundleTotalSize += assetBundleSize; _downloadingAssetBundleList.Add(assetList[i], GetCRC(remoteManifestRaw)); } } } }
public IEnumerator PrepareDownload(string url, string manifestName) { // NOTE(JJO): url이 비어있다면 EDITOR모드임을 가정함. if (string.IsNullOrEmpty(url)) { state = STATE.LOADED; yield break; } state = STATE.PREPARING; downloadUrl = url; // TODO(JJO): StreamingAssets에서 로드한 흔적을 찾는다. string manifestSA = null; string manifestRemote = null; var pathSA = Path.Combine(Application.streamingAssetsPath, "Bundle"); var path = Path.Combine(pathSA, $"{manifestName}.manifest"); using (var request = UnityWebRequest.Get(path)) { yield return(request.SendWebRequest()); if (string.IsNullOrEmpty(request.error) == false) { Debug.LogWarning($"{manifestName} is NOT FOUND from StreamingAssets"); } else { manifestSA = request.downloadHandler.text; } } path = $"{downloadUrl}{manifestName}.manifest"; using (var request = UnityWebRequest.Get(path)) { yield return(request.SendWebRequest()); if (string.IsNullOrEmpty(request.error) == false) { Debug.LogError($"Failed to download - {path}\nReason: {request.error}"); state = STATE.ERROR; yield break; } manifestRemote = request.downloadHandler.text; } if (string.IsNullOrEmpty(manifestSA) == false && manifestSA == manifestRemote) { // NOTE(JJO): 그냥 여기에서 바로 S.A로부터 로드해버리자. path = Path.Combine(pathSA, manifestName); var request = AssetBundle.LoadFromFileAsync(path); yield return(request); _assetBundleManifestObject = request.assetBundle; if (_assetBundleManifestObject == null) { Debug.LogError($"Failed to load - {path}\nReason: Unknown"); state = STATE.ERROR; yield break; } _assetBundleManifest = _assetBundleManifestObject.LoadAsset <AssetBundleManifest>(nameof(AssetBundleManifest)); var assetList = _assetBundleManifest.GetAllAssetBundles(); var listCount = assetList.Length; for (int i = 0; i < listCount; ++i) { path = Path.Combine(pathSA, assetList[i]); request = AssetBundle.LoadFromFileAsync(path); yield return(request); var bundle = request.assetBundle; if (bundle == null) { Debug.LogError($"Failed to load - {path}\nReason: Unknown"); state = STATE.ERROR; yield break; } _assetBundleList.Add(assetList[i], bundle); Debug.Log($"Preload from StreamingAssets - {assetList[i]}"); } } else { path = $"{downloadUrl}{manifestName}"; using (var req = UnityWebRequestAssetBundle.GetAssetBundle(path)) { yield return(req.SendWebRequest()); if (string.IsNullOrEmpty(req.error) == false) { Debug.LogError($"Failed to download - {path}\nReason: Unknown"); state = STATE.ERROR; yield break; } _assetBundleManifestObject = DownloadHandlerAssetBundle.GetContent(req); _assetBundleManifest = _assetBundleManifestObject.LoadAsset <AssetBundleManifest>(nameof(AssetBundleManifest)); } var assetList = _assetBundleManifest.GetAllAssetBundles(); var listCount = assetList.Length; for (int i = 0; i < listCount; ++i) { path = Path.Combine(pathSA, $"{assetList[i]}.manifest"); using (var req = UnityWebRequest.Get(path)) { yield return(req.SendWebRequest()); // NOTE(JJO): StreamingAssets에 파일이 없다면 바로 다운로드 리스트에 추가함. if (string.IsNullOrEmpty(req.error)) { manifestSA = req.downloadHandler.text; } } path = $"{downloadUrl}{assetList[i]}.manifest"; using (var req = UnityWebRequest.Get(path)) { yield return(req.SendWebRequest()); if (string.IsNullOrEmpty(req.error) == false) { Debug.LogError($"Network Error - {assetList[i]}\n{req.error}"); state = STATE.ERROR; yield break; } manifestRemote = req.downloadHandler.text; } // NOTE(JJO): Manifest가 다르다면 다운로드 리스트에 추가함. if (string.IsNullOrEmpty(manifestSA) || manifestSA != manifestRemote) { _downloadingAssetBundleList.Add(assetList[i], GetCRC(manifestRemote)); } else { path = Path.Combine(pathSA, assetList[i]); var request = AssetBundle.LoadFromFileAsync(path); yield return(request); var bundle = request.assetBundle; if (bundle == null) { Debug.LogError($"{assetList[i]} NOT FOUND!"); state = STATE.ERROR; yield break; } _assetBundleList.Add(assetList[i], bundle); Debug.Log($"Preload from StreamingAssets - {assetList[i]}"); } } maximumAssetBundleCount = _downloadingAssetBundleList.Count; } }