您当前的位置: 首页 >  unity

苍狼王unity学院

暂无认证

  • 1浏览

    0关注

    305博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

基于Unity的AssetBundles加载场景、图片和模型等资源。

苍狼王unity学院 发布时间:2019-01-19 16:08:36 ,浏览量:1

1、基于Unity的AssetBundles加载场景、图片和模型等资源。

private byte[] getImageByte(string imagePath)
{
    //读取到文件
    FileStream files = new FileStream(imagePath, FileMode.Open);
    m_ImgByte = new byte[files.Length];
    //新建比特流对象
    if (m_ImgByte.Length != 0)
    {
        Array.Clear(m_ImgByte, 0, m_ImgByte.Length);
        Debug.Log("Clear");
    }
    //将文件写入对应比特流对象
    files.Read(m_ImgByte, 0, m_ImgByte.Length);
    //关闭文件
    files.Close();
    //返回比特流的值
    return m_ImgByte;
}

/// 
/// 载入图片
/// 
/// 
public void LoadTexture2Sprite(string path)
{
    //  Debug.Log(path);
    Texture2D texture = new Texture2D(1920, 1080);
    texture.LoadImage(getImageByte(path));
    Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
  //  m_ImageParent.GetChild(0).GetChild(0).GetComponent().sprite = sprite;
}
/// 
/// 加载模型。
/// 
IEnumerator LoadAssetBund(string m_TargetsPath, string posX, string posY, string posZ, string Yrot, string sCaleY)
{
    AssetBundle asset = AssetBundle.LoadFromFile(m_TargetsPath);//从内存中创建资源   
    yield return asset;
    UnityEngine.Object[] LoadAsset = asset.LoadAllAssets();
    GameObject ga = Instantiate((GameObject)LoadAsset[0]);
    ga.transform.SetParent(m_Target);
    ga.transform.localPosition = new Vector3(float.Parse(posX), float.Parse(posY), float.Parse(posZ));
    ga.transform.localEulerAngles = new Vector3(0, float.Parse(Yrot), 0);
    ga.transform.localScale = new Vector3(1, float.Parse(sCaleY), 1);
}

} 3、加载场景。

关注
打赏
1665389160
查看更多评论
立即登录/注册

微信扫码登录

0.0397s