Advertisement
Selzier

ActionVideoPlayerSetClip.cs

Dec 14th, 2017
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.Video;
  4.  
  5. #if UNITY_EDITOR
  6. using UnityEditor;
  7. #endif
  8.  
  9. namespace AC
  10. {
  11.     [System.Serializable]
  12.     public class ActionVideoPlayerSetClip : Action
  13.     {        
  14.         public VideoPlayer videoPlayer;
  15.         public VideoClip videoClip;
  16.         public bool playClip;
  17.         public int constantID;        
  18.  
  19.         public ActionVideoPlayerSetClip()
  20.         {
  21.             this.isDisplayed = true;
  22.             category = ActionCategory.Custom;
  23.             title = "VideoPlayer SetClip";
  24.             description = "This will set the clip on a Video Player component and optionally play it immediately.";
  25.         }      
  26.        
  27.         override public float Run ()
  28.         {
  29.             videoPlayer.clip = videoClip;
  30.             if (playClip) {
  31.                 videoPlayer.Play();
  32.             }
  33.             return 0f;
  34.         }
  35.                
  36.         #if UNITY_EDITOR
  37.         override public void ShowGUI ()
  38.         {            
  39.             videoPlayer = (VideoPlayer)EditorGUILayout.ObjectField("VideoPlayer Component:", videoPlayer, typeof(VideoPlayer), true);
  40.             if (videoPlayer) {
  41.                 constantID = FieldToID(videoPlayer, constantID);
  42.                 videoPlayer = IDToField(videoPlayer, constantID, true);
  43.             }
  44.             videoClip = (VideoClip)EditorGUILayout.ObjectField("Video Clip:", videoClip, typeof(VideoClip), true);
  45.             playClip = EditorGUILayout.Toggle("Play Clip Automatically:", playClip);
  46.             AfterRunningOption ();
  47.         }
  48.        
  49.         public override string SetLabel ()
  50.         {            
  51.             string labelAdd = " to " + videoClip.name;
  52.             if (playClip) {
  53.                 labelAdd += " and Play";
  54.             }            
  55.             return labelAdd;
  56.         }
  57.         #endif
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement