RHttp









How do I use R Http
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: ServerSettingsInspector.cs Copy
17     public override void OnInspectorGUI()
18     {
19         ServerSettings settings = (ServerSettings)this.target;
20
21         #if UNITY_3_5
22         EditorGUIUtility.LookLikeInspector();
23         #endif
24
25
26         settings.HostType = (ServerSettings.HostingOption)EditorGUILayout.EnumPopup("Hosting", settings.HostType);
27         EditorGUI.indentLevel = 1;
28
29         switch (settings.HostType)
30         {
31             case ServerSettings.HostingOption.BestRegion:
32             case ServerSettings.HostingOption.PhotonCloud:
33                 if (settings.HostType == ServerSettings.HostingOption.PhotonCloud)
34                     settings.PreferredRegion = (CloudRegionCode)EditorGUILayout.EnumPopup("Region", settings.PreferredRegion);
35                 settings.AppID = EditorGUILayout.TextField("AppId", settings.AppID);
36                 settings.Protocol = (ConnectionProtocol)EditorGUILayout.EnumPopup("Protocol", settings.Protocol);
37
38                 if (string.IsNullOrEmpty(settings.AppID) || settings.AppID.Equals("master"))
39                 {
40                     EditorGUILayout.HelpBox("The Photon Cloud needs an AppId (GUID) set.\nYou can find it online in your Dashboard.", MessageType.Warning);
41                 }
42                 break;
43
44             case ServerSettings.HostingOption.SelfHosted:
45                 bool hidePort = false;
46                 if (settings.Protocol == ConnectionProtocol.Udp && (settings.ServerPort == 4530 || settings.ServerPort == 0))
47                 {
48                     settings.ServerPort = 5055;
49                 }
50                 else if (settings.Protocol == ConnectionProtocol.Tcp && (settings.ServerPort == 5055 || settings.ServerPort == 0))
51                 {
52                     settings.ServerPort = 4530;
53                 }
54                 #if RHTTP
55                 if (settings.Protocol == ConnectionProtocol.RHttp)
56                 {
57                     settings.ServerPort = 0;
58                     hidePort = true;
59                 }
60                 #endif
61                 settings.ServerAddress = EditorGUILayout.TextField("Server Address", settings.ServerAddress);
62                 settings.ServerAddress = settings.ServerAddress.Trim();
63                 if (!hidePort)
64                 {
65                     settings.ServerPort = EditorGUILayout.IntField("Server Port", settings.ServerPort);
66                 }
67                 settings.Protocol = (ConnectionProtocol)EditorGUILayout.EnumPopup("Protocol", settings.Protocol);
68                 settings.AppID = EditorGUILayout.TextField("AppId", settings.AppID);
69                 break;
70
71             case ServerSettings.HostingOption.OfflineMode:
72                 EditorGUI.indentLevel = 0;
73                 EditorGUILayout.HelpBox("In 'Offline Mode', the client does not communicate with a server.\nAll settings are hidden currently.", MessageType.Info);
74                 break;
75
76             case ServerSettings.HostingOption.NotSet:
77                 EditorGUI.indentLevel = 0;
78                 EditorGUILayout.HelpBox("Hosting is 'Not Set'.\nConnectUsingSettings() will not be able to connect.\nSelect another option or run the PUN Wizard.", MessageType.Info);
79                 break;
80
81             default:
82                 DrawDefaultInspector();
83                 break;
84         }
85
86         if (PhotonEditor.CheckPunPlus())
87         {
88             settings.Protocol = ConnectionProtocol.Udp;
89             EditorGUILayout.HelpBox("You seem to use PUN+.\nPUN+ only supports reliable UDP so the protocol is locked.", MessageType.Info);
90         }
91
92         settings.AppID = settings.AppID.Trim();
93
94         EditorGUI.indentLevel = 0;
95         SerializedObject sObj = new SerializedObject(this.target);
96         SerializedProperty sRpcs = sObj.FindProperty("RpcList");
97         EditorGUILayout.PropertyField(sRpcs, true);
98         sObj.ApplyModifiedProperties();
99
100         GUILayout.BeginHorizontal();
101         GUILayout.Space(20);
102         if (GUILayout.Button("Refresh RPCs"))
103         {
104             PhotonEditor.UpdateRpcList();
105             Repaint();
106         }
107         if (GUILayout.Button("Clear RPCs"))
108         {
109             PhotonEditor.ClearRpcList();
110         }
111         if (GUILayout.Button("Log HashCode"))
112         {
113             Debug.Log("RPC-List HashCode: " + RpcListHashCode() + ". Make sure clients that send each other RPCs have the same RPC-List.");
114         }
115         GUILayout.Space(20);
116         GUILayout.EndHorizontal();
117
118         //SerializedProperty sp = serializedObject.FindProperty("RpcList");
119         //EditorGUILayout.PropertyField(sp, true);
120
121         if (GUI.changed)
122         {
123             EditorUtility.SetDirty(target);
124         }
125     }
File name: NetworkingPeer.cs Copy
163     private static readonly Dictionary ProtocolToNameServerPort = new Dictionary() { {ConnectionProtocol.Udp, 5058}, {ConnectionProtocol.Tcp, 4533} }; //, { ConnectionProtocol.RHttp, 6063 } };
File name: NetworkingPeer.cs Copy
294     public bool ConnectToNameServer()
295     {
296         if (PhotonHandler.AppQuits)
297         {
298             Debug.LogWarning("Ignoring Connect() because app gets closed. If this is an error, check PhotonHandler.AppQuits.");
299             return false;
300         }
301
302         IsUsingNameServer = true;
303         this.CloudRegion = CloudRegionCode.none;
304
305         if (this.State == global::PeerState.ConnectedToNameServer)
306         {
307             return true;
308         }
309
310         #if RHTTP
311         string address = (this.UsedProtocol == ConnectionProtocol.RHttp) ? this.NameServerAddressHttp : this.NameServerAddress;
312         #else
313         string address = this.NameServerAddress;
314         #endif
315
316         if (!address.Contains(":"))
317         {
318             int port = 0;
319             ProtocolToNameServerPort.TryGetValue(this.UsedProtocol, out port);
320             address = string.Format("{0}:{1}", address, port);
321             Debug.Log("Server to connect to: " + address + " settings protocol: " + PhotonNetwork.PhotonServerSettings.Protocol);
322         }
323         if (!base.Connect(address, "ns"))
324         {
325             return false;
326         }
327
328         this.State = global::PeerState.ConnectingToNameServer;
329         return true;
330     }
File name: NetworkingPeer.cs Copy
336     public bool ConnectToRegionMaster(CloudRegionCode region)
337     {
338         if (PhotonHandler.AppQuits)
339         {
340             Debug.LogWarning("Ignoring Connect() because app gets closed. If this is an error, check PhotonHandler.AppQuits.");
341             return false;
342         }
343
344         IsUsingNameServer = true;
345         this.CloudRegion = region;
346
347         if (this.State == global::PeerState.ConnectedToNameServer)
348         {
349             return this.OpAuthenticate(this.mAppId, this.mAppVersionPun, this.PlayerName, this.CustomAuthenticationValues, region.ToString());
350         }
351
352         #if RHTTP
353         string address = (this.UsedProtocol == ConnectionProtocol.RHttp) ? this.NameServerAddressHttp : this.NameServerAddress;
354         #else
355         string address = this.NameServerAddress;
356         #endif
357
358         if (!address.Contains(":"))
359         {
360             int port = 0;
361             ProtocolToNameServerPort.TryGetValue(this.UsedProtocol, out port);
362             address = string.Format("{0}:{1}", address, port);
363             //Debug.Log("Server to connect to: "+ address + " settings protocol: " + PhotonNetwork.PhotonServerSettings.Protocol);
364         }
365         if (!base.Connect(address, "ns"))
366         {
367             return false;
368         }
369
370         this.State = global::PeerState.ConnectingToNameServer;
371         return true;
372     }
File name: ChatClient.cs Copy
77         private static readonly Dictionary ProtocolToNameServerPort = new Dictionary() { { ConnectionProtocol.Udp, 5058 }, { ConnectionProtocol.Tcp, 4533 } }; //, { ConnectionProtocol.RHttp, 6063 } };

RHttp 135 lượt xem

Gõ tìm kiếm nhanh...