ict.lixian.single/Assets/Scripts/cxx/item/MyCardItem.cs

49 lines
960 B
C#

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