Removed bulk download at the start of program
This commit is contained in:
@@ -54,6 +54,11 @@ public class UmaAssetManager : MonoBehaviour
|
||||
SearchAB(Main, entry, ref result);
|
||||
}
|
||||
|
||||
if (Config.Instance.WorkMode == WorkMode.Standalone)
|
||||
{
|
||||
yield return UmaViewerDownload.DownloadAssets(result.ToList(), UmaSceneController.instance.LoadingProgressChange);
|
||||
}
|
||||
|
||||
var percent_num = result.Count / 100;
|
||||
for (int i = 0; i < result.Count; i++)
|
||||
{
|
||||
@@ -101,7 +106,7 @@ public class UmaAssetManager : MonoBehaviour
|
||||
|
||||
private static bool LoadAB(UmaDatabaseEntry entry, bool neverUnload = false)
|
||||
{
|
||||
string filePath = entry.FilePath;
|
||||
string filePath = entry.FilePath; //downloads the file
|
||||
if (Exist(entry.Name))
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class UmaDatabaseEntry
|
||||
{
|
||||
get
|
||||
{
|
||||
return $"{Config.Instance.MainPath}/dat/{Url.Substring(0, 2)}/{Url}";
|
||||
return $"{Config.Instance.MainPath.Replace("\\", "/")}/dat/{Url.Substring(0, 2)}/{Url}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ using UnityEngine.Networking;
|
||||
using static UmaViewerUI;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using System.Linq;
|
||||
|
||||
public class UmaViewerDownload : MonoBehaviour
|
||||
{
|
||||
@@ -23,6 +24,7 @@ public class UmaViewerDownload : MonoBehaviour
|
||||
private static List<Coroutine> downloadCoroutines = new List<Coroutine>();
|
||||
private static int CurrentCoroutinesCount = 0;
|
||||
private static WaitUntil downloadWaitUntil = new WaitUntil(() => CurrentCoroutinesCount < maxConcurrentDownloads);
|
||||
private static WaitUntil downloadWaitUntilComplete = new WaitUntil(() => CurrentCoroutinesCount == 0);
|
||||
private static List<Task> downloadTasks = new List<Task>();
|
||||
|
||||
public static IEnumerator DownloadText(string url, System.Action<string> callback)
|
||||
@@ -62,52 +64,48 @@ public class UmaViewerDownload : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerator DownloadAssets(List<UmaDatabaseEntry> entrys, Action<int, int, string> callback = null)
|
||||
public static IEnumerator DownloadAssets(List<UmaDatabaseEntry> entries, Action<int, int, string> callback = null)
|
||||
{
|
||||
callback?.Invoke(0, entrys.Count, "DownLoading");
|
||||
var percent_num = entrys.Count / 100;
|
||||
for(int i = 0; i < entrys.Count; i++)
|
||||
entries = entries.Where(e => !File.Exists(e.Path)).ToList();
|
||||
if (entries.Count == 0) yield break;
|
||||
callback?.Invoke(0, entries.Count, "DownLoading");
|
||||
var percent_num = entries.Count / 100;
|
||||
for(int i = 0; i < entries.Count; i++)
|
||||
{
|
||||
var entry = entrys[i];
|
||||
var entry = entries[i];
|
||||
yield return downloadWaitUntil;
|
||||
if(i % percent_num == 0)
|
||||
{
|
||||
callback?.Invoke(i, entrys.Count, "DownLoading");
|
||||
callback?.Invoke(i, entries.Count, "DownLoading");
|
||||
}
|
||||
CurrentCoroutinesCount++;
|
||||
semaphore.WaitAsync();
|
||||
downloadCoroutines.Add(Instance.StartCoroutine(DownloadTask(entry)));
|
||||
}
|
||||
|
||||
yield return downloadWaitUntilComplete;
|
||||
}
|
||||
|
||||
public static IEnumerator DownloadTask(UmaDatabaseEntry entry)
|
||||
{
|
||||
if (!File.Exists(entry.Path))
|
||||
string baseurl = (string.IsNullOrEmpty(Path.GetExtension(entry.Name)) ? GetAssetRequestUrl(entry.Url) : GetGenericRequestUrl(entry.Url));
|
||||
using (UnityWebRequest www = UnityWebRequest.Get(baseurl))
|
||||
{
|
||||
string baseurl = (string.IsNullOrEmpty(Path.GetExtension(entry.Name)) ? GetAssetRequestUrl(entry.Url) : GetGenericRequestUrl(entry.Url));
|
||||
using (UnityWebRequest www = UnityWebRequest.Get(baseurl))
|
||||
yield return www.SendWebRequest();
|
||||
if (www.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
yield return www.SendWebRequest();
|
||||
if (www.result != UnityWebRequest.Result.Success)
|
||||
if (Instance)
|
||||
{
|
||||
if (Instance)
|
||||
{
|
||||
Instance.ShowMessage($"Failed to download resources : {www.error}", UIMessageType.Error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(entry.Path));
|
||||
File.WriteAllBytes(entry.Path, www.downloadHandler.data);
|
||||
CurrentCoroutinesCount--;
|
||||
Instance.ShowMessage($"Failed to download resources : {www.error}", UIMessageType.Error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(entry.Path));
|
||||
File.WriteAllBytes(entry.Path, www.downloadHandler.data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentCoroutinesCount--;
|
||||
}
|
||||
|
||||
CurrentCoroutinesCount--;
|
||||
}
|
||||
|
||||
public static async void DownloadAssets(IEnumerable<UmaDatabaseEntry> entrys)
|
||||
|
||||
@@ -5,8 +5,6 @@ using UnityEngine;
|
||||
using System;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
public class UmaViewerMain : MonoBehaviour
|
||||
{
|
||||
@@ -46,20 +44,18 @@ public class UmaViewerMain : MonoBehaviour
|
||||
private IEnumerator Start()
|
||||
{
|
||||
if (AbList == null) yield break;
|
||||
int loadingStep = 0;
|
||||
int loadingStepsTotal = 11;
|
||||
var UmaCharaData = UmaDatabaseController.Instance.CharaData;
|
||||
var MobCharaData = UmaDatabaseController.Instance.MobCharaData;
|
||||
var loadingUI = UmaSceneController.instance;
|
||||
Dictionary<int, string> enNames = new Dictionary<int, string>();
|
||||
Dictionary<int, string> mobNames = new Dictionary<int, string>();
|
||||
var loadingUI = UmaSceneController.instance;
|
||||
|
||||
if(Config.Instance.WorkMode == WorkMode.Standalone && AbList != null)
|
||||
{
|
||||
var ablist = new List<UmaDatabaseEntry>(AbList.Values);
|
||||
yield return UmaViewerDownload.DownloadAssets(ablist, UmaSceneController.instance.LoadingProgressChange);
|
||||
}
|
||||
|
||||
//Main chara names (En only)
|
||||
if (Config.Instance.Language == Language.En)
|
||||
{
|
||||
loadingUI.LoadingProgressChange(0, 11, "Downloading Character Data");
|
||||
loadingUI.LoadingProgressChange(loadingStep++, loadingStepsTotal, "Downloading Character Data");
|
||||
yield return UmaViewerDownload.DownloadText("https://www.tracenacademy.com/api/BasicCharaDataInfo", txt =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(txt)) return;
|
||||
@@ -74,7 +70,7 @@ public class UmaViewerMain : MonoBehaviour
|
||||
}
|
||||
|
||||
//Mob names (EN & JP)
|
||||
loadingUI.LoadingProgressChange(1, 11, "Downloading Mob Data");
|
||||
loadingUI.LoadingProgressChange(loadingStep++, loadingStepsTotal, "Downloading Mob Data");
|
||||
yield return UmaViewerDownload.DownloadText("https://www.tracenacademy.com/api/BasicMobDataInfo", txt =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(txt)) return;
|
||||
@@ -87,9 +83,17 @@ public class UmaViewerMain : MonoBehaviour
|
||||
}
|
||||
});
|
||||
|
||||
if (Config.Instance.WorkMode == WorkMode.Standalone)
|
||||
{
|
||||
var umaIcons = UmaCharaData.Select(item => AbList.TryGetValue($"chara/chr{item["id"]}/chr_icon_{item["id"]}", out UmaDatabaseEntry entry) ? entry : null).Where(entry => entry != null);
|
||||
var mobIcons = MobCharaData.Select(item => AbList.TryGetValue($"mob/mob_chr_icon_{item["mob_id"]}_000001_01", out UmaDatabaseEntry entry) ? entry : null).Where(entry => entry != null);
|
||||
var costumeIcons = CostumeList;
|
||||
List<UmaDatabaseEntry> filesToDownload = umaIcons.Concat(mobIcons).Concat(costumeIcons).ToList();
|
||||
yield return UmaViewerDownload.DownloadAssets(filesToDownload, UmaSceneController.instance.LoadingProgressChange);
|
||||
filesToDownload.Clear();
|
||||
}
|
||||
|
||||
var UmaCharaData = UmaDatabaseController.Instance.CharaData;
|
||||
loadingUI.LoadingProgressChange(2, 11, "Loading Character Data");
|
||||
loadingUI.LoadingProgressChange(loadingStep++, loadingStepsTotal, "Loading Character Data");
|
||||
yield return null;
|
||||
foreach (var item in UmaCharaData)
|
||||
{
|
||||
@@ -107,8 +111,7 @@ public class UmaViewerMain : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
var MobCharaData = UmaDatabaseController.Instance.MobCharaData;
|
||||
loadingUI.LoadingProgressChange(3, 11, "Loading Mob Data");
|
||||
loadingUI.LoadingProgressChange(loadingStep++, loadingStepsTotal, "Loading Mob Data");
|
||||
yield return null;
|
||||
foreach (var item in MobCharaData)
|
||||
{
|
||||
@@ -128,7 +131,7 @@ public class UmaViewerMain : MonoBehaviour
|
||||
});
|
||||
}
|
||||
|
||||
loadingUI.LoadingProgressChange(4, 11, "Loading Costumes Data");
|
||||
loadingUI.LoadingProgressChange(loadingStep++, loadingStepsTotal, "Loading Costumes Data");
|
||||
yield return null;
|
||||
foreach (var item in CostumeList)
|
||||
{
|
||||
@@ -152,7 +155,7 @@ public class UmaViewerMain : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
loadingUI.LoadingProgressChange(5, 11, "Loading Live Data");
|
||||
loadingUI.LoadingProgressChange(loadingStep++, loadingStepsTotal, "Loading Live Data");
|
||||
yield return null;
|
||||
var asset = AbList["livesettings"];
|
||||
if (asset != null)
|
||||
@@ -188,19 +191,19 @@ public class UmaViewerMain : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
loadingUI.LoadingProgressChange(6, 11, "Loading UI");
|
||||
loadingUI.LoadingProgressChange(loadingStep++, loadingStepsTotal, "Loading UI");
|
||||
yield return null;
|
||||
UI.LoadModelPanels();
|
||||
loadingUI.LoadingProgressChange(7, 11, "Loading UI");
|
||||
loadingUI.LoadingProgressChange(loadingStep++, loadingStepsTotal, "Loading UI");
|
||||
yield return null;
|
||||
UI.LoadMiniModelPanels();
|
||||
loadingUI.LoadingProgressChange(8, 11, "Loading UI");
|
||||
loadingUI.LoadingProgressChange(loadingStep++, loadingStepsTotal, "Loading UI");
|
||||
yield return null;
|
||||
UI.LoadPropPanel();
|
||||
loadingUI.LoadingProgressChange(9, 11, "Loading UI");
|
||||
loadingUI.LoadingProgressChange(loadingStep++, loadingStepsTotal, "Loading UI");
|
||||
yield return null;
|
||||
UI.LoadMapPanel();
|
||||
loadingUI.LoadingProgressChange(10, 11, "Loading UI");
|
||||
loadingUI.LoadingProgressChange(loadingStep++, loadingStepsTotal, "Loading UI");
|
||||
yield return null;
|
||||
UI.LoadLivePanels();
|
||||
loadingUI.LoadingProgressChange(-1, -1);
|
||||
|
||||
Reference in New Issue
Block a user