public LayerEd NewLayer( )
        {
            string name = "";
            int i = 1;
            bool valid = false;
            do
            {
                name = "Layer" + i;
                i++;
                valid = true;
                foreach( LayerEd layer in _layers )
                {
                    if( layer.Name == name )
                    {
                        valid = false;
                        break;
                    }
                }

            } while( !valid );

            LayerEd layer2 = new LayerEd( name );
            NewLayer( layer2 );
            return layer2;
        }
 public void DeleteLayer( LayerEd layer )
 {
     _layers.Remove( layer );
 }
 public void NewLayer( LayerEd layer )
 {
     layer.Container = this;
     _layers.Add( layer );
     layer.AddedToLevel = true;
 }
 public LayerItem( LayerEd layer )
 {
     this.Layer = layer;
 }
        private static void LevelActorReadData( LayerEd layer, BinaryReader file, int version )
        {
            ActorEd actor;

            int id = file.ReadInt32( );
            string actorTypeName = file.ReadString( );
            if( Global.AssetsBrowser.ActorItems.ContainsKey( actorTypeName ) )
            {
                actor = Global.AssetsBrowser.ActorItems[actorTypeName].Actor.CreateActor( id );
                actor.Name = file.ReadString( );
                actor.Position = new Vector2( file.ReadSingle( ), file.ReadSingle( ) );
                actor.Origin = new Vector2( file.ReadSingle( ), file.ReadSingle( ) );
                actor.Scale = file.ReadSingle( );
                actor.Rotation = file.ReadSingle( );
                actor.Visible = file.ReadBoolean( );
                layer.AddActor( actor );

                if( version >= 2 )
                {
                    int tagCount = file.ReadInt32( );
                    actor.Tags = new string[tagCount];
                    for( int i = 0; i < tagCount; i++ )
                    {
                        actor.Tags[i] = file.ReadString( );
                    }

                    //Checks if the actor is a TextActor
                    if( file.ReadBoolean( ) )
                    {
                        actor.Text = file.ReadString( );
                        actor.TextColor = new Color( file.ReadByte( ), file.ReadByte( ), file.ReadByte( ), file.ReadByte( ) );
                    }
                }

                actor.AddedToLevel = true;
            }
            else
            {
                file.ReadString( ); //Name
                file.ReadSingle( ); //Pos X
                file.ReadSingle( ); //Pos Y
                file.ReadSingle( ); //Origin X
                file.ReadSingle( ); //Origin Y
                file.ReadSingle( ); //Scale
                file.ReadSingle( ); //Rotation
                file.ReadBoolean( );//Visible
                if( version >= 2 && file.ReadBoolean( ) ) //IsTextActor
                {
                    file.ReadString( );     //Text
                    file.ReadBytes( 4 );    //TextColor
                }
                MessageBox.Show( Global.EditorTxt.ActortypeNotFoundError, "", MessageBoxButtons.OK, MessageBoxIcon.Warning );
            }
        }
        private static void GameLevelLayerWriteData( LayerEd layer, BinaryWriter file )
        {
            file.Write( layer.Name );
            file.Write( layer.Visible );
            file.Write( layer.Scale );

            file.Write( layer.Actors.Count ); //Number of actors
            foreach( ActorEd actor in layer.Actors )
            {
                GameLevelActorWriteData( actor, file );
            }
        }
        private static void LevelLayerWriteData( LayerEd layer, BinaryWriter writer )
        {
            // ---- Writes the layer data

            writer.Write( layer.Name );
            writer.Write( layer.Visible );
            writer.Write( layer.Locked );
            writer.Write( layer.Scale );

            //Writes the number of actors
            writer.Write( layer.Actors.Count );

            //Iterates through each actor and saves its data
            foreach( ActorEd actor in layer.Actors )
            {
                LevelActorWriteData( actor, writer );
            }
        }
        private static void LevelLayerReadData( LevelEd level, BinaryReader file, int version )
        {
            LayerEd layer = new LayerEd( file.ReadString( ) );
            layer.Visible = file.ReadBoolean( );
            layer.Locked = file.ReadBoolean( );
            layer.Scale = file.ReadSingle( );

            //Gets the number of actors
            int actorsCount = file.ReadInt32( );

            for( int i = 0; i < actorsCount; i++ )
            {
                LevelActorReadData( layer, file, version );
            }

            level.NewLayer( layer );
        }