Example #1
0
        public static void RefreshCurrentBlockList()
        {
            string[]     blocks        = Directory.GetFiles(Application.dataPath + "/" + blockPath);
            List <Block> workingBlocks = new List <Block>();

            for (int i = 0; i < blocks.Length; i++)
            {
                blocks[i] = blocks[i].Replace("\\", "/");

                string[] bPath = blocks[i].Split('/');

                blocks[i] = bPath[bPath.Length - 1];

                GameObject obj = AssetDatabase.LoadAssetAtPath("Assets" + "/" + blockPath + "/" + blocks[i], typeof(GameObject)) as GameObject;

                if (obj != null)
                {
                    OrientedBlock b = obj.GetComponent <OrientedBlock>();

                    if (b != null)
                    {
                        workingBlocks.Add(b);

                        //Pre-request the preview for this block
                        //To clear loads immediately

                        //GetPreviewForGameObject(b.GetDefaultBlock(),false);
                    }
                }
            }

            blockList = workingBlocks.ToArray();
        }
Example #2
0
        void SaveBlock(OrientedBlock block, GameObject blockPrefab)
        {
            //rename the screenshot

            if (blockName != block.name)
            {
                string path = TidyEditorUtility.previewPath + "/" + block.name + ".png";

                AssetDatabase.RenameAsset("Assets/" + TidyEditorUtility.blockPath + "/" + block.name + ".prefab", blockName);

                //rename the block
                workingBlock.name = blockName;

                AssetDatabase.RenameAsset("Assets/" + path, block.name);
            }
            //save the created object over the existing prefab
            //EditorUtility.ReplacePrefab(block.gameObject,blockPrefab.gameObject);

            mapCreator.HideAllBlocksOfType(blockPrefab.name);

            PrefabUtility.DisconnectPrefabInstance(block.gameObject);

            PrefabUtility.ReplacePrefab(block.gameObject, blockPrefab.gameObject);

            PrefabUtility.RevertPrefabInstance(block.gameObject);

            mapCreator.RefreshWorkingBlockMenu();
        }
Example #3
0
        /// <summary>
        /// Cleans a single block
        /// </summary>
        /// <param name="map">
        /// The map containing the target block
        /// </param>
        /// <param name="x">
        /// The x coordinate of the target block
        /// </param>
        /// <param name="y">
        /// The y coordinate of the target block
        /// </param>
        /// <param name="depth">
        /// The depth coordinate of the target block
        /// </param>
        public static void CleanBlock(BlockMap map, int x, int y, int depth)
        {
            Block b = map.GetBlockAt(x, y, depth);

            if (b != null)
            {
                OrientedBlock ob = (OrientedBlock)b;

                if (ob == null)
                {
                    return;
                }

                BlockSet[] bs = ob.GetBlockSetsAsArray();

                BlockSet currentSet = ob.GetCurrentBlockSet();

                for (int k = 0; k < bs.Length; k++)
                {
                    if (bs[k] == currentSet)
                    {
                        continue;
                    }

                    BlockSet bSet = bs[k];

                    for (int l = 0; l < bSet.blockSet.Length; l++)
                    {
                        GameObject.Destroy(bSet.blockSet[l].gameObject);
                    }
                }
            }
        }
Example #4
0
        void CreateNewBlock()
        {
            GameObject newBlock = new GameObject("Block_" + (workingBlocks.Count + 1));

            newBlock.gameObject.hideFlags = HideFlags.HideInHierarchy;

            //We need to set the block up now
            newBlock.AddComponent <OrientedBlock>();
            newBlock.AddComponent <BoxCollider>();

            //Create a prefab
            //UnityEngine.Object prefab = EditorUtility.CreateEmptyPrefab("Assets/"+TidyEditorUtility.blockPath + "/" + newBlock.name + ".prefab");

            UnityEngine.Object prefab = PrefabUtility.CreateEmptyPrefab("Assets/" + TidyEditorUtility.blockPath + "/" + newBlock.name + ".prefab");

            //GameObject newPrefab = EditorUtility.ReplacePrefab(newBlock,prefab);

            GameObject newPrefab = PrefabUtility.ReplacePrefab(newBlock, prefab);

            OrientedBlock po = newPrefab.GetComponent <OrientedBlock>();

            workingBlocks.Add(po);

            if (HasWorkingBlockChanged())
            {
                GetPreviewForGameObject(workingBlockPrefab.GetDefaultBlock(), true);

                if (EditorUtility.DisplayDialog(TidyMessages.BLOCK_EDITOR_SWITCH_DIALOG,
                                                TidyMessages.BLOCK_EDITOR_SWITCH_PROMPT,
                                                TidyMessages.BLOCK_EDITOR_SWITCH_CONFIRM,
                                                TidyMessages.BLOCK_EDITOR_SWITCH_REJECT))
                {
                    HandleBlockChange(po, true);
                }
                else
                {
                    HandleBlockChange(po, false);
                }
            }
            else
            {
                HandleBlockChange(po, false);
            }

            initialPreviewGenerated = false;

            Editor.DestroyImmediate(newBlock);

            mapCreator.RefreshWorkingBlockMenu();
        }
