Example #1
0
 private void SendScreenshot(int clientIndex, Screenshot screenshot)
 {
     Clients[clientIndex].QueueOutgoingMessage(KLFCommon.ServerMessageID.ScreenshotShare, screenshot.ToByteArray());
 }
Example #2
0
        private void SendScreenshotToWatchers(int clientIndex, Screenshot screenshot)
        {
            //Create a list of valid watchers
            List<int> watcherIndices = new List<int>();

            for (int i = 0; i < Clients.Length; i++)
                if (ClientIsReady(i) && Clients[i].CurrentActivity != ServerClient.Activity.Inactive)
                {
                    bool match = false;
                    lock (Clients[i].WatchPlayerNameLock)
                    {
                        match = Clients[i].WatchPlayerName == Clients[clientIndex].Username;
                    }
                    if (match)
                        watcherIndices.Add(i);
                }

            if (watcherIndices.Count > 0)
            {
                //Build the message and send it to all watchers
                byte[] messageBytes = BuildMessageArray(KLFCommon.ServerMessageID.ScreenshotShare, screenshot.ToByteArray());
                foreach (int i in watcherIndices)
                    Clients[i].QueueOutgoingMessage(messageBytes);
            }
        }
Example #3
0
        private IEnumerator ShareScreenshot()
        {
            //Determine the scaled-down dimensions of the screenshot
            int w = 0;
            int h = 0;
            yield return new WaitForEndOfFrame();

            KLFScreenshotDisplay.Settings.GetBoundedDimensions(Screen.width, Screen.height, ref w, ref h);

            //Read the screen pixels into a texture
            Texture2D fullScreenTex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
            fullScreenTex.filterMode = FilterMode.Bilinear;
            fullScreenTex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
            fullScreenTex.Apply();

            RenderTexture renderTex = new RenderTexture(w, h, 24);
            renderTex.useMipMap = false;

            if (KLFGlobalSettings.Instance.SmoothScreens && (Screen.width > w * 2 || Screen.height > h * 2))
            {
                //Blit the full texture to a double-sized texture to improve final quality
                RenderTexture resizeTex = new RenderTexture(w * 2, h * 2, 24);
                Graphics.Blit(fullScreenTex, resizeTex);

                //Blit the double-sized texture to normal-sized texture
                Graphics.Blit(resizeTex, renderTex);
            }
            else
                Graphics.Blit(fullScreenTex, renderTex); //Blit the screen texture to a render texture

            fullScreenTex = null;
            RenderTexture.active = renderTex;
            //Read the pixels from the render texture into a Texture2D
            Texture2D resizedTex = new Texture2D(w, h, TextureFormat.RGB24, false);
            resizedTex.ReadPixels(new Rect(0, 0, w, h), 0, 0);
            resizedTex.Apply();

            RenderTexture.active = null;
            byte[] data = resizedTex.EncodeToPNG();
            Screenshot screenshot = new Screenshot();
            screenshot.Player = PlayerName;
            if (FlightGlobals.ready && FlightGlobals.ActiveVessel != null)
                screenshot.Description = FlightGlobals.ActiveVessel.vesselName;
            screenshot.Image = data;

            Debug.Log("Sharing screenshot");
            EnqueuePluginInteropMessage(KLFCommon.PluginInteropMessageID.ScreenshotShare, screenshot.ToByteArray());
        }