Skip









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

Featured Snippets


File name: ChatGui.cs Copy
103     public void OnGUI()
104     {
105         if (!this.IsVisible)
106         {
107             return;
108         }
109
110         GUI.skin.label.wordWrap = true;
111         //GUI.skin.button.richText = true; // this allows toolbar buttons to have bold/colored text. nice to indicate new msgs
112         //GUILayout.Button("lala"); // as richText, html tags could be in text
113
114
115         if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return))
116         {
117             if ("ChatInput".Equals(GUI.GetNameOfFocusedControl()))
118             {
119                 // focus on input -> submit it
120                 GuiSendsMsg();
121                 return; // showing the now modified list would result in an error. to avoid this, we just skip this single frame
122             }
123             else
124             {
125                 // assign focus to input
126                 GUI.FocusControl("ChatInput");
127             }
128         }
129
130         GUI.SetNextControlName("");
131         GUILayout.BeginArea(this.GuiRect);
132
133         GUILayout.FlexibleSpace();
134
135         if (this.chatClient.State != ChatState.ConnectedToFrontEnd)
136         {
137             GUILayout.Label("Not in chat yet.");
138         }
139         else
140         {
141             List channels = new List(this.chatClient.PublicChannels.Keys); // this could be cached
142             int countOfPublicChannels = channels.Count;
143             channels.AddRange(this.chatClient.PrivateChannels.Keys);
144
145             if (channels.Count > 0)
146             {
147                 int previouslySelectedChannelIndex = this.selectedChannelIndex;
148                 int channelIndex = channels.IndexOf(this.selectedChannelName);
149                 this.selectedChannelIndex = (channelIndex >= 0) ? channelIndex : 0;
150
151                 this.selectedChannelIndex = GUILayout.Toolbar(this.selectedChannelIndex, channels.ToArray(), GUILayout.ExpandWidth(false));
152                 this.scrollPos = GUILayout.BeginScrollView(this.scrollPos);
153
154                 this.doingPrivateChat = (this.selectedChannelIndex >= countOfPublicChannels);
155                 this.selectedChannelName = channels[this.selectedChannelIndex];
156
157                 if (this.selectedChannelIndex != previouslySelectedChannelIndex)
158                 {
159                     // changed channel -> scroll down, if private: pre-fill "to" field with target user's name
160                     this.scrollPos.y = float.MaxValue;
161                     if (this.doingPrivateChat)
162                     {
163                         string[] pieces = this.selectedChannelName.Split(new char[] {':'}, 3);
164                         this.userIdInput = pieces[1];
165                     }
166                 }
167
168                 GUILayout.Label(ChatGui.WelcomeText);
169
170                 if (this.chatClient.TryGetChannel(selectedChannelName, this.doingPrivateChat, out this.selectedChannel))
171                 {
172                     for (int i = 0; i < this.selectedChannel.Messages.Count; i++)
173                     {
174                         string sender = this.selectedChannel.Senders[i];
175                         object message = this.selectedChannel.Messages[i];
176                         GUILayout.Label(string.Format("{0}: {1}", sender, message));
177                     }
178                 }
179
180                 GUILayout.EndScrollView();
181             }
182         }
183
184
185         GUILayout.BeginHorizontal();
186         if (doingPrivateChat)
187         {
188             GUILayout.Label("to:", GUILayout.ExpandWidth(false));
189             GUI.SetNextControlName("WhisperTo");
190             this.userIdInput = GUILayout.TextField(this.userIdInput, GUILayout.MinWidth(100), GUILayout.ExpandWidth(false));
191             string focussed = GUI.GetNameOfFocusedControl();
192             if (focussed.Equals("WhisperTo"))
193             {
194                 if (this.userIdInput.Equals("username"))
195                 {
196                     this.userIdInput = "";
197                 }
198             }
199             else if (string.IsNullOrEmpty(this.userIdInput))
200             {
201                 this.userIdInput = "username";
202             }
203
204         }
205         GUI.SetNextControlName("ChatInput");
206         inputLine = GUILayout.TextField(inputLine);
207         if (GUILayout.Button("Send", GUILayout.ExpandWidth(false)))
208         {
209             GuiSendsMsg();
210         }
211         GUILayout.EndHorizontal();
212         GUILayout.EndArea();
213     }
File name: GUIFriendFinding.cs Copy
28     public static string[] FetchFriendsFromCommunity()
29     {
30         string[] friendsList = new string[9];
31         int u = 0;
32         for (int i = 0; i < friendsList.Length; i++)
33         {
34             string usrName = "usr" + u++;
35             if (usrName.Equals(PhotonNetwork.playerName))
36             {
37                 usrName = "usr" + u++; // skip friend if the name is yours
38             }
39             friendsList[i] = usrName;
40         }
41
42         return friendsList;
43     }
File name: PhotonEditor.cs Copy
909     public static void UpdateRpcList()
910     {
911         List additionalRpcs = new List();
912         HashSet currentRpcs = new HashSet();
913
914         var types = GetAllSubTypesInScripts(typeof(MonoBehaviour));
915
916         foreach (var mono in types)
917         {
918             MethodInfo[] methods = mono.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
919
920             foreach (MethodInfo method in methods)
921             {
922                 if (method.IsDefined(typeof(UnityEngine.RPC), false))
923                 {
924                     currentRpcs.Add(method.Name);
925
926                     if (!additionalRpcs.Contains(method.Name) && !PhotonEditor.Current.RpcList.Contains(method.Name))
927                     {
928                         additionalRpcs.Add(method.Name);
929                     }
930                 }
931             }
932         }
933
934         if (additionalRpcs.Count > 0)
935         {
936             // LIMITS RPC COUNT
937             if (additionalRpcs.Count + PhotonEditor.Current.RpcList.Count >= byte.MaxValue)
938             {
939                 if (currentRpcs.Count <= byte.MaxValue)
940                 {
941                     bool clearList = EditorUtility.DisplayDialog(CurrentLang.IncorrectRPCListTitle, CurrentLang.IncorrectRPCListLabel, CurrentLang.RemoveOutdatedRPCsLabel, CurrentLang.CancelButton);
942                     if (clearList)
943                     {
944                         PhotonEditor.Current.RpcList.Clear();
945                         PhotonEditor.Current.RpcList.AddRange(currentRpcs);
946                     }
947                     else
948                     {
949                         return;
950                     }
951                 }
952                 else
953                 {
954                     EditorUtility.DisplayDialog(CurrentLang.FullRPCListTitle, CurrentLang.FullRPCListLabel, CurrentLang.SkipRPCListUpdateLabel);
955                     return;
956                 }
957             }
958
959             additionalRpcs.Sort();
960             PhotonEditor.Current.RpcList.AddRange(additionalRpcs);
961             EditorUtility.SetDirty(PhotonEditor.Current);
962         }
963     }
File name: NetworkingPeer.cs Copy
3339     private void OnSerializeRead(Hashtable data, PhotonPlayer sender, int networkTime, short correctPrefix)
3340     {
3341         // read view ID from key (byte)0: a int-array (PUN 1.17++)
3342         int viewID = (int)data[(byte)0];
3343
3344
3345         PhotonView view = this.GetPhotonView(viewID);
3346         if (view == null)
3347         {
3348             Debug.LogWarning("Received OnSerialization for view ID " + viewID + ". We have no such PhotonView! Ignored this if you're leaving a room. State: " + this.State);
3349             return;
3350         }
3351
3352         if (view.prefix > 0 && correctPrefix != view.prefix)
3353         {
3354             Debug.LogError("Received OnSerialization for view ID " + viewID + " with prefix " + correctPrefix + ". Our prefix is " + view.prefix);
3355             return;
3356         }
3357
3358         // SetReceiving filtering
3359         if (view.group != 0 && !this.allowedReceivingGroups.Contains(view.group))
3360         {
3361             return; // Ignore group
3362         }
3363
3364
3365         if (view.synchronization == ViewSynchronization.ReliableDeltaCompressed)
3366         {
3367             if (!this.DeltaCompressionRead(view, data))
3368             {
3369                 // Skip this packet as we haven't got received complete-copy of this view yet.
3370                 if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
3371                     Debug.Log("Skipping packet for " + view.name + " [" + view.viewID + "] as we haven't received a full packet for delta compression yet. This is OK if it happens for the first few frames after joining a game.");
3372                 return;
3373             }
3374
3375             // store last received for delta-compression usage
3376             view.lastOnSerializeDataReceived = data[(byte)1] as object[];
3377         }
3378
3379         if (sender.ID != view.ownerId)
3380         {
3381             if (!view.isSceneView || !sender.isMasterClient)
3382             {
3383                 // obviously the owner changed and we didn't yet notice.
3384                 Debug.Log("Adjusting owner to sender of updates. From: " + view.ownerId + " to: " + sender.ID);
3385                 view.ownerId = sender.ID;
3386             }
3387         }
3388
3389         object[] contents = data[(byte)1] as object[];
3390         PhotonStream pStream = new PhotonStream(false, contents);
3391         PhotonMessageInfo info = new PhotonMessageInfo(sender, networkTime, view);
3392
3393         view.DeserializeView( pStream, info );
3394     }
File name: NetworkingPeer.cs Copy
3499     private bool DeltaCompressionRead(PhotonView view, Hashtable data)
3500     {
3501         if (data.ContainsKey((byte)1))
3502         {
3503             // we have a full list of data (cause key 1 is used), so return "we have uncompressed all"
3504             return true;
3505         }
3506
3507         // Compression was applied as data[(byte)2] exists (this is the data with some fields being compressed to null)
3508         // now we also need a previous "full" list of values to restore values that are null in this msg
3509         if (view.lastOnSerializeDataReceived == null)
3510         {
3511             return false; // We dont have a full match yet, we cannot work with missing values: skip this message
3512         }
3513
3514         object[] compressedContents = data[(byte)2] as object[];
3515         if (compressedContents == null)
3516         {
3517             // despite expectation, there is no compressed data in this msg. shouldn't happen. just a null check
3518             return false;
3519         }
3520
3521         int[] indexesThatAreChangedToNull = data[(byte)3] as int[];
3522         if (indexesThatAreChangedToNull == null)
3523         {
3524             indexesThatAreChangedToNull = new int[0];
3525         }
3526
3527         object[] lastReceivedData = view.lastOnSerializeDataReceived;
3528         for (int index = 0; index < compressedContents.Length; index++)
3529         {
3530             if (compressedContents[index] == null && !indexesThatAreChangedToNull.Contains(index))
3531             {
3532                 // we replace null values in this received msg unless a index is in the "changed to null" list
3533                 object lastValue = lastReceivedData[index];
3534                 compressedContents[index] = lastValue;
3535             }
3536         }
3537
3538         data[(byte)1] = compressedContents; // compressedContents are now uncompressed...
3539         return true;
3540     }
File name: SocketUdp.cs Copy
91         public override PhotonSocketError Send(byte[] data, int length)
92         {
93             lock (this.syncer)
94             {
95                 if (!this.sock.Connected)
96                 {
97                     return PhotonSocketError.Skipped;
98                 }
99
100                 try
101                 {
102                     sock.Send(data, 0, length, SocketFlags.None);
103                 }
104                 catch
105                 {
106                     return PhotonSocketError.Exception;
107                 }
108             }
109
110             return PhotonSocketError.Success;
111         }
File name: InRoomChat.cs Copy
25     public void OnGUI()
26     {
27         if (!this.IsVisible || PhotonNetwork.connectionStateDetailed != PeerState.Joined)
28         {
29             return;
30         }
31
32         if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return))
33         {
34             if (!string.IsNullOrEmpty(this.inputLine))
35             {
36                 this.photonView.RPC("Chat", PhotonTargets.All, this.inputLine);
37                 this.inputLine = "";
38                 GUI.FocusControl("");
39                 return; // printing the now modified list would result in an error. to avoid this, we just skip this single frame
40             }
41             else
42             {
43                 GUI.FocusControl("ChatInput");
44             }
45         }
46
47         GUI.SetNextControlName("");
48         GUILayout.BeginArea(this.GuiRect);
49
50         scrollPos = GUILayout.BeginScrollView(scrollPos);
51         GUILayout.FlexibleSpace();
52         for (int i = messages.Count - 1; i >= 0; i--)
53         {
54             GUILayout.Label(messages[i]);
55         }
56         GUILayout.EndScrollView();
57
58         GUILayout.BeginHorizontal();
59         GUI.SetNextControlName("ChatInput");
60         inputLine = GUILayout.TextField(inputLine);
61         if (GUILayout.Button("Send", GUILayout.ExpandWidth(false)))
62         {
63             this.photonView.RPC("Chat", PhotonTargets.All, this.inputLine);
64             this.inputLine = "";
65             GUI.FocusControl("");
66         }
67         GUILayout.EndHorizontal();
68         GUILayout.EndArea();
69     }
File name: ChatClient.cs Copy
343         /// The message object can be anything that Photon can serialize, including (but not limited to)
350         private bool SetOnlineStatus(int status, object message, bool skipMessage)
351         {
352             if (!this.CanChat)
353             {
354                 // TODO: log error
355                 return false;
356             }
357
358             Dictionary parameters = new Dictionary
359                 {
360                     { ChatParameterCode.Status, status },
361                 };
362
363             if (skipMessage)
364             {
365                 parameters[ChatParameterCode.SkipMessage] = true;
366             }
367             else
368             {
369                 parameters[ChatParameterCode.Message] = message;
370             }
371             return this.chatPeer.OpCustom(ChatOperationCode.UpdateStatus, parameters, true);
372         }
File name: AnimationBuilder.cs Copy
222         private void SetGameObjectForRef(GameObject root, Ref childRef, float time)
223         {
224             TimelineKey key = childRef.Referenced;
225             if (time < 0) time = key.Time;
226
227             TimelineKey lastKey;
228             lastKeyframeCache.TryGetValue(key.Timeline, out lastKey);
229
230             //Get the relative path based on the current hierarchy
231             var relativePath = childRef.RelativePath;
232
233             //If this is the root, skip it
234             if (string.IsNullOrEmpty(relativePath))
235             {
236                 Debug.Log("Skipping root node in SetGameObjectForRef (SHOULD NEVER HAPPEN)");
237                 return;
238             }
239
240
241             //Find the gameObject based on relative path
242             var transform = root.transform.Find(relativePath);
243             if (transform == null)
244             {
245                 Debug.LogError("ERROR: Unable to find GameObject at relative path " + relativePath);
246                 return;
247             }
248
249             var gameObject = transform.gameObject;
250             gameObject.SetActive(true);
251
252             //Get transform data from ref
253             Vector3 localPosition;
254             Vector3 localScale;
255             Vector3 localEulerAngles;
256
257             childRef.BakeTransforms(out localPosition, out localEulerAngles, out localScale);
258
259             //Set the current GameObject's transform data
260             transform.localPosition = localPosition;
261             transform.localScale = localScale;
262
263             //Spin the object in the correct direction
264             var oldEulerAngles = transform.localEulerAngles;
265
266             if (oldEulerAngles.z - localEulerAngles.z > 180) localEulerAngles.z += 360;
267             else if (localEulerAngles.z - oldEulerAngles.z > 180) localEulerAngles.z -= 360;
268             /*
269             switch(childRef.Unmapped.Spin)
270             {
271                 case SpinDirection.Clockwise:
272                     while (oldEulerAngles.z > localEulerAngles.z) localEulerAngles.z += 360;
273                     break;
274                 case SpinDirection.CounterClockwise:
275                     while (oldEulerAngles.z < localEulerAngles.z) localEulerAngles.z -= 360;
276                     break;
277             }*/
278             transform.localEulerAngles = localEulerAngles;
279
280             int zIndex = -1;
281             var spriteKey = key as SpriteTimelineKey;
282             if (spriteKey != null)
283             {
284                 zIndex = ((ObjectRef)childRef).ZIndex;
285                 //transform.GetComponent().sortingOrder = zIndex;
286             }
287
288             acb.SetCurve(root.transform, transform, time, lastKey, zIndex);
289
290
291             //Get last-used game object for this Timeline - needed to clean up reparenting
292             GameObject lastGameObject;
293             if (lastGameObjectCache.TryGetValue(key.Timeline, out lastGameObject) && gameObject != lastGameObject)
294             {
295                 //Let Unity handle the global->local position cruft for us
296                 lastGameObject.transform.position = transform.position;
297                 lastGameObject.transform.eulerAngles = transform.eulerAngles;
298
299                 //TODO: Also need to do something about scale - this is a little more tricky
300                 lastGameObject.transform.localScale = localScale;
301
302                 //Deactivate the old object
303                 lastGameObject.SetActive(false);
304
305                 acb.SetCurve(root.transform, lastGameObject.transform, time, lastKey);
306             }
307
308             //Set cached value for last keyframe
309             lastKeyframeCache[key.Timeline] = key;
310         }
File name: Enemy.cs Copy
39   protected override void AttemptMove (int xDir, int yDir)
40   {
41    //Check if skipMove is true, if so set it to false and skip this turn.
42    if(skipMove)
43    {
44     skipMove = false;
45     return;
46
47    }
48
49    //Call the AttemptMove function from MovingObject.
50    base.AttemptMove (xDir, yDir);
51
52    //Now that Enemy has moved, set skipMove to true to skip next move.
53    skipMove = true;
54   }

Download file with original file name:Skip

Skip 143 lượt xem

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