Beispiel #1
0
        public IEnumerator Test6Destroy()
        {
            List <GameObject> objects = SetupScene();
            BVH <GameObject>  bvh     = CreateBVH(objects);

            float t    = 0;
            int   last = 0;

            while (t < TIME_PER_TEST)
            {
                t += Time.deltaTime;
                if (t * 5 > last)
                {
                    last++;
                    if (objects.Count > 0)
                    {
                        GameObject obj = objects[objects.Count - 1];
                        bvh.Remove(obj);
                        objects.RemoveAt(objects.Count - 1);
                        Object.Destroy(obj);
                    }
                }

                bvh.RenderDebug();

                yield return(null);
            }

            DestroyScene(objects);
        }
Beispiel #2
0
        public IEnumerator Test8AddDestroyAndUpdate()
        {
            List <GameObject> objects = SetupScene();
            BVH <GameObject>  bvh     = CreateBVH(objects);

            float t    = 0;
            int   last = 0;

            while (t < TIME_PER_TEST)
            {
                t += Time.deltaTime;
                if (t * 5 > last)
                {
                    last++;

                    if (Random.Range(0, 2) == 1)
                    {
                        GameObject obj = CreateGameObject();
                        objects.Add(obj);
                        bvh.Add(obj);
                    }
                    else if (objects.Count > 0)
                    {
                        GameObject obj = objects[objects.Count - 1];
                        bvh.Remove(obj);
                        objects.RemoveAt(objects.Count - 1);
                        Object.Destroy(obj);
                    }
                }

                foreach (GameObject obj in objects)
                {
                    obj.transform.Translate(obj.transform.forward * Time.deltaTime * 5);
                    bvh.MarkForUpdate(obj);
                }

                bvh.Optimize();
                bvh.RenderDebug();

                yield return(null);
            }

            DestroyScene(objects);
        }