private static void Scatter(OCMap map, List <Vector3i> list) // рассеивание { OCSunLightMap lightmap = map.GetSunLightmap(); for (int i = 0; i < list.Count; i++) { Vector3i pos = list[i]; if (pos.y < 0) { continue; } OCBlockData block = map.GetBlock(pos); int light = lightmap.GetLight(pos) - OCLightComputerUtils.GetLightStep(block); if (light <= MIN_LIGHT) { continue; } foreach (Vector3i dir in Vector3i.directions) { Vector3i nextPos = pos + dir; block = map.GetBlock(nextPos); if (block.IsAlpha() && lightmap.SetMaxLight((byte)light, nextPos)) { list.Add(nextPos); } if (!block.IsEmpty()) { OCLightComputerUtils.SetLightDirty(map, nextPos); } } } }
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Private Member Functions //--------------------------------------------------------------------------- private static void Build(OpenCog.Map.OCChunk chunk, bool onlyLight) { OpenCog.Map.OCMap map = chunk.GetMap(); _meshData.Clear(); for (int z = 0; z < OpenCog.Map.OCChunk.SIZE_Z; z++) { for (int y = 0; y < OpenCog.Map.OCChunk.SIZE_Y; y++) { for (int x = 0; x < OpenCog.Map.OCChunk.SIZE_X; x++) { OCBlockData blockData = chunk.GetBlock(x, y, z); if (blockData != null) { OCBlock block = blockData.block; if (block != null) { Vector3i localPos = new Vector3i(x, y, z); Vector3i worldPos = OpenCog.Map.OCChunk.ToWorldPosition(chunk.GetPosition(), localPos); if (worldPos.y > 0) { block.Build(localPos, worldPos, map, _meshData, onlyLight); } } } } } } }
public static int GetLightStep(OCBlockData block) { if(block == null || block.IsEmpty()) { return 1; } else { return 2; } }
//--------------------------------------------------------------------------- #region Private Member Data //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Accessors and Mutators //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Public Member Functions //--------------------------------------------------------------------------- public void TransferBlock(Vector3i?origin, Vector3i?destination) { if (origin.HasValue && destination.HasValue) { OCMap map = OCMap.Instance; //(OCMap)GameObject.FindSceneObjectsOfType(typeof(OCMap)).FirstOrDefault(); OCGoalController[] goalControllers = (OCGoalController[])GameObject.FindObjectsOfType(typeof(OCGoalController)); foreach (Transform battery in map.BatteriesSceneObject.transform) { if (VectorUtil.AreVectorsEqual(battery.position, new Vector3((float)origin.Value.x, (float)origin.Value.y, (float)origin.Value.z))) { battery.position = new Vector3((float)destination.Value.x, (float)destination.Value.y, (float)destination.Value.z); } } OCBlockData block = map.GetBlock(origin.Value); map.SetBlockAndRecompute(block, destination.Value); map.SetBlockAndRecompute(OCBlockData.CreateInstance <OCBlockData>().Init(null, origin.Value), origin.Value); foreach (OCGoalController goalController in goalControllers) { if (goalController.GoalBlockType == block.block) { goalController.FindGoalBlockPositionInChunks(map.GetChunks()); } } } }
private void GenerateTree(int x, int y, int z) { GenerateLeaves(new Vector3i(x, y + 6, z), new Vector3i(x, y + 6, z)); for (int i = 0; i < 8; i++) { map.SetBlock(OCBlockData.CreateInstance <OCBlockData>().Init(wood, new Vector3i(x, y + i, z)), new Vector3i(x, y + i, z)); } }
private static void RemoveLight(OCMap map, List <Vector3i> list) { OCLightMap lightmap = map.GetLightmap(); foreach (Vector3i pos in list) { lightmap.SetLight(MAX_LIGHT, pos); } List <Vector3i> lightPoints = new List <Vector3i>(); for (int i = 0; i < list.Count; i++) { Vector3i pos = list[i]; if (pos.y < 0) { continue; } int light = lightmap.GetLight(pos) - STEP_LIGHT; lightmap.SetLight(MIN_LIGHT, pos); if (light <= MIN_LIGHT) { continue; } foreach (Vector3i dir in Vector3i.directions) { Vector3i nextPos = pos + dir; OCBlockData block = map.GetBlock(nextPos); if (block.IsAlpha()) { if (lightmap.GetLight(nextPos) <= light) { list.Add(nextPos); } else { lightPoints.Add(nextPos); } } if (block.GetLight() > MIN_LIGHT) { lightPoints.Add(nextPos); } if (!block.IsEmpty()) { OCLightComputerUtils.SetLightDirty(map, nextPos); } } } Scatter(map, lightPoints); }
public static int GetLightStep(OCBlockData block) { if (block == null || block.IsEmpty()) { return(1); } else { return(2); } }
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Private Member Functions //--------------------------------------------------------------------------- private static bool IsFaceVisible(OpenCog.Map.OCMap map, Vector3i nearPos) { OCBlockData blockData = map.GetBlock(nearPos); if (blockData == null) { return(false); } OCBlock block = blockData.block; return(!(block is OCCubeBlock) || block.IsAlpha()); }
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Accessors and Mutators //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Public Member Functions //--------------------------------------------------------------------------- public void CreateBlock(Vector3i?point) { if (point.HasValue) { OCMap map = (OCMap)GameObject.FindSceneObjectsOfType(typeof(OCMap)).FirstOrDefault(); OCBlock block = map.GetBlockSet().GetBlock(_BlockType); //block.SetDirection(GetDirection(-gameObject.transform.forward)); OCBlockData blockData = new OCBlockData(block, VectorUtil.Vector3ToVector3i(point.Value)); map.SetBlockAndRecompute(blockData, point.Value); } }
protected void AddSelectedVoxelPixelland(Vector3 location, Vector3 direction, OCBlock type) { //create a block to fill with dataz OCBlockData block = OCBlockData.CreateInstance <OCBlockData>(); //get the location in vector3i form Vector3i location3i = VectorUtil.Vector3ToVector3i(location); //initialize the block block.Init(type, location3i); //set its direction (which should be calculated using GetDirection on -transform.forward) block.SetDirection(direction); //and set the block map.SetBlockAndRecompute(block, location3i); }
//--------------------------------------------------------------------------- #region Private Member Data //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Accessors and Mutators //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Public Member Functions //--------------------------------------------------------------------------- public void DestroyBlock(Vector3i?point) { if (point.HasValue) { OCMap map = OCMap.Instance; //(OCMap)GameObject.FindSceneObjectsOfType(typeof(OCMap)).FirstOrDefault(); OCGoalController[] goalControllers = (OCGoalController[])GameObject.FindObjectsOfType(typeof(OCGoalController)); OCBlock blockType = map.GetBlock(point.Value).block; map.SetBlockAndRecompute(OCBlockData.CreateInstance <OCBlockData>().Init(null, point.Value), point.Value); foreach (OCGoalController goalController in goalControllers) { if (goalController.GoalBlockType == blockType) { goalController.FindGoalBlockPositionInChunks(map.GetChunks()); } } } }
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Public Member Functions //--------------------------------------------------------------------------- public void CreateBlock(Vector3i?point) { if (point.HasValue) { OCMap map = OCMap.Instance; //(OCMap)GameObject.FindSceneObjectsOfType(typeof(OCMap)).FirstOrDefault(); OCBlock block = map.GetBlockSet().GetBlock(_BlockType); OCGoalController[] goalControllers = (OCGoalController[])GameObject.FindObjectsOfType(typeof(OCGoalController)); foreach (OCGoalController goalController in goalControllers) { if (goalController.GoalBlockType == block) { goalController.FindGoalBlockPositionInChunks(map.GetChunks()); } } //block.SetDirection(GetDirection(-gameObject.transform.forward)); OCBlockData blockData = OCBlockData.CreateInstance <OCBlockData>().Init(block, VectorUtil.Vector3ToVector3i(point.Value)); map.SetBlockAndRecompute(blockData, point.Value); } }
private ActionStatus EndAction() { //OCLogger.Debugging("Ending the " + FullName + " Action."); OCActionArgs args = null; if (_ActionController.Step != null) { args = _ActionController.Step.Arguments; } if (_blockOnFail && _blockOnRunning) { _ActionController.RunningActions.Remove(FullName); } // End animation effects // foreach(OCAnimationEffect afx in _AnimationEffects) // { // afx.Stop(); // } foreach (OCDestroyBlockEffect dbfx in _DestroyBlockEffects) { Vector3i forward = VectorUtil.Vector3ToVector3i(_Source.transform.position + _Source.transform.forward); Vector3i forwardUp = VectorUtil.Vector3ToVector3i(_Source.transform.position + _Source.transform.forward + _Source.transform.up); Vector3i forwardUp2x = VectorUtil.Vector3ToVector3i(_Source.transform.position + _Source.transform.forward + 2 * _Source.transform.up); OCBlockData forwardBlock = _Map.GetBlock(forward); OCBlockData forwardUpBlock = _Map.GetBlock(forwardUp); OCBlockData forwardUp2xBlock = _Map.GetBlock(forwardUp2x); dbfx.DestroyBlock(forward); dbfx.DestroyBlock(forwardUp); dbfx.DestroyBlock(forwardUp2x); args.EndTarget.transform.position = Vector3.zero; args.StartTarget.transform.position = Vector3.zero; // This is just some example code for you Lake, that you can use to give energy to the robot after consuming a battery. if ((forwardBlock.block != null && forwardBlock.block.GetName() == "Battery") || (forwardUpBlock.block != null && forwardUpBlock.block.GetName() == "Battery") || (forwardUp2xBlock.block != null && forwardUp2xBlock.block.GetName() == "Battery")) { UnityEngine.GameObject[] agiArray = UnityEngine.GameObject.FindGameObjectsWithTag("OCAGI"); for (int iAGI = 0; iAGI < agiArray.Length; iAGI++) { UnityEngine.GameObject agiObject = agiArray[iAGI]; //args.EndTarget = agiObject; OCPhysiologicalModel agiPhysModel = agiObject.GetComponent <OCPhysiologicalModel>(); OCPhysiologicalEffect batteryEatEffect = new OCPhysiologicalEffect(OCPhysiologicalEffect.CostLevel.NONE); batteryEatEffect.EnergyIncrease = 0.2f; agiPhysModel.ProcessPhysiologicalEffect(batteryEatEffect); break; } } } //@TODO: Fix this hack... if (Descriptors.Contains("Jump") || Descriptors.Contains("Climb") || Descriptors.Contains("Fall")) { OCCharacterMotor motor = _Source.GetComponent <OCCharacterMotor>(); motor.enabled = true; } if (!Descriptors.Contains("Idle")) { Debug.LogWarning("Ending Action: " + FullName); } // if(args.ActionPlanID != null) // OCConnectorSingleton.Instance.SendActionStatus(args.ActionPlanID, args.SequenceID, args.ActionName, true); return(ActionStatus.SUCCESS); }
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) { OCBlock newBlock = blockSet.GetBlock(ourBlockID); //OCBlockData block = new OpenCog.Map.OCBlockData(newBlock, blockPos); OCBlockData block = (OCBlockData)OCScriptableObject.CreateInstance <OCBlockData>(); block.Init(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()
/// <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."); }
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Private Member Functions //--------------------------------------------------------------------------- private void FindGoalBlockPositionInChunks(List3D <OCChunk> chunks) { Vector3 sourcePos = gameObject.transform.position; Vector3 distanceVec = ((Vector3)GoalBlockPos) - sourcePos; // // if(distanceVec.y < -1.0f + 0.5f && distanceVec.y > -1.0f - 0.5f) // if(distanceVec.sqrMagnitude < 2.25f) // { // Debug.Log("We've arrived at our goal TNT block..."); // map.SetBlockAndRecompute(new OCBlockData(), TargetBlockPos); // TargetBlockPos = Vector3i.zero; // // OCAction[] actions = gameObject.GetComponentsInChildren<OCAction>(); // // foreach(OCAction action in actions) // { // action.EndTarget.transform.position = Vector3.zero; // action.StartTarget.transform.position = Vector3.zero; // } // } bool doesGoalExist = false; //distanceVec = new Vector3(1000,1000,1000); for (int cx = chunks.GetMinX(); cx < chunks.GetMaxX(); ++cx) { for (int cy = chunks.GetMinY(); cy < chunks.GetMaxY(); ++cy) { for (int cz = chunks.GetMinZ(); cz < chunks.GetMaxZ(); ++cz) { Vector3i chunkPos = new Vector3i(cx, cy, cz); OCChunk chunk = chunks.SafeGet(chunkPos); if (chunk != null) { for (int z = 0; z < OCChunk.SIZE_Z; z++) { for (int x = 0; x < OCChunk.SIZE_X; x++) { for (int y = 0; y < OCChunk.SIZE_Y; y++) { Vector3i localPos = new Vector3i(x, y, z); OCBlockData blockData = chunk.GetBlock(localPos); Vector3i candidatePos = OCChunk.ToWorldPosition(chunk.GetPosition(), localPos); Vector3 candidateVec = ((Vector3)candidatePos) - sourcePos; if (!blockData.IsEmpty() && blockData.block.GetName() == _goalBlockType.GetName()) { doesGoalExist = true; if (candidateVec.sqrMagnitude < distanceVec.sqrMagnitude) { GoalBlockPos = candidatePos; distanceVec = candidateVec; if (_ShouldMoveTargets) { OCAction[] actions = gameObject.GetComponentsInChildren <OCAction>(); foreach (OCAction action in actions) { action.EndTarget.transform.position = new Vector3(GoalBlockPos.x, GoalBlockPos.y, GoalBlockPos.z); action.StartTarget.transform.position = gameObject.transform.position; } } Debug.Log("We found some " + _goalBlockType.GetName() + " nearby: " + GoalBlockPos + "!"); } } } } } } } } } if (GoalBlockPos != Vector3i.zero && (!doesGoalExist || _map.GetBlock(GoalBlockPos).IsEmpty())) { Debug.Log("No more " + _goalBlockType.GetName() + "... :("); GoalBlockPos = Vector3i.zero; OCAction[] actions = gameObject.GetComponentsInChildren <OCAction>(); foreach (OCAction action in actions) { action.EndTarget.transform.position = Vector3.zero; action.StartTarget.transform.position = Vector3.zero; } } }