Beispiel #1
0
        void AddTriangles(List <Triangle3> triangles, GameObject gameObject)
        {
            var colliders = gameObject.GetComponentsInChildren <Collider2D>();

            foreach (var collider in colliders)
            {
                var transform = Matrix.FromGameTransform(collider.gameObject.transform);
                if (collider is BoxCollider2D)
                {
                    var        boxCollider = collider as BoxCollider2D;
                    Vector3    goPosition;
                    Quaternion goRotation;
                    Vector3    goScale;
                    Matrix.DecomposeMatrix(ref transform, out goPosition, out goRotation, out goScale);

                    var     collisionheight = 5;
                    var     size            = new Vector3(boxCollider.size.x, collisionheight, boxCollider.size.y);
                    Vector3 scale           = Vector3.Scale(goScale, size);
                    var     boxCenterXZ     = boxCollider.offset;
                    var     boxCenter       = new Vector3(boxCenterXZ.x, 0, boxCenterXZ.y);
                    Vector3 position        = goPosition + goRotation * Vector3.Scale(boxCenter, goScale);
                    transform = Matrix4x4.TRS(position, goRotation, scale);

                    StaticMeshTriangleProvider.AddMeshTriangles(triangles, cubeVertices, cubeIndices, transform);
                }
                else if (collider is CircleCollider2D)
                {
                    // TODO: Implement
                }
            }
        }
        void AddTriangles(List <Triangle3> triangles, GameObject gameObject)
        {
            var colliders = gameObject.GetComponentsInChildren <Collider>();

            foreach (var collider in colliders)
            {
                var transform = Matrix.FromGameTransform(collider.gameObject.transform);
                if (collider is BoxCollider)
                {
                    var        boxCollider = collider as BoxCollider;
                    Vector3    goPosition;
                    Quaternion goRotation;
                    Vector3    goScale;
                    Matrix.DecomposeMatrix(ref transform, out goPosition, out goRotation, out goScale);

                    Vector3 scale     = Vector3.Scale(goScale, boxCollider.size);
                    Vector3 boxCenter = boxCollider.center;
                    Vector3 position  = goPosition + goRotation * Vector3.Scale(boxCenter, goScale);
                    transform = Matrix4x4.TRS(position, goRotation, scale);

                    StaticMeshTriangleProvider.AddMeshTriangles(triangles, cubeVertices, cubeIndices, transform);
                }
                else if (collider is MeshCollider)
                {
                    var meshCollider = collider as MeshCollider;
                    StaticMeshTriangleProvider.AddMeshTriangles(triangles, meshCollider.sharedMesh, transform);
                }
                else if (collider is SphereCollider)
                {
                    // TODO: Implement
                }
                else if (collider is CapsuleCollider)
                {
                    // TODO: Implement
                }
            }
        }