Skip to content

Commit

Permalink
Merge pull request #29 from vrctxl/dev
Browse files Browse the repository at this point in the history
BindVideoPlayer on Screen Manager
  • Loading branch information
jaquadro authored Jan 16, 2024
2 parents 13dce72 + cfb65f4 commit 2dbbe64
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [2.2.6] - 01-16-24

- Added _BindVideoPlayer method to Screen Manager to link manager to a different video player at runtime

## [2.2.5] - 01-03-24

- Added Enable AVPro In Editor option to Video Manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5405,7 +5405,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: VideoTXL 2.2.5
m_Text: VideoTXL 2.2.6
--- !u!1 &4893902363205926727
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,32 @@ protected override void _Init()

public void _PostInit()
{
_BindVideoPlayer(videoPlayer);
}

public void _BindVideoPlayer(TXLVideoPlayer videoPlayer)
{
TXLVideoPlayer prevPlayer = this.videoPlayer;
if (prevPlayer)
{
prevPlayer._Unregister(TXLVideoPlayer.EVENT_VIDEO_STATE_UPDATE, this, nameof(_OnVideoStateUpdate));
if (prevPlayer.VideoManager)
prevPlayer.VideoManager._Unregister(VideoManager.SOURCE_CHANGE_EVENT, this, nameof(_OnSourceChanged));
}

captureRenderer = null;
_screenSource = VideoSource.VIDEO_SOURCE_NONE;

this.videoPlayer = videoPlayer;
if (videoPlayer)
{
videoPlayer._Register(TXLVideoPlayer.EVENT_VIDEO_STATE_UPDATE, this, nameof(_OnVideoStateUpdate));
if (videoPlayer.VideoManager)
{
videoPlayer.VideoManager._Register(VideoManager.SOURCE_CHANGE_EVENT, this, "_OnSourceChanged");
captureRenderer = videoPlayer.VideoManager.CaptureRenderer;
_OnSourceChanged();
}

videoPlayer._Register(TXLVideoPlayer.EVENT_VIDEO_STATE_UPDATE, this, "_OnVideoStateUpdate");
_OnVideoStateUpdate();
videoPlayer.VideoManager._Register(VideoManager.SOURCE_CHANGE_EVENT, this, nameof(_OnSourceChanged));
}

_OnSourceChanged();
_OnVideoStateUpdate();
}

private void OnDisable()
Expand Down Expand Up @@ -597,6 +611,13 @@ public void _OnVideoStateUpdate()
{
_DebugEvent("Event OnVideoStateUpdate");

if (!videoPlayer)
{
_inError = false;
_UpdateScreenMaterial(SCREEN_MODE_LOGO);
return;
}

switch (videoPlayer.playerState)
{
case TXLVideoPlayer.VIDEO_STATE_STOPPED:
Expand All @@ -622,8 +643,11 @@ public void _OnSourceChanged()
{
_DebugEvent("Event OnSourceChanged");

captureRenderer = videoPlayer.VideoManager.CaptureRenderer;
_screenSource = videoPlayer.VideoManager.ActiveSourceType;
if (videoPlayer && videoPlayer.VideoManager)
{
captureRenderer = videoPlayer.VideoManager.CaptureRenderer;
_screenSource = videoPlayer.VideoManager.ActiveSourceType;
}

_ResetCheckScreenMaterial();
}
Expand Down Expand Up @@ -667,11 +691,13 @@ int _CalculateScreenIndex(bool captureValid)
public void _UpdateScreenMaterial(int screenMode)
{
_DebugLowLevel($"Update screen material: mode={screenMode}");
if (_screenMode == screenMode && _screenFit == videoPlayer.screenFit)

int fit = _VideoScreenFit();
if (_screenMode == screenMode && _screenFit == fit)
return;

_screenMode = screenMode;
_screenFit = videoPlayer.screenFit;
_screenFit = fit;

_ResetCheckScreenMaterial();
}
Expand Down Expand Up @@ -800,13 +826,23 @@ public void _CheckUpdateScreenMaterial()
}
}

int _VideoScreenFit()
{
return videoPlayer ? videoPlayer.screenFit : TXLVideoPlayer.SCREEN_FIT;
}

