Skip to content

Instantly share code, notes, and snippets.

@kurtdekker
Created October 7, 2024 19:09
Show Gist options
  • Save kurtdekker/1660bcb8d5773bb82345fb6fa0e47a5d to your computer and use it in GitHub Desktop.
Save kurtdekker/1660bcb8d5773bb82345fb6fa0e47a5d to your computer and use it in GitHub Desktop.
Unity3D streaming assets path for several platforms
using UnityEngine;
// @kurtdekker
public static class StreamingAssetsPath
{
public static string StreamingAssetPathForWWW()
{
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
return "file://" + Application.dataPath + "/StreamingAssets/";
#endif
#if UNITY_ANDROID
return "jar:file://" + Application.dataPath + "!/assets/";
#endif
#if UNITY_IOS
return "file://" + Application.dataPath + "/Raw/";
#endif
throw new System.NotImplementedException( "Check the ifdefs above.");
}
public static string StreamingAssetPathForFileOpen()
{
#if !UNITY_EDITOR && UNITY_ANDROID
throw new System.NotImplementedException( "You cannot open files on Android. Must use WWW");
#endif
Debug.Log( "Application.streamingAssetsPath:" + Application.streamingAssetsPath);
return Application.streamingAssetsPath + "/";
}
public static string GetPlatformPathPrefix()
{
// When building asset bundles Unity names the BundleManifest
// the same as the final chunk in the directory path.
#if UNITY_EDITOR || UNITY_STANDALONE_OSX
return "StandaloneOSXIntel64";
#elif UNITY_IPHONE
return "iOS";
#elif UNITY_ANDROID
return "Android";
#endif
throw new System.NotImplementedException( "Check the ifdefs above.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment