You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
272 lines
10 KiB
272 lines
10 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using System.IO; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
using AX.MessageSystem; |
|
using AX.TrackRecord; |
|
|
|
public class EditNodePlane : MonoBehaviour { |
|
|
|
/// <summary> |
|
/// 标签编辑面板 |
|
/// </summary> |
|
private InputField inputRecordName; |
|
private InputField inputRecordIntro; |
|
private InputField inputRecordShow; |
|
private Button SureBtn; |
|
private Button CloseBtn; |
|
private Button VidoBtn; |
|
private Button PictrueBtn; |
|
public static EditNodePlane instance = null; |
|
private GameObject ShowText; |
|
void Awake () |
|
{ |
|
if (instance == null) |
|
{ |
|
instance = this; |
|
} |
|
|
|
ShowText = GameObject.Find("Canvas").transform.Find("ShowText").gameObject; |
|
inputRecordName = transform.Find("InputName").GetComponent<InputField>(); |
|
inputRecordIntro = transform.Find("Scroll View/Viewport/InputIntro").GetComponent<InputField>(); |
|
inputRecordShow = transform.Find("Scroll View (1)/Viewport/InputIntro").GetComponent<InputField>(); |
|
SureBtn = transform.Find("Yes").GetComponent<Button>(); |
|
SureBtn.onClick.AddListener(SureClick); |
|
|
|
CloseBtn = transform.Find("No").GetComponent<Button>(); |
|
CloseBtn.onClick.AddListener(CloseClick); |
|
|
|
VidoBtn= transform.Find("Vido").GetComponent<Button>(); |
|
VidoBtn.onClick.AddListener(VidoClick); |
|
|
|
PictrueBtn = transform.Find("Picture").GetComponent<Button>(); |
|
PictrueBtn.onClick.AddListener(PictrueClick); |
|
|
|
gameObject.SetActive(false); |
|
} |
|
private bool VideoBool = false; |
|
private string videofile = ""; |
|
|
|
private bool PictureBool = false; |
|
private string pciturefile = ""; |
|
|
|
public void SureClick() |
|
{ |
|
LoadManager.Instance.isChanged = true; |
|
BQeventItem.objAttriList[0].TaskName = inputRecordIntro.text; |
|
BQeventItem.objAttriList[0].ObjName = inputRecordName.text; |
|
BQeventItem.objAttriList[0].TopName = inputRecordShow.text; |
|
if (!VideoBool && !PictureBool) |
|
{ |
|
//LoadManager.Instance.AddLoadTagEvent(inputRecordName.text, inputRecordIntro.text, Game, 0f, ModelADD.None, "", ""); |
|
} |
|
else if (VideoBool && PictureBool) |
|
{ |
|
//LoadManager.Instance.AddLoadTagEvent(inputRecordName.text, inputRecordIntro.text, Game, 0f, ModelADD.All, videofile, pciturefile); |
|
Game.transform.Find("Show").Find("Picture").gameObject.SetActive(true); |
|
Game.transform.Find("Show").Find("Video").gameObject.SetActive(true); |
|
Texture2D texture = CreatTexture(ExamInfoHelpClass.PictureFilePath + pciturefile);//fileName1 |
|
Sprite sprite_ = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); |
|
Game.transform.Find("Show").Find("Picture").GetComponent<Image>().sprite = sprite_; |
|
Game.GetComponent<GetTheJieDian>().EventItem.objAttriList[0].VideoFile = videofile; |
|
Game.GetComponent<GetTheJieDian>().EventItem.objAttriList[0].PictureFile = pciturefile; |
|
} |
|
else if (VideoBool) |
|
{ |
|
|
|
Game.transform.Find("Show").Find("Video").gameObject.SetActive(true); |
|
Game.GetComponent<GetTheJieDian>().EventItem.objAttriList[0].VideoFile = videofile; |
|
} |
|
else if (PictureBool) |
|
{ |
|
//LoadManager.Instance.AddLoadTagEvent(inputRecordName.text, inputRecordIntro.text, Game, 0f, ModelADD.Pict, "", pciturefile); |
|
Game.transform.Find("Show").Find("Picture").gameObject.SetActive(true); |
|
Texture2D texture = CreatTexture(ExamInfoHelpClass.PictureFilePath + pciturefile);//fileName1 |
|
Sprite sprite_ = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); |
|
Game.transform.Find("Show").Find("Picture").GetComponent<Image>().sprite = sprite_; |
|
Game.GetComponent<GetTheJieDian>().EventItem.objAttriList[0].PictureFile = pciturefile; |
|
} |
|
if (Game.transform.Find("Show").Find("Video").gameObject.activeInHierarchy) |
|
{ |
|
BQeventItem.objAttriList[0].modeadd = ModelADD.Video; |
|
} |
|
if (Game.transform.Find("Show").Find("Picture").gameObject.activeInHierarchy) |
|
{ |
|
BQeventItem.objAttriList[0].modeadd = ModelADD.Pict; |
|
} |
|
if (Game.transform.Find("Show").Find("Picture").gameObject.activeInHierarchy && Game.transform.Find("Show").Find("Video").gameObject.activeInHierarchy) |
|
{ |
|
BQeventItem.objAttriList[0].modeadd = ModelADD.All; |
|
} |
|
|
|
|
|
|
|
LoadManager.Instance.ChangeBiaoQian(BQeventItem); |
|
if (inputRecordIntro.text != "") |
|
{ |
|
ShowText.transform.Find("Scroll View").gameObject.SetActive(true); |
|
} |
|
if (inputRecordShow.text != "") |
|
{ |
|
ShowText.transform.Find("LeftShow").gameObject.SetActive(true); |
|
} |
|
ShowText.transform.Find("Scroll View/Viewport/InputField").GetComponent<InputField>().text = inputRecordIntro.text; |
|
ShowText.transform.Find("LeftShow/Scroll View/Viewport/InputField").GetComponent<InputField>().text = inputRecordShow.text; |
|
Game.transform.Find("Text").GetComponent<Text>().text = inputRecordName.text; |
|
Game.GetComponent<GetTheJieDian>().EventItem = BQeventItem; |
|
this.gameObject.SetActive(false); |
|
inputRecordName.text = ""; |
|
inputRecordIntro.text = ""; |
|
inputRecordShow.text = ""; |
|
videofile = ""; |
|
pciturefile = ""; |
|
VideoBool = false; |
|
PictureBool = false; |
|
|
|
} |
|
public void CloseClick() |
|
{ |
|
this.gameObject.SetActive(false); |
|
inputRecordName.text = ""; |
|
inputRecordIntro.text = ""; |
|
inputRecordShow.text = ""; |
|
videofile = ""; |
|
pciturefile = ""; |
|
VideoBool = false; |
|
PictureBool = false; |
|
} |
|
public void VidoClick() |
|
{ |
|
System.Windows.Forms.OpenFileDialog od = new System.Windows.Forms.OpenFileDialog(); |
|
od.Multiselect = false; |
|
string filePath = "";//文件所在路径(包含文件名+扩展名) |
|
//string extendedName = ""; 扩展名 |
|
string fileName = "";//文件名(包含扩展名) |
|
od.Filter = "请选择视频文件(mp4,avi,mkv,wmv)|*.mp4;*.avi;*.mkv;*.wmv|mp4|*.mp4|avi|*.avi|mkv|*.mkv|wmv|*.wmv"; |
|
|
|
|
|
if (od.ShowDialog() == System.Windows.Forms.DialogResult.OK) |
|
{ |
|
filePath = od.FileName; |
|
////extendedName = Path.GetExtension(filePath);获取扩展名 |
|
fileName = Path.GetFileName(filePath); |
|
} |
|
if (filePath == "") |
|
return; |
|
Debug.Log(filePath); |
|
videofile = fileName; |
|
string videofile_ = ExamInfoHelpClass.VideoFilePath + fileName; |
|
VideoBool = true; |
|
|
|
if (!File.Exists(videofile_)) |
|
{ |
|
File.Copy(filePath, ExamInfoHelpClass.VideoFilePath + fileName, true); |
|
} |
|
BQeventItem.objAttriList[0].VideoFile = videofile; |
|
MessageDispatcher.SendMessage("Operatinghints", (object)"添加视频成功"); |
|
} |
|
public void PictrueClick() |
|
{ |
|
System.Windows.Forms.OpenFileDialog od = new System.Windows.Forms.OpenFileDialog(); |
|
od.Multiselect = false; |
|
string filePath = "";//文件所在路径(包含文件名+扩展名) |
|
//string extendedName = ""; 扩展名 |
|
string fileName = "";//文件名(包含扩展名) |
|
od.Filter = "All Image Files|*.bmp;*.ico;*.gif;*.jpeg;*.jpg;*.png;*.tif;*.tiff|Windows Bitmap(*.bmp)|*.bmp|Windows Icon(*.ico)|*.ico|JPEG File Interchange Format (*.jpg)|*.jpg;*.jpeg|Portable Network Graphics (*.png)|*.png|Tag Image File Format (*.tif)|*.tif;*.tiff|FBX | *.FBX"; |
|
if (od.ShowDialog() == System.Windows.Forms.DialogResult.OK) |
|
{ |
|
filePath = od.FileName; |
|
fileName = Path.GetFileName(filePath); |
|
} |
|
|
|
if (filePath == "") |
|
{//防止打开后没选择图片,关闭后,fileName1为空,拆分不出文件名报错 |
|
return; |
|
} |
|
//fileName = isExists(ExamInfoHelpClass.PictureFilePath, fileName, 0); |
|
pciturefile = fileName; |
|
string pciturefile_ = ExamInfoHelpClass.PictureFilePath + fileName; |
|
//File.Copy(filePath, ExamInfoHelpClass.PictureFilePath + fileName, true); |
|
if (!File.Exists(pciturefile_)) |
|
{ |
|
File.Copy(filePath, ExamInfoHelpClass.PictureFilePath + fileName, true); |
|
} |
|
//else |
|
//{ |
|
// File.Delete(pciturefile); |
|
// File.Copy(filePath, ExamInfoHelpClass.PictureFilePath + fileName, true); |
|
//} |
|
PictureBool = true; |
|
BQeventItem.objAttriList[0].PictureFile = pciturefile; |
|
MessageDispatcher.SendMessage("Operatinghints", (object)"添加图片成功"); |
|
} |
|
public static Texture2D CreatTexture(string filename) |
|
{ |
|
//创建文件读取流 |
|
FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); |
|
fileStream.Seek(0, SeekOrigin.Begin); |
|
//创建文件缓冲区 |
|
byte[] bytes = new byte[fileStream.Length]; |
|
//Debug.Log(bytes.Length); |
|
//读取文件 |
|
fileStream.Read(bytes, 0, (int)fileStream.Length); |
|
//释放文件读取流 |
|
fileStream.Close(); |
|
fileStream.Dispose(); |
|
fileStream = null; |
|
|
|
int width = 1024;//1024 |
|
int height = 1024;//1024 |
|
Texture2D texture = new Texture2D(width, height); |
|
|
|
texture.LoadImage(bytes); |
|
|
|
|
|
return texture; |
|
} |
|
EventRecordItem_two BQeventItem; |
|
GameObject Game; |
|
|
|
public void GetBaoQian(EventRecordItem_two eventItem,GameObject Biaoqian) |
|
{ |
|
BQeventItem = eventItem; |
|
Game = Biaoqian; |
|
inputRecordName.text = BQeventItem.objAttriList[0].ObjName; |
|
inputRecordIntro.text = BQeventItem.objAttriList[0].TaskName; |
|
inputRecordShow.text = BQeventItem.objAttriList[0].TopName; |
|
} |
|
|
|
/// <summary> |
|
/// 打开Windows的选择文件弹窗 |
|
/// </summary> |
|
/// <param name="restrain">约束</param> |
|
/// <returns></returns> |
|
public string OpenWindowsForm(string restrain=null) |
|
{ |
|
System.Windows.Forms.OpenFileDialog od = new System.Windows.Forms.OpenFileDialog(); |
|
od.Multiselect = false; |
|
|
|
od.Filter = restrain; |
|
if (od.ShowDialog() == System.Windows.Forms.DialogResult.OK) |
|
{ |
|
return od.FileName; |
|
} |
|
else { |
|
return null; |
|
} |
|
|
|
} |
|
|
|
|
|
public void EditNode() |
|
{ |
|
this.gameObject.SetActive(true); |
|
} |
|
void OnEnable() |
|
{ |
|
|
|
} |
|
|
|
|
|
}
|
|
|