Пример #1
0
        public void GetColliderBoundsPointsRelativeTo()
        {
            var relativeTo = new GameObject();

            relativeTo.transform.position = Vector3.forward;
            relativeTo.transform.rotation = Quaternion.identity;

            BoundsExtensions.GetColliderBoundsPoints(cube, boundsPoints, 0, relativeTo.transform);
            expectedPoints = new Vector3[] {
                new Vector3(-0.5f, -0.5f, -1.5f),
                new Vector3(-0.5f, -0.5f, -0.5f),
                new Vector3(-0.5f, 0.5f, -1.5f),
                new Vector3(-0.5f, 0.5f, -0.5f),
                new Vector3(0.5f, -0.5f, -1.5f),
                new Vector3(0.5f, -0.5f, -0.5f),
                new Vector3(0.5f, 0.5f, -1.5f),
                new Vector3(0.5f, 0.5f, -0.5f),
            };
            Assert.AreEqual(expectedPoints, boundsPoints.ToArray());

            boundsPoints.Clear();
            relativeTo.transform.localScale = 0.5f * Vector3.one;
            BoundsExtensions.GetColliderBoundsPoints(cube, boundsPoints, 0, relativeTo.transform);
            expectedPoints = new Vector3[] {
                new Vector3(-1f, -1f, -3f),
                new Vector3(-1f, -1f, -1f),
                new Vector3(-1f, 1f, -3f),
                new Vector3(-1f, 1f, -1f),
                new Vector3(1f, -1f, -3f),
                new Vector3(1f, -1f, -1f),
                new Vector3(1f, 1f, -3f),
                new Vector3(1f, 1f, -1f),
            };
            Assert.AreEqual(expectedPoints, boundsPoints.ToArray());
        }
 private void AddColliderBoundsToTarget(KeyValuePair <Transform, Collider> colliderByTransform)
 {
     if (colliderByTransform.Key != null)
     {
         BoundsExtensions.GetColliderBoundsPoints(colliderByTransform.Value, totalBoundsCorners, 0);
     }
 }
Пример #3
0
        public void GetColliderBoundsPoints()
        {
            // SetUp
            expectedPoints = new Vector3[] {
                new Vector3(-0.5f, -0.5f, -0.5f),
                new Vector3(-0.5f, -0.5f, 0.5f),
                new Vector3(-0.5f, 0.5f, -0.5f),
                new Vector3(-0.5f, 0.5f, 0.5f),
                new Vector3(0.5f, -0.5f, -0.5f),
                new Vector3(0.5f, -0.5f, 0.5f),
                new Vector3(0.5f, 0.5f, -0.5f),
                new Vector3(0.5f, 0.5f, 0.5f),
            };

            BoundsExtensions.GetColliderBoundsPoints(cube, boundsPoints, 0);

            Assert.AreEqual(expectedPoints, boundsPoints.ToArray());

            boundsPoints.Clear();
            cube.transform.localScale = Vector3.one * 2f;
            BoundsExtensions.GetColliderBoundsPoints(cube, boundsPoints, 0);
            expectedPoints = new Vector3[] {
                new Vector3(-1f, -1f, -1f),
                new Vector3(-1f, -1f, 1f),
                new Vector3(-1f, 1f, -1f),
                new Vector3(-1f, 1f, 1f),
                new Vector3(1f, -1f, -1f),
                new Vector3(1f, -1f, 1f),
                new Vector3(1f, 1f, -1f),
                new Vector3(1f, 1f, 1f),
            };
            Assert.AreEqual(expectedPoints, boundsPoints.ToArray());

            boundsPoints.Clear();
            cube.transform.localScale = new Vector3(10, 1, 1);
            BoundsExtensions.GetColliderBoundsPoints(cube, boundsPoints, 0);

            expectedPoints = new Vector3[] {
                new Vector3(-5f, -0.5f, -0.5f),
                new Vector3(-5f, -0.5f, 0.5f),
                new Vector3(-5f, 0.5f, -0.5f),
                new Vector3(-5f, 0.5f, 0.5f),
                new Vector3(5f, -0.5f, -0.5f),
                new Vector3(5f, -0.5f, 0.5f),
                new Vector3(5f, 0.5f, -0.5f),
                new Vector3(5f, 0.5f, 0.5f),
            };

            Assert.AreEqual(expectedPoints, boundsPoints.ToArray());
        }