Example #5
0
        //Handle a change in block selection
        void HandleBlockChange(OrientedBlock newWorkingBlock, bool saveChanges)
        {
            newObjects.Clear();

            if (workingBlock != null)
            {
                workingBlock.gameObject.hideFlags = 0;

                if (saveChanges)
                {
                    SaveBlock(workingBlock, workingBlockPrefab.gameObject);
                }

                Editor.DestroyImmediate(workingBlock.gameObject);
            }

            if (newWorkingBlock != null)
            {
                //Set the new block
                workingBlockPrefab = newWorkingBlock;

                //We'll actually replace this with hide flags
                //Once we're sure it works

                //workingBlock = EditorUtility.InstantiatePrefab(workingBlockPrefab) as OrientedBlock;

                workingBlock = PrefabUtility.InstantiatePrefab(workingBlockPrefab) as OrientedBlock;

                //Hide in the inspector
                //workingBlock.gameObject.hideFlags = HideFlags.HideInHierarchy;

                //Disappear!

#if UNITY_4_0
                workingBlock.gameObject.SetActive(false);
#else
                //workingBlock.gameObject.SetActiveRecursively(false);
#endif

                blockName = workingBlock.name;
            }

            hasWorkingBlockChanged = false;
        }
Example #6
0
        /// <summary>
        /// Creates a save string for an individual Block
        /// </summary>
        /// <param name="b">
        /// The Block in question
        /// </param>
        /// <param name="library">
        /// The type library constructed in the body of the save Map function
        /// </param>
        /// <returns>
        /// The save string for this block.
        /// </returns>
        public static string BlockToString(Block b, List <string> library)
        {
            OrientedBlock ob = b as OrientedBlock;

            string blockString = "";

            blockString += GetIndexForBlock(ob.name, library) + "" + BLOCK_FIELD_DELIM;

            blockString += ob.GetCurrentVariant() + "" + BLOCK_FIELD_DELIM;

            blockString += ob.x + "," + ob.y + "," + ob.depth + "" + BLOCK_FIELD_DELIM;

            TidyMapBoundObject[] boundObjects = ob.GetComponentsInChildren <TidyMapBoundObject>();

            for (int i = 0; i < boundObjects.Length; i++)
            {
                blockString += boundObjects[i].ToString() + "" + BLOCK_FIELD_DELIM;
            }

            return(blockString);
        }
Example #7
0
    /// <summary>
    ///Add an object to this blockset
    /// </summary>
    /// <param name="o">
    ///The object you wish to add to the blockset
    /// </param>
    public void Editor_AddToBlockSet(GameObject o, OrientedBlock parent)
    {
        int length = blockSet.Length;

        for (int i = 0; i < length; i++)
        {
            if (blockSet[i] == o)
            {
                return;
            }
        }

        this.offset   = new Vector3(parent.x_offset, parent.y_offset, parent.z_offset);
        this.rotation = new Vector3(parent.x_rotation, parent.y_rotation, parent.z_rotation);


        //PREFAB

        /*o.transform.parent = rootObject.transform;
         * o.transform.localPosition = offset;
         *
         * o.transform.localRotation = Quaternion.identity;*/

        GameObject[] newSet = new GameObject[length + 1];

        for (int i = 0; i < length; i++)
        {
            newSet[i] = blockSet[i];
        }

        newSet[length] = o;

        blockSet = newSet;

        //Debug.Log("Adding: " + blockSet.Length);

        CleanBlockSet();

        //Debug.Log("After clean: " + blockSet.Length);
    }
