Skip to content

Commit

Permalink
upload progress
Browse files Browse the repository at this point in the history
  • Loading branch information
200Tigersbloxed committed Oct 16, 2024
1 parent a649ffb commit fed8a41
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
62 changes: 42 additions & 20 deletions Hypernex.CCK.Editor/Editors/ContentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ private void RenderWarn()
}

internal static bool isBuilding;
private static bool isUploading;
private static int AvatarUploadProgress;
private static int WorldUploadProgress;
private World World;
private Avatar SelectedAvatar;
private AssetIdentifier SelectedAssetIdentifier;
Expand Down Expand Up @@ -252,6 +255,7 @@ private void RenderAvatarList()
private void OnAvatarUpload(CallbackResult<UploadResult> result)
{
isBuilding = false;
isUploading = false;
if (result.success)
{
if(!string.IsNullOrEmpty(result.result.AvatarId))
Expand Down Expand Up @@ -281,6 +285,7 @@ private void FinishAvatarBuild(TempDir tempDir)
string assetPath = EditorTools.BuildAssetBundle(SelectedAvatar, tempDir);
if (!string.IsNullOrEmpty(assetPath))
{
isUploading = true;
FileStream fileStream = new FileStream(assetPath, FileMode.Open, FileAccess.Read,
FileShare.Delete | FileShare.Read);
if (fileStream.Length > 1048576 * 90)
Expand All @@ -289,14 +294,16 @@ private void FinishAvatarBuild(TempDir tempDir)
new Thread(() =>
{
AuthManager.Instance.HypernexObject.UploadPart(result =>
{
EditorTools.InvokeOnMainThread((Action) delegate
{
OnAvatarUpload(result);
fileStream.Dispose();
tempDir.Dispose();
});
}, AuthManager.CurrentUser, AuthManager.CurrentToken, fileStream, td, SelectedAvatar.Meta);
EditorTools.InvokeOnMainThread((Action) delegate
{
OnAvatarUpload(result);
fileStream.Dispose();
tempDir.Dispose();
});
}, AuthManager.CurrentUser, AuthManager.CurrentToken, fileStream, td, SelectedAvatar.Meta,
null,
i => AvatarUploadProgress = i);
}).Start();
}
else
Expand All @@ -306,7 +313,7 @@ private void FinishAvatarBuild(TempDir tempDir)
fileStream.Dispose();
tempDir.Dispose();
}, AuthManager.CurrentUser, AuthManager.CurrentToken, fileStream,
SelectedAvatar.Meta);
SelectedAvatar.Meta, i => AvatarUploadProgress = i);
}
else
isBuilding = false;
Expand Down Expand Up @@ -401,6 +408,8 @@ private void RenderAvatar()
return;
}
isBuilding = true;
isUploading = false;
AvatarUploadProgress = 0;
//EditorUtility.SetDirty(SelectedAvatar.gameObject);
//AssetDatabase.SaveAssets();
EditorTools.MakeSave(SelectedAvatar.gameObject);
Expand Down Expand Up @@ -477,8 +486,11 @@ private void RenderAvatar()
else if (isBuilding)
{
EditorGUILayout.EndHorizontal();
GUILayout.Label("Please wait while your Avatar is being Built...",
EditorStyles.centeredGreyMiniLabel);
string text = isUploading
? $"Upload Progress: {AvatarUploadProgress}%"
: "Please wait while your Avatar is being Built...";
if (AvatarUploadProgress >= 100) text = "Processing build...";
GUILayout.Label(text, EditorStyles.centeredGreyMiniLabel);
}
else
EditorGUILayout.EndHorizontal();
Expand Down Expand Up @@ -531,6 +543,7 @@ private static void UploadAllScripts(List<NexboxScript> serverScripts, Action<Li
private void OnWorldUpload(CallbackResult<UploadResult> result, List<NexboxScript> oldServerScripts)
{
isBuilding = false;
isUploading = false;
if (result.success)
{
EditorTools.InvokeOnMainThread((Action)(() =>
Expand Down Expand Up @@ -586,6 +599,7 @@ private void FinishWorldBuild(TempDir tempDir)
string assetPath = r.Item1;
if (!string.IsNullOrEmpty(assetPath))
{
isUploading = true;
FileStream fileStream = new FileStream(assetPath, FileMode.Open, FileAccess.Read,
FileShare.Delete | FileShare.Read);
if(fileStream.Length > 1048576 * 90)
Expand All @@ -594,14 +608,15 @@ private void FinishWorldBuild(TempDir tempDir)
new Thread(() =>
{
AuthManager.Instance.HypernexObject.UploadPart(result =>
{
EditorTools.InvokeOnMainThread((Action)delegate
{
OnWorldUpload(result, r.Item2);
fileStream.Dispose();
tempDir.Dispose();
});
}, AuthManager.CurrentUser, AuthManager.CurrentToken, fileStream, td, null, wmClone);
EditorTools.InvokeOnMainThread((Action) delegate
{
OnWorldUpload(result, r.Item2);
fileStream.Dispose();
tempDir.Dispose();
});
}, AuthManager.CurrentUser, AuthManager.CurrentToken, fileStream, td, null, wmClone,
i => WorldUploadProgress = i);
}).Start();
}
else
Expand All @@ -611,7 +626,7 @@ private void FinishWorldBuild(TempDir tempDir)
fileStream.Dispose();
tempDir.Dispose();
}, AuthManager.CurrentUser, AuthManager.CurrentToken, fileStream,
wmClone);
wmClone, i => WorldUploadProgress = i);
}
else
isBuilding = false;
Expand Down Expand Up @@ -774,6 +789,8 @@ private void RenderWorld()
return;
}
isBuilding = true;
isUploading = false;
WorldUploadProgress = 0;
EditorTools.MakeSave();
if (string.IsNullOrEmpty(World.Meta.Name))
{
Expand Down Expand Up @@ -840,8 +857,13 @@ private void RenderWorld()
GUILayout.Label("You cannot build! Please fix any problems relating to the project or world!",
EditorStyles.centeredGreyMiniLabel);
else if (isBuilding)
GUILayout.Label("Please wait while your World is being Built...",
EditorStyles.centeredGreyMiniLabel);
{
string text = isUploading
? $"Upload Progress: {WorldUploadProgress}%"
: "Please wait while your World is being Built...";
if (WorldUploadProgress >= 100) text = "Processing build...";
GUILayout.Label(text, EditorStyles.centeredGreyMiniLabel);
}
}
}

Expand Down
Binary file modified Hypernex.CCK.Unity/Libs/HypernexSharp.dll
Binary file not shown.

0 comments on commit fed8a41

Please sign in to comment.