Skip to content

Commit

Permalink
working my way through multi platform
Browse files Browse the repository at this point in the history
  • Loading branch information
dooly123 committed Feb 18, 2025
1 parent 7a19b9b commit 7cee0d3
Show file tree
Hide file tree
Showing 14 changed files with 418 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ public static async Task<BasisLoadableBundle> GenerateMetaFromFile(BasisLoadable
BasisLoadableBundle.BasisBundleInformation = ConvertBytesToJson(LoadedMetaData);
return BasisLoadableBundle;
}
public static BasisBundleInformation ConvertBytesToJson(byte[] loadedlocalmeta)
public static BasisBundleConnector ConvertBytesToJson(byte[] loadedlocalmeta)
{
if (loadedlocalmeta == null || loadedlocalmeta.Length == 0)
{
BasisDebug.LogError($"Data for {nameof(BasisBundleInformation)} is empty or null.", BasisDebug.LogTag.Event);
BasisDebug.LogError($"Data for {nameof(BasisBundleConnector)} is empty or null.", BasisDebug.LogTag.Event);
return new BasisBundleInformation() { HasError = true };
}

// Convert the byte array to a JSON string (assuming UTF-8 encoding)
BasisDebug.Log($"Converting byte array to JSON string...", BasisDebug.LogTag.Event);
BasisBundleInformation Information = SerializationUtility.DeserializeValue<BasisBundleInformation>(loadedlocalmeta, DataFormat.JSON);
BasisBundleConnector Information = SerializationUtility.DeserializeValue<BasisBundleConnector>(loadedlocalmeta, DataFormat.JSON);
return Information;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ private async void AddAvatar()
BundleURL = BundleField.text,
MetaURL = MetaField.text
},
BasisBundleInformation = new BasisBundleInformation
{
BasisBundleDescription = new BasisBundleDescription(),
BasisBundleGenerated = new BasisBundleGenerated()
},
BasisBundleConnector = new BasisBundleConnector(),
BasisLocalEncryptedBundle = new BasisStoredEncyptedBundle()
};

