zoukankan      html  css  js  c++  java
  • unity3d 动态加载纹理

    IEnumerator LoadPhoto(){    
            
            string path =Application.dataPath+"/Resources/";
            string[] strs = System.IO.Directory.GetFiles(path);
            foreach (string file in strs)           
            {   System.IO.FileInfo fi = new System.IO.FileInfo(file);
                if (fi.Extension == ".png")
                {
                    
                    string fileName = fi.Name.Substring(0,fi.Name.IndexOf('.'));
                    if(!images.ContainsKey(fileName))
                    {
                        WWW www = new WWW("file://"+path+fi.Name);
                        yield return www.isDone;   
    
                        //Texture2D t2d = Resources.Load("Photos/"+fileName,typeof(Texture2D)) as Texture2D;
                        Texture2D t2d = www.texture;
                        iGUIImage iImage = listBox4.addElement<iGUIImage>();    
                        iImage.image = t2d;
                        iImage.name = fileName;
                        iImage.setWidth(0.24f);
                        iImage.clickCallback = on_ImageClick;
                        images.Add(iImage.name,iImage);
                        Debug.Log("Create name:"+iImage.name);
                        Debug.Log("file name:"+iImage.name);
                        Debug.Log("images count:"+images.Count);
                    }
                }
            }
            
        }

    先用了Resource.Load加载纹理,测试结果是在场景载入的时候可以正确加载,但是在场景运行过程中不能动态加载新增加的资源,后改为WWW加载解决问题。

    Resource到底能否动态加载,稍后再做实验

  • 相关阅读:
    笨蛋蛋都能学会的开机grub消除(双系统开机总是黑屏肿么办--多半是欠reset)
    Find a way HDU
    非常可乐 HDU
    Oil Deposits HDU
    迷宫问题 POJ
    Fire!
    Fire Game FZU
    Pots POJ
    Prime Path POJ
    Jquery鼠标悬停按钮图标动态变化效果
  • 原文地址:https://www.cnblogs.com/88999660/p/2869845.html
Copyright © 2011-2022 走看看