|
@@ -1,172 +0,0 @@
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-#define AVPRO_PACKAGE_UNITYUI
|
|
|
-#if (UNITY_2019_2_OR_NEWER && AVPRO_PACKAGE_UNITYUI) || (!UNITY_2019_2_OR_NEWER)
|
|
|
-
|
|
|
-using UnityEngine;
|
|
|
-using UnityEditor;
|
|
|
-using UnityEditor.UI;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-namespace RenderHeads.Media.AVProVideo.Editor
|
|
|
-{
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- [CustomEditor(typeof(DisplayUGUI), true)]
|
|
|
- [CanEditMultipleObjects]
|
|
|
- public class DisplayUGUIEditor : GraphicEditor
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private static readonly GUIContent m_guiTextUVRectContent = new GUIContent("UV Rect");
|
|
|
-
|
|
|
- private SerializedProperty _propMediaPlayer;
|
|
|
- private SerializedProperty _propUVRect;
|
|
|
- private SerializedProperty _propDefaultTexture;
|
|
|
- private SerializedProperty _propNoDefaultDisplay;
|
|
|
- private SerializedProperty _propDisplayInEditor;
|
|
|
- private SerializedProperty _propSetNativeSize;
|
|
|
- private SerializedProperty _propScaleMode;
|
|
|
-
|
|
|
- [MenuItem("GameObject/UI/AVPro Video uGUI", false, 0)]
|
|
|
- public static void CreateGameObject()
|
|
|
- {
|
|
|
- GameObject parent = Selection.activeGameObject;
|
|
|
- RectTransform parentCanvasRenderer = ( parent != null ) ? parent.GetComponent<RectTransform>() : null;
|
|
|
- if( parentCanvasRenderer )
|
|
|
- {
|
|
|
- GameObject go = new GameObject("AVPro Video");
|
|
|
- go.transform.SetParent(parent.transform, false);
|
|
|
- go.AddComponent<RectTransform>();
|
|
|
- go.AddComponent<CanvasRenderer>();
|
|
|
- go.AddComponent<DisplayUGUI>();
|
|
|
- Selection.activeGameObject = go;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- EditorUtility.DisplayDialog("AVPro Video", "You must make the AVPro Video uGUI object as a child of a Canvas.", "Ok");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public override bool RequiresConstantRepaint()
|
|
|
- {
|
|
|
- DisplayUGUI displayComponent = target as DisplayUGUI;
|
|
|
- return (displayComponent != null && displayComponent.HasValidTexture());
|
|
|
- }
|
|
|
-
|
|
|
- protected override void OnEnable()
|
|
|
- {
|
|
|
- base.OnEnable();
|
|
|
-
|
|
|
- _propMediaPlayer = this.CheckFindProperty("_mediaPlayer");
|
|
|
- _propUVRect = this.CheckFindProperty("_uvRect");
|
|
|
- _propSetNativeSize = this.CheckFindProperty("_setNativeSize");
|
|
|
- _propScaleMode = this.CheckFindProperty("_scaleMode");
|
|
|
- _propNoDefaultDisplay = this.CheckFindProperty("_noDefaultDisplay");
|
|
|
- _propDisplayInEditor = this.CheckFindProperty("_displayInEditor");
|
|
|
- _propDefaultTexture = this.CheckFindProperty("_defaultTexture");
|
|
|
-
|
|
|
- SetShowNativeSize(true);
|
|
|
- }
|
|
|
-
|
|
|
- public override void OnInspectorGUI()
|
|
|
- {
|
|
|
- serializedObject.Update();
|
|
|
-
|
|
|
- EditorGUILayout.PropertyField(_propMediaPlayer);
|
|
|
- EditorGUILayout.PropertyField(_propDisplayInEditor);
|
|
|
- EditorGUILayout.PropertyField(_propNoDefaultDisplay);
|
|
|
- if (!_propNoDefaultDisplay.boolValue)
|
|
|
- {
|
|
|
- EditorGUILayout.PropertyField(_propDefaultTexture);
|
|
|
- }
|
|
|
- AppearanceControlsGUI();
|
|
|
- RaycastControlsGUI();
|
|
|
- EditorGUILayout.PropertyField(_propUVRect, m_guiTextUVRectContent);
|
|
|
-
|
|
|
- EditorGUILayout.PropertyField(_propSetNativeSize);
|
|
|
- EditorGUILayout.PropertyField(_propScaleMode);
|
|
|
-
|
|
|
- SetShowNativeSize(false);
|
|
|
- NativeSizeButtonGUI();
|
|
|
-
|
|
|
- serializedObject.ApplyModifiedProperties();
|
|
|
- }
|
|
|
-
|
|
|
- private void SetShowNativeSize(bool instant)
|
|
|
- {
|
|
|
- base.SetShowNativeSize(_propMediaPlayer.objectReferenceValue != null, instant);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public override bool HasPreviewGUI()
|
|
|
- {
|
|
|
- DisplayUGUI rawImage = target as DisplayUGUI;
|
|
|
- return rawImage != null;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public override void OnPreviewGUI(Rect drawArea, GUIStyle background)
|
|
|
- {
|
|
|
- DisplayUGUI rawImage = target as DisplayUGUI;
|
|
|
- Texture tex = rawImage.mainTexture;
|
|
|
-
|
|
|
- if (tex == null)
|
|
|
- return;
|
|
|
-
|
|
|
-
|
|
|
- Rect outerRect = drawArea;
|
|
|
-
|
|
|
- Matrix4x4 m = GUI.matrix;
|
|
|
-
|
|
|
- if (rawImage.HasValidTexture())
|
|
|
- {
|
|
|
- if (rawImage.Player.TextureProducer.RequiresVerticalFlip())
|
|
|
- {
|
|
|
- GUIUtility.ScaleAroundPivot(new Vector2(1f, -1f), new Vector2(0f, outerRect.y + (outerRect.height / 2f)));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- EditorGUI.DrawTextureTransparent(outerRect, tex, ScaleMode.ScaleToFit);
|
|
|
-
|
|
|
-
|
|
|
- GUI.matrix = m;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public override string GetInfoString()
|
|
|
- {
|
|
|
- DisplayUGUI rawImage = target as DisplayUGUI;
|
|
|
-
|
|
|
- string text = string.Empty;
|
|
|
- if (rawImage.HasValidTexture())
|
|
|
- {
|
|
|
- text += string.Format("Video Size: {0}x{1}\n",
|
|
|
- Mathf.RoundToInt(Mathf.Abs(rawImage.mainTexture.width)),
|
|
|
- Mathf.RoundToInt(Mathf.Abs(rawImage.mainTexture.height)));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- text += string.Format("Display Size: {0}x{1}",
|
|
|
- Mathf.RoundToInt(Mathf.Abs(rawImage.rectTransform.rect.width)),
|
|
|
- Mathf.RoundToInt(Mathf.Abs(rawImage.rectTransform.rect.height)));
|
|
|
-
|
|
|
- return text;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#endif
|