ForgroundData Removal
Mar 31, 2015 5:44:03 GMT
Post by etoreo on Mar 31, 2015 5:44:03 GMT
I am trying to remove trees that intersect with 3D objects (Resource Types) I am placing on the Honey Terrain. Every object I place on the terrain, I see if there is any foreground data that collides with it. If it does, I need to remove that foreground data from the Hex. So I have code that looks like this:
Is there a better way to do this? When I run this code, it crashes with these symptoms: honey.boards.net/thread/20/chunk-height-null-regeneration-terrain
public static void placeResourceOnHex(HoneyFramework.Hex h, Resource.Type type)
{
if(type == Resource.Type.NONE || !HexHelper.canPlaceResourceOnHex (h, type))
return;
GameObject prefab = Instantiate(Resources.Load("Prefabs/ResourceTypes/" + type.ToString())) as GameObject;
Vector3 pos = HoneyFramework.HexCoordinates.HexToWorld3D(h.position);
prefab.transform.position = pos;
bool keepGoing = true;
bool removedForgroundObject = false;
while(keepGoing)
{
keepGoing = false;
foreach (HoneyFramework.ForegroundData fgd in h.foregroundData)
{
if (prefab.GetComponent<SphereCollider>().bounds.Contains (fgd.position))
{
h.foregroundData.Remove (fgd);
keepGoing = true;
removedForgroundObject = true;
break;
}
}
}
if(removedForgroundObject)
{
h.RebuildChunksOwningThisHex();
}
}
Is there a better way to do this? When I run this code, it crashes with these symptoms: honey.boards.net/thread/20/chunk-height-null-regeneration-terrain