UnityTech / UIWidgets

UIWidget is a Unity Package which helps developers to create, debug and deploy efficient, cross-platform Apps.
Other
1.97k stars 256 forks source link

使用Texture widget 错误 #434

Open weacw opened 4 years ago

weacw commented 4 years ago

环境信息

Unity:2019.4f1 UIWidget git拉取 2020/07/21

Code

   public class AccessingCamera : MonoBehaviour
    {
        public VideoClip videoClip;
        public RenderTexture renderTexture;

        public static RenderTexture rt;
        void Start()
        {
            rt = renderTexture;
            var videoPlayer = this.gameObject.AddComponent<VideoPlayer>();
            videoPlayer.clip = this.videoClip;
            videoPlayer.targetTexture = renderTexture;
            videoPlayer.isLooping = true;
            videoPlayer.sendFrameReadyEvents = true;
            videoPlayer.frameReady += (_, __) => Unity.UIWidgets.widgets.Texture.textureFrameAvailable();
            videoPlayer.Play();
        }
    }

Unity.UIWidgets.widgets.Texture.textureFrameAvailable();出错。 因为Window instance = null导致的。

log

AssertionError: Window.instance is null. This usually happens when there is a callback from outside of UIWidgets. Try to use "using (WindowProvider.of(BuildContext).getScope()) { ... }" to wrap your code.
Unity.UIWidgets.ui.Window.get_instance () (at Assets/Scripts/UIWidgets/Runtime/ui/window.cs:114)
Unity.UIWidgets.editor.WindowAdapter.scheduleFrame (System.Boolean regenerateLayerTree) (at Assets/Scripts/UIWidgets/Runtime/editor/editor_window.cs:527)
Unity.UIWidgets.engine.UIWidgetWindowAdapter.scheduleFrame (System.Boolean regenerateLayerTree) (at Assets/Scripts/UIWidgets/Runtime/engine/UIWidgetsPanel.cs:32)
Unity.UIWidgets.widgets.Texture+<>c.<textureFrameAvailable>b__0_0 (Unity.UIWidgets.editor.WindowAdapter w) (at Assets/Scripts/UIWidgets/Runtime/widgets/texture.cs:15)
System.Collections.Generic.List`1[T].ForEach (System.Action`1[T] action) (at <437ba245d8404784b9fbab9b439ac908>:0)
Unity.UIWidgets.widgets.Texture.textureFrameAvailable (Unity.UIWidgets.ui.Window instance) (at Assets/Scripts/UIWidgets/Runtime/widgets/texture.cs:15)
ARToolkitUI.Runtime.AccessingCamera+<>c.<Start>b__3_0 (UnityEngine.Video.VideoPlayer _, System.Int64 __) (at Assets/Scripts/ARToolkitUI/Runtime/AccessingCamera.cs:36)
UnityEngine.Video.VideoPlayer.InvokeFrameReadyCallback_Internal (UnityEngine.Video.VideoPlayer source, System.Int64 frameIdx) (at <458f8466b07c41b2841eecea8f70b2a6>:0)
moonsunsong commented 4 years ago

报错显示了Try to use "using (WindowProvider.of(BuildContext).getScope()) { ... }",用了uiwidgets的地方 应该 `

using (WindowProvider.of(BuildContext).getScope()) {

        rt = renderTexture;
        var videoPlayer = this.gameObject.AddComponent<VideoPlayer>();
        videoPlayer.clip = this.videoClip;
        videoPlayer.targetTexture = renderTexture;
        videoPlayer.isLooping = true;
        videoPlayer.sendFrameReadyEvents = true;
        videoPlayer.frameReady += (_, __) => Unity.UIWidgets.widgets.Texture.textureFrameAvailable();
        videoPlayer.Play();

} `

lai0yu commented 4 years ago

报错显示了Try to use "using (WindowProvider.of(BuildContext).getScope()) { ... }",用了uiwidgets的地方 应该 `

using (WindowProvider.of(BuildContext).getScope()) {

        rt = renderTexture;
        var videoPlayer = this.gameObject.AddComponent<VideoPlayer>();
        videoPlayer.clip = this.videoClip;
        videoPlayer.targetTexture = renderTexture;
        videoPlayer.isLooping = true;
        videoPlayer.sendFrameReadyEvents = true;
        videoPlayer.frameReady += (_, __) => Unity.UIWidgets.widgets.Texture.textureFrameAvailable();
        videoPlayer.Play();

} `

我是这么用的,this.gameObject 指的是场景中挂载了UIWidgetPanel的GameObject,没有报错,希望对你有帮助! image