Skip to content

Commit 1543589

Browse files
authored
Create GetVideoAspectRatioEditor.cs
1 parent be2ea7d commit 1543589

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Custom Contect menu for VideoPlayer component
2+
// used for scaling quad mesh transform localscale.y to match videoplayer aspect ratio
3+
4+
using UnityEngine;
5+
using UnityEditor;
6+
using UnityEngine.Video;
7+
8+
namespace UnityLibrary
9+
{
10+
public class GetVideoAspectRatioEditor : MonoBehaviour
11+
{
12+
[MenuItem("CONTEXT/VideoPlayer/Get Aspect Ratio for Mesh")]
13+
static void DoubleMass(MenuCommand command)
14+
{
15+
// get aspect ratio
16+
VideoPlayer v = (VideoPlayer)command.context;
17+
if (v.clip == null)
18+
{
19+
Debug.LogError("No videoclip assigned..");
20+
return;
21+
}
22+
float aspectRatioY = v.height / (float)v.width;
23+
24+
// scale mesh
25+
Vector3 scale = v.transform.localScale;
26+
// fix only height
27+
scale.y *= aspectRatioY;
28+
v.transform.localScale = scale;
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)