Esempio n. 1
0
    //Generate our map
    public void GenerateMap(int width, int height, int depth,
                            string mapName, Vector3 tileScale,
                            int chunkWidth, int chunkHeight,
                            BlockMap.GrowthAxis growthAxis,
                            float deleteUpdateRate, float createUpdateRate, int actionsPerPass)
    {
        this.deleteRate     = deleteUpdateRate;
        this.createRate     = createUpdateRate;
        this.actionsPerPass = actionsPerPass;

        if (this.blockMap == null)
        {
            InitializeStreamingMap(width, height, depth);

            this.blockMap = BlockUtilities.CreateBlockMap(mapName, tileScale, chunkWidth, chunkHeight, growthAxis);
        }
    }
		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();
												
		}
Esempio n. 3
0
        /// <summary>
        /// Creates a Blockmap from the provided save string. I bet you'd like to know how you can use this! :D No dice.
        /// </summary>
        /// <param name="blockMapString">
        /// The save string.
        /// </param>
        /// <returns>
        /// The created BlockMap, if creation was successful.
        /// </returns>
        public static BlockMap StringToBlockMap(string blockMapString)
        {
            BlockMap map = null;

            string[] mapFields = blockMapString.Split(MAP_STRING_FIELD_DELIM);

            string mapName = mapFields[0];

            string[] scale = mapFields[1].Split(',');

            float tileScale_x, tileScale_y, tileScale_z;

            tileScale_x = float.Parse(scale[0]);
            tileScale_y = float.Parse(scale[1]);
            tileScale_z = float.Parse(scale[2]);

            Vector3 tileScale = new Vector3(tileScale_x, tileScale_y, tileScale_z);

            Debug.Log(mapFields[2]);
            Debug.Log(mapFields[3]);

            int chunkWidth  = int.Parse(mapFields[2]);
            int chunkHeight = int.Parse(mapFields[3]);

            int growthAxis_int = int.Parse(mapFields[4]);

            BlockMap.GrowthAxis growthAxis = (BlockMap.GrowthAxis)growthAxis_int;

            int width      = int.Parse(mapFields[5]);
            int height     = int.Parse(mapFields[6]);
            int lowerDepth = int.Parse(mapFields[7]);
            int upperDepth = int.Parse(mapFields[8]);

            string[] blockLib = mapFields[9].Split(BLOCK_FIELD_DELIM);

            Debug.Log("Map name: " + mapName);
            Debug.Log("Tile Scale: " + tileScale.ToString());
            Debug.Log("Chunk width: " + chunkWidth + " Chunk height: " + chunkHeight);
            Debug.Log("Growth axis: " + growthAxis.ToString());
            Debug.Log("Lower depth: " + lowerDepth + " Upper depth: " + upperDepth);
            Debug.Log("Width: " + width + " Height: " + height);

            string libString = "";

            for (int i = 0; i < blockLib.Length; i++)
            {
                libString += blockLib[i] + " ";
            }

            Debug.Log("Block library: " + libString);

            Debug.Log("All blocks:");

            for (int i = 10; i < mapFields.Length; i++)
            {
                if (mapFields[i] == "")
                {
                    Debug.Log("Empty block");
                }
                else
                {
                    StringToBlock(mapFields[i]);
                }
            }

            return(map);
        }
Esempio n. 4
0
        /// <summary>
        ///Create a new Block Map
        /// </summary>
        /// <param name="mapName">
        /// The name of your new block map
        /// </param>
        /// <param name="tileScale">
        /// The scale of the tiles within your new blockmap
        /// </param>
        /// <param name="chunkWidth">
        /// The width of the chunks within your new blockmap (Recommend: 5)
        /// </param>
        /// <param name="chunkHeight">
        /// The height of the chunks within your new blockmap (Recommend: 5)
        /// </param>
        /// <param name="growthAxis">
        /// The direction in which your new blockmap will grow when blocks are added to it
        /// </param>
        /// <returns>
        /// Your shiny, new blockmap
        /// </returns>
        public static BlockMap CreateBlockMap(string mapName, Vector3 tileScale, int chunkWidth, int chunkHeight, BlockMap.GrowthAxis growthAxis)
        {
            GameObject o = new GameObject(mapName);

            BlockMap bm = o.AddComponent <BlockMap>();

            bm.tileScale   = tileScale;
            bm.chunkWidth  = chunkWidth;
            bm.chunkHeight = chunkHeight;
            bm.growthAxis  = growthAxis;

            bm.editorMap        = false;
            bm.hasBeenPublished = true;

            return(bm);
        }