Hi i need help with my AssetBundles i dont know where is problem i loading it from FTP in editor works fine with unity Remote too if i build&run it is not working i testing it for 3days and without point.That is my first project using AssetBundle because i need sending data to it after build aim confused what aim doing wrong i try build assetbundle using AssetBundleBrowser with script too and before webrequest i try LoadFromCacheOrDownload all working with same issue i using crossdomain.xml on my ftp
thats my testingscript
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
using TMPro;
public class test : MonoBehaviour
{
public string assetName;
public TMP_FontAsset _fontAsset;
void Start()
{
StartCoroutine(DownloadAsset());
}
IEnumerator DownloadAsset()
{
using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle("ftp://ftp:password@domainip/AssetBundles/Android/buttonbundle-Android"))
{
yield return uwr.SendWebRequest();
if (uwr.result == UnityWebRequest.Result.ConnectionError || uwr.result == UnityWebRequest.Result.ProtocolError)
{
Debug.Log(uwr.error);
}
else
{
// Get downloaded asset bundle
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr);
var prefab = bundle.LoadAllAssets();
GameObject content = GameObject.Find("Content");
foreach(GameObject button in prefab)
{
var go = Instantiate(button, content.transform);
go.transform.SetParent(content.transform);
foreach(TextMeshProUGUI tmpro in go.GetComponentsInChildren<TextMeshProUGUI>())
{
tmpro.font = _fontAsset;
//tmpro.fontSize = 20f;
}
}
}
}
}
}
thats my assetBundle build script:
using UnityEditor;
using System.IO;
using UnityEngine;
public class CreateAssetBundles
{
public static string assetBundleDirectory = "Assets/AssetBundles/";
[MenuItem("Assets/Build AssetBundles")]
static void BuildAllAssetBundles()
{
//if main directory doesnt exist create it
if (Directory.Exists(assetBundleDirectory))
{
Directory.Delete(assetBundleDirectory, true);
}
Directory.CreateDirectory(assetBundleDirectory);
//create bundles for all platform (use IOS for editor support on MAC but must be on IOS build platform)
BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, BuildTarget.iOS);
AppendPlatformToFileName("IOS");
Debug.Log("IOS bundle created...");
BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, BuildTarget.Android);
AppendPlatformToFileName("Android");
Debug.Log("Android bundle created...");
RemoveSpacesInFileNames();
AssetDatabase.Refresh();
Debug.Log("Process complete!");
}
static void RemoveSpacesInFileNames()
{
foreach (string path in Directory.GetFiles(assetBundleDirectory))
{
string oldName = path;
string newName = path.Replace(' ', '-');
File.Move(oldName, newName);
}
}
static void AppendPlatformToFileName(string platform)
{
foreach (string path in Directory.GetFiles(assetBundleDirectory))
{
//get filename
string[] files = path.Split('/');
string fileName = files[files.Length - 1];
//delete files we dont need
if (fileName.Contains(".") || fileName.Contains("Bundle"))
{
File.Delete(path);
}
else if (!fileName.Contains("-"))
{
//append platform to filename
FileInfo info = new FileInfo(path);
info.MoveTo(path + "-" + platform);
}
}
}
}
my crossdomain.xml:
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="ftp://myftp:pass@domainip/"/>
<allow-access-from domain="http://www.virtualcaffe.sk"/>
</cross-domain-policy>