IEnumerator WriteScreenshot()
    {
        yield return(new WaitForEndOfFrame());

        Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);

        texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
        texture.Apply(false);

        Color[] color = texture.GetPixels();
        byte[]  RGB   = new byte[color.Length * 3];

        for (int i = 0, c = 0; i < RGB.Length; i += 3, ++c)
        {
            RGB[i]     = (byte)(color[c].r * 255.0f);
            RGB[i + 1] = (byte)(color[c].g * 255.0f);
            RGB[i + 2] = (byte)(color[c].b * 255.0f);
        }

        Destroy(texture);

        // TODO: The image is upside down! "@ares_p: in Unity all texture data starts from "bottom" (OpenGL convention)"
        m_ScreenshotHandle = SteamScreenshots.WriteScreenshot(RGB, (uint)RGB.Length, Screen.width, Screen.height);
        print("SteamScreenshots.WriteScreenshot(" + RGB + ", " + (uint)RGB.Length + ", " + Screen.width + ", " + Screen.height + ") : " + m_ScreenshotHandle);
    }
 /// <summary>
 /// <para> Sets metadata about a screenshot's location (for example, the name of the map)</para>
 /// </summary>
 public static bool SetLocation(ScreenshotHandle hScreenshot, string Location)
 {
     InteropHelp.TestIfAvailableClient();
     using (var Location2 = new InteropHelp.UTF8StringHandle(Location)) {
         return(NativeMethods.ISteamScreenshots_SetLocation(hScreenshot, Location2));
     }
 }
 /// <summary>
 /// <para> Sets metadata about a screenshot's location (for example, the name of the map)</para>
 /// </summary>
 public static bool SetLocation(ScreenshotHandle hScreenshot, string pchLocation)
 {
     InteropHelp.TestIfAvailableClient();
     using (var pchLocation2 = new InteropHelp.UTF8StringHandle(pchLocation)) {
         return(NativeMethods.ISteamScreenshots_SetLocation(CSteamAPIContext.GetSteamScreenshots(), hScreenshot, pchLocation2));
     }
 }
Example #4
0
 public static bool SetLocation(ScreenshotHandle hScreenshot, string pchLocation)
 {
     InteropHelp.TestIfAvailableClient();
     bool result;
     using (InteropHelp.UTF8StringHandle uTF8StringHandle = new InteropHelp.UTF8StringHandle(pchLocation))
     {
         result = NativeMethods.ISteamScreenshots_SetLocation(hScreenshot, uTF8StringHandle);
     }
     return result;
 }
	IEnumerator AddScreenshotToLibrary() {
		while (true) {
			if (System.IO.File.Exists(Application.dataPath + "/screenshot.png")) {
				m_ScreenshotHandle = SteamScreenshots.AddScreenshotToLibrary(Application.dataPath + "/screenshot.png", "", Screen.width, Screen.height);
				print("SteamScreenshots.AddScreenshotToLibrary(\"screenshot.png\", \"\", " + Screen.width + ", " + Screen.height + ") : " + m_ScreenshotHandle);
				yield break;
			}

			yield return null;
		}
	}
    IEnumerator AddScreenshotToLibrary()
    {
        while (true)
        {
            if (System.IO.File.Exists(Application.dataPath + "/screenshot.png"))
            {
                m_ScreenshotHandle = SteamScreenshots.AddScreenshotToLibrary(Application.dataPath + "/screenshot.png", "", Screen.width, Screen.height);
                print("SteamScreenshots.AddScreenshotToLibrary(\"screenshot.png\", \"\", " + Screen.width + ", " + Screen.height + ") : " + m_ScreenshotHandle);
                yield break;
            }

            yield return(null);
        }
    }
	IEnumerator WriteScreenshot() {
		yield return new WaitForEndOfFrame();

		Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
		texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
		texture.Apply(false);

		Color[] color = texture.GetPixels();
		byte[] RGB = new byte[color.Length * 3];

		for(int i = 0, c = 0; i < RGB.Length; i += 3, ++c) {
			RGB[i] = (byte)(color[c].r * 255.0f);
			RGB[i + 1] = (byte)(color[c].g * 255.0f);
			RGB[i + 2] = (byte)(color[c].b * 255.0f);
		}

		Destroy(texture);

		// TODO: The image is upside down! "@ares_p: in Unity all texture data starts from "bottom" (OpenGL convention)"
		m_ScreenshotHandle = SteamScreenshots.WriteScreenshot(RGB, (uint)RGB.Length, Screen.width, Screen.height);
		print("SteamScreenshots.WriteScreenshot(" + RGB + ", " + (uint)RGB.Length + ", " + Screen.width + ", " + Screen.height + ") : " + m_ScreenshotHandle);
	}
 public bool SetLocation(ScreenshotHandle screenshot, string location)
 {
     return(NativeMethods.Screenshots_SetLocation(screenshot.AsUInt32, location));
 }
 public bool TagUser(ScreenshotHandle screenshot, SteamID steamID)
 {
     return(NativeMethods.Screenshots_TagUser(screenshot.AsUInt32, steamID.AsUInt64));
 }
