// CSClodMgr void OnDirtyVoxel(Vector3 pos, byte terrainType) { #if NEW_CLOD_MGR foreach (KeyValuePair <int, CSCreator> kvp in m_Creators) { CSMgCreator mgCreator = kvp.Value as CSMgCreator; if (mgCreator == null) { continue; } if (mgCreator.Assembly != null && mgCreator.Assembly.InLargestRange(pos) && mgCreator.m_Clod != null) { RaycastHit rch; Vector3 realPos = Vector3.zero; if (Physics.Raycast(pos + new Vector3(0, 1, 0), Vector3.down, out rch, 2, 1 << Pathea.Layer.VFVoxelTerrain)) { realPos = rch.point; } else { realPos = pos; } if (!FarmManager.Instance.mPlantHelpMap.ContainsKey(new IntVec3(pos))) { mgCreator.m_Clod.AddClod(realPos, false); } else { mgCreator.m_Clod.AddClod(realPos, true); } } } #else CSMgCreator creator = GetCreator(CSConst.ciDefMgCamp) as CSMgCreator; if (creator.Assembly != null && creator.Assembly.InRange(pos)) { RaycastHit rch; Vector3 realPos = Vector3.zero; if (Physics.Raycast(pos + new Vector3(0, 1, 0), Vector3.down, out rch, 2, 1 << Pathea.Layer.VFVoxelTerrain)) { realPos = rch.point; } else { realPos = pos; } if (!FarmManager.mPlantHelpMap.ContainsKey(new IntVec3(pos))) { CSClodMgr.AddClod(realPos, false); } else { CSClodMgr.AddClod(realPos, true); } } #endif }
void OnDigTerrain(IntVector3 pos) { #if NEW_CLOD_MGR foreach (KeyValuePair <int, CSCreator> kvp in m_Creators) { CSMgCreator mgCreator = kvp.Value as CSMgCreator; if (mgCreator == null) { continue; } mgCreator.m_Clod.DeleteClod(pos); VFVoxel voxel = VFVoxelTerrain.self.Voxels.SafeRead(pos.x, pos.y - 1, pos.z); if ((voxel.Type == PlantConst.DIRTY_TYPE0 || voxel.Type == PlantConst.DIRTY_TYPE1) && voxel.Volume > 128) { RaycastHit rch; if (Physics.Raycast(pos, Vector3.down, out rch, 2, 1 << Pathea.Layer.VFVoxelTerrain)) { mgCreator.m_Clod.AddClod(rch.point, false); } else { mgCreator.m_Clod.AddClod(new Vector3(pos.x, pos.y - 0.7f, pos.z), false); } } } #else CSClodMgr.DeleteClod(pos); VFVoxel voxel = VFVoxelTerrain.self.Voxels.SafeRead(pos.x, pos.y - 1, pos.z); if (voxel.Type == CSClodMgr.TerrainType) { RaycastHit rch; if (Physics.Raycast(pos, Vector3.down, out rch, 2, 1 << Pathea.Layer.VFVoxelTerrain)) { CSClodMgr.AddClod(rch.point, false); } else { CSClodMgr.AddClod(new Vector3(pos.x, pos.y - 0.7f, pos.z), false); } } #endif }
public IEnumerator SearchVaildClodForAssembly(CSAssembly assem) { if (assem == null) { yield break; } if (assem.isSearchingClod) { yield break; } assem.isSearchingClod = true; CSMgCreator mgCreator = assem.m_Creator as CSMgCreator; mgCreator.m_Clod.Clear(); int width = Mathf.RoundToInt(assem.LargestRadius); // - 10; int length = width; int height = width; Vector3 int_pos = new Vector3(Mathf.FloorToInt(assem.Position.x), Mathf.FloorToInt(assem.Position.y), Mathf.FloorToInt(assem.Position.z)); Vector3 min_pos = int_pos - new Vector3(width, length, height); //Vector3 max_pos = int_pos + new Vector3(width, length, height); Vector3 pos = min_pos; float sqrRadius = assem.LargestRadius * assem.LargestRadius; length *= 2; width *= 2; height *= 2; int raycast_count = 0; int break_count = 0; for (int i = 0; i < width; i++) { for (int j = 0; j < length; j++, break_count++) { Vector3 prv_pos = Vector3.zero; VFVoxel prv_voxel = new VFVoxel(); for (int k = 0; k < height; k++) { pos = min_pos + new Vector3(i, k, j); if ((pos - int_pos).sqrMagnitude > sqrRadius) { continue; } VFVoxel voxel = VFVoxelTerrain.self.Voxels.SafeRead((int)pos.x, (int)pos.y, (int)pos.z); if (voxel.Volume < 128) { if (prv_voxel.Volume > 128 && (prv_voxel.Type == 19 || prv_voxel.Type == 63)) { RaycastHit rch; Vector3 clod_pos = Vector3.zero; if (Physics.Raycast(new Vector3(prv_pos.x, prv_pos.y + 1, prv_pos.z), Vector3.down, out rch, 2, 1 << Pathea.Layer.VFVoxelTerrain)) { raycast_count++; clod_pos = rch.point; } else { clod_pos = new Vector3(prv_pos.x, prv_pos.y + 0.4f, prv_pos.z); } #if NEW_CLOD_MGR if (!FarmManager.Instance.mPlantHelpMap.ContainsKey(new IntVec3(prv_pos))) { mgCreator.m_Clod.AddClod(clod_pos, false); } else { mgCreator.m_Clod.AddClod(clod_pos, true); } #else if (!FarmManager.mPlantHelpMap.ContainsKey(new IntVec3(prv_pos))) { CSClodMgr.AddClod(clod_pos, false); } else { CSClodMgr.AddClod(clod_pos, true); } #endif } } prv_pos = pos; prv_voxel = voxel; } if (break_count >= 30 || raycast_count >= 30) { raycast_count = 0; break_count = 0; yield return(0); if (assem == null) { yield break; } } } } if (assem != null) { assem.isSearchingClod = false; } yield return(0); }