Expand Down Expand Up @@ -128,10 +124,11 @@ private async Task Initialize()
BasisLoadableBundle bundle = new BasisLoadableBundle
{
BasisRemoteBundleEncrypted = info.StoredRemote,
BasisBundleInformation = new BasisBundleInformation
BasisBundleConnector = new BasisBundleConnector
{
BasisBundleDescription = new BasisBundleDescription(),
BasisBundleGenerated = new BasisBundleGenerated()
BasisBundleGenerated = new BasisBundleGenerated[] { new BasisBundleGenerated() },
UniqueVersion = ""
},
BasisLocalEncryptedBundle = info.StoredLocal,
UnlockPassword = activeKeys[Index].Pass
Expand Down Expand Up @@ -173,7 +170,7 @@ private async Task CreateAvatarButtons(List<BasisDataStoreAvatarKeys.AvatarKey>
try
{
await BasisLoadHandler.HandleMetaLoading(wrapper, Report, new CancellationToken());
buttonText.text = wrapper.LoadableBundle.BasisBundleInformation.BasisBundleDescription.AssetBundleName;
buttonText.text = wrapper.LoadableBundle.BasisBundleConnector.BasisBundleDescription.AssetBundleName;
}
catch (Exception E)
{
Expand Down Expand Up @@ -201,7 +198,7 @@ private async void OnButtonPressed(BasisLoadableBundle avatarLoadRequest)
{
if (BasisLocalPlayer.Instance != null)
{
var assetMode = avatarLoadRequest.BasisBundleInformation.BasisBundleGenerated.AssetMode;
var assetMode = avatarLoadRequest.BasisBundleConnector.BasisBundleGenerated[0].AssetMode;
var mode = !string.IsNullOrEmpty(assetMode) && byte.TryParse(assetMode, out var result) ? result : (byte)0;
await BasisLocalPlayer.Instance.CreateAvatar(mode, avatarLoadRequest);
}
Expand Down
178 changes: 178 additions & 0 deletions Basis/Packages/com.basis.sdk/Scripts/BasisBundleConnector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

[System.Serializable]
public class BasisBundleConnector
{
public string UniqueVersion;
public BasisBundleDescription BasisBundleDescription;
public BasisBundleGenerated[] BasisBundleGenerated;

public BasisBundleConnector(string version, BasisBundleDescription basisBundleDescription, BasisBundleGenerated[] basisBundleGenerated)
{
UniqueVersion = version ?? throw new ArgumentNullException(nameof(version));
BasisBundleDescription = basisBundleDescription ?? throw new ArgumentNullException(nameof(basisBundleDescription));
BasisBundleGenerated = basisBundleGenerated ?? throw new ArgumentNullException(nameof(basisBundleGenerated));
}
public BasisBundleConnector()
{
}
public bool CheckVersion(string version)
{
return UniqueVersion.ToLower() == version.ToLower();
}

public bool GetPlatform(out BasisBundleGenerated platformBundle)
{
platformBundle = BasisBundleGenerated.FirstOrDefault(bundle => PlatformMatch(bundle.Platform));
return platformBundle != null;
}

private static readonly Dictionary<string, HashSet<RuntimePlatform>> platformMappings = new Dictionary<string, HashSet<RuntimePlatform>>()
{
{ Enum.GetName(typeof(BuildTarget), BuildTarget.StandaloneWindows), new HashSet<RuntimePlatform> { RuntimePlatform.WindowsEditor, RuntimePlatform.WindowsPlayer, RuntimePlatform.WindowsServer } },
{ Enum.GetName(typeof(BuildTarget), BuildTarget.StandaloneWindows64), new HashSet<RuntimePlatform> { RuntimePlatform.WindowsEditor, RuntimePlatform.WindowsPlayer, RuntimePlatform.WindowsServer } },
{ Enum.GetName(typeof(BuildTarget), BuildTarget.Android), new HashSet<RuntimePlatform> { RuntimePlatform.Android } },
{ Enum.GetName(typeof(BuildTarget), BuildTarget.StandaloneLinux64), new HashSet<RuntimePlatform> { RuntimePlatform.LinuxEditor, RuntimePlatform.LinuxPlayer, RuntimePlatform.LinuxServer } },
{ Enum.GetName(typeof(BuildTarget), BuildTarget.iOS), new HashSet<RuntimePlatform> { RuntimePlatform.IPhonePlayer, RuntimePlatform.OSXPlayer, RuntimePlatform.OSXEditor } }
};
public enum BuildTarget
{
StandaloneWindows = 5,
iOS = 9,
Android = 13,
StandaloneWindows64 = 19,
WebGL = 20,
WSAPlayer = 21,
StandaloneLinux64 = 24,
PS4 = 31,
XboxOne = 33,
tvOS = 37,
Switch = 38,
LinuxHeadlessSimulation = 41,
GameCoreXboxSeries = 42,
GameCoreXboxOne = 43,
PS5 = 44,
EmbeddedLinux = 45,
QNX = 46,
VisionOS = 47,
ReservedCFE = 48,
}
public bool PlatformMatch(string platformRequest)
{
return platformMappings.TryGetValue(platformRequest, out var validPlatforms) && validPlatforms.Contains(Application.platform);
}

/// <summary>
/// Validates the BasisBundleConnector and its dependencies for null or empty values.
/// </summary>
public bool Validate(out List<string> errors)
{
errors = new List<string>();

// Check Version
if (string.IsNullOrWhiteSpace(UniqueVersion))
errors.Add("Version is null or empty.");

// Check BasisBundleDescription
if (BasisBundleDescription == null)
{
errors.Add("BasisBundleDescription is null.");
}
else
{
if (string.IsNullOrWhiteSpace(BasisBundleDescription.AssetBundleName))
errors.Add("BasisBundleDescription.AssetBundleName is null or empty.");

if (string.IsNullOrWhiteSpace(BasisBundleDescription.AssetBundleDescription))
errors.Add("BasisBundleDescription.AssetBundleDescription is null or empty.");
}

// Check BasisBundleGenerated
if (BasisBundleGenerated == null || BasisBundleGenerated.Length == 0)
{
errors.Add("BasisBundleGenerated array is null or empty.");
}
else
{
for (int i = 0; i < BasisBundleGenerated.Length; i++)
{
var bundle = BasisBundleGenerated[i];
if (bundle == null)
{
errors.Add($"BasisBundleGenerated[{i}] is null.");
continue;
}

if (string.IsNullOrWhiteSpace(bundle.AssetBundleHash))
errors.Add($"BasisBundleGenerated[{i}].AssetBundleHash is null or empty.");

if (string.IsNullOrWhiteSpace(bundle.AssetMode))
errors.Add($"BasisBundleGenerated[{i}].AssetMode is null or empty.");

if (string.IsNullOrWhiteSpace(bundle.AssetToLoadName))
errors.Add($"BasisBundleGenerated[{i}].AssetToLoadName is null or empty.");

if (string.IsNullOrWhiteSpace(bundle.Password))
errors.Add($"BasisBundleGenerated[{i}].Password is null or empty.");

if (string.IsNullOrWhiteSpace(bundle.Platform))
errors.Add($"BasisBundleGenerated[{i}].Platform is null or empty.");

if (string.IsNullOrWhiteSpace(bundle.BundleDiscoveryURL))
errors.Add($"BasisBundleGenerated[{i}].BundleDiscoveryURL is null or empty.");
}
}

return errors.Count == 0;
}
}

[System.Serializable]
public class BasisBundleDescription
{
public string AssetBundleName;//user friendly name of this asset.
public string AssetBundleDescription;//the description of this asset
public BasisBundleDescription()
{

}
public BasisBundleDescription(string assetBundleName, string assetBundleDescription)
{
AssetBundleName = assetBundleName ?? throw new ArgumentNullException(nameof(assetBundleName));
AssetBundleDescription = assetBundleDescription ?? throw new ArgumentNullException(nameof(assetBundleDescription));
}
}
[System.Serializable]
public class BasisBundleGenerated
{
public string AssetBundleHash;//hash stored separately
public string AssetMode;//Scene or Gameobject
public string AssetToLoadName;// assets name we are using out of the box.
public uint AssetBundleCRC;//CRC of the assetbundle
public bool IsEncrypted = true;//if the bundle is encrypted

public string Password;//this unlocks the bundle at the url below
public string Platform;//Deployed Platform
//instead of the full url we just swap the final part of the url with this
public bool BundleDiscoveryPartiallyURl = true;
//for example mybundle.extension
public string BundleDiscoveryURL;
public BasisBundleGenerated()
{
}
public BasisBundleGenerated(string assetBundleHash, string assetMode, string assetToLoadName, uint assetBundleCRC, bool isEncrypted, string password, string platform, bool BundleDiscoveryPartiallyURl, string bundleDiscoveryURL)
{
AssetBundleHash = assetBundleHash ?? throw new ArgumentNullException(nameof(assetBundleHash));
AssetMode = assetMode ?? throw new ArgumentNullException(nameof(assetMode));
AssetToLoadName = assetToLoadName ?? throw new ArgumentNullException(nameof(assetToLoadName));
AssetBundleCRC = assetBundleCRC;
IsEncrypted = isEncrypted;
Password = password ?? throw new ArgumentNullException(nameof(password));
Platform = platform ?? throw new ArgumentNullException(nameof(platform));
this.BundleDiscoveryPartiallyURl = BundleDiscoveryPartiallyURl;
BundleDiscoveryURL = bundleDiscoveryURL ?? throw new ArgumentNullException(nameof(bundleDiscoveryURL));
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 0 additions & 22 deletions Basis/Packages/com.basis.sdk/Scripts/BasisBundleInformation.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ public class BasisLoadableBundle
//encrypted state
public BasisRemoteEncyptedBundle BasisRemoteBundleEncrypted = new BasisRemoteEncyptedBundle();
public BasisStoredEncyptedBundle BasisLocalEncryptedBundle= new BasisStoredEncyptedBundle();
//loaded MetaFile
public BasisBundleInformation BasisBundleInformation = new BasisBundleInformation();
public BasisBundleConnector BasisBundleConnector;
}
Loading

0 comments on commit 7cee0d3

Please sign in to comment.