Example #10
0
        internal bool TagUser(ScreenshotHandle hScreenshot, SteamId steamID)
        {
            var returnValue = _TagUser(Self, hScreenshot, steamID);

            return(returnValue);
        }
    public void RenderOnGUI()
    {
        GUILayout.BeginArea(new Rect(Screen.width - 200, 0, 200, Screen.height));
        GUILayout.Label("Variables:");
        GUILayout.Label("m_ScreenshotHandle: " + m_ScreenshotHandle);
        GUILayout.Label("m_Hooked: " + m_Hooked);
        GUILayout.EndArea();

        GUILayout.BeginVertical("box");
        m_ScrollPos = GUILayout.BeginScrollView(m_ScrollPos, GUILayout.Width(Screen.width - 215), GUILayout.Height(Screen.height - 33));

        if (GUILayout.Button("WriteScreenshot(RGB, (uint)RGB.Length, Screen.width, Screen.height)"))
        {
            // We start a Coroutine with the actual implementation of this test because Texture2D.ReadPixels() has to be called at the end of the frame.
            StartCoroutine(WriteScreenshot());
        }

        if (GUILayout.Button("AddScreenshotToLibrary(Application.dataPath + \"/screenshot.png\", \"\", Screen.width, Screen.height)"))
        {
            Application.CaptureScreenshot("screenshot.png");
            // Application.CaptureScreenshot is asyncronous, therefore we have to wait until the screenshot is created.
            StartCoroutine(AddScreenshotToLibrary());
        }

        if (GUILayout.Button("TriggerScreenshot()"))
        {
            SteamScreenshots.TriggerScreenshot();
            print("SteamScreenshots.TriggerScreenshot()");
        }

        if (GUILayout.Button("HookScreenshots(!m_Hooked)"))
        {
            SteamScreenshots.HookScreenshots(!m_Hooked);
            print("SteamScreenshots.HookScreenshots(" + !m_Hooked + ")");
            m_Hooked = !m_Hooked;
        }

        if (GUILayout.Button("SetLocation(m_ScreenshotHandle, \"LocationTest\")"))
        {
            bool ret = SteamScreenshots.SetLocation(m_ScreenshotHandle, "LocationTest");
            print("SteamScreenshots.SetLocation(" + m_ScreenshotHandle + ", " + "\"LocationTest\"" + ") : " + ret);
        }

        if (GUILayout.Button("TagUser(m_ScreenshotHandle, TestConstants.Instance.k_SteamId_rlabrecque)"))
        {
            bool ret = SteamScreenshots.TagUser(m_ScreenshotHandle, TestConstants.Instance.k_SteamId_rlabrecque);
            print("SteamScreenshots.TagUser(" + m_ScreenshotHandle + ", " + TestConstants.Instance.k_SteamId_rlabrecque + ") : " + ret);
        }

        if (GUILayout.Button("TagPublishedFile(m_ScreenshotHandle, PublishedFileId_t.Invalid)"))
        {
            bool ret = SteamScreenshots.TagPublishedFile(m_ScreenshotHandle, PublishedFileId_t.Invalid);
            print("SteamScreenshots.TagPublishedFile(" + m_ScreenshotHandle + ", " + PublishedFileId_t.Invalid + ") : " + ret);
        }

        GUILayout.Label("IsScreenshotsHooked() : " + SteamScreenshots.IsScreenshotsHooked());

        if (GUILayout.Button("AddVRScreenshotToLibrary(EVRScreenshotType.k_EVRScreenshotType_None, null, null)"))
        {
            ScreenshotHandle ret = SteamScreenshots.AddVRScreenshotToLibrary(EVRScreenshotType.k_EVRScreenshotType_None, null, null);
            print("SteamScreenshots.AddVRScreenshotToLibrary(" + EVRScreenshotType.k_EVRScreenshotType_None + ", " + null + ", " + null + ") : " + ret);
        }

        GUILayout.EndScrollView();
        GUILayout.EndVertical();
    }
