void Update () {
//判断异步对象并且异步对象没有加载完毕,显示进度
if(getSubjectData!=null&&!getSubjectData.isDone)
{
Debug.LogError("正在加载...");
}
}
PlayerPrefs.SetString("Name", "Jams");
string name= PlayerPrefs.GetString("Name");
2.Unity3d加载资源。
(1)加载某文件下某类资源Object[] m_skyboxs = Resources.LoadAll("skybox", typeof(Material));
for(int i = 0; i < m_skyboxs.Length; i++)
{
Material mat = (Material)m_skyboxs[i];
//使用mat
}
(2)加载某一个资源
Material mat = (Material)Resources.Load("skybox/school3.mat");
Material mat = (Material)Resources.Load("skybox/school3.mat");
Skybox sb = currentCamera.GetComponent();
sb.material = mat;
public class PersonInfoScript : MonoBehaviour {
//音乐文件
public AudioSource ButtonVoice;
[HideInInspector]//不显示在Inspector面板中
public string Name
[HideInInspector]
public string Old;
[HideInInspector]
public string Sex;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
//....
}
personObj.GetComponent().Name = "Jams";
Sprite tmpsprite = Sprite.Create(www.texture,new Rect(0,0,www.texture.width, www.texture.height),new Vector2(0.5f,0.5f));
WWWForm form = new WWWForm();
form.AddField("userid","ABC");
WWW getRecommandedData = new WWW("http://localhost/test.php",form);
yield return getRecommandedData;
if(!string.IsNullOrEmpty(getRecommandedData.error))
{
Debug.LogError("无法连接到服务器,请刷新重试");
yield break;
}
string srcString = getRecommandedData.text;
void Update () {
//判断异步对象并且异步对象没有加载完毕,显示进度
if(getSubjectData!=null&&!getSubjectData.isDone)
{
Debug.LogError("正在加载...");
}
}
WWW downloadOperation = new WWW(url);
yield return downloadOperation;
if(string.IsNullOrEmpty(downloadOperation.error))
{
Byte[] b = downloadOperation.bytes;
File.WriteAllBytes(localPath, b);
}
WWW www = new WWW("file:///C:/test.png");
yield return www;
if(string.IsNullOrEmpty(www.error))
{
Material mat = (Material)Resources.Load("panorama", typeof(Material));
mat.mainTexture = www.texture;
}
MediaPlayer组件的File属性就可以了,也可以OpenVideoFromFile方法。
MediaPlayer mp = gameObject.GetComponentInChildren();
mp.OpenVideoFromFile(RenderHeads.Media.AVProVideo.MediaPlayer.FileLocation.RelativeToPeristentDataFolder, "test.mp4",true);
11.安卓环境下文件下载保存目录为Application.persistentDataPath
12.加掉大图片到纹理
WWW www = new WWW("file:///C:/test.jpg");
yield return www;
if(string.IsNullOrEmpty(www.error)&&www.isDone)
{
Texture2D txt2d = new Texture2D(2000, 1000, TextureFormat.RGB24, true);//经测试,最后一个参数一定要为true
www.LoadImageIntoTexture(txt2d);
Material mat = (Material)Resources.Load("panorama", typeof(Material));
if(mat != null)
mat.mainTexture = txt2d;
}