SHC
How do I use S H C
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: ServerSettingsInspector.cs
Copy
127 private int RpcListHashCode()
128 {
129 // this is a hashcode generated to (more) easily compare this Editor's RPC List with some other
130 int hashCode = PhotonEditor.Current.RpcList.Count + 1;
131 foreach (string s in PhotonEditor.Current.RpcList)
132 {
133 int h1 = s.GetHashCode();
134 hashCode = ((h1 << 5) + h1) ^ hashCode;
135 }
136
137 return hashCode;
138 }
File name: PhotonNetwork.cs
Copy
1269 public static void RefreshCloudServerRating()
1270 {
1271 throw new NotImplementedException("not available at the moment");
1272 }
File name: PhotonPlayer.cs
Copy
124 public override bool Equals(object p)
125 {
126 PhotonPlayer pp = p as PhotonPlayer;
127 return (pp != null && this.GetHashCode() == pp.GetHashCode());
128 }
File name: PhotonPlayer.cs
Copy
130 public override int GetHashCode()
131 {
132 return this.ID;
133 }
File name: RoomInfo.cs
Copy
155 public override int GetHashCode()
156 {
157 return this.nameField.GetHashCode();
158 }
File name: Movable.cs
Copy
16 public virtual void MoveToXZ(Node node, Action finishCallback) {
17 StopMoveCoroutine();
18 moveCoroutine = StartCoroutine(IEMoveToXZ(node, finishCallback));
19 }
File name: Movable.cs
Copy
21 public virtual void MoveBy(Vector3 addPos, Action finishCallback) {
22 StopMoveCoroutine();
23 moveCoroutine = StartCoroutine(IEMoveBy(addPos, finishCallback));
24 }
File name: Movable.cs
Copy
32 protected virtual IEnumerator IEMoveBy(Vector3 addPos, Action finishCallback) {
33 ready = false;
34 Vector3 origPos = transform.position;
35 Vector3 targPos = origPos + addPos;
36
37 while (true) {
38 if (IsNear(targPos)) {
39 ready = true;
40 if (finishCallback != null) finishCallback();
41 yield break;
42 }
43 transform.position = Vector3.MoveTowards(transform.position,targPos,speed * Time.deltaTime);
44
45 yield return null;
46 }
47 }
File name: Movable.cs
Copy
49 protected virtual IEnumerator IEMoveToXZ(Node node, Action finishCallback) {
50 ready = false;
51 Vector3 origPos = transform.position;
52 Vector3 targPos = node.transform.position;
53 targPos.y = origPos.y;
54 while (true) {
55 if (IsNear(targPos)) {
56 ready = true;
57 if (finishCallback != null) finishCallback();
58 yield break;
59 }
60 transform.position = Vector3.MoveTowards(transform.position,targPos,speed * Time.deltaTime);
61 yield return null;
62 }
63 }
Download file with original file name:SHC
SHC 109 lượt xem
Gõ tìm kiếm nhanh...