public void Add(Entity e, Bounds bounds) { if (!worldBounds.Intersects(bounds)) { // out of the world: Remove(e); return; } var node = new VolumetricAssetOctreeNode(e, bounds); if (knownEntities.Contains(e)) { octree.Remove(node); } else { knownEntities.Add(e); } var max = math.max(mapBounds.max, bounds.max); var min = math.min(mapBounds.min, bounds.min); mapBounds.SetMinMax(min, max); octree.Add(node, bounds); }
public void CollectFish(GameObject fish) { // find matching matching FishInfo FishInfo info = null; int i = 0; int n = fishies.Count; for (i = 0; i < n; i++) { if (fishies[i].gameObject == fish) { info = fishies[i]; break; } } if (info != null) { octree.Remove(info); // Move last fish to fill space instead of shifting all fish. This might cause // a fish to skip an ApplyZones in an interval. fishies[i] = fishies[n - 1]; fishies.RemoveAt(n - 1); } Destroy(fish); }
private void Start() { // Initial size (metres), initial centre position, minimum node size (metres), looseness boundsTree = new BoundsOctree <Collider>(worldSize, pos, minNodeSize, loosenessval); // Initial size (metres), initial centre position, minimum node size (metres) //pointTree = new PointOctree<GameObject>(150, .pos, 1); for (int i = 0; i < count; i++) { var obj = GameObject.CreatePrimitive(PrimitiveType.Cube).GetComponent <Collider>(); obj.transform.SetParent(transform, false); obj.transform.position = new Vector3(Random.Range(0, worldSize), 0, Random.Range(0, worldSize)); obj.transform.localScale = new Vector3(Random.Range(1, 4), Random.Range(1, 4), Random.Range(1, 4)); var mat = new Material(obj.GetComponent <Renderer>().material); obj.GetComponent <Renderer>().material = mat; if (i % Mathf.CeilToInt(1 / percent) == 0) { StartCoroutine(RandomMove(obj, () => { boundsTree.Remove(obj); boundsTree.Add(obj, obj.bounds); })); } else if (i % Mathf.CeilToInt(1 / percent) == 1) { objs.Add(obj); mats.Add(mat); isCollide.Add(false); StartCoroutine(RandomMove(obj, null)); } else { boundsTree.Add(obj, obj.bounds); } } testObj = GameObject.CreatePrimitive(PrimitiveType.Cube).transform; mat = new Material(testObj.GetComponent <Renderer>().material); testObj.GetComponent <Renderer>().material = mat; }
public void RefreshMemory() { //bool hasFinished = true; List <hotspot> allLanding = primeLanding.GetAllItems(); nLandingSpots = allLanding.Count; foreach (var spot in allLanding) { List <hotspot> colliding; primeLanding.GetColliding(out colliding, new Bounds(spot.location, spot.heat * Vector3.one)); if (colliding.Count > 1) { hotspot newSpot = new hotspot(colliding); primeLanding.Add(newSpot, new Bounds(newSpot.location, hotspot.GetBucketSize(minLandingSize, minMemoryDistance, oneMeterMemoryDistance, newSpot.location, _thisT.position) * Vector3.one)); foreach (var item in colliding) { primeLanding.Remove(item); } //hasFinished = false; break; } } }
public void RemoveObject(T obj) { m_AllObjects.Remove(obj); m_Octree.Remove(obj); }