Protocol
How do I use Protocol
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PhotonEditor.cs
Copy
727 protected virtual void OnGuiSetupSelfhosting()
728 {
729 GUILayout.Label(CurrentLang.YourPhotonServerLabel);
730
731 this.photonAddress = EditorGUILayout.TextField(CurrentLang.AddressIPLabel, this.photonAddress);
732 this.photonPort = EditorGUILayout.IntField(CurrentLang.PortLabel, this.photonPort);
733 this.photonProtocol = (ConnectionProtocol)EditorGUILayout.EnumPopup("Protocol", this.photonProtocol);
734 EditorGUILayout.Separator();
735
736 GUILayout.BeginHorizontal();
737 if (GUILayout.Button(CurrentLang.CancelButton))
738 {
739 GUIUtility.keyboardControl = 0;
740 this.ReApplySettingsToWindow();
741 }
742
743 if (GUILayout.Button(CurrentLang.SaveButton))
744 {
745 GUIUtility.keyboardControl = 0;
746
747 PhotonEditor.Current.UseMyServer(this.photonAddress, this.photonPort, null);
748 PhotonEditor.Current.Protocol = this.photonProtocol;
749 PhotonEditor.Save();
750
751 Inspect();
752 EditorUtility.DisplayDialog(CurrentLang.SettingsSavedTitle, CurrentLang.SettingsSavedMessage, CurrentLang.OkButton);
753 }
754
755 GUILayout.EndHorizontal();
756
757
758 GUILayout.Space(20);
759
760
761 // license
762 GUILayout.BeginHorizontal();
763 GUILayout.Label(CurrentLang.LicensesLabel, EditorStyles.boldLabel, GUILayout.Width(100));
764
765 if (GUILayout.Button(new GUIContent(CurrentLang.LicenseDownloadText, CurrentLang.LicenseDownloadTooltip)))
766 {
767 EditorUtility.OpenWithDefaultApp(UrlFreeLicense);
768 }
769
770 GUILayout.EndHorizontal();
771
772
773 GUILayout.Space(20);
774
775
776 GUILayout.Label(CurrentLang.TryPhotonAppLabel);
777
778 if (GUILayout.Button(CurrentLang.GetCloudAppButton))
779 {
780 this.cloudAppId = string.Empty;
781 this.photonSetupState = PhotonSetupStates.RegisterForPhotonCloud;
782 }
783
784 EditorGUILayout.Separator();
785 GUILayout.Label(CurrentLang.OwnHostCloudCompareLabel);
786 if (GUILayout.Button(CurrentLang.ComparisonPageButton))
787 {
788 Application.OpenURL(UrlCompare);
789 }
790 }
File name: PhotonEditor.cs
Copy
901 protected void ReApplySettingsToWindow()
902 {
903 this.cloudAppId = string.IsNullOrEmpty(PhotonEditor.Current.AppID) ? string.Empty : PhotonEditor.Current.AppID;
904 this.photonAddress = string.IsNullOrEmpty(PhotonEditor.Current.ServerAddress) ? string.Empty : PhotonEditor.Current.ServerAddress;
905 this.photonPort = PhotonEditor.Current.ServerPort;
906 this.photonProtocol = PhotonEditor.Current.Protocol;
907 }
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: CustomTypes.cs
Copy
45 private static short SerializeVector3(MemoryStream outStream, object customobject)
46 {
47 Vector3 vo = (Vector3)customobject;
48
49 int index = 0;
50 lock (memVector3)
51 {
52 byte[] bytes = memVector3;
53 Protocol.Serialize(vo.x, bytes, ref index);
54 Protocol.Serialize(vo.y, bytes, ref index);
55 Protocol.Serialize(vo.z, bytes, ref index);
56 outStream.Write(bytes, 0, 3 * 4);
57 }
58
59 return 3 * 4;
60 }
File name: CustomTypes.cs
Copy
62 private static object DeserializeVector3(MemoryStream inStream, short length)
63 {
64 Vector3 vo = new Vector3();
65 lock (memVector3)
66 {
67 inStream.Read(memVector3, 0, 3 * 4);
68 int index = 0;
69 Protocol.Deserialize(out vo.x, memVector3, ref index);
70 Protocol.Deserialize(out vo.y, memVector3, ref index);
71 Protocol.Deserialize(out vo.z, memVector3, ref index);
72 }
73
74 return vo;
75 }
File name: CustomTypes.cs
Copy
79 private static short SerializeVector2(MemoryStream outStream, object customobject)
80 {
81 Vector2 vo = (Vector2)customobject;
82 lock (memVector2)
83 {
84 byte[] bytes = memVector2;
85 int index = 0;
86 Protocol.Serialize(vo.x, bytes, ref index);
87 Protocol.Serialize(vo.y, bytes, ref index);
88 outStream.Write(bytes, 0, 2 * 4);
89 }
90
91 return 2 * 4;
92 }
File name: CustomTypes.cs
Copy
94 private static object DeserializeVector2(MemoryStream inStream, short length)
95 {
96 Vector2 vo = new Vector2();
97 lock (memVector2)
98 {
99 inStream.Read(memVector2, 0, 2 * 4);
100 int index = 0;
101 Protocol.Deserialize(out vo.x, memVector2, ref index);
102 Protocol.Deserialize(out vo.y, memVector2, ref index);
103 }
104
105 return vo;
106 }
File name: CustomTypes.cs
Copy
110 private static short SerializeQuaternion(MemoryStream outStream, object customobject)
111 {
112 Quaternion o = (Quaternion)customobject;
113
114 lock (memQuarternion)
115 {
116 byte[] bytes = memQuarternion;
117 int index = 0;
118 Protocol.Serialize(o.w, bytes, ref index);
119 Protocol.Serialize(o.x, bytes, ref index);
120 Protocol.Serialize(o.y, bytes, ref index);
121 Protocol.Serialize(o.z, bytes, ref index);
122 outStream.Write(bytes, 0, 4 * 4);
123 }
124
125 return 4 * 4;
126 }
File name: CustomTypes.cs
Copy
128 private static object DeserializeQuaternion(MemoryStream inStream, short length)
129 {
130 Quaternion o = new Quaternion();
131
132 lock (memQuarternion)
133 {
134 inStream.Read(memQuarternion, 0, 4 * 4);
135 int index = 0;
136 Protocol.Deserialize(out o.w, memQuarternion, ref index);
137 Protocol.Deserialize(out o.x, memQuarternion, ref index);
138 Protocol.Deserialize(out o.y, memQuarternion, ref index);
139 Protocol.Deserialize(out o.z, memQuarternion, ref index);
140 }
141
142 return o;
143 }
File name: CustomTypes.cs
Copy
146 private static short SerializePhotonPlayer(MemoryStream outStream, object customobject)
147 {
148 int ID = ((PhotonPlayer)customobject).ID;
149
150 lock (memPlayer)
151 {
152 byte[] bytes = memPlayer;
153 int off = 0;
154 Protocol.Serialize(ID, bytes, ref off);
155 outStream.Write(bytes, 0, 4);
156 return 4;
157 }
158 }
Protocol 144 lượt xem
Gõ tìm kiếm nhanh...