Unity application development based on UIWidgets (3)

      Let’s talk about the interaction settings between UIWidgets and 3D. UIWidgets officially indicates that it can interact with 3D. However, if you operate directly in Unity, for example, it is normal to click a button to trigger a transformation of position, rotation, and zoom, but if it changes continuously, the screen will become stuck.

        In the above picture, I added a button with auto-rotation button, and added a UIWidgets button on the interface. You can see that in the running state, the square of the scene scene will continue to rotate, but the rotation of the game scene will be quite Caton. The reason for this phenomenon is because the UI of UIWidgets is at the forefront, and the update mechanism of UIWidgets is that if the interface does not change or setstate() is not called, the interface is basically not refreshed, but the cube changes every frame, so This led to the phenomenon of one card one card.

        If you know the reason, it's easy to solve it, just let the UI refresh every frame. I ran a true loop in the UIWidgets script. Every frame triggers an empty SetState() event (if you don’t understand setState, you can understand the flushing mechanism of fluter), and then the 3d display is normal. But it feels weird, because every frame is refreshed, the drawcall comes up again. . .

        Later, after consulting the developer of UIWidgets, the other party gave the correct method, which is to set the two delegates of Windows to empty methods when UIWidgetsPanel is initialized.

Window.onFrameRateSpeedUp = ()=> { };
Window.onFrameRateCoolDown = ()=> { };

        This point is explained on the official github of the official UIWidgets. It’s just that the interface of the international server was accidentally opened at that time. It was all in English, but I didn’t find it. Then, because of the test above, I thought that UIWidgets could not do the UI and 3D interaction really suffers from bad English. . . Sigh again for the awesomeness of UIWidgets!

        Next is the interactive operation of UIWidgets on the 3D code, because UIWidgets are dynamically generated, and the classes that inherit UIWidgetsPanel, StatefulWidget, and StatelessWidget are not the same as the MonoBehaviour class. You cannot directly declare a public GameObject or Transform and then drag it directly. Direct reference, custom classes are not okay. My own approach is to write a singleton class to reference these classes and objects, and then mount it on the empty objects of the scene, so that I can use UIWidgets classes to directly reference the singleton To call.

        And because it is not directly inherited from MonoBehaviour, the coroutine method is not available, but the existing methods of UIWidgets can still be used to simulate the coroutine

        void Refresh()
        {
            Promise.Delayed(TimeSpan.FromSeconds(0.3f)).Then(
                () =>
                {
                            //dosomethings
                            setState();
                    Refresh();
                }
                );
        }

The above method can not trigger the refresh event. At the beginning, I used this to force the interface to refresh to achieve the effect of synchronously updating the 3d interface. Promise is a class of UIWidgets, which should be used for asynchronous operations, processing queues, etc. Tools.

        Basically, UIWidgets needs to interact with 3D, just change it according to the above configuration. Then the next step is to talk about the app part!

Guess you like

Origin blog.csdn.net/ssssssilver/article/details/107294672