public void DrawScene (SceneView sceneView)
		{			
			//Do all of our casting now
			CheckMouseOver();
						
			if(currentBehaviour != MapPaintBehaviour.Disabled && currentBehaviour != MapPaintBehaviour.Block_Move && currentBehaviour != MapPaintBehaviour.Plugin_Active){
				int controlID = GUIUtility.GetControlID(FocusType.Passive);
					
				Tools.current = Tool.None;
			
				if(Event.current.type == EventType.Layout){
					HandleUtility.AddDefaultControl(controlID);
				}
			}
			
			if(currentBehaviour == MapPaintBehaviour.Block_Move){
				
				Tools.current = Tool.Move;
				
			}
			
			if(currentBehaviour == MapPaintBehaviour.Edit_Functions){
				
				for(int i = 0; i < existentBlockMaps.Length; i++){
					
					if(existentBlockMaps[i].functionalOverlay == null){
						
						continue;
					}
					
					DrawFunctionalOverlays(existentBlockMaps[i]);
					
				}
				
				
				if(functionBlock == null || setTidyTarget){
					
					Block b = mouseoverBlock;
					
					if(b != null){
						
						Color c = Handles.color;
					
						Handles.color = Color.yellow;
						
						float radius = b.blockMap.tileScale.y * 0.4f;
						
						Handles.DrawWireDisc(b.gameObject.transform.position,b.gameObject.transform.forward,radius);
						
						Handles.color = c;
						
					}
				}
				
			}
			
			if(drawingPath && pathBlocks.Count > 0){
				
				BlockMap pathMap = pathBlocks[0].blockMap;
				
				float radius = pathMap.tileScale.y * 0.4f;
				
				Color c = Handles.color;
				Handles.color = Color.green;
				
				for(int i = 0; i < pathBlocks.Count; i++){
					
					Handles.DrawWireDisc(pathBlocks[i].transform.position,pathBlocks[i].transform.forward,radius);
					
					if(i > 0){
						
						Handles.DrawLine(pathBlocks[i].transform.position,pathBlocks[i-1].transform.position);
						
					}
					
				}
				
				Handles.color = c;
				
			}
			
			//Debug.Log("Handle utility repaint");
			
			//HandleUtility.Repaint();
			
			Handles.BeginGUI();
						
			GUILayout.BeginArea(new Rect(0.0f,0.0f,Screen.width,Screen.height));
			
			GUILayout.BeginVertical();
						
			if(currentBehaviour == MapPaintBehaviour.Disabled){
				
				Color c = GUI.color;
				
				GUI.color = Color.white;
				
				GUILayout.Label(TidyMessages.MAP_CREATOR_INACTIVE);
									
				GUI.color = c;
												
			}
			else{
			
				Color c = GUI.color;
			
				GUI.color = Color.green;
				
				if(currentBehaviour == MapPaintBehaviour.Cycle){
					GUILayout.Label(TidyMessages.MAP_CREATOR_CYCLING_ACTIVE);
				}
				else
				if(currentBehaviour == MapPaintBehaviour.Paint){
					GUILayout.Label(TidyMessages.MAP_CREATOR_PAINTING_ACTIVE);
				}
				else
				if(currentBehaviour == MapPaintBehaviour.Block_Move){
					GUILayout.Label(TidyMessages.MAP_CREATOR_BLOCK_MOVE_ACTIVE);
				}		
				
				GUI.color = c;
				
				OutputMouseoverState();
			}
			
						
			GUILayout.EndVertical();
									
			GUILayout.EndArea();
			
			Handles.EndGUI();
			
			if(currentBehaviour == MapPaintBehaviour.Block_Move){
				
					if(selectedBlock != null && focusMap != null){
						
						if(selectedBlock.transform.localPosition != selectedBlockPosition){
					
							if(canAct){
						
								HandleBlockMove(selectedBlock,selectedBlockPosition);
								selectedBlockPosition = selectedBlock.transform.localPosition;
							
								HasActed();
							
							}
						}
						
					}
				
				
			}
			
			bool initializedChunk = false;
					
			if(currentBehaviour != MapPaintBehaviour.Disabled && currentBehaviour != MapPaintBehaviour.Block_Move){
											
				if(Event.current.type == EventType.MouseUp || Event.current.type == EventType.mouseUp){
					
					leftMouseDown = false;
					rightMouseDown = false;
					
				}
				
				
				//these things only occur on mousedown
				if(Event.current.type == EventType.mouseDown || Event.current.type == EventType.MouseDown && (SceneView.currentDrawingSceneView.position.Contains(Event.current.mousePosition))){
				
					//only on left click
					if(Event.current.button == 0){
								
						rightMouseDown = false;
						
						leftMouseDown = true;
												
						if(currentBehaviour == MapPaintBehaviour.DrawPath){
							
							if(mouseoverBlock != null){
							
								if(CanAddToPath(mouseoverBlock)){
									pathBlocks.Add(mouseoverBlock);
									drawingPath = true;
								}
								
							}
							
						}
						else
						if(currentBehaviour == MapPaintBehaviour.Paint || currentBehaviour == MapPaintBehaviour.Cycle){
							
							//we are changing a chunk!
							if(mouseoverChunk != null){
								BlockMap map = mouseoverChunk.GetParentMap();
								
								focusMap = map;
								
								OrientedBlock[] defaultBlocks = new OrientedBlock[map.chunkWidth*map.chunkHeight];
								
								bool isEmptyBlock = TidyEditorUtility.IsEmptyBlock(workingBlock);
								
								TriggerSelection();
								
								for(int i = 0; i < defaultBlocks.Length; i++){
									
									//defaultBlocks[i] = EditorUtility.InstantiatePrefab(workingBlock) as OrientedBlock;
									
									if(isEmptyBlock){
										
										defaultBlocks[i] = GameObject.Instantiate(workingBlock) as OrientedBlock;
										
										defaultBlocks[i].name = workingBlock.name;
										
										
										if(map.growthAxis == BlockMap.GrowthAxis.Up){
										
											defaultBlocks[i].transform.localScale = new Vector3(map.tileScale.x,map.tileScale.y,map.tileScale.z);
											
										}
										else if(map.growthAxis == BlockMap.GrowthAxis.Forward){
											
											defaultBlocks[i].transform.localScale = new Vector3(map.tileScale.x,map.tileScale.z,map.tileScale.y);
											
										}
										
									}
									else{
										
										defaultBlocks[i] = PrefabUtility.InstantiatePrefab(workingBlock) as OrientedBlock;
										
										defaultBlocks[i].name = workingBlock.name;
																				
										BoxCollider b = defaultBlocks[i].GetComponent<BoxCollider>();
										
										
										if(map.growthAxis == BlockMap.GrowthAxis.Up){
											b.size = new Vector3(map.tileScale.x,map.tileScale.y,map.tileScale.z);
										}
										else{
											b.size = new Vector3(map.tileScale.x,map.tileScale.z,map.tileScale.y);
										}
									}
								}
								
								int depth = mouseoverChunk.depth;
								
								//MapChunk mc = map.GetChunkAt(mouseoverChunk.GetX(),mouseoverChunk.GetY(),depth,false);
								
								map.Editor_InitializeChunkAt(mouseoverChunk.GetX(),mouseoverChunk.GetY(),depth,defaultBlocks,TidyEditorUtility.GetMapChunkPrefab());
								
								HasActed();
								
								initializedChunk = true;
								
								//and then refresh the blocks around it
																
								int m_x = mouseoverChunk.GetX();
								int m_y = mouseoverChunk.GetY();
								
								//MapChunk adjacentChunk = null;
								
								for(int x = m_x-1; x <= m_x+1; x++){
									for(int y = m_y-1; y <= m_y+1; y++){
																			
										MapChunk m = mouseoverChunk.parentMap.GetChunkAt(x,y,depth,false);
										
										if(m != null && m.Editor_IsInitialized()){
											
											//Debug.Log("Set chunk dirty at: " + x + ", " + y);
											
											m.RefreshChunk();
											
											//for(int i = 0; i < m.chunkPieces.Length; i++){
												//EditorUtility.SetDirty(m.chunkPieces[i]);
											//}
											
											//EditorUtility.SetDirty(m);
											
											/*if(!(x == m_x && y == m_y)){
												
												if(x == m_x || y == m_y){
													
													adjacentChunk = m;
												}
											}*/
											
										}
									}
								}
								
								/*if(backgroundMaterial != null && (workingBlock.isNullBlock || workingBlock.actAsEmptyBlock)){
																	
									//We have to do this from a populated area to an unpopulated are
									
									int x_lower = 0;
									int x_upper = mouseoverChunk.parentMap.chunkWidth;
									int x_direction = 1;
									int y_lower = 0;
									int y_upper = mouseoverChunk.parentMap.chunkHeight;
									int y_direction = 1;
									
									if(adjacentChunk != null){
										
										int x_dif = m_x - adjacentChunk.GetX();
										int y_dif = m_y - adjacentChunk.GetY();
										
										if(x_dif == -1){
											x_lower = mouseoverChunk.parentMap.chunkWidth-1;
											x_upper = -1;
											x_direction = -1;
										}
										
										if(y_dif == -1){
											y_lower = mouseoverChunk.parentMap.chunkHeight-1;
											y_upper = -1;
											y_direction = -1;
										}
										
									}
									
									List<Vector3> coord = new List<Vector3>();
									
									for(int x = x_lower; x != x_upper; x+=x_direction){
										for(int y = y_lower; y != y_upper; y+=y_direction){
																						
											Block b = mouseoverChunk.GetBlockAtChunkCoord(x,y);
											
											coord.Add(new Vector3(b.x,b.y,b.depth));
											
										}
									}
									
									if(!mouseoverChunk.parentMap.HasBackgroundEntryFor(backgroundMaterial.name)){
																				
										mouseoverChunk.parentMap.AddBackground(backgroundMaterial);
									}
									
									mouseoverChunk.parentMap.AddToBackground(coord.ToArray(),backgroundMaterial.name);
								}*/
								
								SetEntireMapDirty(mouseoverChunk.parentMap);
																
							}
							
						}
						
						if(mouseoverBlock != null && !initializedChunk){
				
							if(currentBehaviour == MapPaintBehaviour.Cycle){
																			
								CycleBlock(mouseoverBlock);
								
							}
							
						}
						
						if(currentBehaviour == MapPaintBehaviour.Edit_Functions && functionBlock != null){
						}
						else{
							Event.current.Use();
						}
						
						
					}
					
					//on right-click
					if(Event.current.button == 1){
						
						rightMouseDown = true;
						
						leftMouseDown = false;
						
						if(mouseoverBlock != null){
											
							if(currentBehaviour == MapPaintBehaviour.Cycle){
																			
								CycleBlockVariation(mouseoverBlock,1);
								
							}
							
						}
						
												
						if(currentBehaviour == MapPaintBehaviour.DrawPath){
							
							if(mouseoverBlock != null){
							
								RemoveFromPath(mouseoverBlock);
								
								if(pathBlocks.Count == 0){
									drawingPath = false;
								}
								
							}
							
						}
						
					}
					
					//On middle mouse
					if(Event.current.button == 2){
						
						rightMouseDown = false;
						
						leftMouseDown = false;
						
						if(mouseoverBlock != null){
				
							if(currentBehaviour == MapPaintBehaviour.Cycle){
																			
								CycleBlockVariation(mouseoverBlock,-1);
								
							}
							
						}
						
					}
				
				}
			}
			
			if(leftMouseDown && currentBehaviour == MapPaintBehaviour.Edit_Functions){
				leftMouseDown = false;
				
				if(functionBlock == null && mouseoverBlock != null){
					SetFunctionBlock(mouseoverBlock);
				}
				
				if(setTidyTarget && mouseoverBlock != null && functionBlock != null){
					setTidyTarget = false;
					currentTidyTarget = new TidyTarget(functionBlock,mouseoverBlock);
				}
			}
			
			if(leftMouseDown && currentBehaviour == MapPaintBehaviour.Paint_Background){
				
				if(mouseoverBlock != null){
					AddToBackground(mouseoverBlock);			
				}
			}
			
			if(functionBlock != null){
				
				//Draw the function block UI
				
				DrawFunctionBlockUI();
				
			}
			
			if(leftMouseDown && currentBehaviour == MapPaintBehaviour.Delete_Chunk && mouseoverChunk != null){
				DeleteChunk(mouseoverChunk);
				leftMouseDown = false;
			}
			
			if(leftMouseDown && currentBehaviour == MapPaintBehaviour.Paint && mouseoverBlock != null  && !initializedChunk){
				
				PaintBlock(mouseoverBlock);
				
			}
			
			if(rightMouseDown && currentBehaviour == MapPaintBehaviour.Paint && mouseoverBlock != null  && !initializedChunk){
				
				//Nope: As this overrides the ability to move the camera around with right click
				
				//PaintEmptyBlock(mouseoverBlock);
				
			}
			
			if(leftMouseDown && currentBehaviour == MapPaintBehaviour.Add_Layer_Above && (mouseoverChunk != null || mouseoverBlock != null)){
				
				
				MapChunk c = mouseoverChunk;
				
				if(c == null){
					
					c = mouseoverBlock.blockMap.GetChunkForBlockCoordinate(mouseoverBlock.x,mouseoverBlock.y,mouseoverBlock.depth);
					
				}
				
				AddLayerChunk(c,1);
				
				parentWindow.Repaint();
				
				leftMouseDown = false;
				
			}
			
			if(leftMouseDown && currentBehaviour == MapPaintBehaviour.Add_Layer_Below && (mouseoverChunk != null || mouseoverBlock != null)){
				
				
				MapChunk c = mouseoverChunk;
				
				if(c == null){
					
					c = mouseoverBlock.blockMap.GetChunkForBlockCoordinate(mouseoverBlock.x,mouseoverBlock.y,mouseoverBlock.depth);
					
				}
				
				AddLayerChunk(c,-1);
				
				parentWindow.Repaint();
				
				leftMouseDown = false;
				
			}
			
			/*for(int i = 0; i < plugins.Length; i++){
				
				if(plugins[i].obj == null){
					continue;
				}
				
				plugins[i].obj.DrawScene(sceneView);
			}*/
		}
		void DrawFunctionBlockUI(){
						
			Color c = Handles.color;
			Handles.color = Color.yellow;
			
			float radius = functionBlock.blockMap.tileScale.y * 0.4f;
			
			Handles.DrawWireDisc(functionBlock.transform.position,functionBlock.transform.forward,radius);
			
			Handles.color = c;
			
			Vector2 pos = HandleUtility.WorldToGUIPoint(functionBlock.transform.position);
			
			Handles.BeginGUI();
			
			Rect r = new Rect(pos.x - 150.0f,pos.y + 25.0f,300.0f,175.0f);
			
			//GUI.skin = TidyEditorUtility.GetEditorGUISkin();
			
			//GUI.Box(r,"");
			
			//GUI.skin = null;
			
			GUI.DrawTexture(r,GetIcon(TidyFileNames.AREA_BACKGROUND));
			
			GUILayout.BeginArea(r);
			
			GUILayout.BeginVertical();
			
			GUILayout.Space(10.0f);
			
			if(functionData == null){
				//draw the 'add data' UI
				
				
			
				//draw the close UI
				GUILayout.BeginHorizontal();
				
				GUILayout.Label("Add object:");
				
				GUILayout.FlexibleSpace();
				
				if(GUILayout.Button("X")){
					SetEntireMapDirty(functionBlock.blockMap);
					functionBlock = null;
					functionData = null;
					prop = null;
				}
				
				GUILayout.EndHorizontal();
				
				if(functionalComponents != null && functionalComponents.Length > 0){
					for(int i = 0; i < functionalComponents.Length; i++){
						
						if(GUILayout.Button(functionalComponents[i].name)){
						
							TidyFunctionalObject o = UnityEngineInternal.APIUpdaterRuntimeServices.AddComponent(functionBlock.blockMap.gameObject, "Assets/Tidy Tile Mapper/Editor/Editor Logic/TidyMapCreator.cs (1502,33)", functionalComponents[i].name) as TidyFunctionalObject;
							
							o.SetParentBlock(functionBlock);
														
							functionBlock.blockMap.functionalOverlay.AddData(o);
							
							SetEntireMapDirty(functionBlock.blockMap);
							
							SetFunctionBlock(functionBlock);
														
						}
						
					}
				}
				else{
					GUILayout.Label("None");
				}
				
				
			}
			else{
				
				GUILayout.Label(functionData.parentBlock.name + " at " +"["+functionData.parentBlock.x + "," + functionData.parentBlock.y + "," + functionData.parentBlock.depth+"]");
				
				//draw the close UI
				GUILayout.BeginHorizontal();
				
				GUILayout.Label(functionData.GetType().Name);
				
				GUILayout.FlexibleSpace();
				
				if(GUILayout.Button("X")){
					SetEntireMapDirty(functionBlock.blockMap);
					functionBlock = null;
					functionData = null;
					prop= null;
				}
				
				GUILayout.EndHorizontal();
				
				GUILayout.Space(10.0f);
				
				fScrollPos = GUILayout.BeginScrollView(fScrollPos);
								
				try{
							
					prop = functionSObj.GetIterator();
					
					if(prop != null && functionSObj != null && functionData != null){
												
						prop.NextVisible(true);
											
						bool searchDeep = true;
						
						do{
														
							searchDeep = true;
							
							if(prop.propertyPath == "m_Script"){
								continue;
							}
							
							if(prop.name == "parentBlock"){
								continue;
							}
							
							if(prop.type == "Vector3f"){
								searchDeep = false;
							}
							
							if(prop.type == "Vector3f" && prop.name == "targetDifference" && currentTidyTarget != null){
								
								prop.vector3Value = currentTidyTarget.targetDifference;
								
								currentTidyTarget = null;
							}
							
							if(prop.name == "TidyTarget_parentBlock" && currentTidyTarget != null){
								
								prop.objectReferenceValue = currentTidyTarget.TidyTarget_parentBlock;
								
							}
							
							if(prop.type == "TidyTarget"){
																	
								EditorGUILayout.BeginHorizontal();
							
								GUILayout.Label(prop.name + ":");
								
								GUILayout.FlexibleSpace();
								
								Color gc = GUI.color;
								
								if(setTidyTarget == true){
									GUI.color = Color.green;
								}
								
								if(GUILayout.Button("Set")){
									setTidyTarget = true;
									//tidyTargetName = prop.name;
									currentTidyTarget = null;
								}
								
								GUI.color = gc;
								
								EditorGUILayout.EndHorizontal();
								
								continue;
							}
						
							EditorGUILayout.BeginHorizontal();
							EditorGUILayout.PropertyField(prop);
							
							EditorGUILayout.EndHorizontal();
							
						}while(prop.NextVisible(searchDeep));
						
						prop.Reset();
						
						functionSObj.ApplyModifiedProperties();	
						
						functionSObj.Update();
					}
					else{
						GUILayout.Label("Data null.");
					}
					
				}catch(Exception e){Debug.LogWarning(e.ToString());}
					
				GUILayout.EndScrollView();
				
				GUILayout.BeginHorizontal();
				
				GUILayout.FlexibleSpace();
				
				if(GUILayout.Button("Delete")){
					
					TidyFunctionalObject o = functionBlock.blockMap.functionalOverlay.RemoveDataAt(functionBlock.x,functionBlock.y,functionBlock.depth);
					
					GameObject.DestroyImmediate(o);
					
					functionData = null;
					prop = null;
										
					SetEntireMapDirty(functionBlock.blockMap);
					
					functionBlock = null;
				}
				
				GUILayout.EndHorizontal();
			}
						
			GUILayout.EndVertical();
				
			GUILayout.EndArea();
			
			Handles.EndGUI();
		}