Skip to content

Commit

Permalink
ready to make it work on the other side now
Browse files Browse the repository at this point in the history
  • Loading branch information
dooly123 committed Feb 19, 2025
1 parent da3e356 commit 3c9d7da
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public static class BasisBundleBuild
}

BasisAssetBundleObject Objects = AssetDatabase.LoadAssetAtPath<BasisAssetBundleObject>(BasisAssetBundleObject.AssetBundleObject);

if (Directory.Exists(Objects.AssetBundleDirectory))
{
System.IO.Directory.Delete(Objects.AssetBundleDirectory,true);
}
Debug.Log("Generating random bytes for hex string...");
byte[] randomBytes = GenerateRandomBytes(32);
string hexString = ByteArrayToHexString(randomBytes);
Expand Down Expand Up @@ -79,8 +82,6 @@ public static class BasisBundleBuild
await BasisBasisBundleInformationHandler.BasisBundleConnector(Objects, BasisBundleConnector, hexString,true);

Debug.Log("Successfully built asset bundle.");

// Restore the original build target
if (EditorUserBuildSettings.activeBuildTarget != originalActiveTarget)
{
EditorUserBuildSettings.SwitchActiveBuildTarget(
Expand All @@ -90,9 +91,62 @@ public static class BasisBundleBuild
Debug.Log($"Switched back to original build target: {originalActiveTarget}");
}
await AssetBundleBuilder.SaveFileAsync(Objects.AssetBundleDirectory, Objects.ProtectedPasswordFileName, "txt", hexString);

MoveFilesUpAndDeleteFolders(Objects.AssetBundleDirectory);

OpenRelativePath(Objects.AssetBundleDirectory);
return (true, "Success");
}
static void MoveFilesUpAndDeleteFolders(string parentDir)
{
if (!Directory.Exists(parentDir))
{
BasisDebug.Log("Directory does not exist.");
return;
}

foreach (string subDir in Directory.GetDirectories(parentDir))
{
try
{
foreach (string file in Directory.GetFiles(subDir))
{
string fileName = Path.GetFileName(file);
string destFile = Path.Combine(parentDir, fileName);

// Ensure unique filenames
destFile = GetUniqueFileName(destFile);

File.Move(file, destFile);
BasisDebug.Log($"Moved: {file} -> {destFile}");
}

// Delete the empty folder
Directory.Delete(subDir, true);
BasisDebug.Log($"Deleted folder: {subDir}");
}
catch (Exception ex)
{
BasisDebug.LogError($"Error processing {subDir}: {ex.Message}");
}
}
}

static string GetUniqueFileName(string path)
{
string directory = Path.GetDirectoryName(path);
string fileName = Path.GetFileNameWithoutExtension(path);
string extension = Path.GetExtension(path);
int count = 1;

while (File.Exists(path))
{
path = Path.Combine(directory, $"{fileName} ({count}){extension}");
count++;
}

return path;
}
public static string OpenRelativePath(string relativePath)
{
// Get the root path of the project (up to the Assets folder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ public class BasisAssetBundleObject : ScriptableObject
public string TemporaryStorage = "Packages/com.basis.basisdk/TemporaryStorage";
public string BundleExtension = ".bundle";
public string hashExtension = ".hash";
public string BasisMetaExtension = ".BasisMeta";
public string BasisBundleEncryptedExtension = ".BasisEncryptedBundle";
public string BasisBundleDecryptedExtension = ".BasisDecryptedBundle";
public string BasisMetaEncryptedExtension = ".BasisEncryptedMeta";
public string BasisMetaExtension = ".BME";
public string BasisBundleEncryptedExtension = ".BEB";
public string BasisBundleDecryptedExtension = ".BDB";
public string BasisMetaEncryptedExtension = ".BEM";
public string ProtectedPasswordFileName = "dontuploadmepassword";
public bool useCompression = true;
public bool GenerateImage = true;
Expand Down Expand Up @@ -44,10 +44,10 @@ private void RestoreDefaults(BasisAssetBundleObject assetBundleObject)
assetBundleObject.TemporaryStorage = "Packages/com.basis.basisdk/TemporaryStorage";
assetBundleObject.BundleExtension = ".bundle";
assetBundleObject.hashExtension = ".hash";
assetBundleObject.BasisMetaExtension = ".BasisMeta";
assetBundleObject.BasisBundleEncryptedExtension = ".BasisEncryptedBundle";
assetBundleObject.BasisBundleDecryptedExtension = ".BasisDecryptedBundle";
assetBundleObject.BasisMetaEncryptedExtension = ".BasisEncryptedMeta";
assetBundleObject.BasisMetaExtension = ".BME";
assetBundleObject.BasisBundleEncryptedExtension = ".BEB";
assetBundleObject.BasisBundleDecryptedExtension = ".BDB";
assetBundleObject.BasisMetaEncryptedExtension = ".BEM";
assetBundleObject.useCompression = true;
assetBundleObject.GenerateImage = true;
assetBundleObject.BuildTarget = BuildTarget.StandaloneWindows;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
public static class BasisGenerateUniqueID
{
/// <summary>
/// This will generate a new unique ID for the prefab, scene, or asset bundle.
/// Generates a unique ID using a GUID and the current UTC date (yyyyMMdd).
/// </summary>
/// <returns>A unique identifier combining a GUID and UTC ticks.</returns>
/// <returns>A unique identifier combining a GUID and UTC date.</returns>
public static string GenerateUniqueID()
{
Guid newGuid = Guid.NewGuid(); // Generate a new GUID
long utcTicks = DateTime.UtcNow.Ticks; // Get the current UTC ticks
string utcDate = DateTime.UtcNow.ToString("yyyyMMdd"); // Get the current UTC date (YYYYMMDD)
string guid = newGuid.ToString("N"); // Remove dashes from GUID

// Format the GUID and ticks into a proper string
return $"{newGuid}_{utcTicks}";
return $"{guid}{utcDate}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ MonoBehaviour:
TemporaryStorage: Assets/TemporaryStorage
BundleExtension: .bundle
hashExtension: .hash
BasisMetaExtension: .BasisMeta
BasisBundleEncryptedExtension: .BasisEncryptedBundle
BasisBundleDecryptedExtension: .BasisDecryptedBundle
BasisMetaEncryptedExtension: .BasisEncryptedMeta
BasisMetaExtension: .BME
BasisBundleEncryptedExtension: .BEB
BasisBundleDecryptedExtension: .BDB
BasisMetaEncryptedExtension: .BEM
ProtectedPasswordFileName: dontuploadmepassword
useCompression: 1
GenerateImage: 1
Expand Down

0 comments on commit 3c9d7da

Please sign in to comment.