Removed bulk download at the start of program

This commit is contained in:
katboi01
2024-11-11 18:52:12 +01:00
parent 57b9d03244
commit c0631b617c
6 changed files with 66 additions and 53 deletions
+1
View File
@@ -68,3 +68,4 @@ Config.json
/gltf
/Assets/Plugins/RootMotion/FinalIK/_Integration
/Poses
/Assets/AmplifyShaderEditor.meta
+6 -1
View File
@@ -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}";
}
}
+24 -26
View File
@@ -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)
+25 -22
View File
@@ -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);
+9 -3
View File
@@ -3,7 +3,7 @@
--- !u!129 &1
PlayerSettings:
m_ObjectHideFlags: 0
serializedVersion: 22
serializedVersion: 23
productGUID: 466286cbc59748b4ca46e7b05d5929c2
AndroidProfiler: 0
AndroidFilterTouchesWhenObscured: 0
@@ -134,7 +134,7 @@ PlayerSettings:
16:10: 1
16:9: 1
Others: 1
bundleVersion: 2.1.15
bundleVersion: 2.1.16
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
@@ -150,6 +150,7 @@ PlayerSettings:
m_ColorGamuts: 00000000
targetPixelDensity: 395
resolutionScalingMode: 1
resetResolutionOnWindowResize: 0
androidSupportedAspectRatio: 1
androidMaxAspectRatio: 2.1
applicationIdentifier:
@@ -596,8 +597,11 @@ PlayerSettings:
switchNetworkInterfaceManagerInitializeEnabled: 1
switchPlayerConnectionEnabled: 1
switchUseNewStyleFilepaths: 0
switchUseLegacyFmodPriorities: 1
switchUseMicroSleepForYield: 1
switchEnableRamDiskSupport: 0
switchMicroSleepForYieldTime: 25
switchRamDiskSpaceSize: 12
ps4NPAgeRating: 12
ps4NPTitleSecret:
ps4NPTrophyPackPath:
@@ -695,7 +699,7 @@ PlayerSettings:
webGLDecompressionFallback: 0
scriptingDefineSymbols:
1: AMPLIFY_SHADER_EDITOR;UNITY_POST_PROCESSING_STACK_V2
7: UNITY_POST_PROCESSING_STACK_V2
7: UNITY_POST_PROCESSING_STACK_V2;AMPLIFY_SHADER_EDITOR
13: UNITY_POST_PROCESSING_STACK_V2
14: UNITY_POST_PROCESSING_STACK_V2
19: UNITY_POST_PROCESSING_STACK_V2
@@ -756,6 +760,7 @@ PlayerSettings:
metroFTAName:
metroFTAFileTypes: []
metroProtocolName:
vcxProjDefaultLanguage:
XboxOneProductId:
XboxOneUpdateKey:
XboxOneSandboxId:
@@ -799,6 +804,7 @@ PlayerSettings:
m_VersionName:
apiCompatibilityLevel: 6
activeInputHandler: 0
windowsGamepadBackendHint: 0
cloudProjectId:
framebufferDepthMemorylessMode: 0
qualitySettingsNames: []