public static void DrawBlockEditor(OCBlock block, OCBlockSet blockSet) { GUILayout.BeginVertical(GUI.skin.box); { string name = EditorGUILayout.TextField("Name", block.GetName()); block.SetName( FixNameString(name) ); if(block is OCGlassBlock) { OCGlassBlock glass = (OCGlassBlock)block; GameObject interior = (GameObject)EditorGUILayout.ObjectField("Interior", glass.GetInterior(), typeof(GameObject), true, null); glass.SetInterior( interior ); } int atlas = EditorGUIUtils.Popup( "Atlas", block.AtlasID, blockSet.Atlases ); block.AtlasID = atlas; int light = EditorGUILayout.IntField("Light", block.GetLight()); block.SetLight(light); } GUILayout.EndVertical(); Texture texture = block.GetTexture(); if(texture != null) { FieldInfo field = DrawFacesList(block, texture); int face = (int)field.GetValue(block); DrawFaceEditor(ref face, block.Atlas, ref atlasMatrix); field.SetValue(block, face); } }
public OCTerrainGenerator(OpenCog.Map.OCMap map) { this.map = map; Debug.Log("OCTerrainGenerator is getting the BlockSet from the Map."); OpenCog.BlockSet.OCBlockSet blockSet = map.GetBlockSet(); Debug.Log("BlockSet retrieved..."); water = blockSet.GetBlock("Water"); grass = blockSet.GetBlock("Grass"); if (grass == null) { Debug.Log("We have no Grass! :("); for (int i = 0; i < blockSet.Blocks.Length; i++) { Debug.Log("But we have " + blockSet.Blocks[i].GetName()); } } dirt = blockSet.GetBlock("Dirt"); sand = blockSet.GetBlock("Sand"); stone = blockSet.GetBlock("Stone"); snow = blockSet.GetBlock("Snow"); ice = blockSet.GetBlock("Ice"); }
public OCTreeGenerator(OpenCog.Map.OCMap map) { this.map = map; OpenCog.BlockSet.OCBlockSet blockSet = map.GetBlockSet(); wood = blockSet.GetBlock("Wood"); leaves = blockSet.GetBlock("Leaves"); }
private void GenerateBlockForIsland(Vector3i worldPos, int deep, int height) { if (caveNoise3D.GetNoise(worldPos.x, worldPos.y, worldPos.z) > 0.7f) { return; } float noise = islandNoise3D.GetNoise(worldPos.x, worldPos.y, worldPos.z); OpenCog.BlockSet.BaseBlockSet.OCBlock block = null; if (IsInRange(noise, 0, 0.2f)) { block = sand; } if (IsInRange(noise, 0.2f, 0.6f)) { block = dirt; } if (IsInRange(noise, 0.6f, 1f)) { block = stone; } if (block != null) { map.SetBlock(block, worldPos); } }
private static XmlNode WriteBlockList(OCBlock[] list, XmlDocument document) { XmlNode node = document.CreateElement("OCBlockList"); foreach(OCBlock block in list) { XmlNode childNode = WriteBlock(block, document); node.AppendChild(childNode); } return node; }
private static XmlNode WriteBlock(OCBlock block, XmlDocument document) { XmlNode node = document.CreateElement(block.GetType().Name); FieldInfo[] fields = GetFields(block.GetType()); foreach(FieldInfo field in fields) { XmlNode childNode = WriteField(field, block, document); if(childNode != null) node.AppendChild(childNode); } return node; }
private static OpenCog.BlockSet.BaseBlockSet.OCBlock[] ReadBlockList(XmlNode blockSetNode) { XmlNode node = FindNodeByName(blockSetNode, "OCBlockList"); List <BaseBlockSet.OCBlock> list = new List <BaseBlockSet.OCBlock>(); foreach (XmlNode childNode in node.ChildNodes) { OpenCog.BlockSet.BaseBlockSet.OCBlock block = ReadBlock(childNode); list.Add(block); } return(list.ToArray()); }
private static FieldInfo DrawFacesList(OCBlock block, Texture texture) { List<FieldInfo> fields = GetFaces(block); Rect[] faces = new Rect[fields.Count]; string[] names = new string[fields.Count]; for(int i=0; i<fields.Count; i++) { int pos = (int) fields[i].GetValue( block ); faces[i] = block.ToRect(pos); names[i] = FixNameString(fields[i].Name); } selectedFace = Mathf.Clamp(selectedFace, 0, fields.Count-1); selectedFace = DrawFacesList(texture, faces, names, selectedFace); return fields[selectedFace]; }
private void GenerateBlockForBaseTerrain(Vector3i worldPos) { float noise = terrainNoise3D.GetNoise(worldPos.x, worldPos.y, worldPos.z); OpenCog.BlockSet.BaseBlockSet.OCBlock block = null; if (IsInRange(noise, 0, 0.2f)) { block = sand; } if (IsInRange(noise, 0.2f, 0.6f)) { block = dirt; } if (IsInRange(noise, 0.6f, 1f)) { block = stone; } if (block != null) { map.SetBlock(block, worldPos); } }
public OCTreeGenerator(OpenCog.Map.OCMap map, OpenCog.BlockSet.BaseBlockSet.OCBlock wood, OpenCog.BlockSet.BaseBlockSet.OCBlock leaves) { this.map = map; this.wood = wood; this.leaves = leaves; }
public void LoadLevel() { int verticalOffset = 85; Debug.Log("About to load level folder: " + _fullMapPath + "."); Substrate.AnvilWorld mcWorld = Substrate.AnvilWorld.Create(_fullMapPath); Substrate.AnvilRegionManager mcAnvilRegionManager = mcWorld.GetRegionManager(); OpenCog.BlockSet.OCBlockSet blockSet = _map.GetBlockSet(); //_map.GetSunLightmap().SetSunHeight(20, 4, 4); int createCount = 0; System.Collections.Generic.Dictionary <int, int> unmappedBlockTypes = new System.Collections.Generic.Dictionary <int, int>(); //Debug.Log("In LoadLevel, there are " + blockSet.BlockCount + " blocks available."); foreach (Substrate.AnvilRegion mcAnvilRegion in mcAnvilRegionManager) { // Loop through x-axis of chunks in this region for (int iMCChunkX = 0; iMCChunkX < mcAnvilRegion.XDim; iMCChunkX++) { // Loop through z-axis of chunks in this region. for (int iMCChunkZ = 0; iMCChunkZ < mcAnvilRegion.ZDim; iMCChunkZ++) { // Retrieve the chunk at the current position in our 2D loop... Substrate.ChunkRef mcChunkRef = mcAnvilRegion.GetChunkRef(iMCChunkX, iMCChunkZ); if (mcChunkRef != null) { if (mcChunkRef.IsTerrainPopulated) { // Ok...now to stick the blocks in... int iMCChunkY = 0; OCChunk chunk = null; //new OCChunk(_map, new Vector3i(iMCChunkX, iMCChunkY, iMCChunkZ)); OCChunk lastChunk = null; Vector3i chunkPos = new Vector3i(mcAnvilRegion.ChunkGlobalX(iMCChunkX), iMCChunkY + verticalOffset, mcAnvilRegion.ChunkGlobalZ(iMCChunkZ)); Vector3i lastChunkPos = Vector3i.zero; chunk = _map.GetChunkInstance(chunkPos); for (int iMCChunkInternalY = 0; iMCChunkInternalY < mcChunkRef.Blocks.YDim; iMCChunkInternalY++) { if (iMCChunkInternalY / OCChunk.SIZE_Y > iMCChunkY) { lastChunk = chunk; lastChunkPos = chunkPos; chunkPos = new Vector3i(mcAnvilRegion.ChunkGlobalX(iMCChunkX), (iMCChunkInternalY + verticalOffset) / OCChunk.SIZE_Y, mcAnvilRegion.ChunkGlobalZ(iMCChunkZ)); chunk = _map.GetChunkInstance(chunkPos); } for (int iMCChunkInternalX = 0; iMCChunkInternalX < mcChunkRef.Blocks.XDim; iMCChunkInternalX++) { for (int iMCChunkInternalZ = 0; iMCChunkInternalZ < mcChunkRef.Blocks.ZDim; iMCChunkInternalZ++) { int iBlockID = mcChunkRef.Blocks.GetID(iMCChunkInternalX, iMCChunkInternalY, iMCChunkInternalZ); if (iBlockID != 0) { Vector3i blockPos = new Vector3i(iMCChunkInternalX, iMCChunkInternalY % OCChunk.SIZE_Y, iMCChunkInternalZ); int ourBlockID = -1; // switch (iBlockID) // { // case 3: // Dirt to first grass // ourBlockID = 1; // break; // case 12: // Grass to grass // ourBlockID = 1; // break; // case 13: // Gravel to stone // ourBlockID = 4; // break; // case 1: // Stone to second stone // ourBlockID = 5; // break; // case 16: // Coal ore to fungus // ourBlockID = 17; // break; // case 15: // Iron ore to pumpkin // ourBlockID = 20; // break; // case 9: // Water to water // ourBlockID = 8; // //Debug.Log ("Creating some water at [" + blockPos.x + ", " + blockPos.y + ", " + blockPos.z + "]"); // break; //// case 2: //// iBlockID = 16; //// break; //// case 4: //// iBlockID = 16; //// break; //// case 18: //// iBlockID = 16; //// break; // default: // { // //Debug.Log ("Unmapped BlockID: " + iBlockID); // // if (!unmappedBlockTypes.ContainsKey (iBlockID)) // { // unmappedBlockTypes.Add (iBlockID, 1); // } // else // { // unmappedBlockTypes[iBlockID] += 1; // } // // break; // } // } if (mcToOCBlockDictionary.ContainsKey(iBlockID)) { ourBlockID = mcToOCBlockDictionary[iBlockID]; } else { if (!unmappedBlockTypes.ContainsKey(iBlockID)) { unmappedBlockTypes.Add(iBlockID, 1); } else { unmappedBlockTypes[iBlockID] += 1; } } if (ourBlockID != -1) { OpenCog.BlockSet.BaseBlockSet.OCBlock newBlock = blockSet.GetBlock(ourBlockID); OCBlockData block = new OpenCog.Map.OCBlockData(newBlock, blockPos); chunk.SetBlock(block, blockPos); OpenCog.Map.Lighting.OCLightComputer.RecomputeLightAtPosition(_map, blockPos); if (block.block.GetName() == "Battery") { GameObject batteryPrefab = OCMap.Instance.BatteryPrefab; if (batteryPrefab == null) { UnityEngine.Debug.Log("OCBuilder::Update, batteryPrefab == null"); } else { GameObject battery = (GameObject)GameObject.Instantiate(batteryPrefab); battery.transform.position = blockPos; battery.name = "Battery"; battery.transform.parent = OCMap.Instance.BatteriesSceneObject.transform; } } if (block.block.GetName() == "Hearth") { GameObject hearthPrefab = OCMap.Instance.HearthPrefab; if (hearthPrefab == null) { UnityEngine.Debug.Log("OCBuilder::Update, hearthPrefab == null"); } else { GameObject hearth = (GameObject)GameObject.Instantiate(hearthPrefab); hearth.transform.position = blockPos; hearth.name = "Hearth"; hearth.transform.parent = OCMap.Instance.HearthsSceneObject.transform; } } createCount += 1; } } } // End for (int iMCChunkInternalZ = 0; iMCChunkInternalZ < mcChunkRef.Blocks.ZDim; iMCChunkInternalZ++) } // End for (int iMCChunkInternalY = 0; iMCChunkInternalY < mcChunkRef.Blocks.YDim; iMCChunkInternalY++) string chunkCoord = chunkPos.x + ", " + chunkPos.z; if (!chunkList.ContainsKey(chunkCoord)) { chunkList.Add(chunkCoord, chunkPos); } if (iMCChunkY < iMCChunkInternalY / OCChunk.SIZE_Y) { _map.Chunks.AddOrReplace(lastChunk, lastChunkPos); _map.UpdateChunkLimits(lastChunkPos); _map.SetDirty(lastChunkPos); iMCChunkY = iMCChunkInternalY / OCChunk.SIZE_Y; } } // End for (int iMCChunkInternalX = 0; iMCChunkInternalX < mcChunkRef.Blocks.XDim; iMCChunkInternalX++) } // End if (mcChunkRef.IsTerrainPopulated) } // End if (mcChunkRef != null) } // End for (int iMCChunkZ = 0; iMCChunkZ < mcAnvilRegion.ZDim; iMCChunkZ++) } // End for (int iMCChunkX = 0; iMCChunkX < mcAnvilRegion.XDim; iMCChunkX++) } // End foreach( Substrate.AnvilRegion mcAnvilRegion in mcAnvilRegionManager ) foreach (Vector3i chunkToLight in chunkList.Values) { OpenCog.Map.Lighting.OCChunkSunLightComputer.ComputeRays(_map, chunkToLight.x, chunkToLight.z); OpenCog.Map.Lighting.OCChunkSunLightComputer.Scatter(_map, null, chunkToLight.x, chunkToLight.z); } foreach (System.Collections.Generic.KeyValuePair <int, int> unmappedBlockData in unmappedBlockTypes) { UnityEngine.Debug.Log("Unmapped BlockID '" + unmappedBlockData.Key + "' found " + unmappedBlockData.Value + " times."); } Debug.Log("Loaded level: " + _fullMapPath + ", created " + createCount + " blocks."); _map.AddColliders(); } // End public void LoadLevel()
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Public Member Functions //--------------------------------------------------------------------------- public IEnumerator Start() { _map = OCMap.Instance;//(OCMap)GameObject.FindObjectOfType (typeof(OCMap)); _goalBlockType = _map.GetBlockSet().GetBlock(_blockType); List3D<OCChunk> chunks = _map.GetChunks (); // Since this is probably bogging down the gameplay, switch it to block creation only. FindGoalBlockPositionInChunks(chunks); while (Application.isPlaying) { yield return new WaitForSeconds (1.0f); UpdateGoal(); } // yield return 0; }
private static List<FieldInfo> GetFaces(OCBlock block) { FieldInfo[] fields = block.GetType().GetFields( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic ); List<FieldInfo> list = new List<FieldInfo>(); foreach(FieldInfo field in fields) { if(field.FieldType == typeof(int)) list.Add(field); } return list; }
private static bool DrawItem(Rect position, OCBlock block, bool selected, int index) { Rect texturePosition = position; texturePosition.height = texturePosition.width; Rect labelPosition = position; labelPosition.yMin += texturePosition.height; if(selected) BlockEditorUtils.FillRect(labelPosition, new Color( 61/255f, 128/255f, 223/255f )); if(block != null) { block.DrawPreview(texturePosition); GUI.Label(labelPosition, block.GetName()); } else { BlockEditorUtils.FillRect(texturePosition, Color.grey); GUI.Label(labelPosition, "Null"); } if(Event.current.type == EventType.MouseDown && Event.current.button == 0 && position.Contains(Event.current.mousePosition)) { Event.current.Use(); return true; } return false; }