Tap









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

Featured Snippets


File name: ChatGui.cs Copy
58     public void Start()
59     {
60         DontDestroyOnLoad(this.gameObject);
61         Application.runInBackground = true; // this must run in background or it will drop connection if not focussed.
62
63         if (string.IsNullOrEmpty(this.UserName))
64         {
65             this.UserName = "user" + Environment.TickCount%99; //made-up username
66         }
67
68         chatClient = new ChatClient(this);
69         chatClient.Connect(ChatAppId, "1.0", this.UserName, null);
70
71         if (this.AlignBottom)
72         {
73             this.GuiRect.y = Screen.height - this.GuiRect.height;
74         }
75         if (this.FullScreen)
76         {
77             this.GuiRect.x = 0;
78             this.GuiRect.y = 0;
79             this.GuiRect.width = Screen.width;
80             this.GuiRect.height = Screen.height;
81         }
82
83         Debug.Log(this.UserName);
84     }
File name: NamePickGui.cs Copy
38     public void OnGUI()
39     {
40         // Enter-Key handling:
41         if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return))
42         {
43             if (!string.IsNullOrEmpty(this.InputLine))
44             {
45                 this.StartChat();
46                 return;
47             }
48         }
49
50
51         GUI.skin.label.wordWrap = true;
52         GUILayout.BeginArea(guiCenteredRect);
53
54
55         if (this.chatComponent != null && string.IsNullOrEmpty(this.chatComponent.ChatAppId))
56         {
57             GUILayout.Label("To continue, configure your Chat AppId.\nIt's listed in the Chat Dashboard (online).\nStop play-mode and edit:\nScripts/ChatGUI in the Hierarchy.");
58             if (GUILayout.Button("Open Chat Dashboard"))
59             {
60                 Application.OpenURL("https://www.exitgames.com/en/Chat/Dashboard");
61             }
62             GUILayout.EndArea();
63             return;
64         }
65
66         GUILayout.Label(this.helpText);
67
68         GUILayout.BeginHorizontal();
69         GUI.SetNextControlName("NameInput");
70         this.InputLine = GUILayout.TextField(this.InputLine);
71         if (GUILayout.Button("Connect", GUILayout.ExpandWidth(false)))
72         {
73             this.StartChat();
74         }
75         GUILayout.EndHorizontal();
76
77         GUILayout.EndArea();
78
79
80         GUI.FocusControl("NameInput");
81     }
File name: PunStartup.cs Copy
80     public static void SetPunDemoBuildSettings()
81     {
82         // find path of pun guide
83         string[] tempPaths = Directory.GetDirectories(Application.dataPath + "/Photon Unity Networking", "Demos", SearchOption.AllDirectories);
84         if (tempPaths == null || tempPaths.Length != 1)
85         {
86             return;
87         }
88
89         // find scenes of guide
90         string guidePath = tempPaths[0];
91         tempPaths = Directory.GetFiles(guidePath, "*.unity", SearchOption.AllDirectories);
92
93         if (tempPaths == null || tempPaths.Length == 0)
94         {
95             return;
96         }
97
98         // add found guide scenes to build settings
99         List sceneAr = new List();
100         for (int i = 0; i < tempPaths.Length; i++)
101         {
102             //Debug.Log(tempPaths[i]);
103             string path = tempPaths[i].Substring(Application.dataPath.Length - "Assets".Length);
104             path = path.Replace('\\', '/');
105             //Debug.Log(path);
106
107             if (path.Contains("PUNGuide_M2H"))
108             {
109                 continue;
110             }
111
112             if (path.Contains("Hub"))
113             {
114                 sceneAr.Insert(0, new EditorBuildSettingsScene(path, true));
115                 continue;
116             }
117
118             sceneAr.Add(new EditorBuildSettingsScene(path, true));
119         }
120
121         EditorBuildSettings.scenes = sceneAr.ToArray();
122         EditorApplication.OpenScene(sceneAr[0].path);
123     }
File name: PhotonEditor.cs Copy
420     protected virtual void OnGuiRegisterCloudApp()
421     {
422         GUI.skin.label.wordWrap = true;
423         if (!this.isSetupWizard)
424         {
425             GUILayout.BeginHorizontal();
426             GUILayout.FlexibleSpace();
427             if (GUILayout.Button(CurrentLang.MainMenuButton, GUILayout.ExpandWidth(false)))
428             {
429                 this.SwitchMenuState(GUIState.Main);
430             }
431
432             GUILayout.EndHorizontal();
433
434             GUILayout.Space(15);
435         }
436
437         if (this.photonSetupState == PhotonSetupStates.RegisterForPhotonCloud)
438         {
439             GUI.skin.label.fontStyle = FontStyle.Bold;
440             GUILayout.Label(CurrentLang.ConnectButton);
441             EditorGUILayout.Separator();
442             GUI.skin.label.fontStyle = FontStyle.Normal;
443
444             GUILayout.Label(CurrentLang.UsePhotonLabel);
445             EditorGUILayout.Separator();
446             this.emailAddress = EditorGUILayout.TextField(CurrentLang.EmailLabel, this.emailAddress);
447
448             if (GUILayout.Button(CurrentLang.SendButton))
449             {
450                 GUIUtility.keyboardControl = 0;
451                 this.RegisterWithEmail(this.emailAddress);
452             }
453
454             GUILayout.Space(20);
455
456
457             GUILayout.Label(CurrentLang.SignedUpAlreadyLabel);
458             if (GUILayout.Button(CurrentLang.SetupButton))
459             {
460                 this.photonSetupState = PhotonSetupStates.SetupPhotonCloud;
461             }
462             EditorGUILayout.Separator();
463
464
465             GUILayout.Label(CurrentLang.RegisterByWebsiteLabel);
466             if (GUILayout.Button(CurrentLang.AccountWebsiteButton))
467             {
468                 EditorUtility.OpenWithDefaultApp(UrlAccountPage + Uri.EscapeUriString(this.emailAddress));
469             }
470
471             EditorGUILayout.Separator();
472
473             GUILayout.Label(CurrentLang.SelfHostLabel);
474
475             if (GUILayout.Button(CurrentLang.SelfHostSettingsButton))
476             {
477                 this.photonSetupState = PhotonSetupStates.SetupSelfHosted;
478             }
479
480             GUILayout.FlexibleSpace();
481
482
483             if (!InternalEditorUtility.HasAdvancedLicenseOnBuildTarget(BuildTarget.Android) || !InternalEditorUtility.HasAdvancedLicenseOnBuildTarget(BuildTarget.iOS))
484             {
485                 GUILayout.Label(CurrentLang.MobileExportNoteLabel);
486             }
487             EditorGUILayout.Separator();
488         }
489         else if (this.photonSetupState == PhotonSetupStates.EmailAlreadyRegistered)
490         {
491             GUI.skin.label.fontStyle = FontStyle.Bold;
492             GUILayout.Label(CurrentLang.OopsLabel);
493             GUI.skin.label.fontStyle = FontStyle.Normal;
494
495             GUILayout.Label(CurrentLang.EmailInUseLabel);
496
497             if (GUILayout.Button(CurrentLang.SeeMyAccountPageButton))
498             {
499                 EditorUtility.OpenWithDefaultApp(UrlCloudDashboard + Uri.EscapeUriString(this.emailAddress));
500             }
501
502             EditorGUILayout.Separator();
503
504             GUILayout.Label(CurrentLang.KnownAppIdLabel);
505             GUILayout.BeginHorizontal();
506             if (GUILayout.Button(CurrentLang.CancelButton))
507             {
508                 this.photonSetupState = PhotonSetupStates.RegisterForPhotonCloud;
509             }
510
511             if (GUILayout.Button(CurrentLang.SetupButton))
512             {
513                 this.photonSetupState = PhotonSetupStates.SetupPhotonCloud;
514             }
515
516             GUILayout.EndHorizontal();
517         }
518         else if (this.photonSetupState == PhotonSetupStates.SetupPhotonCloud)
519         {
520             // cloud setup
521             GUI.skin.label.fontStyle = FontStyle.Bold;
522             GUILayout.Label(CurrentLang.PhotonCloudConnect);
523             GUI.skin.label.fontStyle = FontStyle.Normal;
524
525             EditorGUILayout.Separator();
526             this.OnGuiSetupCloudAppId();
527             this.OnGuiCompareAndHelpOptions();
528         }
529         else if (this.photonSetupState == PhotonSetupStates.SetupSelfHosted)
530         {
531             // self-hosting setup
532             GUI.skin.label.fontStyle = FontStyle.Bold;
533             GUILayout.Label(CurrentLang.SetupOwnHostLabel);
534             GUI.skin.label.fontStyle = FontStyle.Normal;
535
536             EditorGUILayout.Separator();
537
538             this.OnGuiSetupSelfhosting();
539             this.OnGuiCompareAndHelpOptions();
540         }
541     }
File name: PhotonEditor.cs Copy
543     protected virtual void OnGuiMainWizard()
544     {
545         GUILayout.BeginHorizontal();
546         GUILayout.FlexibleSpace();
547         GUILayout.Label(WizardIcon);
548         GUILayout.FlexibleSpace();
549         GUILayout.EndHorizontal();
550
551         EditorGUILayout.Separator();
552
553         GUILayout.Label(CurrentLang.PUNWizardLabel, EditorStyles.boldLabel);
554         if (isPunPlus)
555         {
556             GUILayout.Label(CurrentLang.MobilePunPlusExportNoteLabel);
557         }
558         else if (!InternalEditorUtility.HasAdvancedLicenseOnBuildTarget(BuildTarget.Android) || !InternalEditorUtility.HasAdvancedLicenseOnBuildTarget(BuildTarget.iOS))
559         {
560             GUILayout.Label(CurrentLang.MobileExportNoteLabel);
561         }
562         EditorGUILayout.Separator();
563
564
565         // settings button
566         GUILayout.BeginHorizontal();
567         GUILayout.Label(CurrentLang.SettingsButton, EditorStyles.boldLabel, GUILayout.Width(100));
568         if (GUILayout.Button(new GUIContent(CurrentLang.SetupButton, CurrentLang.SetupServerCloudLabel)))
569         {
570             this.InitPhotonSetupWindow();
571         }
572
573         GUILayout.EndHorizontal();
574         EditorGUILayout.Separator();
575
576
577         // find / select settings asset
578         GUILayout.BeginHorizontal();
579         GUILayout.Label(CurrentLang.SettingsFileLabel, EditorStyles.boldLabel, GUILayout.Width(100));
580         if (GUILayout.Button(new GUIContent(CurrentLang.LocateSettingsButton, CurrentLang.SettingsHighlightLabel)))
581         {
582             EditorGUIUtility.PingObject(PhotonEditor.Current);
583         }
584
585         GUILayout.EndHorizontal();
586
587
588         GUILayout.FlexibleSpace();
589
590         // converter
591         GUILayout.BeginHorizontal();
592         GUILayout.Label(CurrentLang.ConverterLabel, EditorStyles.boldLabel, GUILayout.Width(100));
593         if (GUILayout.Button(new GUIContent(CurrentLang.StartButton, CurrentLang.UNtoPUNLabel)))
594         {
595             PhotonConverter.RunConversion();
596         }
597
598         GUILayout.EndHorizontal();
599         EditorGUILayout.Separator();
600
601
602         // documentation
603         GUILayout.BeginHorizontal();
604         GUILayout.Label(CurrentLang.DocumentationLabel, EditorStyles.boldLabel, GUILayout.Width(100));
605         GUILayout.BeginVertical();
606         if (GUILayout.Button(new GUIContent(CurrentLang.OpenPDFText, CurrentLang.OpenPDFTooltip)))
607         {
608             EditorUtility.OpenWithDefaultApp(DocumentationLocation);
609         }
610
611         if (GUILayout.Button(new GUIContent(CurrentLang.OpenDevNetText, CurrentLang.OpenDevNetTooltip)))
612         {
613             EditorUtility.OpenWithDefaultApp(UrlDevNet);
614         }
615
616         if (GUILayout.Button(new GUIContent(CurrentLang.OpenCloudDashboardText, CurrentLang.OpenCloudDashboardTooltip)))
617         {
618             EditorUtility.OpenWithDefaultApp(UrlCloudDashboard + Uri.EscapeUriString(this.emailAddress));
619         }
620
621         if (GUILayout.Button(new GUIContent(CurrentLang.OpenForumText, CurrentLang.OpenForumTooltip)))
622         {
623             EditorUtility.OpenWithDefaultApp(UrlForum);
624         }
625
626         GUILayout.EndVertical();
627         GUILayout.EndHorizontal();
628     }
File name: PhotonEditor.cs Copy
630     protected virtual void OnGuiCompareAndHelpOptions()
631     {
632         GUILayout.FlexibleSpace();
633
634         GUILayout.Label(CurrentLang.QuestionsLabel);
635         if (GUILayout.Button(CurrentLang.SeeForumButton))
636         {
637             Application.OpenURL(UrlForum);
638         }
639
640         if (photonSetupState != PhotonSetupStates.SetupSelfHosted)
641         {
642             if (GUILayout.Button(CurrentLang.OpenDashboardButton))
643             {
644                 EditorUtility.OpenWithDefaultApp(UrlCloudDashboard + Uri.EscapeUriString(this.emailAddress));
645             }
646         }
647     }
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: PunSceneSettings.cs Copy
23     {
24         get
25         {
26             if (!string.IsNullOrEmpty(punSceneSettingsCsPath))
27             {
28                 return punSceneSettingsCsPath;
29             }
30
31             // Unity 4.3.4 does not yet have AssetDatabase.FindAssets(). Would be easier.
32             var result = Directory.GetFiles(Application.dataPath, "PunSceneSettings.cs", SearchOption.AllDirectories);
33             if (result.Length >= 1)
34             {
35                 punSceneSettingsCsPath = Path.GetDirectoryName(result[0]);
36                 punSceneSettingsCsPath = punSceneSettingsCsPath.Replace('\\', '/');
37                 punSceneSettingsCsPath = punSceneSettingsCsPath.Replace(Application.dataPath, "Assets");
38
39                 // AssetDatabase paths have to use '/' and are relative to the project's folder. Always.
40                 punSceneSettingsCsPath = punSceneSettingsCsPath + "/" + SceneSettingsFileName;
41             }
42
43             return punSceneSettingsCsPath;
44         }
45     }
File name: NetworkingPeer.cs Copy
144     private readonly Dictionary dataPerGroupReliable = new Dictionary(); // only used in RunViewUpdate()
145     private readonly Dictionary dataPerGroupUnreliable = new Dictionary(); // only used in RunViewUpdate()
152     internal protected ServerConnection server { get; private set; }
File name: NetworkingPeer.cs Copy
3147     public void RunViewUpdate()
3148     {
3149         if (!PhotonNetwork.connected || PhotonNetwork.offlineMode)
3150         {
3151             return;
3152         }
3153
3154         if (this.mActors == null ||
3155#if !PHOTON_DEVELOP
3156             this.mActors.Count <= 1
3157#endif
3158             )
3159         {
3160             return; // No need to send OnSerialize messages (these are never buffered anyway)
3161         }
3162
3163         dataPerGroupReliable.Clear();
3164         dataPerGroupUnreliable.Clear();
3165
3166         /* Format of the data hashtable:
3167          * Hasthable dataPergroup*
3168          * [(byte)0] = this.ServerTimeInMilliSeconds;
3169          * OPTIONAL: [(byte)1] = currentLevelPrefix;
3170          * + data
3171          */
3172
3173         foreach (KeyValuePair kvp in this.photonViewList)
3174         {
3175             PhotonView view = kvp.Value;
3176
3177             if (view.synchronization != ViewSynchronization.Off)
3178             {
3179                 // Fetch all sending photonViews
3180                 if (view.isMine)
3181                 {
3182                     #if UNITY_2_6_1 || UNITY_2_6 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
3183                     if (!view.gameObject.active)
3184                     {
3185                         continue; // Only on actives
3186                     }
3187                     #else
3188                     if (!view.gameObject.activeInHierarchy)
3189                     {
3190                         continue; // Only on actives
3191                     }
3192                     #endif
3193
3194                     if (this.blockSendingGroups.Contains(view.group))
3195                     {
3196                         continue; // Block sending on this group
3197                     }
3198
3199                     // Run it trough its OnSerialize
3200                     Hashtable evData = this.OnSerializeWrite(view);
3201                     if (evData == null)
3202                     {
3203                         continue;
3204                     }
3205
3206                     if (view.synchronization == ViewSynchronization.ReliableDeltaCompressed || view.mixedModeIsReliable)
3207                     {
3208                         if (!evData.ContainsKey((byte)1) && !evData.ContainsKey((byte)2))
3209                         {
3210                             // Everything has been removed by compression, nothing to send
3211                         }
3212                         else
3213                         {
3214                             if (!dataPerGroupReliable.ContainsKey(view.group))
3215                             {
3216                                 dataPerGroupReliable[view.group] = new Hashtable();
3217                                 dataPerGroupReliable[view.group][(byte)0] = this.ServerTimeInMilliSeconds;
3218                                 if (currentLevelPrefix >= 0)
3219                                 {
3220                                     dataPerGroupReliable[view.group][(byte)1] = this.currentLevelPrefix;
3221                                 }
3222                             }
3223                             Hashtable groupHashtable = dataPerGroupReliable[view.group];
3224                             groupHashtable.Add((short)groupHashtable.Count, evData);
3225                         }
3226                     }
3227                     else
3228                     {
3229                         if (!dataPerGroupUnreliable.ContainsKey(view.group))
3230                         {
3231                             dataPerGroupUnreliable[view.group] = new Hashtable();
3232                             dataPerGroupUnreliable[view.group][(byte)0] = this.ServerTimeInMilliSeconds;
3233                             if (currentLevelPrefix >= 0)
3234                             {
3235                                 dataPerGroupUnreliable[view.group][(byte)1] = this.currentLevelPrefix;
3236                             }
3237                         }
3238                         Hashtable groupHashtable = dataPerGroupUnreliable[view.group];
3239                         groupHashtable.Add((short)groupHashtable.Count, evData);
3240                     }
3241                 }
3242                 else
3243                 {
3244                     // Debug.Log(" NO OBS on " + view.name + " " + view.owner);
3245                 }
3246             }
3247             else
3248             {
3249             }
3250         }
3251
3252         //Send the messages: every group is send in it's own message and unreliable and reliable are split as well
3253         RaiseEventOptions options = new RaiseEventOptions();
3254
3255#if PHOTON_DEVELOP
3256         options.Receivers = ReceiverGroup.All;
3257#endif
3258
3259         foreach (KeyValuePair kvp in dataPerGroupReliable)
3260         {
3261             options.InterestGroup = (byte)kvp.Key;
3262             this.OpRaiseEvent(PunEvent.SendSerializeReliable, kvp.Value, true, options);
3263         }
3264         foreach (KeyValuePair kvp in dataPerGroupUnreliable)
3265         {
3266             options.InterestGroup = (byte)kvp.Key;
3267             this.OpRaiseEvent(PunEvent.SendSerialize, kvp.Value, false, options);
3268         }
3269     }

Download file with original file name:Tap

Tap 118 lượt xem

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