private void autoResizeGameObject() { var mesh = gameObject.GetComponent <MeshFilter>().mesh; if (mesh == null) { Debug.LogError("Cannot adjust game object dimensions to movie, no mesh attached (try a plane)"); } else { float objectWidth = mesh.bounds.size.x * gameObject.transform.localScale.x; float objectHeight = mesh.bounds.size.z * gameObject.transform.localScale.z; float movieAspect = MetaioSDKUnity.getMovieTextureDisplayAspect(movieGeometry); // NOT movieWidth/movieHeight, this is the DAR if (objectWidth <= 0.01 || objectHeight <= 0.01) { Debug.LogWarning("Not adjusting game object dimensions to movie, X or Z bound/scale is zero, is this a plane mesh?"); } else if (Math.Abs(objectWidth / objectHeight - movieAspect) > 0.03) { Debug.Log(string.Format("Adjusting game object to movie texture aspect ratio {0}", movieAspect)); if (isRotatedCCW) { // Implementation note: If isRotatedCCW=true, then movieWidth/movieHeight are actually swapped, i.e. // represent the inverse display size. // In that case, we'll rotate the mesh (see below), so X scale is for height, Z scale for width gameObject.transform.localScale = new Vector3( gameObject.transform.localScale.x * movieAspect, gameObject.transform.localScale.y, gameObject.transform.localScale.z * (objectWidth / objectHeight)); } else { gameObject.transform.localScale = new Vector3( gameObject.transform.localScale.x, gameObject.transform.localScale.y, gameObject.transform.localScale.z * (objectWidth / objectHeight) / movieAspect); } } else { Debug.Log("Not adjusting game object dimensions, already has same aspect ratio as movie"); } } }