Пример #1
0
        protected override void OnUpdate()
        {
            if (!initialized)
            {
                return;
            }
            var env    = World.TinyEnvironment();
            var config = env.GetConfigData <DisplayInfo>();

            var wantwebgl = config.renderMode == RenderMode.Auto || config.renderMode == RenderMode.WebGL;
            int wCanvas = 0, hCanvas = 0;

            HTMLNativeCalls.getCanvasSize(ref wCanvas, ref hCanvas);
            HTMLNativeCalls.getFrameSize(ref config.frameWidth, ref config.frameHeight);
            if (config.autoSizeToFrame)
            {
                config.width  = config.frameWidth;
                config.height = config.frameHeight;
            }
            if (wCanvas != config.width || hCanvas != config.height || wantwebgl != iswebgl)
            {
                iswebgl                  = HTMLNativeCalls.setCanvasSizeAndMode(config.width, config.height, wantwebgl);
                config.renderMode        = iswebgl ? RenderMode.WebGL : RenderMode.Canvas;
                config.framebufferWidth  = config.width;
                config.framebufferHeight = config.height;
            }
            env.SetConfigData(config);

            double newFrameTime = HTMLNativeCalls.time();

            env.StepWallRealtimeFrame(newFrameTime - frameTime);
            frameTime = newFrameTime;
        }
Пример #2
0
 protected override void OnDestroy()
 {
     // close window
     Console.WriteLine("HTML Window shutdown.");
     HTMLNativeCalls.shutdown(0);
     base.OnDestroy();
 }
Пример #3
0
        public override void DebugReadbackImage(out int w, out int h, out NativeArray <byte> pixels)
        {
            var env    = World.TinyEnvironment();
            var config = env.GetConfigData <DisplayInfo>();

            pixels = new NativeArray <byte>(config.framebufferWidth * config.framebufferHeight * 4, Allocator.Persistent);
            unsafe
            {
                HTMLNativeCalls.debugReadback(config.framebufferWidth, config.framebufferHeight, pixels.GetUnsafePtr());
            }

            w = config.framebufferWidth;
            h = config.framebufferHeight;
        }
Пример #4
0
        protected override void OnStartRunning()
        {
            base.OnStartRunning();
            if (initialized)
            {
                return;
            }

            Console.WriteLine("HTML Window init.");
            try
            {
                initialized = HTMLNativeCalls.init();
            }
            catch
            {
                Console.WriteLine("  Excepted (Is lib_unity_tiny2d_html.dll missing?).");
                initialized = false;
            }
            if (!initialized)
            {
                Console.WriteLine("  Failed.");
                return;
            }

            var env    = World.TinyEnvironment();
            var config = env.GetConfigData <DisplayInfo>();

            HTMLNativeCalls.getFrameSize(ref config.frameWidth, ref config.frameHeight);
            HTMLNativeCalls.getScreenSize(ref config.screenWidth, ref config.screenHeight);
            if (config.autoSizeToFrame)
            {
                config.width  = config.frameWidth;
                config.height = config.frameHeight;
            }
            bool wantwebgl = config.renderMode == RenderMode.Auto || config.renderMode == RenderMode.WebGL;

            iswebgl                  = HTMLNativeCalls.setCanvasSizeAndMode(config.width, config.height, wantwebgl);
            config.renderMode        = iswebgl ? RenderMode.WebGL : RenderMode.Canvas;
            config.framebufferWidth  = config.width;
            config.framebufferHeight = config.height;
            env.SetConfigData(config);

            frameTime = HTMLNativeCalls.time();
        }
Пример #5
0
 public override void InfiniteMainLoop(MainLoopDelegate m)
 {
     staticM = m;
     HTMLNativeCalls.set_animation_frame_callback(Marshal.GetFunctionPointerForDelegate((MainLoopDelegate)ManagedRAFCallback));
     Console.WriteLine("HTML Main loop exiting.");
 }