File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments