public void SetData(PosAndDir data, DepthInfo[] infos, Transform infoParent, Material mat) { _data = data; _depthBuffer = infos; _infoParent = infoParent; this.GetComponent <Renderer>().material = mat; YearsEvent ye = PictureHandle.Instance.GetYearInfo(data); _mat = mat; _mat.SetTexture("_TexArrOne", PictureHandle.Instance.TexArr); _mat.SetInt("_Index", _data.picIndex); _mat.renderQueue = 3000; Texture2D tex = null; foreach (Texture2D texture2D in yearTexs) { if (texture2D.name == ye.Years) { tex = texture2D; break; } } _mat.SetTexture("_Year", tex); this.transform.rotation = Quaternion.Euler(0f, 0f, 0f); }
/// <summary> /// 导入数据 /// </summary> public void LoadData(YearsEvent yearsEvent, Texture2DArray texArry) { _yearsEvent = yearsEvent; _yearText.text = _yearsEvent.Years; _describe.text = _yearsEvent.Describe; _describe.transform.GetComponent <ContentSizeFitter>().SetLayoutVertical(); textureIndex = _yearsEvent.PictureIndes; _mat = Resources.Load <Material>("ItemShader"); _mat = Instantiate(_mat); //拷贝一份 _image.material = _mat; if (yearsEvent.PictureIndes.Count == 1) { this.transform.Find("previous").gameObject.SetActive(false); this.transform.Find("next").gameObject.SetActive(false); } if (!string.IsNullOrEmpty(yearsEvent.YearEventVideo)) { _mp4Url = "file://" + yearsEvent.YearEventVideo; _videoPlayer.url = _mp4Url; this.transform.Find("previous").gameObject.SetActive(false); this.transform.Find("next").gameObject.SetActive(true); } _mat.SetTexture("_TexArrOne", texArry); _mat.SetInt("_Index", textureIndex[0]); _image.Rebuild(CanvasUpdate.LatePreRender); _curIndex = 0; ShowImage(_curIndex); }
public YearsEvent GetYearInfo(PosAndDir pad) { if (pad.picIndex < 0) { return(null); } YearsEvent ye = null; foreach (YearsInfo yearsInfo in _yesrsInfos) { foreach (var yearsEvent in yearsInfo.yearsEvents) { foreach (int inde in yearsEvent.PictureIndes) { if (pad.picIndex == inde) { ye = yearsEvent; break; } } } } if (ye == null) { throw new UnityException("没有找到相应的年代事件"); } return(ye); //Debug.Log(ye.ToString()); }
public List <YearsInfo> LoadPicture(string path) { List <YearsInfo> years = new List <YearsInfo>(); DirectoryInfo directoryInfo = new DirectoryInfo(path); DirectoryInfo[] infos = directoryInfo.GetDirectories();//获取年份目录 foreach (DirectoryInfo info in infos) { DirectoryInfo[] temps = info.GetDirectories();//获取年份下事件 YearsInfo tempYearsInfo = new YearsInfo(); tempYearsInfo.Years = info.Name; tempYearsInfo.EventCount = temps.Length; int index = 0; foreach (DirectoryInfo temp in temps) { index++; YearsEvent yearsEvent = new YearsEvent(); yearsEvent.Years = info.Name; yearsEvent.IndexPos = index; FileInfo[] fileInfos = temp.GetFiles(); foreach (FileInfo fileInfo in fileInfos) { if (fileInfo.Extension == ".txt") { yearsEvent.DescribePath = fileInfo.FullName; byte[] bytes = File.ReadAllBytes(fileInfo.FullName); string str = Encoding.UTF8.GetString(bytes); yearsEvent.Describe = str; } else if (fileInfo.Extension == ".jpg" || fileInfo.Extension == ".JPG" || fileInfo.Extension == ".jpeg") { yearsEvent.PicturesPath.Add(fileInfo.FullName); } else if (fileInfo.Extension == ".mp4") { yearsEvent.YearEventVideo = fileInfo.FullName; } else if (fileInfo.Extension == ".png" || fileInfo.Extension == ".PNG") { yearsEvent.PicturesPath.Add(fileInfo.FullName); // Debug.Log(fileInfo.FullName); } } tempYearsInfo.yearsEvents.Add(yearsEvent); } years.Add(tempYearsInfo); } return(years); }
/// <summary> /// 根据图片索引拿到年代事件信息 /// </summary> public void GetYearInfo(PosAndDir pad, Transform canvas) { if (pad.picIndex < 0) { return; } YearsEvent ye = null; foreach (YearsInfo yearsInfo in _yesrsInfos) { foreach (var yearsEvent in yearsInfo.yearsEvents) { foreach (int inde in yearsEvent.PictureIndes) { if (pad.picIndex == inde) { ye = yearsEvent; break; } } } } if (ye == null) { throw new UnityException("没有找到相应的年代事件"); } GameObject temp = Instantiate(_info, canvas.transform); Item item = temp.GetComponent <Item>(); item.LoadData(ye, TexArr); Vector3 screenPos = Camera.main.WorldToScreenPoint(pad.position); RectTransform rectTransform = item.GetComponent <RectTransform>(); // rectTransform.SetSiblingIndex(2); rectTransform.DOScale(1f, 0.75f); //rectTransform.DOLocalRotate(new Vector3(0f, 360, 0f), 1f, RotateMode.LocalAxisAdd).OnComplete((() => //{ // item.RotEnd(); //})); rectTransform.anchoredPosition = screenPos; if (screenPos.y >= 2300f) { screenPos.y = 2300f; } if (screenPos.y <= 1100f) { screenPos.y = 1100f; } if (screenPos.x >= 6500f) { screenPos.x = 6500f; } if (screenPos.x <= 1000f) { screenPos.x = 1000f; } rectTransform.DOAnchorPos(screenPos, 0.35f); //Debug.Log(ye.ToString()); }