Skip to content

Commit

Permalink
Fix fullscreen mode for WebGL
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikLassahn committed Mar 28, 2018
1 parent 9a3112c commit cda62f9
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 65 deletions.
16 changes: 8 additions & 8 deletions Assets/Examples/Scenes/Vimeo Player.unity
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,6 @@ MonoBehaviour:
handleRect: {fileID: 1445815480}
tooltipRect: {fileID: 879018526}
position: 0.444
onPositionChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: Unity.VideoHelper.FloatEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null
onSeeked:
m_PersistentCalls:
m_Calls:
Expand Down Expand Up @@ -1903,7 +1898,7 @@ MonoBehaviour:
m_GameObject: {fileID: 1657851164}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1392445389, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Script: {fileID: 11500000, guid: a6e5a9941adb81a4b9351a703392f514, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
Expand Down Expand Up @@ -1931,10 +1926,15 @@ MonoBehaviour:
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 1657851168}
m_OnClick:
OnClick:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
m_TypeName: UnityEngine.Events.UnityEvent, UnityEngine.CoreModule, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
OnDoubleClick:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.Events.UnityEvent, UnityEngine.CoreModule, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!114 &1657851168
MonoBehaviour:
Expand Down
106 changes: 74 additions & 32 deletions Assets/Examples/Scenes/YouTube Player.unity
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ RectTransform:
m_Father: {fileID: 2040481571}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 50, y: -135}
m_SizeDelta: {x: 100, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &77671953
MonoBehaviour:
Expand Down Expand Up @@ -378,7 +378,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &158675321
RectTransform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1286,11 +1286,6 @@ MonoBehaviour:
handleRect: {fileID: 1911512926}
tooltipRect: {fileID: 1920210364}
position: 0.398
onPositionChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: Unity.VideoHelper.FloatEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null
onSeeked:
m_PersistentCalls:
m_Calls:
Expand Down Expand Up @@ -1613,6 +1608,7 @@ GameObject:
- component: {fileID: 495730001}
- component: {fileID: 495730003}
- component: {fileID: 495730002}
- component: {fileID: 495730005}
- component: {fileID: 495730004}
m_Layer: 5
m_Name: Normal | Fullscreen
Expand Down Expand Up @@ -1691,6 +1687,52 @@ MonoBehaviour:
m_FlexibleWidth: -1
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &495730005
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 495730000}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a6e5a9941adb81a4b9351a703392f514, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 495730002}
OnClick:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.Events.UnityEvent, UnityEngine.CoreModule, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
OnDoubleClick:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.Events.UnityEvent, UnityEngine.CoreModule, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!1 &528747141
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1724,10 +1766,10 @@ RectTransform:
m_Father: {fileID: 2040481571}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 50, y: -165}
m_SizeDelta: {x: 100, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &528747143
MonoBehaviour:
Expand Down Expand Up @@ -3296,10 +3338,10 @@ RectTransform:
m_Father: {fileID: 2040481571}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 50, y: -45}
m_SizeDelta: {x: 100, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1140252625
MonoBehaviour:
Expand Down Expand Up @@ -3477,10 +3519,10 @@ RectTransform:
m_Father: {fileID: 2040481571}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 50, y: -105}
m_SizeDelta: {x: 100, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1232994918
MonoBehaviour:
Expand Down Expand Up @@ -3590,10 +3632,10 @@ RectTransform:
m_Father: {fileID: 2040481571}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 50, y: -75}
m_SizeDelta: {x: 100, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1342722966
MonoBehaviour:
Expand Down Expand Up @@ -3958,10 +4000,10 @@ RectTransform:
m_Father: {fileID: 2040481571}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 50, y: -15}
m_SizeDelta: {x: 100, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1595895798
MonoBehaviour:
Expand Down Expand Up @@ -5062,7 +5104,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &2040481571
RectTransform:
m_ObjectHideFlags: 0
Expand All @@ -5086,7 +5128,7 @@ RectTransform:
m_AnchorMin: {x: 1, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: -50, y: 90}
m_SizeDelta: {x: 100, y: 0}
m_SizeDelta: {x: 100, y: 180}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2040481572
MonoBehaviour:
Expand Down
2 changes: 1 addition & 1 deletion Assets/VideoPlayer Helper/Scripts/ClickRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ClickRouter : Selectable, IPointerClickHandler
public UnityEvent OnClick = new UnityEvent();
public UnityEvent OnDoubleClick = new UnityEvent();

public void OnPointerClick(PointerEventData eventData)
public virtual void OnPointerClick(PointerEventData eventData)
{
if (eventData.clickCount == 2)
OnDoubleClick.Invoke();
Expand Down
36 changes: 36 additions & 0 deletions Assets/VideoPlayer Helper/Scripts/DirectClickRouter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using UnityEngine;
using UnityEngine.EventSystems;

namespace Unity.VideoHelper
{
/// <summary>
/// Forwards clicks when the pointer is pressed.
/// Use <see cref="ClickRouter"/> for forwarding upon release of the pointer.
/// </summary>
/// <remarks>
/// Use this component on GameObjects that initiate fullscreen in WebGL builds.
/// There is a browser limitation that ensures that you can only go fullscreen when a user clicks the page.
/// Not using <see cref="OnPointerDown(PointerEventData)"/> requires another click for Unity to go into fullscreen.
/// </remarks>
public class DirectClickRouter : ClickRouter
{
private float lastClickTime = 0f;
private const float clickInterval = 0.3f;

public override void OnPointerClick(PointerEventData eventData)
{
// do nothing
}

public override void OnPointerDown(PointerEventData eventData)
{
if (lastClickTime + clickInterval > Time.time)
OnDoubleClick.Invoke();
else
OnClick.Invoke();

lastClickTime = Time.time;
}
}
}

13 changes: 13 additions & 0 deletions Assets/VideoPlayer Helper/Scripts/DirectClickRouter.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Assets/VideoPlayer Helper/Scripts/DisplayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal DisplayControllerInternal(int display)
private GameObject fullscreenCanvas;
private RectTransform target, targetParent;

private bool IsAlwaysFullscreen;
private bool isAlwaysFullscreen;
private int targetDisplay;

#endregion
Expand Down Expand Up @@ -86,7 +86,7 @@ public void ToFullscreen(RectTransform rectTransform)
target.anchorMax = target.offsetMax = Vector2.one;
target.localScale = Vector3.one;

IsAlwaysFullscreen = Screen.fullScreen;
isAlwaysFullscreen = Screen.fullScreen;
Screen.fullScreen = true;
}

Expand All @@ -105,7 +105,7 @@ public void ToNormal()

fullscreenCanvas.SetActive(false);

Screen.fullScreen = IsAlwaysFullscreen;
Screen.fullScreen = isAlwaysFullscreen;
}

