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); } }
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}"); }
public void UnBindButtonEvent(string bindName) { if (this._bindInfoGroup.ContainsKey(bindName) == false) { Debug.LogWarning($"Not Binding Info Bind Name : {bindName}"); return; } this._bindInfoGroup.Remove(bindName); }
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 void BindButtonEvent(string bindName, IInputBindParam bindParam) { if (this._bindInfoGroup.ContainsKey(bindName) == true) { Debug.LogWarning($"Already Binding Info Bind Name : {bindName}"); return; } this._bindInfoGroup.Add(bindName, bindParam); }
public IEnumerator LoadLevelAsync(string assetBundleName, string levelName, bool isAdditive) { if (_assetBundleList.ContainsKey(assetBundleName) == false) { Debug.LogError($"{assetBundleName} is NULL!"); yield break; } yield return(SceneManager.LoadSceneAsync(levelName, isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single)); }
public void StopEffect(int index) { if (index < 0 || index >= _effectSource.Count) { Debug.LogError($"Invalid index - {index}"); return; } _effectSource[index].Stop(); }
public override T Load <T>(string assetBundleName, string assetName) { if (isInitialized == false) { Debug.LogWarning("Initialized FIRST!"); return(null); } var result = assetBundleManager.LoadAsset <T>(assetBundleName, assetName); return(result); }
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 void UnloadAssetBundle(string assetBundleName, bool unloadAll = true) { AssetBundle assetBundle; if (!_assetBundleList.TryGetValue(assetBundleName, out assetBundle)) { Debug.LogError($"Failed to unload - {assetBundleName} is NOT FOUND!"); return; } assetBundle.Unload(unloadAll); _assetBundleList.Remove(assetBundleName); }
public async Task <T> LoadAssetAsync <T>(string assetBundleName, string assetName) where T : Object { AssetBundle assetBundle; if (_assetBundleList.TryGetValue(assetBundleName, out assetBundle) == false) { Debug.LogError($"Failed to load - {assetBundleName} is NOT EXIST!"); return(null); } var request = assetBundle.LoadAssetAsync <T>(assetName); await request; return(request.asset as T); }
private bool LoadClip(string clip) { if (_clipsDic.ContainsKey(clip) == false) { var audio = _resourceLoader?.Invoke(_assetBundleName, clip); if (audio != null) { _clipsDic.Add(clip, audio); } else { Debug.LogError($"AudioClip이 없어요! - {clip}"); return(false); } } return(true); }
public T LoadAsset <T>(string assetBundleName, string assetName) where T : Object { AssetBundle assetBundle; if (_assetBundleList.TryGetValue(assetBundleName, out assetBundle) == false) { Debug.LogError($"Failed to load - {assetBundleName} / {assetName} is NOT EXIST!"); return(null); } var result = assetBundle.LoadAsset <T>(assetName); if (result != null) { return(result); } Debug.LogError($"Failed to load - {assetBundleName} / {assetName} is NULL!"); return(null); }
public IEnumerator PreloadAllAssetBundle() { if (_assetBundleManifest == null) { Debug.LogError($"AssetBundleManifest is NULL!"); yield break; } state = STATE.LOADING; loadedAssetBundleCount = 0; var assetList = _assetBundleManifest.GetAllAssetBundles(); var listCount = assetList.Length; for (var i = 0; i < listCount; ++i) { yield return(LoadAssetBundle(assetList[i])); if (state == STATE.ERROR) { yield break; } // TODO(JJO): Dependency Load var dependencies = _assetBundleManifest.GetAllDependencies(assetList[i]); var dependencyCount = dependencies.Length; maximumAssetBundleCount += dependencyCount; for (var depIndex = 0; depIndex < dependencyCount; ++depIndex) { yield return(LoadAssetBundle(dependencies[depIndex])); if (state == STATE.ERROR) { yield break; } } } state = STATE.LOADED; }
public IEnumerator LoadAssetAsync <T>(string assetBundleName, string assetName, System.Action <T> outAction) where T : Object { //#if UNITY_EDITOR // if (SimulateAssetBundleInEditor) // { // var result = AssetDatabase.LoadAssetAtPath<T>(assetName); // if (result == null) // { // Log.Error($"[LoadAssetBundle] Failed to load - {assetName} is NULL!"); // } // // outAction(result); // // yield break; // } //#endif AssetBundle assetBundle; if (_assetBundleList.TryGetValue(assetBundleName, out assetBundle) == false) { Debug.LogError($"Failed to load - {assetBundleName} is NOT EXIST!"); yield break; } var request = assetBundle.LoadAssetAsync <T>(assetName); yield return(request); if (request.asset != null) { outAction(request.asset as T); } else { Debug.LogError($"Failed to load - {assetName} is NULL!"); } }
public override async Task <T> LoadAsync <T>(string assetBundleName, string assetName) { if (isInitialized == false) { Debug.LogWarning("Initialized FIRST!"); return(null); } var result = await Observable.Start(async() => { var asset = await assetBundleManager.LoadAssetAsync <T>(assetBundleName, assetName); if (asset == null) { Debug.LogError($"{assetName} is null"); return(null); } return(asset); }); return(result.Result); }
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 Color32 HexToColor(string hex) { hex = hex.Replace("0x", ""); hex = hex.Replace("#", ""); if (hex.Length < 6 || hex.Length > 8) { Debug.LogError($"[JJUtils|HexToColor] Parameter is invalid! - {hex}"); return(new Color32()); } var r = byte.Parse(hex.Substring(0, 2), NumberStyles.HexNumber); var g = byte.Parse(hex.Substring(2, 2), NumberStyles.HexNumber); var b = byte.Parse(hex.Substring(4, 2), NumberStyles.HexNumber); byte a = 255; if (hex.Length == 8) { a = byte.Parse(hex.Substring(6, 2), NumberStyles.HexNumber); } return(new Color32(r, g, b, a)); }
public static T Load <T>() { if (_loader == null) { Debug.LogError($"NOTE(jjo): ResourceLoader is NOT INITIALIZED!"); return(default);
public static void ResetPlayerPrefData() { Debug.Log("reset playerpref data"); UnityEngine.PlayerPrefs.DeleteAll(); }
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; } }
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)); } } } }