void SetAnchor(HorizontalPivot varPivot, UIRect.AnchorPoint varAnchorPoint, float varAbsolute) { if (varPivot == HorizontalPivot.Left) { varAnchorPoint.Set(0f, varAbsolute); } else if (varPivot == HorizontalPivot.Center) { varAnchorPoint.Set(0.5f, varAbsolute); } else { varAnchorPoint.Set(1f, varAbsolute); } }
protected static Vector3 GetPivotOrigin(HorizontalPivot horizontal, VerticalPivot vertical, Rect rect, float scaledWidth) { Vector3 origin = new Vector3(); switch (horizontal) { case HorizontalPivot.Left: origin.x = rect.xMin + scaledWidth; break; case HorizontalPivot.Right: origin.x = rect.xMax; break; case HorizontalPivot.Center: default: origin.x = scaledWidth / 2f; break; } switch (vertical) { case VerticalPivot.Top: origin.y = rect.yMax; break; case VerticalPivot.Bottom: origin.y = rect.yMin; break; case VerticalPivot.Center: default: origin.y = 0f; break; } return(origin); }
public void Resize( int width,int height,HorizontalPivot horizontalPivot,VerticalPivot verticalPivot ) { if( _Width == width && _Height == height ) { return; } Point2 offset = new Point2(0,0); switch( horizontalPivot ) { case HorizontalPivot.Left: offset.x = 0; break; case HorizontalPivot.Center: offset.x = (width-_Width)/2; break; case HorizontalPivot.Right: offset.x = width-_Width; break; } switch( verticalPivot ) { case VerticalPivot.Top: offset.y = height-_Height; break; case VerticalPivot.Center: offset.y = (height-_Height)/2; break; case VerticalPivot.Bottom: offset.y = 0; break; } _Width = width; _Height = height; List<Point2> removeCells = new List<Point2>(); foreach( Cell cell in _Cells ) { if( offset.x != 0 || offset.y != 0 ) { Point2 preChunkPos = cell.position/32; Chunk preChunk = GetChunk( preChunkPos ); preChunk.dirty = true; cell.position += offset; if( cell.collider != null ) { float halfSize = 0.5f; Vector3 localPos = MapPointToLocalPoint( cell.position ); #if UNITY_5 cell.collider.offset = new Vector2( localPos.x+halfSize,localPos.y+halfSize ); #else cell.collider.center = new Vector2( localPos.x+halfSize,localPos.y+halfSize ); #endif } Point2 nextChunkPos = cell.position/32; Chunk nextChunk = GetChunk( nextChunkPos ); if( nextChunk == null ) { nextChunk = AddChunk( nextChunkPos ); } nextChunk.dirty = true; } if( !IsCellContains( cell.position ) ) { removeCells.Add( cell.position ); } } _ChangedCellDic = offset.x != 0 || offset.y != 0; foreach( Point2 pos in removeCells ) { RemoveTile( pos,false ); } }
protected static void SetRendererPosition(ref Vector3 caret, Transform trans, HorizontalPivot horizontal, VerticalPivot vertical, Bounds spriteBounds, float scale, float spacing) { Vector3 offset = new Vector3(); offset.x = -(spriteBounds.center.x + spriteBounds.extents.x) * scale; switch (vertical) { case VerticalPivot.Top: offset.y = -(spriteBounds.center.y + spriteBounds.extents.y) * scale; break; case VerticalPivot.Bottom: offset.y = spriteBounds.center.y + spriteBounds.extents.y * scale; break; } trans.localPosition = caret + offset; trans.localScale = new Vector3(scale, scale, 1f); caret.x -= spriteBounds.size.x * scale + spacing; }