//获取精灵信息 private SpriteInfor GetSpriteInfo(int index, int row, int column, Vector2 size, Vector2 texSize) { SpriteInfor infor = Pool <SpriteInfor> .Get(); infor.Id = index; infor.Rect = new Rect(size.y * column, texSize.y - (row + 1) * size.x, size.x, size.y); infor.DrawTexCoord = new Rect(infor.Rect.x / texSize.x, infor.Rect.y / texSize.y , infor.Rect.width / texSize.x, infor.Rect.height / texSize.y); infor.Uv = GetSpriteUV(texSize, infor.Rect); return(infor); }
/// <summary> /// 更新信息 /// </summary> public void UpdateSpriteGroup() { if (_spriteAsset && _spriteAsset.TexSource && _spriteAsset.Row > 1 && _spriteAsset.Column > 1) { int count = _spriteAsset.IsStatic ? _spriteAsset.Row * _spriteAsset.Column : _spriteAsset.Row; if (_spriteAsset.ListSpriteGroup.Count != count) { _spriteAsset.ListSpriteGroup.Clear(); //更新 //---------------------------------- Vector2 texSize = new Vector2(_spriteAsset.TexSource.width, _spriteAsset.TexSource.height); Vector2 size = new Vector2((_spriteAsset.TexSource.width / (float)_spriteAsset.Column) , (_spriteAsset.TexSource.height / (float)_spriteAsset.Row)); if (_spriteAsset.IsStatic) { int index = -1; for (int i = 0; i < _spriteAsset.Row; i++) { for (int j = 0; j < _spriteAsset.Column; j++) { index++; SpriteInforGroup inforGroup = Pool <SpriteInforGroup> .Get(); SpriteInfor infor = GetSpriteInfo(index, i, j, size, texSize); inforGroup.Tag = "emoji_" + infor.Id; inforGroup.ListSpriteInfor.Add(infor); _spriteAsset.ListSpriteGroup.Add(inforGroup); } } } else { int index = -1; for (int i = 0; i < _spriteAsset.Row; i++) { SpriteInforGroup inforGroup = Pool <SpriteInforGroup> .Get(); inforGroup.Tag = "emoji_" + (index + 1); for (int j = 0; j < _spriteAsset.Column; j++) { index++; SpriteInfor infor = GetSpriteInfo(index, i, j, size, texSize); inforGroup.ListSpriteInfor.Add(infor); } _spriteAsset.ListSpriteGroup.Add(inforGroup); } } } } }