Advertisement
lucasteles42

Unity WebRequest Custom

May 26th, 2022
1,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. public enum MyHttpVerb { POST, GET, CREATE, DELETE, PUT, HEAD }
  2. public class MyUnityWebRequest : UnityWebRequest
  3. {
  4.     static Dictionary<MyHttpVerb, string> dePara =
  5.         new Dictionary<MyHttpVerb, string>()
  6.     {
  7.         [MyHttpVerb.POST] = kHttpVerbPOST,
  8.         [MyHttpVerb.GET] = kHttpVerbGET,
  9.         [MyHttpVerb.CREATE] = kHttpVerbCREATE,
  10.         [MyHttpVerb.DELETE] = kHttpVerbDELETE,
  11.         [MyHttpVerb.PUT] = kHttpVerbPUT,
  12.         [MyHttpVerb.HEAD] = kHttpVerbHEAD,
  13.     };
  14.    
  15.     public MyUnityWebRequest(Uri uri, MyHttpVerb method) : base(uri, dePara[method]) { }
  16.     public MyUnityWebRequest(string uri, MyHttpVerb method) : base(uri, dePara[method]) { }
  17.    
  18. }
  19.  
  20. public class Xablau : MonoBehaviour
  21. {
  22.     void Start()
  23.     {
  24.         using (var webRequest = new MyUnityWebRequest("http://example.com",MyHttpVerb.POST))
  25.         {
  26.             // le o request
  27.         }
  28.     }
  29. }
  30.  
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement