Off
How do I use Off
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
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: HubGui.cs
Copy
22 void Start()
23 {
24 m_Headline = new GUIStyle(this.Skin.label);
25 m_Headline.padding = new RectOffset(3, 0, 0, 0);
26 }
File name: PickupCamera.cs
Copy
41 void OnEnable()
42 {
43 if( this.photonView != null && !this.photonView.isMine )
44 {
45 this.enabled = false;
46 return;
47 }
48
49 if( !cameraTransform && Camera.main )
50 cameraTransform = Camera.main.transform;
51 if( !cameraTransform )
52 {
53 Debug.Log( "Please assign a camera to the ThirdPersonCamera script." );
54 enabled = false;
55 }
56
57 m_CameraTransformCamera = cameraTransform.GetComponent
58
59
60 _target = transform;
61 if( _target )
62 {
63 controller = _target.GetComponent
64 }
65
66 if( controller )
67 {
68 CharacterController characterController = (CharacterController)_target.GetComponent
69 centerOffset = characterController.bounds.center - _target.position;
70 headOffset = centerOffset;
71 headOffset.y = characterController.bounds.max.y - _target.position.y;
72 }
73 else
74 Debug.Log( "Please assign a target to the camera that has a ThirdPersonController script attached." );
75
76
77 Cut( _target, centerOffset );
78 }
File name: PickupCamera.cs
Copy
80 void DebugDrawStuff()
81 {
82 Debug.DrawLine( _target.position, _target.position + headOffset );
83
84 }
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
198 void SetUpRotation( Vector3 centerPos, Vector3 headPos )
199 {
200 // Now it's getting hairy. The devil is in the details here, the big issue is jumping of course.
201 // * When jumping up and down we don't want to center the guy in screen space.
202 // This is important to give a feel for how high you jump and avoiding large camera movements.
203 //
204 // * At the same time we dont want him to ever go out of screen and we want all rotations to be totally smooth.
205 //
206 // So here is what we will do:
207 //
208 // 1. We first find the rotation around the y axis. Thus he is always centered on the y-axis
209 // 2. When grounded we make him be centered
210 // 3. When jumping we keep the camera rotation but rotate the camera to get him back into view if his head is above some threshold
211 // 4. When landing we smoothly interpolate towards centering him on screen
212 Vector3 cameraPos = cameraTransform.position;
213 Vector3 offsetToCenter = centerPos - cameraPos;
214
215 // Generate base rotation only around y-axis
216 Quaternion yRotation = Quaternion.LookRotation( new Vector3( offsetToCenter.x, 0, offsetToCenter.z ) );
217
218 Vector3 relativeOffset = Vector3.forward * distance + Vector3.down * height;
219 cameraTransform.rotation = yRotation * Quaternion.LookRotation( relativeOffset );
220
221 // Calculate the projected center position and top position in world space
222 Ray centerRay = m_CameraTransformCamera.ViewportPointToRay( new Vector3( 0.5f, 0.5f, 1 ) );
223 Ray topRay = m_CameraTransformCamera.ViewportPointToRay( new Vector3( 0.5f, clampHeadPositionScreenSpace, 1 ) );
224
225 Vector3 centerRayPos = centerRay.GetPoint( distance );
226 Vector3 topRayPos = topRay.GetPoint( distance );
227
228 float centerToTopAngle = Vector3.Angle( centerRay.direction, topRay.direction );
229
230 float heightToAngle = centerToTopAngle / ( centerRayPos.y - topRayPos.y );
231
232 float extraLookAngle = heightToAngle * ( centerRayPos.y - centerPos.y );
233 if( extraLookAngle < centerToTopAngle )
234 {
235 extraLookAngle = 0;
236 }
237 else
238 {
239 extraLookAngle = extraLookAngle - centerToTopAngle;
240 cameraTransform.rotation *= Quaternion.Euler( -extraLookAngle, 0, 0 );
241 }
242 }
File name: PickupController.cs
Copy
73 // Are we jumping? (Initiated with jump button and not grounded yet)
77 // Are we moving backwards (This locks the camera to not do a 180 degree spin)
81 // When did the user start walking (Used for going into trot after a while)
87 // the height we jumped from (Used to determine for how long to apply extra jump power after jumping.)
101 void Awake()
102 {
103 // PUN: automatically determine isControllable, if this GO has a PhotonView
104 PhotonView pv = this.gameObject.GetComponent
105 if (pv != null)
106 {
107 isControllable = pv.isMine;
108
109 // The pickup demo assigns this GameObject as the PhotonPlayer.TagObject. This way, we can access this character (controller, position, etc) easily
110 if (this.AssignAsTagObject)
111 {
112 pv.owner.TagObject = this.gameObject;
113 }
114
115 // please note: we change this setting on ANY PickupController if "DoRotate" is off. not only locally when it's "our" GameObject!
116 if (pv.observed is Transform && !DoRotate)
117 {
118 pv.onSerializeTransformOption = OnSerializeTransform.OnlyPosition;
119 }
120 }
121
122
123 moveDirection = transform.TransformDirection(Vector3.forward);
124
125 _animation = GetComponent
126 if (!_animation)
127 Debug.Log("The character you would like to control doesn't have animations. Moving her might look weird.");
128
129 if (!idleAnimation)
130 {
131 _animation = null;
132 Debug.Log("No idle animation found. Turning off animations.");
133 }
134 if (!walkAnimation)
135 {
136 _animation = null;
137 Debug.Log("No walk animation found. Turning off animations.");
138 }
139 if (!runAnimation)
140 {
141 _animation = null;
142 Debug.Log("No run animation found. Turning off animations.");
143 }
144 if (!jumpPoseAnimation && canJump)
145 {
146 _animation = null;
147 Debug.Log("No jump animation found and the character has canJump enabled. Turning off animations.");
148 }
149 }
File name: PickupDemoGui.cs
Copy
15 public void OnGUI()
16 {
17 if (!PhotonNetwork.inRoom)
18 {
19 return;
20 }
21
22
23 if (this.ShowScores)
24 {
25 GUILayout.Label("Your Score: " + PhotonNetwork.player.GetScore());
26 }
27
28
29 if (this.ShowDropButton)
30 {
31 foreach (PickupItem item in PickupItem.DisabledPickupItems)
32 {
33 if (item.PickupIsMine && item.SecondsBeforeRespawn <= 0)
34 {
35 if (GUILayout.Button("Drop " + item.name))
36 {
37 item.Drop(); // drops the item at the place where it originates
38 }
39
40 GameObject playerCharGo = PhotonNetwork.player.TagObject as GameObject;
41 if (playerCharGo != null && GUILayout.Button("Drop here " + item.name))
42 {
43 // drop the item at some other place. next to the user's character would be fine...
44 Vector3 random = Random.insideUnitSphere;
45 random.y = 0;
46 random = random.normalized;
47 Vector3 itempos = playerCharGo.transform.position + this.DropOffset * random;
48
49 item.Drop(itempos);
50 }
51 }
52 }
53 }
54
55
56 if (this.ShowTeams)
57 {
58 foreach (var teamName in PunTeams.PlayersPerTeam.Keys)
59 {
60 GUILayout.Label("Team: " + teamName.ToString());
61 List
62 foreach (PhotonPlayer player in teamPlayers)
63 {
64 GUILayout.Label(" " + player.ToStringFull() + " Score: " + player.GetScore());
65 }
66 }
67
68 if (GUILayout.Button("to red"))
69 {
70 PhotonNetwork.player.SetTeam(PunTeams.Team.red);
71 }
72 if (GUILayout.Button("to blue"))
73 {
74 PhotonNetwork.player.SetTeam(PunTeams.Team.blue);
75 }
76 }
77 }
File name: ThirdPersonCamera.cs
Copy
40 void OnEnable()
41 {
42 if( !cameraTransform && Camera.main )
43 cameraTransform = Camera.main.transform;
44 if( !cameraTransform )
45 {
46 Debug.Log( "Please assign a camera to the ThirdPersonCamera script." );
47 enabled = false;
48 }
49
50 m_CameraTransformCamera = cameraTransform.GetComponent
51
52 _target = transform;
53 if( _target )
54 {
55 controller = _target.GetComponent
56 }
57
58 if( controller )
59 {
60 CharacterController characterController = (CharacterController)_target.GetComponent
61 centerOffset = characterController.bounds.center - _target.position;
62 headOffset = centerOffset;
63 headOffset.y = characterController.bounds.max.y - _target.position.y;
64 }
65 else
66 Debug.Log( "Please assign a target to the camera that has a ThirdPersonController script attached." );
67
68
69 Cut( _target, centerOffset );
70 }
Download file with original file name:Off
Off 107 lượt xem
Gõ tìm kiếm nhanh...