bool GenerateIndices( Cell cell ) { int oldPartsID = cell.partsID; cell.partsID = 0; Point2 aroundPos = new Point2(); int id = cell.tileID; for( int y=0;y<2;y++ ) { for( int x=0;x<2;x++ ) { int vx = (x%2==0)?-1:1; int vy = (y%2==0)?1:-1; aroundPos.x = cell.position.x + 0; aroundPos.y = cell.position.y + vy; int longitudinalID = id; if( IsCellContains( aroundPos ) ) { longitudinalID = GetTileID( aroundPos ); } aroundPos.x = cell.position.x + vx; aroundPos.y = cell.position.y + 0; int transverseID = id; if( IsCellContains( aroundPos ) ) { transverseID = GetTileID( aroundPos ); } aroundPos.x = cell.position.x + vx; aroundPos.y = cell.position.y + vy; int obliqueID = id; if( IsCellContains( aroundPos ) ) { obliqueID = GetTileID( aroundPos ); } int index = 4; if (id == transverseID && id == longitudinalID && id == obliqueID) index = 0; else if (id == transverseID && id == longitudinalID) index = 3; else if (id == longitudinalID) index = 2; else if (id == transverseID) index = 1; cell.SetPartsIndex( x,y,index ); } } if( cell.partsID != oldPartsID ) { Chunk chunk = GetChunk ( cell.position/32 ); if( chunk != null ) { chunk.dirty = true; } return true; } return false; }
void UpdateEraser() { int controlID = GUIUtility.GetControlID(GetHashCode(), FocusType.Passive); Event current = Event.current; EventType eventType = current.GetTypeForControl( controlID ); if( eventType == EventType.MouseUp ) { if( GUIUtility.hotControl == controlID ) { GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; Undo.CollapseUndoOperations( Undo.GetCurrentGroup() ); current.Use (); System.GC.Collect(); } } Point2 pos; if( !_Map.RayToPoint( HandleUtility.GUIPointToWorldRay( current.mousePosition ),out pos ) ) { return; } int cursorWidth = NostalgiaSettings.cursorWidth; int cursorHeight = NostalgiaSettings.cursorHeight; Point2 minPos = new Point2( pos.x-cursorWidth/2,pos.y-cursorHeight/2 ); DrawCursor( minPos,cursorWidth,cursorHeight ); bool dirty = false; switch( eventType ) { case EventType.MouseDown: if( current.button == 0 ) { GUIUtility.hotControl = GUIUtility.keyboardControl = controlID; Undo.IncrementCurrentGroup(); Undo.RegisterCompleteObjectUndo( records.ToArray(),"Erase Tile" ); for( int x=0;x<cursorWidth;x++ ) { for( int y=0;y<cursorHeight;y++ ) { if( _Map.RemoveTile( minPos+new Point2(x,y),!current.shift ) ) { dirty = true; } } } Undo.CollapseUndoOperations( Undo.GetCurrentGroup() ); current.Use (); } break; case EventType.MouseDrag: if( GUIUtility.hotControl == controlID ) { if( current.button == 0 ) { Undo.RegisterCompleteObjectUndo( records.ToArray(),"Erase Tile" ); for( int x=0;x<cursorWidth;x++ ) { for( int y=0;y<cursorHeight;y++ ) { if( _Map.RemoveTile( minPos+new Point2(x,y),!current.shift ) ) { dirty = true; } } } Undo.CollapseUndoOperations( Undo.GetCurrentGroup() ); current.Use (); } } break; } if( dirty ) { EditorUtility.SetDirty( _Map ); } }
Chunk AddChunk( Point2 pos ) { GameObject obj = ComponentUtility.CreateGameObject( "Chunk"); obj.hideFlags = HideFlags.HideInHierarchy; obj.transform.parent = transform; obj.transform.localPosition = Vector3.zero; obj.transform.localRotation = Quaternion.identity; obj.transform.localScale = Vector3.one; Chunk chunk = obj.AddComponent<Chunk>(); chunk.map = this; chunk.position = pos; chunk.sortingLayerID = _SortingLayerID; chunk.sortingOrder = _SortingOrder; chunkDic.Add( pos,chunk ); _Chunks.Add ( chunk ); return chunk; }
public bool FillTile( Point2 pos,int width,int height,int tileID,int partsID,bool autoTiling ) { bool changed = false; if( _FilledCells != null ) { _FilledCells.Clear(); } else { _FilledCells = new HashSet<Point2>(); } for( int x=0;x<width;x++ ) { for( int y=0;y<height;y++ ) { Point2 tilePos = new Point2(x,height-y-1); Point2 cellPos = pos+new Point2(x,y); if( IsCellContains( cellPos ) ) { if( PutTile( cellPos,tileID,partsID,tilePos,false,!autoTiling ) || autoTiling ) { _FilledCells.Add( cellPos ); changed = true; } } } } if( autoTiling ) { HashSet<Point2> aroundCells = new HashSet<Point2>(); foreach( Point2 currentPos in _FilledCells ) { Cell cell = GetCell( currentPos ); if( GenerateIndices( cell ) ) { changed = true; } for( int x=-1;x<=1;x++ ) { for( int y=-1;y<=1;y++ ) { if( x==0 && y==0 ) { continue; } Point2 aroundPos = cell.position + new Point2( x,y ); if( IsCellContains( aroundPos ) && !_FilledCells.Contains( aroundPos ) ) { aroundCells.Add( aroundPos ); } } } } foreach( Point2 aroundPos in aroundCells ) { Cell cell = GetCell( aroundPos ); if( cell != null ) { if( GenerateIndices( cell ) ) { changed = true; } } } } return changed; }
public Tile GetTile( Point2 pos ) { return GetTile( GetCell( pos ) ); }
void ScanLine( int leftX, int rightX, int y,Stack<Point2> stack ) { Point2 leftPos = new Point2(leftX, y); while( leftPos.x <= rightX ) { for (; leftPos.x <= rightX; leftPos.x++) { if( !_FilledCells.Contains( leftPos ) && GetTileID( leftPos ) == _FillFirstTileID ) { break; } } if( rightX < leftPos.x ) break; for (; leftPos.x <= rightX; leftPos.x++) { if( GetTileID( leftPos ) != _FillFirstTileID) { break; } } stack.Push( new Point2(leftPos.x - 1, leftPos.y) ); } }
public bool ColorBrush( Vector2 center,float radius,Color color,bool halftile ) { Vector2 extents = new Vector2( radius,radius ); Point2 mapMinPos = LocalPointToMapPoint( center-extents ); Point2 mapMaxPos = LocalPointToMapPoint( center+extents ); float halfSize = 0.5f; bool dirty = false; Point2 mapPos = new Point2(); for( mapPos.x = mapMinPos.x;mapPos.x<=mapMaxPos.x;++mapPos.x ) { for( mapPos.y = mapMinPos.y;mapPos.y<=mapMaxPos.y;++mapPos.y ) { Cell cell = GetCell( mapPos ); if( cell == null ) { continue; } Vector2 cellPos = MapPointToLocalPoint( cell.position ); for( int y=0;y<2;y++ ) { for( int x=0;x<2;x++ ) { Vector2 vertex = cellPos + new Vector2( x*halfSize,(1-y)*halfSize ); Vector2[] vertices = new Vector2[]{ vertex + new Vector2( 0.0f, halfSize), vertex + new Vector2( halfSize, halfSize), vertex + new Vector2( 0.0f, 0.0f), vertex + new Vector2( halfSize, 0.0f), }; bool check = true; for( int index=0;index<4;index++ ) { if( halftile ) { if( (vertices[index]-center).magnitude > radius ) { check = false; } } else { float t = 1.0f-Mathf.Clamp01( (vertices[index]-center).magnitude / radius ); Color oldColor = cell.GetVertexColor(x,y,index); Color nextColor = Color.Lerp( oldColor,color,t ); cell.SetVertexColor( x,y,index,nextColor ); if( t != 0.0f ) { dirty = true; } } } if( halftile && check ) { for( int index=0;index<4;index++ ) { cell.SetVertexColor( x,y,index,color ); } dirty = true; } } } Point2 chunkPos = cell.position/32; Chunk chunk = GetChunk( chunkPos ); if( chunk != null ) { chunk.dirty = true; } } } return dirty; }
public void UpdateMesh() { Mesh mesh = cachedMesh; mesh.Clear(); if( map == null || map.tileSet == null || map.tileSet.material == null ) { return; } _MeshRenderer.sharedMaterial = map.material; Point2 basePos = GetBasePos(); int xMax = Mathf.Min( basePos.x+32,map.width ); int yMax = Mathf.Min( basePos.y+32,map.height ); Point2 pos = new Point2(); for( pos.x = basePos.x;pos.x<xMax;pos.x++ ) { for( pos.y = basePos.y;pos.y<yMax;pos.y++ ) { Cell cell = map.GetCell( pos ); if( cell!= null ) { UpdateTile( cell ); } } } mesh.vertices = _Vertices.ToArray(); mesh.colors = _Colors.ToArray(); mesh.uv = _UVs.ToArray(); mesh.uv2 = _Animations.ToArray(); mesh.triangles = _Indices.ToArray(); mesh.RecalculateNormals(); mesh.RecalculateBounds(); _Vertices.Clear(); _Colors.Clear (); _UVs.Clear (); _Animations.Clear(); _Indices.Clear(); }
public Vector3 MapPointToLocalPoint( Point2 pos ) { return new Vector3( pos.x , pos.y,0.0f ); }
public Point2( Point2 p ) { this.x = p.x; this.y = p.y; }
/// <summary> /// SortingOrderの取得もしくは設定。 /// </summary> /// <value> /// Sorting Order /// </value> /// <summary> /// Gets or sets the sorting order. /// </summary> /// <value> /// The sorting order. /// </value> #else #endif #region Methods public bool HadCells() { Point2 basePos = GetBasePos(); int xMax = Mathf.Min( basePos.x+32,map.width ); int yMax = Mathf.Min( basePos.y+32,map.height ); Point2 pos = new Point2(); for( pos.x = basePos.x;pos.x<xMax;pos.x++ ) { for( pos.y = basePos.y;pos.y<yMax;pos.y++ ) { Cell cell = map.GetCell( pos ); if( cell!= null ) { return true; } } } return false; }
/// <summary> /// タイルID。 /// <see cref="Nostalgia.TileSet.tiles"/>のインデックス。 /// </summary> /// <summary> /// The tile ID. /// Index of <see cref="Nostalgia.TileSet.tiles"/>. /// </summary> #else #endif #if NOSTALGIA_DOC_JA /// <summary> /// タイル内の位置 /// </summary> /// <summary> /// Position within the tile. /// </summary> #else #endif #if NOSTALGIA_DOC_JA /// <summary> /// パーツID。 /// オートタイルのパーツ状態。 /// </summary> /// <summary> /// The parts ID. /// Parts of the state auto tile. /// </summary> #else #endif #if NOSTALGIA_DOC_JA /// <summary> /// Collider /// </summary> /// <summary> /// The collider. /// </summary> #else #endif #if NOSTALGIA_DOC_JA /// <summary> /// <see cref="Nostalgia.Cell"/>クラスの新しいインスタンスを初期化。 /// </summary> /// <param name="position"> /// 座標 /// </param> /// <param name="tileID"> /// タイルID /// </param> /// <summary> /// Initializes a new instance of the <see cref="Nostalgia.Cell"/> class. /// </summary> /// <param name="position"> /// Position. /// </param> /// <param name="tileID"> /// Tile ID. /// </param> #else #endif #region Constructors public Cell( Point2 position,int tileID ) { this.position = new Point2(position); this.tileID = tileID; }
void UpdateRectabgle() { int controlID = GUIUtility.GetControlID(GetHashCode(), FocusType.Passive); Event current = Event.current; Point2 pos; bool hit = _Map.RayToPoint( HandleUtility.GUIPointToWorldRay( current.mousePosition ),out pos ); Point2 minPos = new Point2(); int width = 1; int height = 1; if( GUIUtility.hotControl == controlID ) { minPos.x = Mathf.Min( pos.x,_BeginPos.x ); minPos.y = Mathf.Min( pos.y,_BeginPos.y ); width = Mathf.Max( pos.x,_BeginPos.x ) - minPos.x + 1; height = Mathf.Max( pos.y,_BeginPos.y ) - minPos.y + 1; DrawCursor( minPos,width,height ); } else { if( hit ) { DrawCursor( pos,1,1 ); } } switch( current.GetTypeForControl( controlID ) ) { case EventType.MouseDown: if( hit) { if( current.button == 0 ) { GUIUtility.hotControl = GUIUtility.keyboardControl = controlID; _BeginPos = pos; current.Use (); } } break; case EventType.MouseUp: if( GUIUtility.hotControl == controlID ) { GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; Undo.IncrementCurrentGroup(); Undo.RegisterCompleteObjectUndo( records.ToArray(),"Fill Tile" ); if( _Map.FillTile( minPos,width,height,_CurrentTileID,_CurrentPartsID,!current.shift ) ) { EditorUtility.SetDirty( _Map ); } Undo.CollapseUndoOperations( Undo.GetCurrentGroup() ); current.Use (); System.GC.Collect(); } break; } }
void UpdatePencil() { int controlID = GUIUtility.GetControlID(GetHashCode(), FocusType.Passive); Event current = Event.current; EventType eventType = current.GetTypeForControl( controlID ); if( eventType == EventType.MouseUp ) { if( GUIUtility.hotControl == controlID ) { GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; Undo.CollapseUndoOperations( Undo.GetCurrentGroup() ); current.Use (); System.GC.Collect(); } } Point2 pos; if( !_Map.RayToPoint( HandleUtility.GUIPointToWorldRay( current.mousePosition ),out pos ) ) { return; } int cursorWidth = NostalgiaSettings.cursorWidth; int cursorHeight = NostalgiaSettings.cursorHeight; Tile currentTile = _Map.tileSet.tiles[_CurrentTileID]; if( currentTile.type == Tile.Type.Normal ) { cursorWidth = Mathf.Max(cursorWidth,currentTile.width); cursorHeight = Mathf.Max(cursorHeight,currentTile.height); } Point2 minPos = new Point2( pos.x-cursorWidth/2,pos.y-cursorHeight/2 ); DrawCursor( minPos,cursorWidth,cursorHeight ); switch( eventType ) { case EventType.MouseDown: if( current.button == 0 ) { GUIUtility.hotControl = GUIUtility.keyboardControl = controlID; Undo.IncrementCurrentGroup(); Undo.RegisterCompleteObjectUndo( records.ToArray(),"Put Tile" ); if( _Map.FillTile( minPos,cursorWidth,cursorHeight,_CurrentTileID,_CurrentPartsID,!current.shift ) ) { EditorUtility.SetDirty( _Map ); } Undo.CollapseUndoOperations( Undo.GetCurrentGroup() ); current.Use (); } break; case EventType.MouseDrag: if( GUIUtility.hotControl == controlID ) { if( current.button == 0 ) { Undo.RegisterCompleteObjectUndo( records.ToArray(),"Put Tile" ); if( _Map.FillTile( minPos,cursorWidth,cursorHeight,_CurrentTileID,_CurrentPartsID,!current.shift ) ) { EditorUtility.SetDirty( _Map ); } Undo.CollapseUndoOperations( Undo.GetCurrentGroup() ); current.Use (); } } break; } }
Chunk GetChunk( Point2 pos ) { Chunk chunk = null; if( chunkDic.TryGetValue( pos,out chunk ) ) { return chunk; } return null; }
public Vector3 MapPointToWorldPoint( Point2 pos ) { return transform.TransformPoint( MapPointToLocalPoint( pos ) ); }
bool IsCellContains( Point2 pos ) { return 0<=pos.x && pos.x < _Width && 0<=pos.y && pos.y < _Height; }
public bool PutTile( Point2 pos,int tileID,int partsID,Point2 tilePos,bool autoTiling,bool changeParts ) { bool changed = false; if( !IsCellContains( pos ) ) { return false; } bool add = false; Point2 chunkPos = pos/32; Chunk chunk = GetChunk( chunkPos ); if( chunk == null ) { chunk = AddChunk( chunkPos ); changed = true; } Cell cell = GetCell( pos ); if( cell == null ) { cell = new Cell( pos,tileID ); add = true; changed = true; } Tile tile = _TileSet.tiles[tileID]; if( tile.collider ) { if( cell.collider == null ) { cell.collider = ComponentUtility.AddComponent<BoxCollider2D>( gameObject ); cell.collider.hideFlags = HideFlags.HideInInspector; } cell.collider.sharedMaterial = tile.physicsMaterial; cell.collider.isTrigger = tile.isTrigger; float halfSize = 0.5f; Vector3 localPos = MapPointToLocalPoint( pos ); #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 cell.collider.size = new Vector2( 1.0f,1.0f ); if( _ColliderCellDic != null && !_ColliderCellDic.ContainsKey( cell.collider ) ) { _ColliderCellDic.Add( cell.collider,cell ); } } else { if( cell.collider != null ) { if( _ColliderCellDic != null && _ColliderCellDic.ContainsKey( cell.collider ) ) { _ColliderCellDic.Remove( cell.collider ); } ComponentUtility.Destroy( cell.collider ); cell.collider = null; } } Point2 tilePosTmp = ( tile.type == Tile.Type.Normal )?new Point2( Mod(tilePos.x,tile.width),Mod(tilePos.y,tile.height) ) : Point2.zero; if( cell.tilePos != tilePosTmp ) { cell.tilePos = tilePosTmp; changed = true; } if( add ) { _Cells.Add( cell ); if( _CellDic != null ) { _CellDic.Add( cell.position,cell ); } } else { if( cell.tileID != tileID ) { cell.tileID = tileID; changed = true; } } if( changeParts ) { if( autoTiling ) { int cellPartsID = cell.partsID; GenerateIndices( cell ); if( cell.partsID != cellPartsID ) { changed = true; } for( int x=-1;x<=1;x++ ) { for( int y=-1;y<=1;y++ ) { if( x==0 && y==0 ) { continue; } Cell aroundCell = GetCell( pos + new Point2( x,y ) ); if( aroundCell != null ) { if( GenerateIndices( aroundCell ) ) { changed = true; } } } } } else { if( cell.partsID != partsID ) { cell.partsID = partsID; changed = true; } } } if( changed ) { chunk.dirty = true; } return changed; }
public bool BucketTile( Point2 pos,int tileID,int partsID,bool autoTiling ) { bool changed = false; _FillFirstTileID = GetTileID( pos ); if( _FilledCells != null ) { _FilledCells.Clear(); } else { _FilledCells = new HashSet<Point2>(); } Stack<Point2> stack = new Stack<Point2>(); stack.Push ( pos ); Point2 leftPos = new Point2(); Point2 rightPos = new Point2(); while( stack.Count > 0 ) { Point2 currentPos = stack.Pop(); if( _FilledCells.Contains( currentPos ) ) { continue; } leftPos.x = currentPos.x; leftPos.y = currentPos.y; while( 1 <= leftPos.x ) { leftPos.x--; if( GetTileID( leftPos ) != _FillFirstTileID ) { leftPos.x++; break; } } rightPos.x = currentPos.x; rightPos.y = currentPos.y; while( rightPos.x < _Width -1 ) { rightPos.x++; if( GetTileID( rightPos ) != _FillFirstTileID ) { rightPos.x--; break; } } for( int fillX = leftPos.x ; fillX<=rightPos.x ; fillX++ ) { Point2 fillPos = new Point2( fillX,currentPos.y ); Point2 tilePos = fillPos-pos; tilePos.y = -tilePos.y; if( PutTile( fillPos,tileID,partsID,tilePos,false,!autoTiling ) || autoTiling ) { _FilledCells.Add( fillPos ); changed = true; } } if(currentPos.y + 1 < _Height) { ScanLine(leftPos.x, rightPos.x, currentPos.y + 1, stack); } if( 0 <= currentPos.y - 1) { ScanLine(leftPos.x, rightPos.x, currentPos.y - 1, stack); } } if( autoTiling ) { HashSet<Point2> aroundCells = new HashSet<Point2>(); foreach( Point2 currentPos in _FilledCells ) { Cell cell = GetCell( currentPos ); if( GenerateIndices( cell ) ) { changed = true; } for( int x=-1;x<=1;x++ ) { for( int y=-1;y<=1;y++ ) { if( x==0 && y==0 ) { continue; } Point2 aroundPos = cell.position + new Point2( x,y ); if( IsCellContains( aroundPos ) && !_FilledCells.Contains( aroundPos ) ) { aroundCells.Add( aroundPos ); } } } } foreach( Point2 aroundPos in aroundCells ) { Cell cell = GetCell( aroundPos ); if( cell != null ) { if( GenerateIndices( cell ) ) { changed = true; } } } } return changed; }
public bool RayToPoint( Ray ray,out Point2 pos ) { Plane plane = new Plane( transform.forward,transform.position ); float enter = 0.0f; if( plane.Raycast( ray,out enter ) ) { Vector3 hitPos = ray.GetPoint( enter ); pos = WorldPointToMapPoint( hitPos ); return IsCellContains( pos ); } pos = null; return false; }
public bool ColorBrushRectangle( Vector2 pos,float width,float height,Color color,bool halftile ) { Rect rect = new Rect( pos.x,pos.y,width,height ); Point2 mapMinPos = LocalPointToMapPoint( pos ); Point2 mapMaxPos = LocalPointToMapPoint( pos + new Vector2( width,height ) ); float halfSize = 0.5f; bool dirty = false; Point2 mapPos = new Point2(); for( mapPos.x = mapMinPos.x;mapPos.x<=mapMaxPos.x;++mapPos.x ) { for( mapPos.y = mapMinPos.y;mapPos.y<=mapMaxPos.y;++mapPos.y ) { Cell cell = GetCell( mapPos ); if( cell == null ) { continue; } Vector2 cellPos = MapPointToLocalPoint( cell.position ); for( int y=0;y<2;y++ ) { for( int x=0;x<2;x++ ) { Vector2 vertex = cellPos + new Vector2( x*halfSize,(1-y)*halfSize ); Vector2[] vertices = new Vector2[]{ vertex + new Vector2( 0.0f, halfSize), vertex + new Vector2( halfSize, halfSize), vertex + new Vector2( 0.0f, 0.0f), vertex + new Vector2( halfSize, 0.0f), }; bool check = true; for( int index=0;index<4;index++ ) { if( halftile ) { if( !rect.Contains( vertices[index] ) ) { check = false; } } else { if( rect.Contains( vertices[index] ) ) { cell.SetVertexColor( x,y,index,color ); dirty = true; } } } if( halftile && check ) { for( int index=0;index<4;index++ ) { cell.SetVertexColor( x,y,index,color ); } dirty = true; } } } Point2 chunkPos = cell.position/32; Chunk chunk = GetChunk( chunkPos ); if( chunk != null ) { chunk.dirty = true; } } } return dirty; }
public bool RemoveTile( Point2 pos,bool autoTiling ) { Cell cell = GetCell( pos ); if( cell==null ) { return false; } if( cell.collider != null ) { if( _ColliderCellDic != null && _ColliderCellDic.ContainsKey( cell.collider ) ) { _ColliderCellDic.Remove( cell.collider ); } ComponentUtility.Destroy( cell.collider ); cell.collider = null; } _Cells.Remove( cell ); if( _CellDic!=null ) { _CellDic.Remove( pos ); } Point2 chunkPos = cell.position/32; Chunk chunk = GetChunk( chunkPos ); if( chunk != null ) { if( !chunk.HadCells() ) { ComponentUtility.Destroy( chunk.gameObject ); _Chunks.Remove( chunk ); if( _ChunkDic!=null ) { _ChunkDic.Remove ( chunkPos ); } } else { chunk.dirty = true; } } if( autoTiling ) { for( int x=-1;x<=1;x++ ) { for( int y=-1;y<=1;y++ ) { if( x==0 && y==0 ) { continue; } Point2 aroundPos = pos + new Point2( x,y ); Cell aroundCell = GetCell( aroundPos ); if( aroundCell != null ) { GenerateIndices( aroundCell ); } } } } return true; }
public Cell GetCell( Point2 pos ) { Cell cell = null; if( cellDic.TryGetValue( pos,out cell ) ) { return cell; } return null; }
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 ); } }
public int GetTileID( Point2 pos ) { Cell cell = GetCell( pos ); if( cell==null ) { return -1; } return cell.tileID; }
void DrawCursor( Point2 pos,int width,int height ) { DrawCursor( _Map.MapPointToLocalPoint( pos ),width,height ); }