public void GeneratePlants(int cx, int cz) { for (int z = -1; z < OpenCog.Map.OCChunk.SIZE_Z + 1; z++) { for (int x = -1; x < OpenCog.Map.OCChunk.SIZE_X + 1; x++) { Vector3i worldPos = new Vector3i(cx * OpenCog.Map.OCChunk.SIZE_X + x, 0, cz * OpenCog.Map.OCChunk.SIZE_Z + z); worldPos.y = map.GetMaxY(worldPos.x, worldPos.z); for (; worldPos.y >= WATER_LEVEL; worldPos.y--) { if (map.GetBlock(worldPos).block == dirt && map.GetSunLightmap().GetLight(worldPos + Vector3i.up) > 5) { map.SetBlock(grass, worldPos); } } } } }
/// <summary> /// Update is called once per frame. /// </summary> public void Update() { if (UnityEngine.Screen.showCursor) { return; } if (UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.LeftControl)) { Vector3i?point = GetCursor(false); if (point.HasValue) { byte sun = _map.GetSunLightmap().GetLight(point.Value); byte light = _map.GetLightmap().GetLight(point.Value); Debug.Log(OCLogSymbol.DETAILEDINFO + "Sun " + " " + sun + " Light " + light); } } if (UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.RightControl)) { Vector3i?point = GetCursor(true); if (point.HasValue) { byte sun = _map.GetSunLightmap().GetLight(point.Value); byte light = _map.GetLightmap().GetLight(point.Value); Debug.Log(OCLogSymbol.DETAILEDINFO + "Sun " + sun + " Light " + light); } } if (UnityEngine.Input.GetMouseButtonDown(0)) { Vector3i?point = GetCursor(true); if (point.HasValue) { // Vector3i above = point.Value; // above.y += 1; // OCBlockData blockAbove = _map.GetBlock(above); // OCBlockData blockData = _map.GetBlock (point.Value); // if(blockAbove.IsEmpty() && !blockData.IsEmpty()) // { // _map.SetBlockAndRecompute(blockData, above); // _map.SetBlockAndRecompute(OCBlockData.CreateInstance<OCBlockData>().Init(null, point.Value), point.Value); // } // else Debug.Log(OCLogSymbol.DEBUG + "DeleteSelectedVoxel called from CreateBlockEffect"); GameManager.world.voxels.DeleteSelectedVoxel(point.Value); } } if (UnityEngine.Input.GetMouseButtonDown(1)) { Vector3i?point = GetCursor(false); if (point.HasValue) { bool empty = !BlockCharacterCollision.GetContactBlockCharacter(point.Value, transform.position, gameObject.GetComponent <CharacterController>()).HasValue; if (empty) { Debug.Log(OCLogSymbol.DEBUG + "AddSelectedVoxel called from OCBuilder"); GameManager.world.voxels.AddSelectedVoxel(point.Value, -transform.forward, _selectedBlock); OCGoalController[] goalControllers = (OCGoalController[])GameObject.FindObjectsOfType(typeof(OCGoalController)); foreach (OCGoalController goalController in goalControllers) { if (goalController.GoalBlockType == _selectedBlock) { Vector3 sourcePos = goalController.gameObject.transform.position; Vector3 oldDistanceVec = ((Vector3)goalController.GoalBlockPos) - sourcePos; Vector3 newDistanceVec = point.Value - sourcePos; if (newDistanceVec.sqrMagnitude < oldDistanceVec.sqrMagnitude) { goalController.GoalBlockPos = point.Value; goalController.MoveTargetsIfNecessary(); } } } } } } Vector3i?cursor = GetCursor(true); _cursor.SetActive(cursor.HasValue); if (cursor.HasValue) { _cursor.transform.position = cursor.Value; } //System.Console.WriteLine(OCLogSymbol.DETAILEDINFO +gameObject.name + " is updated."); }
/// <summary> /// Update is called once per frame. /// </summary> public void Update() { if (UnityEngine.Screen.showCursor) { return; } if (UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.LeftControl)) { Vector3i?point = GetCursor(false); if (point.HasValue) { byte sun = _map.GetSunLightmap().GetLight(point.Value); byte light = _map.GetLightmap().GetLight(point.Value); OCLogger.Info("Sun " + " " + sun + " Light " + light); } } if (UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.RightControl)) { Vector3i?point = GetCursor(true); if (point.HasValue) { byte sun = _map.GetSunLightmap().GetLight(point.Value); byte light = _map.GetLightmap().GetLight(point.Value); OCLogger.Info("Sun " + sun + " Light " + light); } } if (UnityEngine.Input.GetMouseButtonDown(0)) { Vector3i?point = GetCursor(true); if (point.HasValue) { _map.SetBlockAndRecompute(new OpenCog.Map.OCBlockData(), point.Value); } } if (UnityEngine.Input.GetMouseButtonDown(1)) { Vector3i?point = GetCursor(false); if (point.HasValue) { bool empty = !BlockCharacterCollision.GetContactBlockCharacter(point.Value, transform.position, gameObject.GetComponent <CharacterController>()).HasValue; if (empty) { OpenCog.Map.OCBlockData block = new OpenCog.Map.OCBlockData(_selectedBlock, OpenCog.Utility.VectorUtil.Vector3ToVector3i(point.Value)); block.SetDirection(GetDirection(-transform.forward)); _map.SetBlockAndRecompute(block, point.Value); } } } Vector3i?cursor = GetCursor(true); _cursor.SetActive(cursor.HasValue); if (cursor.HasValue) { _cursor.transform.position = cursor.Value; } OCLogger.Fine(gameObject.name + " is updated."); }
/// <summary> /// Update is called once per frame. /// </summary> public void Update() { if (UnityEngine.Screen.showCursor) { return; } if (UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.LeftControl)) { Vector3i?point = GetCursor(false); if (point.HasValue) { byte sun = _map.GetSunLightmap().GetLight(point.Value); byte light = _map.GetLightmap().GetLight(point.Value); OCLogger.Info("Sun " + " " + sun + " Light " + light); } } if (UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.RightControl)) { Vector3i?point = GetCursor(true); if (point.HasValue) { byte sun = _map.GetSunLightmap().GetLight(point.Value); byte light = _map.GetLightmap().GetLight(point.Value); OCLogger.Info("Sun " + sun + " Light " + light); } } if (UnityEngine.Input.GetMouseButtonDown(0)) { Vector3i?point = GetCursor(true); if (point.HasValue) { // Vector3i above = point.Value; // above.y += 1; // OCBlockData blockAbove = _map.GetBlock(above); // OCBlockData blockData = _map.GetBlock (point.Value); // if(blockAbove.IsEmpty() && !blockData.IsEmpty()) // { // _map.SetBlockAndRecompute(blockData, above); // _map.SetBlockAndRecompute(OCBlockData.CreateInstance<OCBlockData>().Init(null, point.Value), point.Value); // } // else _map.SetBlockAndRecompute(OCBlockData.CreateInstance <OCBlockData>().Init(null, point.Value), point.Value); } } if (UnityEngine.Input.GetMouseButtonDown(1)) { Vector3i?point = GetCursor(false); if (point.HasValue) { bool empty = !BlockCharacterCollision.GetContactBlockCharacter(point.Value, transform.position, gameObject.GetComponent <CharacterController>()).HasValue; if (empty) { OpenCog.Map.OCBlockData block = OCBlockData.CreateInstance <OCBlockData>().Init(_selectedBlock, OpenCog.Utility.VectorUtil.Vector3ToVector3i(point.Value)); block.SetDirection(GetDirection(-transform.forward)); _map.SetBlockAndRecompute(block, point.Value); OCGoalController[] goalControllers = (OCGoalController[])GameObject.FindObjectsOfType(typeof(OCGoalController)); foreach (OCGoalController goalController in goalControllers) { if (goalController.GoalBlockType == _selectedBlock) { Vector3 sourcePos = goalController.gameObject.transform.position; Vector3 oldDistanceVec = ((Vector3)goalController.GoalBlockPos) - sourcePos; Vector3 newDistanceVec = point.Value - sourcePos; if (newDistanceVec.sqrMagnitude < oldDistanceVec.sqrMagnitude) { goalController.GoalBlockPos = point.Value; goalController.MoveTargetsIfNecessary(); } } } } } } Vector3i?cursor = GetCursor(true); _cursor.SetActive(cursor.HasValue); if (cursor.HasValue) { _cursor.transform.position = cursor.Value; } OCLogger.Fine(gameObject.name + " is updated."); }