Tanoda
HttpCookie.cs
Go to the documentation of this file.
1using System;
2using System.Globalization;
3using System.Runtime.InteropServices;
4
5public static class HttpCookie
6{
7#if UNITY_WEBGL
12 [DllImport("__Internal")]
13 private static extern string getHttpCookies();
19 [DllImport("__Internal")]
20 private static extern string getHttpCookie(string name);
30 [DllImport("__Internal")]
31 private static extern void setHttpCookie(string name, string value, string expires, string path, string domain, string secure);
32
38#endif
39 public static string GetCookie(string name)
40 {
41#if UNITY_EDITOR || UNITY_STANDALONE
42 return "";
43#else
44 return getHttpCookie(name);
45#endif
46 }
47
52 public static void RemoveCookie(string name)
53 {
54#if UNITY_EDITOR || UNITY_STANDALONE
55#else
56 setHttpCookie(name, string.Empty, "0", string.Empty, string.Empty, string.Empty);
57#endif
58 }
59
60 public static void RemoveRootCookie(string name)
61 {
62#if UNITY_EDITOR || UNITY_STANDALONE
63#else
64 setHttpCookie(name, string.Empty, "0", "/", string.Empty, string.Empty);
65#endif
66 }
67
73 public static void SetCookie(string name, string value)
74 {
75#if UNITY_EDITOR || UNITY_STANDALONE
76 return;
77#endif
78 SetCookie(name, value, string.Empty, string.Empty, string.Empty, string.Empty);
79 }
80
90 public static void SetCookie(string name, string value, DateTime date)
91 {
92 var dateJS = date.ToUniversalTime().ToString("ddd, dd'-'MMM'-'yyyy HH':'mm':'ss 'GMT'",
93 CultureInfo.CreateSpecificCulture("en-US"));
94 SetCookie(name, value, dateJS, string.Empty, string.Empty, string.Empty);
95 }
96
109 public static void SetCookie(string name, string value, string expires, string path, string domain, string secure)
110 {
111#if UNITY_WEBGL && !UNITY_EDITOR
112 setHttpCookie(name, value, expires, path, domain, secure);
113#endif
114 }
115}