void Start() { // targetImage = GetComponent<RawImage>(); if (!targetImage.GetComponent <CefInputSystem>()) { targetImage.gameObject.AddComponent <CefInputSystem>(); } browserTexture = new Texture2D(width, height, TextureFormat.BGRA32, false); tempImageLength = browserTexture.GetRawTextureData().Length; cef = new CefController(PipeName); if (StartAndConnectServer()) { CefInputSystem.current.SetController(cef); UnityEngine.Debug.Log("[CEF] Connected to proxy server process."); } targetImage.texture = browserTexture; targetImage.uvRect = new Rect(0f, 0f, 1f, -1f); targetImage.rectTransform.pivot = new Vector2(0, 1); cef.MessageReceived += OnCefMessage; frameBuffer = new byte[0]; frameBufferChanged = false; }
public Form1() { InitializeComponent(); int defWidth = 1024; int defHeight = 768; _texture = new Bitmap(defWidth, defHeight); controller = new CefController(); controller.MessageReceived += MessageReceived; controller.ConnectionStateChanged += ConnectionChanged; this.KeyPreview = true; this.KeyUp += Form1_KeyUp; this.KeyDown += Form1_KeyDown; this.KeyPress += Form1_KeyPress; this.PreviewKeyDown += Form1_PreviewKeyDown; pictureBox1.MouseMove += PictureBox1_MouseMove; pictureBox1.MouseWheel += PictureBox1_MouseWheel; this.Shown += Form1_Shown; SetKeyEventsForControls(Controls); }
void Start() { targetImage = GetComponent <RawImage>(); browserTexture = new Texture2D(1024, 768, TextureFormat.BGRA32, false); cef = new CefController(PipeName); if (StartAndConnectServer()) { UnityEngine.Debug.Log("[CEF] Connected to proxy server process."); } targetImage.texture = browserTexture; targetImage.uvRect = new Rect(0f, 0f, 1f, -1f); cef.MessageReceived += OnCefMessage; frameBuffer = new byte[0]; frameBufferChanged = false; }
private void Form1_Shown(object sender, EventArgs e) { _controller = new CefController(); _controller.MessageReceived += MessageReceived; _controller.ConnectionStateChanged += ConnectionChanged; this.KeyPreview = true; this.KeyUp += Form1_KeyUp; this.KeyDown += Form1_KeyDown; this.KeyPress += Form1_KeyPress; this.PreviewKeyDown += Form1_PreviewKeyDown; pictureBox1.MouseMove += PictureBox1_MouseMove; pictureBox1.MouseWheel += PictureBox1_MouseWheel; ConnectionChanged(_controller, false); Task.Run(new Action(() => { while (this.Visible && !this.Disposing && !this.IsDisposed) { bool haveFps = false; int fps = 0; if (_frameCounterCounter >= 10) { fps = _frameCounterCurrent; _frameCounterCounter = 0; _frameCounterCurrent = 0; haveFps = true; } _frameCounterCounter++; try { Invoke(new Action(() => { if (_controller != null && _controller.Connected) { if (_frameCounterStat > 0) { lblFrames.Text = _frameCounterStat.ToString(); } if (_controller.MessagesReceivedCount > 0) { lblPkIn.Text = _controller.MessagesReceivedCount.ToString(); } if (_controller.MessagesSentCount > 0) { lblPkOut.Text = _controller.MessagesSentCount.ToString(); } if (haveFps) { lblFps.Text = fps.ToString() + " FPS"; } } })); } catch (ObjectDisposedException) { return; } Thread.Sleep(100); } })); SetKeyEventsForControls(Controls); }
public void SetController(CefController cef) { this.cef = cef; }