时间乃是最大的革新家,又一个新年过去了
一年到头积蓄没有,钱包—囊中羞涩,年龄倒是在一年年增长,时光如梭,岁月蹉跎。
想想来写点什么,可又没什么技术点突破,没什么更新的,但总想来这留下个今天的足迹。
Windows USB Reader读卡器,这类硬件不需要驱动,就相当在键盘上输入一串字符串,然后根据对应的需求展示对应的效果。
foreach (char c in Input.inputString)
{
if (c == '\b') // has backspace/delete been pressed?
{
if (t.text.Length != 0)
{
t.text = t.text.Substring(0, t.text.Length - 1);
print(t.text.Length);
}
}
else if ((c == '\n') || (c == '\r')) // enter/return
{
string a = t.text;
print("User entered their name: " + t.text);
STemp = a;
if (STemp.Length == 10)
{
MediaCtrl.OBJS["标题"].GetComponent<Text>().text = null;
MediaCtrl.OBJS["内容"].GetComponent<Text>().text = null;
ChangeContents(STemp);
print(STemp);
print(STemp.Length);
s = "";
return;
}
else
{
STemp = "";
t.text = null;
Kz_Start = false;
return;
}
}
else
{
print("加等");
t.text += c;
}
}
/// <summary>
/// 加载XML
/// </summary>
public void LoadXml()
{
XmlNode root = doc.SelectSingleNode("root");
foreach (XmlElement item in root)
{
//print(item.GetAttribute("id"));
//print(item.ChildNodes[0].InnerText);
//print(item.ChildNodes[1].InnerText);
//print(item.ChildNodes[2].InnerText);
if (item.GetAttribute("id") == SerialPort.instance.STemp)
{
print("我试加载XML");
print(item.ChildNodes[0].InnerText);
print(item.ChildNodes[1].InnerText);
//测试
SerialPort.instance.t.text = SerialPort.instance.s;
MediaCtrl.instance.Title = item.ChildNodes[0].InnerText;
MediaCtrl.instance.jieshao = item.ChildNodes[1].InnerText;
Text title = MediaCtrl.OBJS["标题"].GetComponent<Text>();
//title.text = null;
title.text = MediaCtrl.instance.Title;
Text t = MediaCtrl.OBJS["内容"].GetComponent<Text>();
//t.text = null;
t.text = MediaCtrl.instance.jieshao;
MediaCtrl.instance.fn_TextEffects(t, 3.5f);
string str = item.ChildNodes[2].InnerText;
string strImage = item.ChildNodes[3].InnerText;
print(strImage + " 加载高光图片");
//MediaCtrl.instance.videoPlayers[4].clip = Application.streamingAssetsPath + "/剪辑/"+ str+ ".mp4";
if (videoPlayer != null)
{
videoPlayer.url = GetFilePath("剪辑", str, ".mp4");
videoPlayer.Play();
}
//StartCoroutine(LoadFromLocal(Application.dataPath + "/../" + "截图" + "/" + str,s));
StartCoroutine(LoadFromLocal(Application.dataPath + "/../" + "图片" + "/" + strImage + ".png", (s) =>
{
MediaCtrl.OBJS["高光图片"].GetComponent<Image>().sprite = s;
MediaCtrl.OBJS["高光图片"].GetComponent<Image>().SetNativeSize();
}));
//s.Invoke(MediaCtrl.OBJS["高光图片"].GetComponent<Image>().sprite);
SerialPort.instance.STemp = "";
}
}
}
//加载图片
/// <summary>
/// 加载本地图片
/// </summary>
/// <param name="_path"></param>
/// <param name="_ac"></param>
/// <returns></returns>
IEnumerator LoadFromLocal(string _path, Action<Sprite> _ac)
{
#if UNITY_ANDROID
UnityWebRequest request = UnityWebRequest.Get("file://" + _path);
#elif UNITY_STANDALONE_WIN
//UnityWebRequest request = UnityWebRequest.Get(_path);
UnityWebRequest request = UnityWebRequestTexture.GetTexture(_path);
#endif
yield return request.SendWebRequest();
//byte[] bytes = request.downloadHandler.data;
//_ac(bytes);
Texture2D t2d = DownloadHandlerTexture.GetContent(request);
Sprite s = Sprite.Create(t2d, new Rect(0, 0, t2d.width, t2d.height), Vector2.zero);
_ac(s);
}
//加载视频路径
string GetFilePath(string foldPath, string fileName, string fileFormat = ".mp4")
{
string filePath;
#if UNITY_IPHONE
if (!string.IsNullOrEmpty(foldPath))
{
filePath="file://"+Application.dataPath + "/Raw/"+foldPath+"/"+fileName+fileFormat;
}
else
{
filePath="file://"+Application.dataPath + "/Raw/"+fileName+fileFormat;
}
#endif
if (!string.IsNullOrEmpty(foldPath))
{
// 上一个路径/../ 当前路径/./ 下一个路径/
filePath = Application.dataPath + "/../" + foldPath + "/" + fileName + fileFormat;
print(filePath);
}
else
{
filePath = Application.dataPath /*+ "/StreamingAssets/" */+ fileName + fileFormat;
//filePath = Application.dataPath +"/" + foldPath + "/" + fileName + fileFormat;
filePath = Application.dataPath + "/../" + foldPath + "/" + fileName + fileFormat;
}
return filePath;
}
XML
效果图
1.
2.