/// <summary> /// 获取移动的目标点 /// </summary> /// <param name="items"></param> /// <returns></returns> List <Vector3> GetMoveEndPoint(List <CaricaturePlayerModule> items, CaricaturePlayerModule aboutInsertionItem = null, CaricaturePlayerModule oldItem = null, bool isOneItem = false) { List <Vector3> tagePoints = new List <Vector3>(); for (int i = items.Count - 1; i >= 0; i--) { CaricaturePlayerModule item = items[i]; float maxHeight = (_thisRect.rect.height / 2) + item._ThisRect.rect.height / 2; float maxWide = 0; float y = 0; float x = 0; if (item._DirectionType == ChapterTool.CaricatureModuleDirectionType.Up) { x = item._ThisRect.localPosition.x; } else { switch (item._DirectionType) { case ChapterTool.CaricatureModuleDirectionType.Left: maxWide = (_thisRect.rect.width / 2) - item._ThisRect.rect.width / 2; x = maxWide + item._SkewingValue.x; break; case ChapterTool.CaricatureModuleDirectionType.Right: maxWide = -(_thisRect.rect.width / 2) + item._ThisRect.rect.width / 2; x = maxWide + item._SkewingValue.x; break; } } if (tagePoints.Count <= 0) { if (aboutInsertionItem == null) { float bottomY = _thisRect.rect.height / 2; if (oldItem == null) { if (isOneItem) { bottomY = (bottomY) - item._ThisRect.rect.height / 2; } else { bottomY = -(bottomY) + item._ThisRect.rect.height / 2; } } else { bottomY = oldItem._ThisRect.localPosition.y - oldItem._ThisRect.rect.height / 2 - item._ThisRect.rect.height / 2 - item._Interval; } tagePoints.Add(new Vector3(x, bottomY)); } else { float bottomY = _thisRect.rect.height / 2; if (aboutInsertionItem._DirectionType == ChapterTool.CaricatureModuleDirectionType.Up) { if (item._DirectionType != ChapterTool.CaricatureModuleDirectionType.Up) { switch (item._DirectionType) { case ChapterTool.CaricatureModuleDirectionType.Left: maxWide = (_thisRect.rect.width / 2) - item._ThisRect.rect.width / 2; x = maxWide + item._SkewingValue.x; if (Mathf.Abs(item._ThisRect.localPosition.x - x) > 1) { bottomY = -(bottomY) + item._ThisRect.rect.height / 2; } else { bottomY = -(bottomY) + item._ThisRect.rect.height / 2 + aboutInsertionItem._Interval; } break; case ChapterTool.CaricatureModuleDirectionType.Right: maxWide = -(_thisRect.rect.width / 2) + item._ThisRect.rect.width / 2; x = maxWide + item._SkewingValue.x; if (Mathf.Abs(item._ThisRect.localPosition.x - x) > 1) { bottomY = -(bottomY) + item._ThisRect.rect.height / 2; } else { bottomY = -(bottomY) + item._ThisRect.rect.height / 2 + aboutInsertionItem._Interval; } break; } } else { bottomY = -(bottomY) + item._ThisRect.rect.height / 2 + aboutInsertionItem._Interval; } } else { if (!aboutInsertionItem._IsShow) { aboutInsertionItem.Show(GetShowRect()); aboutInsertionItem._ThisRect.localPosition = GetBornTagePoint(aboutInsertionItem); } bottomY = aboutInsertionItem._ThisRect.localPosition.y + item._ThisRect.rect.height / 2 + aboutInsertionItem._Interval + aboutInsertionItem._ThisRect.rect.height / 2; } tagePoints.Add(new Vector3(x, bottomY)); } } else { Vector3 lastPoint = tagePoints[tagePoints.Count - 1]; Vector3 tagePoint = Vector3.zero; y = lastPoint.y + items[i + 1]._ThisRect.rect.height / 2 + items[i + 1]._Interval + item._ThisRect.rect.height / 2 + item._SkewingValue.y; if (y > maxHeight) { y = maxHeight; } switch (item._DirectionType) { case ChapterTool.CaricatureModuleDirectionType.Left: maxWide = (_thisRect.rect.width / 2) - item._ThisRect.rect.width / 2; x = maxWide + item._SkewingValue.x; if (Mathf.Abs(item._ThisRect.localPosition.x - x) > 1 /* item._ThisRect.localPosition.x != x*/) { y = item._ThisRect.localPosition.y; } break; case ChapterTool.CaricatureModuleDirectionType.Right: maxWide = -(_thisRect.rect.width / 2) + item._ThisRect.rect.width / 2; x = maxWide + item._SkewingValue.x; if (Mathf.Abs(item._ThisRect.localPosition.x - x) > 1) { y = item._ThisRect.localPosition.y; } break; } tagePoint = new Vector3(x, y); tagePoints.Add(tagePoint); } } tagePoints.Reverse(); CaricaturePlayerModule lastItem = items[items.Count - 1]; Vector3 lastItemTagePoint = tagePoints[tagePoints.Count - 1]; float minY = _thisRect.rect.height / 2; minY = -(minY) + lastItem._ThisRect.rect.height / 2; if (minY >= lastItemTagePoint.y) { _theFirstScreen = true; } return(tagePoints); }
/// <summary> /// 移动 /// </summary> /// <param name="datas"></param> async void MoveItems(List <CaricaturePlayerModule> oldItems, List <CaricaturePlayerModule> datas) { List <CaricaturePlayerModule> oldItemList = new List <CaricaturePlayerModule>(); oldItemList.AddRange(oldItems); List <CaricaturePlayerModule> newItemList = new List <CaricaturePlayerModule>(); newItemList.AddRange(datas); List <CaricaturePlayerModule> moveItems = new List <CaricaturePlayerModule>(); List <int> hidItems = new List <int>(); int initialItemIndex = 0; for (int i = 0; i < datas.Count; i++) { CaricaturePlayerModule initialItem = datas[i]; if (initialItemIndex >= 1) { break; } else { if (initialItem._CaricaturePlayerSpecialModuleBasics == null) { await initialItem.Show(GetShowRect()); } else { initialItem.Show(); } //设置初始位置 CaricaturePlayerModule oldItem = null; if (oldItemList != null && oldItemList.Count > 0) { oldItem = oldItemList[oldItemList.Count - 1]; } initialItem._ThisRect.localPosition = GetBornTagePoint(initialItem, oldItem); moveItems.Add(initialItem); newItemList.Remove(initialItem); initialItemIndex++; if (initialItem._CaricaturePlayerSpecialModuleBasics != null) { Debug.Log("初始"); } } } //条漫第一格是否移动完毕 bool isOneItem = false; //将旧item加入移动队列 if (oldItemList != null && oldItemList.Count > 0) { float minY = _thisRect.rect.height / 2; minY = -(minY) + moveItems[0]._ThisRect.rect.height / 2; if (_theFirstScreen) { List <CaricaturePlayerModule> newMoveItems = new List <CaricaturePlayerModule>(); newMoveItems.AddRange(oldItemList); newMoveItems.AddRange(moveItems); oldItemList.Clear(); moveItems.Clear(); moveItems.AddRange(newMoveItems); } isOneItem = false; } else { isOneItem = true; } bool _isMove = true; //获取初始移动终点 List <Vector3> tagePoints = new List <Vector3>(); if (!_theFirstScreen && oldItemList != null && oldItemList.Count > 0) { tagePoints = GetMoveEndPoint(moveItems, null, oldItemList[oldItemList.Count - 1], isOneItem); } else { tagePoints = GetMoveEndPoint(moveItems, null, null, isOneItem); } while (_isMove) { hidItems.Clear(); for (int i = 0; i < moveItems.Count; i++) { CaricaturePlayerModule moveItem = moveItems[i]; //修改item层级 if (i != 0) { CaricaturePlayerModule lastMonveItem = moveItems[i - 1]; int siblingIndex = lastMonveItem._ThisRect.GetSiblingIndex(); switch (moveItem._Hierarchy) { case 0: case 1: siblingIndex = siblingIndex + 1; break; case -1: siblingIndex = siblingIndex - 1; break; } moveItem._ThisRect.SetSiblingIndex(siblingIndex); } Vector3 tagePoint = tagePoints[i]; float speed = 5; //左右插入速度更改 if (moveItem._DirectionType != ChapterTool.CaricatureModuleDirectionType.Up && Mathf.Abs(moveItem._ThisRect.localPosition.x - tagePoint.x) > 1) { speed = 20; } else { speed = 18; } moveItem._ThisRect.localPosition = Vector3.MoveTowards(moveItem._ThisRect.localPosition, tagePoint, speed); //判断是否超出屏幕 float maxY = (_thisRect.rect.height / 2) + moveItem._ThisRect.rect.height / 2; if (moveItem._ThisRect.localPosition.y >= maxY) { hidItems.Add(i); } } //关闭超出屏幕的item for (int i = 0; i < hidItems.Count; i++) { HideItem(moveItems[hidItems[i]]); moveItems.RemoveAt(hidItems[i]); tagePoints.RemoveAt(hidItems[i]); } //将旧item加入移动队列 if (oldItemList != null && oldItemList.Count > 0) { CaricaturePlayerModule oldLastItem = oldItemList[oldItemList.Count - 1]; CaricaturePlayerModule moveOneItem = moveItems[0]; float tageY = oldLastItem._ThisRect.localPosition.y - oldLastItem._ThisRect.rect.height / 2 - moveOneItem._ThisRect.rect.height / 2 - moveOneItem._Interval; Vector3 tagePoint = new Vector3(moveOneItem._ThisRect.localPosition.x, tageY, moveOneItem._ThisRect.localPosition.z); Debug.Log("_____________________________" + tagePoint); Debug.Log("_____________________________" + _theFirstScreen); Debug.Log("_____________________________" + Vector3.Distance(tagePoint, moveOneItem._ThisRect.localPosition)); float minY = _thisRect.rect.height / 2; minY = -(minY) + moveOneItem._ThisRect.rect.height / 2; Debug.Log("_____________________________" + (moveOneItem._ThisRect.localPosition.y < minY)); if (/*!_theFirstScreen &&*/ /*moveOneItem._ThisRect.localPosition.y< tagePoint.y*/ Vector3.Distance(tagePoint, moveOneItem._ThisRect.localPosition) < 10 && moveOneItem._ThisRect.localPosition.y < minY) { List <CaricaturePlayerModule> newMoveItems = new List <CaricaturePlayerModule>(); newMoveItems.AddRange(oldItemList); newMoveItems.AddRange(moveItems); oldItemList.Clear(); moveItems.Clear(); moveItems.AddRange(newMoveItems); if (newItemList == null || newItemList.Count <= 0) { tagePoints = GetMoveEndPoint(moveItems); } } else { if (newItemList == null || newItemList.Count <= 0) { tagePoints = GetMoveEndPoint(moveItems, null, oldLastItem); } } } //将下一个item加入移动队列 if (newItemList != null && newItemList.Count > 0) { CaricaturePlayerModule newFirstItem = newItemList[0]; if (newFirstItem._CaricaturePlayerSpecialModuleBasics == null) { //提前生成下一个item if (!newFirstItem._IsShow) { newFirstItem.Show(GetShowRect()); } } else { newFirstItem.Show(); } newFirstItem._ThisRect.localPosition = GetBornTagePoint(newFirstItem); CaricaturePlayerModule moveLastItem = moveItems[moveItems.Count - 1]; float yValue = (moveLastItem._ThisRect.localPosition.y - moveLastItem._ThisRect.rect.height / 2) - newFirstItem._Interval - newFirstItem._ThisRect.rect.height / 2; if (newFirstItem._ThisRect.localPosition.y <= yValue) { moveItems.Add(newFirstItem); newItemList.Remove(newFirstItem); } //更新移动目标终点 if (newItemList != null && newItemList.Count > 0) { tagePoints = GetMoveEndPoint(moveItems, newItemList[0]); } else { tagePoints = GetMoveEndPoint(moveItems); } } else { if ((newItemList == null || newItemList.Count <= 0) && Vector3.Distance(moveItems[moveItems.Count - 1]._ThisRect.localPosition, tagePoints[tagePoints.Count - 1]) <= 1) { _isMove = false; } } await UniTask.Delay(TimeSpan.FromMilliseconds(10)); } _currShowCaricatures.Clear(); if (oldItemList != null && oldItemList.Count > 0) { _currShowCaricatures.AddRange(oldItemList); } _currShowCaricatures.AddRange(moveItems); _currShowItem = _currShowCaricatures[_currShowCaricatures.Count - 1]; if (_currShowItem != null) { _currShowItem.MoveEnd(); if ((_currShowItem._Dialogues == null || _currShowItem._Dialogues.Count <= 0) && isOneItem) { ClickBtn(); } } Debug.Log("移动完毕"); }