效果圖:
打包一個root.assetbundle文件,添加如下腳本:
public class LoadSence : MonoBehaviour
{
public Texture Background;
public Texture loading;
private float time=0;
public string url = null;
private WWW www;
void Awake()
{
//加載路徑
if (Application.platform == RuntimePlatform.WindowsEditor)
{
url = "file:///" + Application.dataPath + "/StreamingAssets/WebPlayer/";
}
else if (Application.platform == RuntimePlatform.WindowsWebPlayer)
{
}
}
void Start()
{
StartCoroutine(LoadSenceAssetbundle());
}
void FixedUpdate()
{
time += Time.deltaTime;
}
void OnGUI()
{
if (www != null)
{
//背景圖片
GUI.SetNextControlName("Background");
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), Background, ScaleMode.StretchToFill);
GUI.depth = 0;
//loading的圖片(旋轉)
GUI.SetNextControlName("loading");
GUIUtility.RotateAroundPivot(300*time, new Vector2(Screen.width / 2, Screen.height / 2));
GUI.DrawTexture(new Rect(Screen.width / 2 - 75, Screen.height / 2 - 75, 150, 150), loading, ScaleMode.ScaleToFit);
GUI.depth = -1;
}
}
IEnumerator LoadSenceAssetbundle()
{
//加載Root.assetbundle文件
www = new WWW(url + "Root.assetbundle");
while (!www.isDone)
{
yield return www;
}
Instantiate(www.assetBundle.mainAsset);
www.assetBundle.Unload(false);
if (www != null)
{
www.Dispose();
www = null;
}
}
}