-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working my way through multi platform
- Loading branch information
Showing
14 changed files
with
418 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
Basis/Packages/com.basis.sdk/Scripts/BasisBundleConnector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
Basis/Packages/com.basis.sdk/Scripts/BasisBundleConnector.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
Basis/Packages/com.basis.sdk/Scripts/BasisBundleInformation.cs
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
Basis/Packages/com.basis.sdk/Scripts/BasisBundleInformation.cs.meta
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.