Advanced









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

Featured Snippets


File name: HubGui.cs Copy
28     void OnGUI()
29     {
30         GUI.skin = this.Skin;
31         GUILayout.Space(10);
32
33         GUILayout.BeginHorizontal();
34         GUILayout.Space(10);
35         scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Width(320));
36
37         GUILayout.Label("Basics", m_Headline);
38         if (GUILayout.Button("Demo Boxes", GUILayout.Width(280)))
39         {
40             demoDescription = "Demo Boxes\n\nUses ConnectAndJoinRandom script.\n(joins a random room or creates one)\n\nInstantiates simple prefab.\nSynchronizes positions without smoothing.";
41             demoBtn = new DemoBtn() { Text = "Start", Link = "DemoBoxes-Scene" };
42         }
43         if (GUILayout.Button("Demo Worker", GUILayout.Width(280)))
44         {
45             demoDescription = "Demo Worker\n\nJoins the default lobby and shows existing rooms.\nLets you create or join a room.\nInstantiates an animated character.\nSynchronizes position and animation state of character with smoothing.\nImplements simple in-room Chat via RPC calls.";
46             demoBtn = new DemoBtn() { Text = "Start", Link = "DemoWorker-Scene" };
47         }
48         if (GUILayout.Button("Movement Smoothing", GUILayout.Width(280)))
49         {
50             demoDescription = "Movement Smoothing\n\nUses ConnectAndJoinRandom script.\nShows several basic ways to update positions of remote objects.";
51             demoBtn = new DemoBtn() { Text = "Start", Link = "DemoSynchronization-Scene" };
52         }
53
54         GUILayout.Label("Advanced", m_Headline);
55         if (GUILayout.Button("Ownership Transfer", GUILayout.Width(280)))
56         {
57             demoDescription = "Ownership Transfer\n\nShows how to transfer the ownership of a PhotonView.\nThe owner will send position updates of the GameObject.\nTransfer can be edited per PhotonView and set to Fixed (no transfer), Request (owner has to agree) or Takeover (owner can't object).";
58             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoChangeOwner-Scene" };
59             this.webLink = new DemoBtn();
60         }
61         if (GUILayout.Button("Pickup, Teams, Scores", GUILayout.Width(280)))
62         {
63             demoDescription = "Pickup, Teams, Scores\n\nUses ConnectAndJoinRandom script.\nImplements item pickup with RPCs.\nUses Custom Properties for Teams.\nCounts score per player and team.\nUses PhotonPlayer extension methods for easy Custom Property access.";
64             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoPickup-Scene" };
65             this.webLink = new DemoBtn();
66         }
67
68         GUILayout.Label("Feature Demos", m_Headline);
69         if (GUILayout.Button("Chat", GUILayout.Width(280)))
70         {
71             demoDescription = "Chat\n\nUses the Chat API (now part of PUN).\nSimple UI.\nYou can enter any User ID.\nAutomatically subscribes some channels.\nAllows simple commands via text.\n\nRequires configuration of Chat App ID in scene.";
72             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoChat-Scene" };
73             this.webLink = new DemoBtn();
74         }
75         if (GUILayout.Button("RPG Movement", GUILayout.Width(280)))
76         {
77             demoDescription = "RPG Movement\n\nDemonstrates how to use the PhotonTransformView component to synchronize position updates smoothly using inter- and extrapolation.\n\nThis demo also shows how to setup a Mecanim Animator to update animations automatically based on received position updates (without sending explicit animation updates).";
78             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoRPGMovement-Scene" };
79             this.webLink = new DemoBtn();
80         }
81         if (GUILayout.Button("Mecanim Animations", GUILayout.Width(280)))
82         {
83             demoDescription = "Mecanim Animations\n\nThis demo shows how to use the PhotonAnimatorView component to easily synchronize Mecanim animations.\n\nIt also demonstrates another feature of the PhotonTransformView component which gives you more control how position updates are inter-/extrapolated by telling the component how fast the object moves and turns using SetSynchronizedValues().";
84             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoMecanim-Scene" };
85             this.webLink = new DemoBtn();
86         }
87         if (GUILayout.Button("2D Game", GUILayout.Width(280)))
88         {
89             demoDescription = "2D Game Demo\n\nSynchronizes animations, positions and physics in a 2D scene.";
90             this.demoBtn = new DemoBtn() { Text = "Start", Link = "Demo2DJumpAndRunWithPhysics-Scene" };
91             this.webLink = new DemoBtn();
92         }
93         if (GUILayout.Button("Friends & Authentication", GUILayout.Width(280)))
94         {
95             demoDescription = "Friends & Authentication\n\nShows connect with or without (server-side) authentication.\n\nAuthentication requires minor server-side setup (in Dashboard).\n\nOnce connected, you can find (made up) friends.\nJoin a room just to see how that gets visible in friends list.";
96             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoFriends-Scene" };
97             this.webLink = new DemoBtn();
98         }
99
100         GUILayout.Label("Tutorial", m_Headline);
101         if (GUILayout.Button("Marco Polo Tutorial", GUILayout.Width(280)))
102         {
103             demoDescription = "Marco Polo Tutorial\n\nFinal result you could get when you do the Marco Polo Tutorial.\nSlightly modified to be more compatible with this package.";
104             this.demoBtn = new DemoBtn() { Text = "Start", Link = "MarcoPolo-Scene" };
105             this.webLink = new DemoBtn() { Text = "Open Tutorial (www)", Link = "http://tinyurl.com/nmylf44" };
106         }
107         GUILayout.EndScrollView();
108
109         GUILayout.BeginVertical(GUILayout.Width(Screen.width - 345));
110         GUILayout.Label(demoDescription);
111         GUILayout.Space(10);
112         if (!string.IsNullOrEmpty(this.demoBtn.Text))
113         {
114             if (GUILayout.Button(this.demoBtn.Text))
115             {
116                 Application.LoadLevel(this.demoBtn.Link);
117             }
118         }
119         if (!string.IsNullOrEmpty(this.webLink.Text))
120         {
121             if (GUILayout.Button(this.webLink.Text))
122             {
123                 Application.OpenURL(this.webLink.Link);
124             }
125         }
126         GUILayout.EndVertical();
127
128
129         GUILayout.EndHorizontal();
130     }
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     }

Download file with original file name:Advanced

Advanced 132 lượt xem

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