Example #8
0
        /// <summary>
        ///Returns an empty block (useful for deleting blocks but retaining trigger functionality)
        /// </summary>
        /// <param name="map">
        /// The map to which this block will be added (required in order to correctly size the trigger of the block)
        /// </param>
        /// <returns>
        /// Returns an empty block
        /// </returns>
        public static Block GetEmptyBlock(BlockMap map)
        {
            GameObject o = null;

            if (AssetPool.IsPoolingEnabled())
            {
                o = AssetPool.Instantiate("Void");

                if (o != null)
                {
                    return(o.GetComponent <Block>());
                }
            }

            o = new GameObject("Void");
            OrientedBlock ob = o.AddComponent <OrientedBlock>();
            BoxCollider   b  = o.AddComponent <BoxCollider>();

            b.isTrigger        = true;
            b.size             = map.tileScale;
            ob.isNullBlock     = true;
            ob.actAsEmptyBlock = true;
            return(ob as Block);
        }
		public void SetWorkingBlockNonEmpty(){
			
			if(workingBlock.isNullBlock){
				if(workingBlocks.Count > 0){
					workingBlock = workingBlocks[1];
				}
			}
		}
		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);
			}*/
		}
Example #11
0
	/// <summary>
	///Add an object to this blockset 
	/// </summary>
	/// <param name="o">
	///The object you wish to add to the blockset
	/// </param>
	public void Editor_AddToBlockSet(GameObject o, OrientedBlock parent){
				
		int length = blockSet.Length;
		
		for(int i = 0; i < length; i++){
			
			if(blockSet[i] == o){
				return;
			}
		}
		
		this.offset = new Vector3(parent.x_offset,parent.y_offset,parent.z_offset);
		this.rotation = new Vector3(parent.x_rotation,parent.y_rotation,parent.z_rotation);
		
		
		//PREFAB
		/*o.transform.parent = rootObject.transform;
		o.transform.localPosition = offset;
		
		o.transform.localRotation = Quaternion.identity;*/
		
		GameObject[] newSet = new GameObject[length+1];
		
		for(int i = 0; i < length; i++){
			newSet[i] = blockSet[i];
		}
		
		newSet[length] = o;
		
		blockSet = newSet;
		
		//Debug.Log("Adding: " + blockSet.Length);
		
		CleanBlockSet();
		
		//Debug.Log("After clean: " + blockSet.Length);
		
	}
		public void SetBlockDirty(OrientedBlock workingBlock){
			
			EditorUtility.SetDirty(workingBlock);
						
		}
		//Handle a change in block selection
		void HandleBlockChange(OrientedBlock newWorkingBlock, bool saveChanges){
			
			newObjects.Clear();
						
			if(workingBlock != null){
				
				workingBlock.gameObject.hideFlags = 0;
				
				if(saveChanges){
					
					SaveBlock(workingBlock,workingBlockPrefab.gameObject);
					
				}
								
				Editor.DestroyImmediate(workingBlock.gameObject);
			
			}
			
			if(newWorkingBlock != null){
			
				//Set the new block
				workingBlockPrefab = newWorkingBlock;
			
				//We'll actually replace this with hide flags
				//Once we're sure it works
				
				//workingBlock = EditorUtility.InstantiatePrefab(workingBlockPrefab) as OrientedBlock;
				
				workingBlock = PrefabUtility.InstantiatePrefab(workingBlockPrefab) as OrientedBlock;
				
				//Hide in the inspector
				//workingBlock.gameObject.hideFlags = HideFlags.HideInHierarchy;
				
				//Disappear!
				
#if UNITY_4_0
				workingBlock.gameObject.SetActive(false);
#else
				workingBlock.gameObject.SetActiveRecursively(false);
#endif
				
				blockName = workingBlock.name;
					
			}
			
			hasWorkingBlockChanged = false;
			
		}
