public ScollerItemBase RefushCell(int index) { ScollerItemBase tmpCell = FindCell(index); return(tmpCell); }
/// <summary> /// 前面已经实例化了一个cell 在最后 现在修正 index number /// </summary> /// <param name="content"></param> public void AddCellToLastCellNumber(RectTransform content) { // ScollerItemBase tmpLastIndex = FindLastIndexCell(); ScollerItemBase tmpLastNumber = FindLastIndexCell(); int tmpIndex = tmpLastNumber.CellIndex; sbyte tmpNuber = tmpLastNumber.CellNumber; ScollerMoveIterm tmpAdd = AddChild(content.childCount - 1, content); for (int i = 0; i < scolerIterms.Count; i++) { ScollerItemBase tmpIterm = scolerIterms[i]; if (tmpIterm.CellIndex > tmpIndex) { tmpIterm.CellIndex += 1; } } tmpAdd.CellNumber = (sbyte)(tmpNuber + 1); tmpAdd.CellIndex = tmpIndex + 1; }
/// <summary> /// 1 水平左 2 水平右 4,竖直上 3,竖直下 /// </summary> /// <param name="pos"></param> /// <returns></returns> private byte RejugdeDirect(Vector2 pos, ScollerItemBase tmpCellOne) { if (Direct == ScollerDirect.Horizontal) { if (curScolerPos.x < pos.x) { if (pos.x - curScolerPos.x >= tmpCellOne.GetCellWidth()) { curScolerPos = pos; return(0); } curScolerPos = pos; return(2); } else { if (curScolerPos.x - pos.x >= tmpCellOne.GetCellWidth()) { curScolerPos = pos; return(0); } curScolerPos = pos; return(1); } } else if (Direct == ScollerDirect.Vertical) { if (curScolerPos.y <= pos.y) { if (pos.y - curScolerPos.y >= tmpCellOne.GetCellHeight()) { curScolerPos = pos; return(0); } curScolerPos = pos; return(3); } else { if (curScolerPos.y - pos.y >= tmpCellOne.GetCellHeight()) { curScolerPos = pos; return(0); } curScolerPos = pos; return(4); } } return(0); }
public void MoveTo(ScollerItemBase toItem) { Vector3 frontPos = toItem.GetTargetPosition(); this.cellNumber = toItem.cellNumber; targetPos = cellTransform.localPosition = frontPos; }
/// <summary> /// 更新cell /// </summary> /// <param name="index"></param> /// <param name="tmpCell"></param> void UpdateCell(int index, ScollerItemBase tmpCell) { //UnityEngine.Debug.LogError("index ============ " + index); tmpCell.cellTransform.name = "Iterm==" + tmpCell.CellNumber + "==index==" + index; //Debug.Log(index + "===" + tmpCell["SonButton"].name); if (cellChanger != null) { cellChanger(index, tmpCell); } }
public void UpdateContentReCorrect(ScollerItemBase firstItem) { content.localPosition = contentLocalPosition; ScollerItemBase tmpLast = FindCell(1); tmpLast.CellLocalPosition = Vector3.zero; scollerAnimal.FollowFront(1); firstItem.FollowBack(tmpLast); }
//private bool isPlaying; //public bool IsPlaying //{ // get // { // return isPlaying; // } // set // { // } //} public ScollerAnimal(RectTransform content, ScollerDirect tmpDirect) { scolerIterms = new List <ScollerItemBase>(); direct = tmpDirect; float tmpHeight = 0.0f; for (int i = 0; i < content.childCount; i++) { RectTransform tmpChild = content.GetChild(i).GetComponent <RectTransform>(); ScollerItemBase tmpItem = new ScollerItemBase(tmpChild, (sbyte)i, direct); // Debug.Log("tmpIterm-=="+ tmpIterm.cellPos+"==i=="+i); scolerIterms.Add(tmpItem); if (direct == ScollerDirect.Vertical) { tmpHeight += tmpChild.sizeDelta.y; } else { tmpHeight += tmpChild.sizeDelta.x; } } if (direct == ScollerDirect.Vertical) { if (tmpHeight < content.sizeDelta.y) { isPlaying = false; } else { isPlaying = true; } } else { if (tmpHeight < content.sizeDelta.x) { isPlaying = false; } else { isPlaying = true; } } }
public void RefrushCellOrder(int insertIndex, ScollerMoveIterm inserIterm) { //先找到插入的位置 ScollerItemBase frontItem = FindCellByIndex(insertIndex); int tmpIndex = frontItem.CellIndex; sbyte tmpCellNub = frontItem.CellNumber; //更改其它 cell index for (int i = 0; i < scolerIterms.Count; i++) { ScollerItemBase tmpIterm = scolerIterms[i]; if (tmpIterm.CellIndex >= insertIndex) { tmpIterm.CellNumber += 1; tmpIterm.CellIndex += 1; } } // 将最后一个cell 移动要要插入的位置 inserIterm.MoveTo(frontItem); inserIterm.CellNumber = tmpCellNub; inserIterm.CellIndex = tmpIndex; ChangeBackCellPos(tmpCellNub); //for (int i = 0; i < scolerIterms.Count; i++) //{ // ScollerMoveIterm tmpIterm = (ScollerMoveIterm)scolerIterms[i]; // Debug.Log("tmpIterm.cell index===" + tmpIterm.CellIndex + "==cell number==" + tmpIterm.CellNumber); // if (tmpIterm.CellIndex > inserIterm.CellIndex) // { // ScollerItemBase tmpFront = FindCellByIndex(tmpIterm.CellIndex - 1); // tmpIterm.CaculateMovePosition(tmpFront); // } //} // inserIterm.CellLocalPosition = inserIterm.GetTargetPosition(); // inserIterm.cellIndex = frontItem.cellIndex + 1; }
public void DeleteCell(int cellIndex, Object cellObj) { if (genScollerHelp != null) { if (cellToatalCount <= 0 || sollerAnimal.PlayingAnimal) { return; } ScollerItemBase tmpDeleteCell = sollerAnimal.FindCellByIndex(cellIndex); if (tmpDeleteCell == null) { return; } genScollerHelp.DeleteCell(); IsPlayingAnimal = genScollerHelp.IsPlayingAnimal; cellToatalCount -= 1; if (cellToatalCount <= 0) { return; } ///如果还是无限滚动在最后增加一个单元格 如果不是了 就删除单元格 if (!IsPlayingAnimal) { sollerAnimal.DeleteContent(cellIndex); } else { //先在最后添加一个 genScollerHelp.AddContent(cellObj); RectTransform content = transform.GetChild(0).GetComponent <RectTransform>(); sollerAnimal.AddCellToLastCellNumber(content); // 当前的删除掉 sollerAnimal.DeleteContent(tmpDeleteCell.CellIndex); } looper.RefushCellCount(); } }
public void FollowBack(ScollerItemBase backItem) { Vector3 tmpPos = backItem.CellLocalPosition; if (direct == ScollerDirect.Horizontal) { tmpPos.y -= GetCellHeight(); CellLocalPosition = tmpPos; } else { tmpPos.y += GetCellHeight(); CellLocalPosition = tmpPos; } }
public virtual void ExChangeCell(ScollerItemBase toItem, byte direct) { //向右 if (direct == 1) { cellNumber = (sbyte)(toItem.cellNumber - 1); cellIndex = toItem.cellIndex - 1; float tmpX = toItem.GetTargetPosition().x - GetCellWidth(); //Mathf.Abs(toItem.GetTargetPosition().x) - Mathf.Abs(cellWidth); cellTransform.localPosition = new Vector3(tmpX, toItem.GetTargetPosition().y, toItem.GetTargetPosition().z); }// 向左 else if (direct == 2) { cellNumber = (sbyte)(toItem.cellNumber + 1); float tmpX = Mathf.Abs(toItem.GetTargetPosition().x) + Mathf.Abs(toItem.GetCellWidth()); cellTransform.localPosition = new Vector3(tmpX, toItem.GetTargetPosition().y, toItem.GetTargetPosition().z); cellIndex = toItem.cellIndex + 1; } // 向下拖 else if (direct == 3) { cellNumber = (sbyte)(toItem.cellNumber - 1); cellIndex = toItem.cellIndex - 1; float tmpY = GetCellHeight(); // Mathf.Abs(toItem.GetTargetPosition().y) - Mathf.Abs(cellHeight); cellTransform.localPosition = new Vector3(toItem.GetTargetPosition().x, toItem.GetTargetPosition().y + tmpY, toItem.GetTargetPosition().z); } // 向上拖 else if (direct == 4) { cellNumber = (sbyte)(toItem.cellNumber + 1); cellIndex = toItem.cellIndex + 1; float tmpY = Mathf.Abs(toItem.GetTargetPosition().y) + Mathf.Abs(toItem.GetCellHeight()); cellTransform.localPosition = new Vector3(toItem.GetTargetPosition().x, -tmpY, toItem.GetTargetPosition().z); } targetPos = cellTransform.localPosition; }
public override void CellWillChange(ScollerItemBase from, ScollerItemBase to, byte direct) { base.CellWillChange(from, to, direct); ScollerMoveIterm tmpFront = (ScollerMoveIterm)from; bool hidden = tmpFront.HiddenNoAnimal(); //if (hidden) //{ // ChangeBackCellPos(tmpFront.cellNumber); //} }
// public void FollowFront(ScollerItemBase frontItem) { Vector3 frontPos = frontItem.GetTargetPosition(); if (direct == ScollerDirect.Horizontal) { frontPos.x += frontItem.GetCellWidth(); } else { frontPos.y -= frontItem.GetCellHeight(); } targetPos = cellTransform.localPosition = frontPos; }
private void UpdateContent() { ScollerItemBase tmpItem = FindCell(cellCount - 1); // Debug.Log(" last tmpItem.cellIndex== " + tmpItem.cellIndex); if (Direct == ScollerDirect.Horizontal) { float tmpWidth = Mathf.Abs(tmpItem.cellTransform.localPosition.x) + tmpItem.GetCellWidth(); content.sizeDelta = new Vector2(tmpWidth, content.sizeDelta.y); } else { float tmpHeigth = Mathf.Abs(tmpItem.cellTransform.localPosition.y) + tmpItem.GetCellHeight(); content.sizeDelta = new Vector2(content.sizeDelta.x, tmpHeigth); } }
public void FollowFront(int cellnumber) { for (int i = 0; i < scolerIterms.Count; i++) { if (scolerIterms[i].CellNumber > cellnumber) { ScollerItemBase tmpItem = scolerIterms[i]; ScollerItemBase tmpFront = FindCellByNumber(tmpItem.CellNumber - 1); if (tmpFront != null) { tmpItem.FollowFront(tmpFront); // tmpItem.CaculateTargetPosition(currentOpeCell.hidlePanel.sizeDelta, currentOpeCell.isHide); } } } }
public void UpdateContentHead() { ScollerItemBase tmpLast = FindCell(0); if (tmpLast.CellLocalPosition != Vector3.zero) { content.localPosition = contentLocalPosition; // Debug.Log("coming 1111111111111" + tmpLast.CellLocalPosition); tmpLast.CellLocalPosition = Vector3.zero; scollerAnimal.FollowFront(0); } //if (Direct == ScollerDirect.Vertical) //{ // if (tmpLast.CellLocalPosition!= Vector3.zero) // { // tmpLast.CellLocalPosition = Vector3.zero; // scollerAnimal.FollowFront(0); // } //} //else //{ // if (tmpLast.CellLocalPosition.x != 0) // { // tmpLast.CellLocalPosition = Vector3.zero; // scollerAnimal.FollowFront(0); // } //} // firstItem.FollowBack(tmpLast); }
public void CaculateMovePosition(ScollerItemBase frontItem) { Vector3 frontPos = frontItem.GetTargetPosition(); if (direct == ScollerDirect.Horizontal) { frontPos.x += frontItem.GetCellWidth(); } else { frontPos.y -= frontItem.GetCellHeight(); } isPlaying = true; //UnityEngine.Debug.Log("CaculateMovePosition isPlaying" + cellIndex); animalState = 2; targetPos = frontPos; }
private void ExchangeCellAndAnimal(int from, byte tmpDirect, ScollerItemBase lastItem) { ScollerItemBase fromItem = FindCell(from); fromItem.WillChangeCell(lastItem, tmpDirect); scollerAnimal.CellWillChange(fromItem, lastItem, tmpDirect); fromItem.ExChangeCell(lastItem, tmpDirect); scollerAnimal.CellExchange(fromItem, lastItem, tmpDirect); updateCell(fromItem.CellIndex, fromItem); fromItem.ChangeCellFinish(lastItem, tmpDirect); scollerAnimal.CellWillChangeFinish(fromItem, lastItem, tmpDirect); }
public virtual void CellExchange(ScollerItemBase from, ScollerItemBase to, byte direct) { if (direct == 1 || direct == 3) { for (int i = 0; i < scolerIterms.Count; i++) { ScollerItemBase tmpItem = scolerIterms[i]; tmpItem.CellNumber += 1; // tmpItem.cellTransform.name = "Item" + tmpItem.cellNumber +"==index=="+tmpItem.cellIndex; } } else if (direct == 2 || direct == 4) { for (int i = 0; i < scolerIterms.Count; i++) { ScollerItemBase tmpItem = scolerIterms[i]; tmpItem.CellNumber -= 1; // tmpItem.cellTransform.name = "Item" + tmpItem.cellNumber + "==index==" + tmpItem.cellIndex ; } } }
public virtual void WillChangeCell(ScollerItemBase toItem, byte direct) { }
/// <summary> /// /// </summary> /// <param name="from"></param> /// <param name="toIndex"></param> /// <param name="tmpDirect"> 1 水平右 2 水平左 4,竖直上 3,竖直下 </param> private void ExchangeCell(int from, int toIndex, byte tmpDirect) { switch (tmpDirect) { // 1 水平右 case 1: { ScollerItemBase tmpLast = FindCell(toIndex); if (tmpLast.CellIndex <= 0) { Debug.Log(" 1111111111111111111 ==" + toIndex); UpdateContentHead(); return; } ExchangeCellAndAnimal(from, tmpDirect, tmpLast); UpdateContent(); } break; case 2: { ScollerItemBase tmpLast = FindCell(toIndex); if (tmpLast.CellIndex >= totalCellCount - 1) { UpdateContent(); return; } ExchangeCellAndAnimal(from, tmpDirect, tmpLast); UpdateContent(); } break; // 3,竖直下 case 3: { ScollerItemBase tmpLast = FindCell(toIndex); // Debug.Log("tmpLast.cellIndex 333333==2222=" + tmpLast.CellIndex + "==from==" + from + "==toIndex ==" + toIndex); if (tmpLast.CellIndex <= 0) { UpdateContentHead(); return; } ExchangeCellAndAnimal(from, tmpDirect, tmpLast); UpdateContent(); } break; //4,竖直上 case 4: { ScollerItemBase tmpLast = FindCell(toIndex); if (tmpLast.CellIndex >= totalCellCount - 1) { UpdateContent(); return; } ExchangeCellAndAnimal(from, tmpDirect, tmpLast); UpdateContent(); } break; } }
public virtual void CellWillChangeFinish(ScollerItemBase from, ScollerItemBase to, byte direct) { }
private void ScolerValueChange(Vector2 pos) { if (!IsPlayingAnimal) { return; } RefushCellCount(); Vector3 contPos = content.InverseTransformPoint(conner); ScollerItemBase tmpItem = FindCell(1); byte tmpDirect = RejugdeDirect(contPos, tmpItem); if (tmpDirect == 0) { return; } switch (tmpDirect) { // 1 水平右 case 1: { float tmpFloat = Mathf.Abs(contPos.x - tmpItem.GetTargetPosition().x); ScollerItemBase iterm0 = FindCell(0); if (tmpFloat >= iterm0.GetCellWidth() * 0.5f && contPos.x < tmpItem.GetTargetPosition().x) { ExchangeCell(cellCount - 1, 0, tmpDirect); } // UpdateContent(); } break; //2 水平左 case 2: { float tmpFloat = Mathf.Abs(tmpItem.GetTargetPosition().x - contPos.x); if (tmpFloat >= tmpItem.GetCellWidth() * 0.5f && contPos.x > tmpItem.GetTargetPosition().x) { ExchangeCell(0, cellCount - 1, tmpDirect); } // UpdateContent(); } break; // 4,向上拖 case 4: { float tmpFloat = Mathf.Abs(tmpItem.GetTargetPosition().y - contPos.y); if ((tmpFloat >= tmpItem.GetCellHeight() * 0.5f) && (tmpItem.GetTargetPosition().y > contPos.y)) { ExchangeCell(0, cellCount - 1, tmpDirect); } // UpdateContent(); } break; //3,向下拖 case 3: { float tmpFloat = Mathf.Abs(contPos.y - tmpItem.GetTargetPosition().y); ScollerItemBase iterm0 = FindCell(0); if (tmpFloat >= iterm0.GetCellHeight() * 0.8f && tmpItem.GetTargetPosition().y < contPos.y) { ExchangeCell(cellCount - 1, 0, tmpDirect); } // UpdateContent(); } break; } }
public ScollerLooper(ScrollRect scol, RectTransform cont, int cout, ScollerAnimal animal, UpdateCellDelegate update) { scoller = scol; content = cont; updateCell = update; totalCellCount = cout; // Debug.Log("totalCellCount=="+ totalCellCount); contentLocalPosition = cont.localPosition; if (scol.horizontal) { Direct = ScollerDirect.Horizontal; } else { Direct = ScollerDirect.Vertical; // connerTwo.y += content.sizeDelta.y; } if (animal != null) { scollerAnimal = animal; scolerIterms = animal.scolerIterms; } else { scollerAnimal = new ScollerAnimal(content, direct); scolerIterms = scollerAnimal.scolerIterms; } // cellCount = scolerIterms.Count; RefushCellCount(); scollerAnimal.cellListen = new ScollerAnimal.CellChangeListen(UpdateContent); // ScollerItemBase tmpItem2 = FindCell(1); conner = cont.TransformPoint(Vector3.zero); //connerTwo = cont.TransformPoint(Vector3.zero); // scollerAnimal.Direct = Direct; Vector3 tmpConor = cont.InverseTransformPoint(conner); scoller.onValueChanged.AddListener(ScolerValueChange); }
public virtual void ChangeCellFinish(ScollerItemBase toItem, byte direct) { }
public override void ExChangeCell(ScollerItemBase toItem, byte direct) { base.ExChangeCell(toItem, direct); }
public override void ChangeCellFinish(ScollerItemBase toItem, byte direct) { base.ChangeCellFinish(toItem, direct); Reset(); }