bool _IsQuest()
{
return videoPlayer ? videoPlayer.IsQuest : false;
}

void _ResetCaptureData()
{
currentTexture = null;
currentAVPro = false;
currentInvert = false;
currentGamma = false;
currentFit = videoPlayer.screenFit;
currentFit = _VideoScreenFit();
currentAspectRatio = 0;
}

Expand Down Expand Up @@ -834,7 +870,7 @@ void _UpdateCaptureData(Texture replacementTex, Texture captureTex)

if (currentAVPro)
{
currentInvert = !videoPlayer.IsQuest;
currentInvert = !_IsQuest();
currentGamma = true;
}

Expand Down Expand Up @@ -909,6 +945,7 @@ void _UpdateObjects(Material replacementMat)

void _UpdateMaterials()
{
int fit = _VideoScreenFit();
for (int i = 0; i < materialUpdateList.Length; i++)
{
Material mat = materialUpdateList[i];
Expand All @@ -921,7 +958,7 @@ void _UpdateMaterials()
_SetMatIntProperty(mat, shaderPropAVProList[baseIndexMat + i], currentAVPro ? 1 : 0);
_SetMatIntProperty(mat, shaderPropInvertList[baseIndexMat + i], currentGamma ? 1 : 0);
_SetMatIntProperty(mat, shaderPropGammaList[baseIndexMat + i], currentInvert ? 1 : 0);
_SetMatIntProperty(mat, shaderPropFitList[baseIndexMat + i], videoPlayer.screenFit);
_SetMatIntProperty(mat, shaderPropFitList[baseIndexMat + i], fit);
_SetMatFloatProperty(mat, shaderPropAspectRatioList[baseIndexMat + i], currentAspectRatio);
}

Expand All @@ -939,7 +976,7 @@ void _UpdateMaterials()
_SetMatIntProperty(mat, shaderPropAVProList[baseIndexCrt], currentAVPro ? 1 : 0);
_SetMatIntProperty(mat, shaderPropGammaList[baseIndexCrt], currentGamma ? 1 : 0);
_SetMatIntProperty(mat, shaderPropInvertList[baseIndexCrt], currentInvert ? 1 : 0);
_SetMatIntProperty(mat, shaderPropFitList[baseIndexCrt], videoPlayer.screenFit);
_SetMatIntProperty(mat, shaderPropFitList[baseIndexCrt], fit);
_SetMatFloatProperty(mat, shaderPropAspectRatioList[baseIndexCrt], currentAspectRatio);

bool isRT = currentTexture.GetType() == typeof(RenderTexture) || currentTexture.GetType() == typeof(CustomRenderTexture);
Expand All @@ -956,6 +993,7 @@ void _UpdateMaterials()

void _UpdatePropertyBlocks()
{
int fit = _VideoScreenFit();
for (int i = 0; i < propMeshList.Length; i++)
{
MeshRenderer renderer = propMeshList[i];
Expand All @@ -974,7 +1012,7 @@ void _UpdatePropertyBlocks()
_SetIntProperty(shaderPropAVProList[baseIndexProp + i], currentAVPro ? 1 : 0);
_SetIntProperty(shaderPropGammaList[baseIndexProp + i], currentGamma ? 1 : 0);
_SetIntProperty(shaderPropInvertList[baseIndexProp + i], currentInvert ? 1 : 0);
_SetIntProperty(shaderPropFitList[baseIndexProp + i], videoPlayer.screenFit);
_SetIntProperty(shaderPropFitList[baseIndexProp + i], fit);
_SetFloatProperty(shaderPropAspectRatioList[baseIndexProp + i], currentAspectRatio);

if (useMatIndex)
Expand Down
2 changes: 1 addition & 1 deletion Packages/com.texelsaur.video/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"email": "",
"url": "https://texelsaurus.com"
},
"version": "2.2.5",
"version": "2.2.6",
"description": "Highly configurable general purpose sync and non-sync video players.",
"gitDependencies": {},
"vpmDependencies": {
Expand Down

0 comments on commit 2dbbe64

Please sign in to comment.