Example #14
0
 public void SetBlockDirty(OrientedBlock workingBlock)
 {
     EditorUtility.SetDirty(workingBlock);
 }
		void PopulateBlockList(){
			
			Block[] b = TidyEditorUtility.GetCurrentBlocks();
						
			workingBlocks = new List<OrientedBlock>();
			
			if(b != null){
				
				for(int i = 0; i < b.Length; i++){
					
					if(b[i].GetDefaultBlock() != null){
						workingBlocks.Add(b[i] as OrientedBlock);
					}
					
				}
				
			}
			
			workingBlocks.Insert(0,TidyEditorUtility.GetNullBlock() as OrientedBlock);
			
			//Working block
			if(workingBlocks.Count > 0){
				
				workingBlock = workingBlocks[0];
		
			}
		}
		public void DrawWindow ()
		{				
			if(existentBlockMaps == null){
				
				RefreshExistentBlockMaps();
			}
			
			if(workingBlocks == null){
				
				PopulateBlockList();
			}
			
			if(italicStyle == null){
					
				//Set up our italic style
				italicStyle = new GUIStyle(EditorStyles.label);
				
				italicStyle.fontStyle = FontStyle.Italic;
				
			}
			
			
			//Color c = GUI.color;
			
			float width = (parentWindow.position.width + 20.0f);
			
			if(width <= idealBlockIconWidth){
				tilesAcross = 1;
				extraBit = width - idealBlockIconWidth;
			}
			else{
				tilesAcross = (int)((width) / idealBlockIconWidth);
				extraBit = ((width) % (float) idealBlockIconWidth) / (float)tilesAcross;
				
				if(tilesAcross == 0){
					tilesAcross = 1;
					extraBit = width - idealBlockIconWidth;
				}
			}
			
			windowScrollPos = EditorGUILayout.BeginScrollView(windowScrollPos);
											
			EditorGUILayout.BeginVertical();
			
			GUILayout.Space(10.0f);
						
			GUILayout.Label(TidyMessages.MAP_CREATOR_BLOCK_CATEGORY,EditorStyles.boldLabel);
			
			EditorGUILayout.BeginHorizontal();
			
			GUILayout.FlexibleSpace();
			
			if(GUILayout.Button(new GUIContent(TidyMessages.MAP_CREATOR_BLOCK_EDITOR,TidyTooltips.MAP_CREATOR_BLOCK_EDITOR))){
									
				EditorApplication.ExecuteMenuItem("Window/Tidy Block Editor");
								
			}
			
			GUILayout.Space(20.0f);
			
			EditorGUILayout.EndHorizontal();
			
			GUILayout.Space(10.0f);
			
			DrawHorizontalLine();
			
			GUILayout.Label(TidyMessages.MAP_CREATOR_CREATE_MAP_CATEGORY,EditorStyles.boldLabel);
			
			GUILayout.Space(10.0f);
						
			if(currentBehaviour != MapPaintBehaviour.Disabled){
				GUI.enabled = false;
			}
			
			if(TidyEditorUtility.GetMapChunkPrefab() != null){
				
				EditorGUILayout.BeginHorizontal();
				
				GUILayout.Label(TidyMessages.MAP_CREATOR_NEW_MAP_NAME,GUILayout.ExpandWidth(false));
				
				newMapName = GUILayout.TextField(newMapName,GUILayout.ExpandWidth(true));
				
				EditorGUILayout.EndHorizontal();
				
				foldMapOptions = EditorGUILayout.Foldout(foldMapOptions,TidyMessages.MAP_CREATOR_ADVANCED_MAP_OPTIONS);
				
				if(foldMapOptions){
					
					EditorGUILayout.BeginHorizontal();
					
					EditorGUI.indentLevel = 1;
					
					EditorGUILayout.PrefixLabel(TidyMessages.MAP_CREATOR_TILE_WIDTH);
					
					GUILayout.FlexibleSpace();
					
					tileWidth = EditorGUILayout.FloatField(tileWidth,GUILayout.ExpandWidth(false));
					
					if(tileWidth <= 0.0f){
						tileWidth = 1.0f;
					}
					
					EditorGUILayout.EndHorizontal();
					
					EditorGUILayout.BeginHorizontal();
					
					EditorGUILayout.PrefixLabel(TidyMessages.MAP_CREATOR_TILE_HEIGHT);
					
					GUILayout.FlexibleSpace();
					
					tileHeight = EditorGUILayout.FloatField(tileHeight,GUILayout.ExpandWidth(false));
					
					if(tileHeight <= 0.0f){
						tileHeight = 1.0f;
					}
					
					EditorGUILayout.EndHorizontal();
					
					EditorGUILayout.BeginHorizontal();
					
					EditorGUILayout.PrefixLabel(TidyMessages.MAP_CREATOR_TILE_DEPTH);
					
					GUILayout.FlexibleSpace();
					
					tileDepth = EditorGUILayout.FloatField(tileDepth,GUILayout.ExpandWidth(false));
					
					if(tileDepth <= 0.0f){
						tileDepth = 1.0f;
					}
										
					EditorGUILayout.EndHorizontal();
					
					EditorGUILayout.BeginHorizontal();
					
					EditorGUILayout.PrefixLabel(TidyMessages.MAP_CREATOR_NEW_MAP_CHUNK_WIDTH);
										
					GUILayout.FlexibleSpace();
					
					chunkWidth = EditorGUILayout.IntField(chunkWidth,GUILayout.ExpandWidth(false));
					
					if(chunkWidth <= 0){
						chunkWidth = 1;
					}
										
					EditorGUILayout.EndHorizontal();
					
					EditorGUILayout.BeginHorizontal();
					
					EditorGUILayout.PrefixLabel(TidyMessages.MAP_CREATOR_NEW_MAP_CHUNK_HEIGHT);
										
					GUILayout.FlexibleSpace();
					
					chunkHeight = EditorGUILayout.IntField(chunkHeight,GUILayout.ExpandWidth(false));
					
					if(chunkHeight <= 0){
						chunkHeight = 1;
					}
										
					EditorGUILayout.EndHorizontal();
					
					EditorGUILayout.BeginHorizontal();
					
					EditorGUILayout.PrefixLabel(TidyMessages.MAP_CREATOR_MAP_GROW_AXIS);
					
					GUILayout.FlexibleSpace();
					
					growthAxis = (BlockMap.GrowthAxis)EditorGUILayout.EnumPopup(growthAxis,GUILayout.ExpandWidth(false));
					
					EditorGUILayout.EndHorizontal();
					
					EditorGUI.indentLevel = 0;
					
				}
				
				EditorGUILayout.BeginHorizontal();
				
				GUILayout.FlexibleSpace();
				
				if(GUILayout.Button(new GUIContent(TidyMessages.MAP_CREATOR_ADD_MAP,TidyTooltips.MAP_CREATOR_ADD_MAP))){
					
					if(workingBlock == null){
						
						mapCreationMessage = TidyMessages.MAP_CREATOR_NO_BLOCK_CHOSEN;
						
					}
					else
					if(string.IsNullOrEmpty(newMapName)){
						
						mapCreationMessage = TidyMessages.MAP_CREATOR_NO_NAME;
						
					}
					else 
					if(MapNameExists(newMapName)){
						mapCreationMessage = TidyMessages.MAP_CREATOR_NAME_EXISTS;
					}
					else{
						
						mapCreationMessage = TidyMessages.MAP_CREATOR_MAP_CREATED;
						
						CreateMap(newMapName);
						
						RefreshExistentBlockMaps();
						
					}
					
					newMapName = "";
					
				}
				
				GUILayout.Space(20.0f);
				
				EditorGUILayout.EndHorizontal();
						
				GUILayout.Space(10.0f);
				
								
			}
			else{
				GUILayout.Label(TidyMessages.MAP_CREATOR_NO_CHUNK_ERROR);
			}
			
			
			GUILayout.Space(10.0f);
			
			GUILayout.Label(mapCreationMessage,italicStyle);
			
			if(currentBehaviour != MapPaintBehaviour.Disabled){
				GUI.enabled = true;
			}
			
			GUILayout.Space(10.0f);
			
			DrawHorizontalLine();
			
			GUILayout.Label(TidyMessages.MAP_CREATOR_STREAMING_MAPS,EditorStyles.boldLabel);
						
			if(GUILayout.Button(TidyMessages.MAP_CREATOR_ADD_STREAMING_MAP)){
				
				//Add a streaming map to the scene
				GameObject newStreamingMap = new GameObject("Streaming Map");
				
				//We are doing this by name and not by type because...
				//I am currently working in a C# project
				//To be compiled to a DLL
				//(For good but complex reasons)
				//And StreamingMap is in another project
				
				bool success = true;
				
				try{
					newStreamingMap.AddComponent<StreamingMap>();
				}catch(Exception e){
					
					Editor.DestroyImmediate(newStreamingMap);
					success = false;
					Debug.LogError("When creating streaming map:\n" + e.ToString());
				}
				
				if(success){
					
					EditorUtility.SetDirty(newStreamingMap.gameObject);
					Selection.activeGameObject = newStreamingMap;
					
				}
			}
			
			GUILayout.Space(10.0f);
			
			DrawHorizontalLine();
			
			DrawMapInfo();
			
			GUILayout.Space(10.0f);
			
			DrawFunctionalOverlayArea();
			
			DrawMapTools();
						
			DrawToolOptions();
			
			GUILayout.Space(10.0f);
			
			DrawHorizontalLine();
			
			GUILayout.Label(TidyMessages.MAP_CREATOR_BLOCK_LIST);
			
			int rows = workingBlocks.Count / tilesAcross + 1;
			
			blockWindowScrollPos = EditorGUILayout.BeginScrollView(blockWindowScrollPos,GUILayout.Width(parentWindow.position.width),GUILayout.MinHeight(idealBlockIconWidth * rows + 10.0f));
			
			Rect scrollVertRect = EditorGUILayout.BeginVertical();
		
			GUI.Box(scrollVertRect,"");
			
			for(int i = 0; i < workingBlocks.Count; i++){
				
				if(workingBlocks[i] == null){
					RefreshWorkingBlockMenu();
					continue;
				}
				
				if(i % tilesAcross == 0){
					
					if(i > 0){
						GUILayout.FlexibleSpace();
						EditorGUILayout.EndHorizontal();
					}
					
					EditorGUILayout.BeginHorizontal();
					
				}
				
				if(GUILayout.Button(new GUIContent("",workingBlocks[i].name),GUILayout.Width(idealBlockIconWidth+extraBit),GUILayout.Height(idealBlockIconWidth+extraBit))){
					workingBlock = workingBlocks[i];
				}
				
				GameObject pObject = workingBlocks[i].GetDefaultBlock();
				
				if(pObject == null){
					pObject = workingBlocks[i].gameObject;
				}
				
				Texture2D texture = GetPreviewForGameObject(pObject,false);				
				
				if(texture != null){
					GUI.DrawTexture(GUILayoutUtility.GetLastRect(),texture,ScaleMode.ScaleAndCrop,false);
				}
				
				if(workingBlocks[i] == workingBlock){
					GUI.DrawTexture(GUILayoutUtility.GetLastRect(),itemSelectedTexture,ScaleMode.ScaleToFit,true);	
				}
				
				if(i == workingBlocks.Count-1){
					GUILayout.FlexibleSpace();
					EditorGUILayout.EndHorizontal();
					
				}
				
			}
			
			EditorGUILayout.EndVertical();
						
			EditorGUILayout.EndScrollView();
			
			EditorGUILayout.BeginHorizontal();
			
			GUILayout.FlexibleSpace();
			
			if(GUILayout.Button("Refresh")){
				
				RefreshWorkingBlockMenu();
				
			}
			
			GUILayout.Space(20.0f);
			
			EditorGUILayout.EndHorizontal();
			
			GUILayout.Space(10.0f);
			
			DrawHorizontalLine();
			
			DrawBackgroundPanel();
			
			GUILayout.Space(10.0f);
			
			DrawHorizontalLine();
			
			GUILayout.Space(10.0f);
			
			DrawPlugins();
			
			/*GUILayout.Space(10.0f);
			
			DrawHorizontalLine();*/
			
			DrawMapVisibilityPanel();
			
			GUILayout.Space(10.0f);
			
			DrawHorizontalLine();
			
			GUILayout.Space(10.0f);
			
			foldAdvancedOptions = EditorGUILayout.Foldout(foldAdvancedOptions,TidyMessages.MAP_CREATOR_TIDY_ADVANCED_OPTIONS);
			
			if(foldAdvancedOptions){
				
				DrawAdvancedOptions();
				
			}
			
			GUILayout.Space(10.0f);
			
			DrawHorizontalLine();			
			
			GUILayout.FlexibleSpace();
			
			EditorGUILayout.EndVertical();
			
			EditorGUILayout.EndScrollView();
												
		}
		void SaveBlock(OrientedBlock block, GameObject blockPrefab){
			
			//rename the screenshot
					
			if(blockName != block.name){
			
				string path = TidyEditorUtility.previewPath+"/"+block.name+".png";
						
				AssetDatabase.RenameAsset("Assets/"+TidyEditorUtility.blockPath+"/"+block.name+".prefab",blockName);
				
				//rename the block
				workingBlock.name = blockName;
				
				AssetDatabase.RenameAsset("Assets/"+path,block.name);
									
			}
			//save the created object over the existing prefab
			//EditorUtility.ReplacePrefab(block.gameObject,blockPrefab.gameObject);
			
			mapCreator.HideAllBlocksOfType(blockPrefab.name);
			
			PrefabUtility.DisconnectPrefabInstance(block.gameObject);
			
			PrefabUtility.ReplacePrefab(block.gameObject,blockPrefab.gameObject);
					
			PrefabUtility.RevertPrefabInstance(block.gameObject);
			
			mapCreator.RefreshWorkingBlockMenu();
			
		}