Question by
CrandellWS · Feb 09, 2018 at 12:18 AM ·
androidtextureandroid buildassetbundleassetbundles
AssetBundle Textures not loading
Found a project https://unitylist.com/p/3vq/Card-Example-Unity
and wanted to make it work on Android. Stumped by the Texture not loading The code line is:
GetComponent<Renderer>().material.mainTexture = cardBundle.LoadAsset<Texture>(TexturePath);
public AssetBundle LoadBundle(string path)
{
string name = System.IO.Path.GetFileNameWithoutExtension(path);
AssetBundle assetBundle = GetBundle(name);
if (assetBundle == null)
{
assetBundle = new AssetBundle();
//assetBundle = AssetBundle.LoadFromFile(path);
assetBundle = AssetBundle.LoadFromFile(System.IO.Path.Combine(Application.streamingAssetsPath, path));
assetBundle.name = name;
AssetBundleList.Add(assetBundle);
return assetBundle;
}
else
{
return assetBundle;
}
}
The path is set as a variable card.TexturePath
public void InstanatiateDeck(string cardBundlePath)
{
AssetBundle cardBundle = BundleSingleton.Instance.LoadBundle(cardBundlePath);
string[] nameArray = cardBundle.GetAllAssetNames();
for (int i = 0; i < nameArray.Length; ++i)
{
GameObject cardInstance = (GameObject)Instantiate(_cardPrefab);
Card card = cardInstance.GetComponent<Card>();
card.gameObject.name = Path.GetFileNameWithoutExtension(nameArray[ i ]);
card.TexturePath = nameArray[ i ];
card.SourceAssetBundlePath = cardBundlePath;
card.transform.position = new Vector3(0, 10, 0);
card.FaceValue = StringToFaceValue(card.gameObject.name);
CardList.Add(card);
}
}
View and download this project on GitHub https://github.com/CrandellWS/Unity-Card-Basics/
Any help is appreciated
Thanks.
Comment
Your answer
Follow this Question
Related Questions
Problem with AssetVundle and ScriptableObjects 0 Answers
After compiling and installing apk game becomes transparent and you can see the mobile home screen 1 Answer
Problem with body texture after build 0 Answers
AssetBundle Manager Doesn't fetch assetBundle on Andriod 0 Answers
Asset Bundle error 0 Answers