public void SortPocketListAfterPlay() { Debug.Log("!!!!SortPocketListAfterPlay"); if (PocketLocator.childCount <= 0) { Debug.Log("nopockets"); return; } //updatePocketPosition(); if (_playIndex == -1) { Debug.LogError("errororoororororoor"); } // before play, pockets count == n // after play, pockets count == n - 1 // played index caculated before play if (_playIndex == PocketLocator.childCount) { _drawTile = null; _playIndex = -1; Debug.Log("play last one"); return; } MahjongTile iter = null; int insertIndex = -1; if (_drawTile != null) { for (int i = 0; i < _sortPocketList.Count; ++i) { iter = _sortPocketList [i]; iter.ClickCount = 0; if (TileDef.Comparison(_drawTile.Def, iter.Def) <= 0) { insertIndex = i; break; } } Debug.Log("!!!!_drawTile " + _drawTile + " " + Proxy.Index + " sort after play " + insertIndex + "####" + _playIndex); } if (insertIndex == -1 && _playIndex >= 0) { for (int i = _playIndex; i < _sortPocketList.Count; ++i) { Vector3 pos = i * _direction * MahjongTile.Width; _sortPocketList [i].Moveto(pos, true); } Debug.Log("!!!!return" + Proxy.Index + " sort after play " + insertIndex + "####" + _playIndex); return; } Debug.Log(Proxy.Index + " sort after play " + insertIndex + "####" + _playIndex); if (insertIndex > _playIndex) { for (int i = _playIndex; i < insertIndex; ++i) { Vector3 pos = i * _direction * MahjongTile.Width; _sortPocketList [i].ClickCount = 0; _sortPocketList [i].Moveto(pos, true); } } else if (insertIndex < _playIndex) { for (int i = insertIndex; i < _playIndex; ++i) { Vector3 pos = (i + 1) * _direction * MahjongTile.Width; _sortPocketList [i].ClickCount = 0; _sortPocketList [i].Moveto(pos, true); } } Vector3 insertPosition = insertIndex * _direction * MahjongTile.Width; _sortPocketList.Remove(_drawTile); _sortPocketList.Insert(insertIndex, _drawTile); if (insertIndex < _sortPocketList.Count - 1) { _drawTile.Insert(insertPosition, true); } else { _drawTile.Moveto(insertPosition, true); } _drawTile = null; _playIndex = -1; Debug.Log(Proxy.Index + "playindex -1 @@@"); }