Example #12
0
		public static extern bool ISteamScreenshots_SetLocation(ScreenshotHandle hScreenshot, InteropHelp.UTF8StringHandle pchLocation);
Example #13
0
		public static extern bool ISteamScreenshots_TagPublishedFile(ScreenshotHandle hScreenshot, PublishedFileId_t unPublishedFileID);
Example #14
0
        static bool TakeScreenshot(IntPtr hwnd)
        {
            bool   success = false;
            IntPtr hBmp    = IntPtr.Zero;
            // Get DC of game window
            IntPtr hDC = PlatformInvokeUSER32.GetDC(hwnd);

            if (hDC != IntPtr.Zero)
            {
                // Make compatible DC that we can blit to
                IntPtr hMemDC = PlatformInvokeGDI32.CreateCompatibleDC(hDC);
                if (hMemDC != IntPtr.Zero)
                {
                    // Get size of what we're trying to take a screenshot of
                    if (PlatformInvokeUSER32.GetClientRect(hwnd, out PlatformInvokeUSER32.RECT rect))
                    {
                        int width  = rect.right - rect.left;
                        int height = rect.bottom - rect.top;
                        // Create bitmap
                        hBmp = PlatformInvokeGDI32.CreateCompatibleBitmap(hDC, width, height);
                        if (hBmp != IntPtr.Zero)
                        {
                            // Blit the thing
                            IntPtr hOld = PlatformInvokeGDI32.SelectObject(hMemDC, hBmp);
                            PlatformInvokeGDI32.BitBlt(hMemDC, 0, 0, width, height, hDC, rect.left, rect.top, PlatformInvokeGDI32.SRCCOPY);
                            PlatformInvokeGDI32.SelectObject(hMemDC, hOld);
                            success = true;
                        }
                    }
                    PlatformInvokeGDI32.DeleteDC(hMemDC);
                }
                PlatformInvokeUSER32.ReleaseDC(hwnd, hDC);
            }

            if (success)
            {
                // Use .NET's graphics processing to extract our pixels
                using (Bitmap bmp = Image.FromHbitmap(hBmp))
                {
                    // Remember to clean up the native bitmap from earlier
                    PlatformInvokeGDI32.DeleteObject(hBmp);

                    // Lock the bitmap data and prepare a buffer
                    BitmapData bits   = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                    byte[]     buffer = new byte[bmp.Width * bmp.Height * 3];
                    int        i      = 0;

                    unsafe
                    {
                        byte *scanline = (byte *)bits.Scan0;
                        while (i < buffer.Length)
                        {
                            for (int j = 0; j < bits.Width; ++j)
                            {
                                // The buffer in .NET is BGR, so flip it to RGB when copying
                                buffer[i++] = scanline[2];
                                buffer[i++] = scanline[1];
                                buffer[i++] = scanline[0];
                                scanline   += 3;
                            }
                            scanline += bits.Stride - bits.Width * 3;
                        }
                    }

                    // Unlock the bits
                    bmp.UnlockBits(bits);

                    // Send it off to Steam
                    ScreenshotHandle hScreenshot = SteamScreenshots.WriteScreenshot(buffer, (uint)buffer.Length, bmp.Width, bmp.Height);
                    success = hScreenshot != ScreenshotHandle.Invalid;
                }
            }

            return(success);
        }
Example #15
0
 public static bool TagPublishedFile(ScreenshotHandle hScreenshot, PublishedFileId_t unPublishedFileID)
 {
     InteropHelp.TestIfAvailableClient();
     return NativeMethods.ISteamScreenshots_TagPublishedFile(hScreenshot, unPublishedFileID);
 }
 /// <summary>
 /// <para> Tags a user as being visible in the screenshot</para>
 /// </summary>
 public static bool TagUser(ScreenshotHandle hScreenshot, SteamId steamID)
 {
     InteropHelp.TestIfAvailableClient();
     return(NativeMethods.ISteamScreenshots_TagUser(hScreenshot, steamID));
 }
 /// <summary>
 /// <para> Tags a published file as being visible in the screenshot</para>
 /// </summary>
 public static bool TagPublishedFile(ScreenshotHandle hScreenshot, PublishedFileId ufileId)
 {
     InteropHelp.TestIfAvailableClient();
     return(NativeMethods.ISteamScreenshots_TagPublishedFile(hScreenshot, ufileId));
 }
