My
How do I use My
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 = "
41 demoBtn = new DemoBtn() { Text = "Start", Link = "DemoBoxes-Scene" };
42 }
43 if (GUILayout.Button("Demo Worker", GUILayout.Width(280)))
44 {
45 demoDescription = "
46 demoBtn = new DemoBtn() { Text = "Start", Link = "DemoWorker-Scene" };
47 }
48 if (GUILayout.Button("Movement Smoothing", GUILayout.Width(280)))
49 {
50 demoDescription = "
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 = "
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 = "
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 = "
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 = "
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 = "
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 = "
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 = "
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 = "
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: PickupCamera.cs
Copy
94 void Apply( Transform dummyTarget, Vector3 dummyCenter )
95 {
96 // Early out if we don't have a target
97 if( !controller )
98 return;
99
100 Vector3 targetCenter = _target.position + centerOffset;
101 Vector3 targetHead = _target.position + headOffset;
102
103 // DebugDrawStuff();
104
105 // Calculate the current & target rotation angles
106 float originalTargetAngle = _target.eulerAngles.y;
107 float currentAngle = cameraTransform.eulerAngles.y;
108
109 // Adjust real target angle when camera is locked
110 float targetAngle = originalTargetAngle;
111
112 // When pressing Fire2 (alt) the camera will snap to the target direction real quick.
113 // It will stop snapping when it reaches the target
114 if( Input.GetButton( "Fire2" ) )
115 snap = true;
116
117 if( snap )
118 {
119 // We are close to the target, so we can stop snapping now!
120 if( AngleDistance( currentAngle, originalTargetAngle ) < 3.0f )
121 snap = false;
122
123 currentAngle = Mathf.SmoothDampAngle( currentAngle, targetAngle, ref angleVelocity, snapSmoothLag, snapMaxSpeed );
124 }
125 // Normal camera motion
126 else
127 {
128 if( controller.GetLockCameraTimer() < lockCameraTimeout )
129 {
130 targetAngle = currentAngle;
131 }
132
133 // Lock the camera when moving backwards!
134 // * It is really confusing to do 180 degree spins when turning around.
135 if( AngleDistance( currentAngle, targetAngle ) > 160 && controller.IsMovingBackwards() )
136 targetAngle += 180;
137
138 currentAngle = Mathf.SmoothDampAngle( currentAngle, targetAngle, ref angleVelocity, angularSmoothLag, angularMaxSpeed );
139 }
140
141
142 // When jumping don't move camera upwards but only down!
143 if( controller.IsJumping() )
144 {
145 // We'd be moving the camera upwards, do that only if it's really high
146 float newTargetHeight = targetCenter.y + height;
147 if( newTargetHeight < targetHeight || newTargetHeight - targetHeight > 5 )
148 targetHeight = targetCenter.y + height;
149 }
150 // When walking always update the target height
151 else
152 {
153 targetHeight = targetCenter.y + height;
154 }
155
156 // Damp the height
157 float currentHeight = cameraTransform.position.y;
158 currentHeight = Mathf.SmoothDamp( currentHeight, targetHeight, ref heightVelocity, heightSmoothLag );
159
160 // Convert the angle into a rotation, by which we then reposition the camera
161 Quaternion currentRotation = Quaternion.Euler( 0, currentAngle, 0 );
162
163 // Set the position of the camera on the x-z plane to:
164 // distance meters behind the target
165 cameraTransform.position = targetCenter;
166 cameraTransform.position += currentRotation * Vector3.back * distance;
167
168 // Set the height of the camera
169 cameraTransform.position = new Vector3( cameraTransform.position.x, currentHeight, cameraTransform.position.z );
170
171 // Always look at the target
172 SetUpRotation( targetCenter, targetHead );
173 }
File name: PickupCamera.cs
Copy
180 void Cut( Transform dummyTarget, Vector3 dummyCenter )
181 {
182 float oldHeightSmooth = heightSmoothLag;
183 float oldSnapMaxSpeed = snapMaxSpeed;
184 float oldSnapSmooth = snapSmoothLag;
185
186 snapMaxSpeed = 10000;
187 snapSmoothLag = 0.001f;
188 heightSmoothLag = 0.001f;
189
190 snap = true;
191 Apply( transform, Vector3.zero );
192
193 heightSmoothLag = oldHeightSmooth;
194 snapMaxSpeed = oldSnapMaxSpeed;
195 snapSmoothLag = oldSnapSmooth;
196 }
File name: ThirdPersonCamera.cs
Copy
86 void Apply( Transform dummyTarget, Vector3 dummyCenter )
87 {
88 // Early out if we don't have a target
89 if( !controller )
90 return;
91
92 Vector3 targetCenter = _target.position + centerOffset;
93 Vector3 targetHead = _target.position + headOffset;
94
95 // DebugDrawStuff();
96
97 // Calculate the current & target rotation angles
98 float originalTargetAngle = _target.eulerAngles.y;
99 float currentAngle = cameraTransform.eulerAngles.y;
100
101 // Adjust real target angle when camera is locked
102 float targetAngle = originalTargetAngle;
103
104 // When pressing Fire2 (alt) the camera will snap to the target direction real quick.
105 // It will stop snapping when it reaches the target
106 if( Input.GetButton( "Fire2" ) )
107 snap = true;
108
109 if( snap )
110 {
111 // We are close to the target, so we can stop snapping now!
112 if( AngleDistance( currentAngle, originalTargetAngle ) < 3.0f )
113 snap = false;
114
115 currentAngle = Mathf.SmoothDampAngle( currentAngle, targetAngle, ref angleVelocity, snapSmoothLag, snapMaxSpeed );
116 }
117 // Normal camera motion
118 else
119 {
120 if( controller.GetLockCameraTimer() < lockCameraTimeout )
121 {
122 targetAngle = currentAngle;
123 }
124
125 // Lock the camera when moving backwards!
126 // * It is really confusing to do 180 degree spins when turning around.
127 if( AngleDistance( currentAngle, targetAngle ) > 160 && controller.IsMovingBackwards() )
128 targetAngle += 180;
129
130 currentAngle = Mathf.SmoothDampAngle( currentAngle, targetAngle, ref angleVelocity, angularSmoothLag, angularMaxSpeed );
131 }
132
133
134 // When jumping don't move camera upwards but only down!
135 if( controller.IsJumping() )
136 {
137 // We'd be moving the camera upwards, do that only if it's really high
138 float newTargetHeight = targetCenter.y + height;
139 if( newTargetHeight < targetHeight || newTargetHeight - targetHeight > 5 )
140 targetHeight = targetCenter.y + height;
141 }
142 // When walking always update the target height
143 else
144 {
145 targetHeight = targetCenter.y + height;
146 }
147
148 // Damp the height
149 float currentHeight = cameraTransform.position.y;
150 currentHeight = Mathf.SmoothDamp( currentHeight, targetHeight, ref heightVelocity, heightSmoothLag );
151
152 // Convert the angle into a rotation, by which we then reposition the camera
153 Quaternion currentRotation = Quaternion.Euler( 0, currentAngle, 0 );
154
155 // Set the position of the camera on the x-z plane to:
156 // distance meters behind the target
157 cameraTransform.position = targetCenter;
158 cameraTransform.position += currentRotation * Vector3.back * distance;
159
160 // Set the height of the camera
161 cameraTransform.position = new Vector3( cameraTransform.position.x, currentHeight, cameraTransform.position.z );
162
163 // Always look at the target
164 SetUpRotation( targetCenter, targetHead );
165 }
File name: ThirdPersonCamera.cs
Copy
172 void Cut( Transform dummyTarget, Vector3 dummyCenter )
173 {
174 float oldHeightSmooth = heightSmoothLag;
175 float oldSnapMaxSpeed = snapMaxSpeed;
176 float oldSnapSmooth = snapSmoothLag;
177
178 snapMaxSpeed = 10000;
179 snapSmoothLag = 0.001f;
180 heightSmoothLag = 0.001f;
181
182 snap = true;
183 Apply( transform, Vector3.zero );
184
185 heightSmoothLag = oldHeightSmooth;
186 snapMaxSpeed = oldSnapMaxSpeed;
187 snapSmoothLag = oldSnapSmooth;
188 }
File name: NetworkCharacter.cs
Copy
17 void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
18 {
19 if (stream.isWriting)
20 {
21 // We own this player: send the others our data
22 stream.SendNext(transform.position);
23 stream.SendNext(transform.rotation);
24
25 myThirdPersonController myC = GetComponent
26 stream.SendNext((int)myC._characterState);
27 }
28 else
29 {
30 // Network player, receive data
31 this.correctPlayerPos = (Vector3)stream.ReceiveNext();
32 this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
33
34 myThirdPersonController myC = GetComponent
35 myC._characterState = (CharacterState)stream.ReceiveNext();
36 }
37 }
File name: RandomMatchmaker.cs
Copy
24 void OnJoinedRoom()
25 {
26 GameObject monster = PhotonNetwork.Instantiate("monsterprefab", Vector3.zero, Quaternion.identity, 0);
27 monster.GetComponent
28 myPhotonView = monster.GetComponent
29 }
File name: RandomMatchmaker.cs
Copy
31 void OnGUI()
32 {
33 GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
34
35 if (PhotonNetwork.connectionStateDetailed == PeerState.Joined)
36 {
37 bool shoutMarco = GameLogic.playerWhoIsIt == PhotonNetwork.player.ID;
38
39 if (shoutMarco && GUILayout.Button("Marco!"))
40 {
41 myPhotonView.RPC("Marco", PhotonTargets.All);
42 }
43 if (!shoutMarco && GUILayout.Button("Polo!"))
44 {
45 myPhotonView.RPC("Polo", PhotonTargets.All);
46 }
47 }
48 }
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
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 }
Download file with original file name:My
My 107 lượt xem
Gõ tìm kiếm nhanh...