using System; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; public class MyCardItem : MonoBehaviour { /// /// 照片名称 /// public string Nameid; private void Awake() { tex = new Texture2D(0,0); } private void OnDestroy() { if(tex!=null) { Destroy(tex); } } Texture2D tex; /// /// 切换照片 /// public void ChangeTexture(string filePath,Action callback=null) { if(File.Exists(filePath)) { FileInfo info = new FileInfo(filePath); byte[] tmp=File.ReadAllBytes(filePath); tex.LoadImage(tmp); GetComponent().material.mainTexture = tex; callback(true, "设置成功"); } else { callback(false, "不存在此文件"); } } }