Example #18
0
        internal bool SetLocation(ScreenshotHandle hScreenshot, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8StringToNative))] string pchLocation)
        {
            var returnValue = _SetLocation(Self, hScreenshot, pchLocation);

            return(returnValue);
        }
Example #19
0
        internal bool TagPublishedFile(ScreenshotHandle hScreenshot, PublishedFileId unPublishedFileID)
        {
            var returnValue = _TagPublishedFile(Self, hScreenshot, unPublishedFileID);

            return(returnValue);
        }
Example #20
0
 private static extern bool _TagPublishedFile(IntPtr self, ScreenshotHandle hScreenshot, PublishedFileId unPublishedFileID);
 public bool TagPublishedFile(ScreenshotHandle screenshot, PublishedFileId publishedFileID)
 {
     return(NativeMethods.Screenshots_TagPublishedFile(screenshot.AsUInt32, publishedFileID.AsUInt64));
 }
 /// <summary>
 /// <para> Tags a user as being visible in the screenshot</para>
 /// </summary>
 public static bool TagUser(ScreenshotHandle hScreenshot, CSteamID steamID)
 {
     InteropHelp.TestIfAvailableClient();
     return(NativeMethods.ISteamScreenshots_TagUser(CSteamAPIContext.GetSteamScreenshots(), hScreenshot, steamID));
 }
 public bool SetLocation(ScreenshotHandle screenshot, string location)
 {
     return NativeMethods.Screenshots_SetLocation( screenshot.AsUInt32, location );
 }
Example #24
0
 private static extern bool _SetLocation(IntPtr self, ScreenshotHandle hScreenshot, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8StringToNative))] string pchLocation);
Example #25
0
 public static bool TagUser(ScreenshotHandle hScreenshot, CSteamID steamID)
 {
     InteropHelp.TestIfAvailableClient();
     return NativeMethods.ISteamScreenshots_TagUser(hScreenshot, steamID);
 }
 public bool TagPublishedFile(ScreenshotHandle screenshot, PublishedFileId publishedFileID)
 {
     return NativeMethods.Screenshots_TagPublishedFile( screenshot.AsUInt32, publishedFileID.AsUInt64 );
 }
Example #27
0
		public static extern bool ISteamScreenshots_TagUser(ScreenshotHandle hScreenshot, CSteamID steamID);
 public bool TagUser(ScreenshotHandle screenshot, SteamID steamID)
 {
     return NativeMethods.Screenshots_TagUser( screenshot.AsUInt32, steamID.AsUInt64 );
 }
Example #29
0
		// Sets metadata about a screenshot's location (for example, the name of the map)
		public static bool SetLocation(ScreenshotHandle hScreenshot, string pchLocation) {
			InteropHelp.TestIfAvailableClient();
			return NativeMethods.ISteamScreenshots_SetLocation(hScreenshot, pchLocation);
		}
Example #30
0
 private static extern bool _TagUser(IntPtr self, ScreenshotHandle hScreenshot, SteamId steamID);
 /// <summary>
 /// <para> Tags a published file as being visible in the screenshot</para>
 /// </summary>
 public static bool TagPublishedFile(ScreenshotHandle hScreenshot, PublishedFileId_t unPublishedFileID)
 {
     InteropHelp.TestIfAvailableClient();
     return(NativeMethods.ISteamScreenshots_TagPublishedFile(CSteamAPIContext.GetSteamScreenshots(), hScreenshot, unPublishedFileID));
 }
		/// <summary>
		/// <para> Sets metadata about a screenshot's location (for example, the name of the map)</para>
		/// </summary>
		public static bool SetLocation(ScreenshotHandle hScreenshot, string pchLocation) {
			InteropHelp.TestIfAvailableClient();
			using (var pchLocation2 = new InteropHelp.UTF8StringHandle(pchLocation)) {
				return NativeMethods.ISteamScreenshots_SetLocation(hScreenshot, pchLocation2);
			}
		}