#endregion
Expand All @@ -121,7 +121,7 @@ private void Setup()
canvas.targetDisplay = targetDisplay;

var scaler = fullscreenCanvas.GetComponent<CanvasScaler>();
scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
scaler.uiScaleMode = CanvasScaler.ScaleMode.ConstantPixelSize;
}

#endregion
Expand Down
17 changes: 1 addition & 16 deletions Assets/VideoPlayer Helper/Scripts/Timeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public class Timeline : Selectable, IDragHandler, ICanvasElement, IInitializePot
[Range(0, 1)]
private float position;

[SerializeField]
private FloatEvent onPositionChanged = new FloatEvent();

[SerializeField]
private FloatEvent onSeeked = new FloatEvent();

Expand Down Expand Up @@ -75,11 +72,6 @@ public float Position
set { SetPosition(value); }
}

//public UnityEvent<float> OnPositionChanged
//{
// get { return onPositionChanged; }
//}

public UnityEvent<float> OnSeeked
{
get { return onSeeked; }
Expand Down Expand Up @@ -305,7 +297,7 @@ private void UpdateDrag(PointerEventData eventData, Camera cam)
localCursor -= clickRect.rect.position;

Position = Mathf.Clamp01((localCursor - handleOffset)[0] / clickRect.rect.size[0]);
OnSeeked.Invoke(Position);
onSeeked.Invoke(Position);
}
}

Expand All @@ -329,9 +321,6 @@ private void SetPosition(float newPosition, bool sendCallback = true)
position = newPosition;

UpdateVisuals();

//if (sendCallback)
// OnPositionChanged.Invoke(newPosition);
}

#endregion
Expand Down Expand Up @@ -425,10 +414,6 @@ public virtual void OnDrag(PointerEventData eventData)

public void Rebuild(CanvasUpdate executing)
{
#if UNITY_EDITOR
if (executing == CanvasUpdate.Prelayout)
onPositionChanged.Invoke(position);
#endif
}

public void LayoutComplete()
Expand Down
Loading

0 comments on commit cda62f9

Please sign in to comment.