Current









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

Featured Snippets


File name: FormBaoCao.cs Copy
40         private void btnLoc_Click(object sender, EventArgs e)
41         {
42             SqlConnection con = dal.GetConnect();
43             con.Open();
44             string sql = "select *from SinhVien where MaLop=@MaLop";
45             SqlDataAdapter da = new SqlDataAdapter(sql, con);
46             da.SelectCommand.Parameters.AddWithValue("@MaLop", cmbMaLop.SelectedValue.ToString());
47             DataTable dt = new DataTable();
48             da.Fill(dt);
49             crBaoCao cr = new crBaoCao();
50             ConnectionInfo crConnectionInfo = new ConnectionInfo();
51             crConnectionInfo.ServerName = "Ty-PC";
52             crConnectionInfo.DatabaseName = "CNPM_1";
53             crConnectionInfo.UserID = "sa";
54             crConnectionInfo.Password = "04091990";
55             TableLogOnInfos crTableLogonInfos = new TableLogOnInfos();
56             foreach (CrystalDecisions.CrystalReports.Engine.Table table in cr.Database.Tables)
57             {
58                 TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();
59                 crTableLogonInfo.TableName = table.Name;
60                 crTableLogonInfo.ConnectionInfo = crConnectionInfo;
61                 crTableLogonInfos.Add(crTableLogonInfo);
62                 table.ApplyLogOnInfo(crTableLogonInfo);
63
64             }
65             crvHocKyHocPhan.LogOnInfo = crTableLogonInfos;
66             cr.SetDataSource(dt);
67             ParameterValues a = new ParameterValues();
68             ParameterDiscreteValue b = new ParameterDiscreteValue();
69             b.Value = cmbMaLop.SelectedValue.ToString();
70             a.Add(b);
71             cr.DataDefinition.ParameterFields["txtMaLop"].ApplyCurrentValues(a);
72             crvHocKyHocPhan.ReportSource = cr;
73             crvHocKyHocPhan.Show();
74         }
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: ChatGui.cs Copy
215     private void GuiSendsMsg()
216     {
217         if (string.IsNullOrEmpty(this.inputLine))
218         {
219
220             GUI.FocusControl("");
221             return;
222         }
223
224         if (this.inputLine[0].Equals('\\'))
225         {
226             string[] tokens = this.inputLine.Split(new char[] {' '}, 2);
227             if (tokens[0].Equals("\\help"))
228             {
229                 this.PostHelpToCurrentChannel();
230             }
231             if (tokens[0].Equals("\\state"))
232             {
233                 int newState = int.Parse(tokens[1]);
234                 this.chatClient.SetOnlineStatus(newState, new string[] { "i am state " + newState }); // this is how you set your own state and (any) message
235             }
236             else if (tokens[0].Equals("\\subscribe") && !string.IsNullOrEmpty(tokens[1]))
237             {
238                 this.chatClient.Subscribe(tokens[1].Split(new char[] {' ', ','}));
239             }
240             else if (tokens[0].Equals("\\unsubscribe") && !string.IsNullOrEmpty(tokens[1]))
241             {
242                 this.chatClient.Unsubscribe(tokens[1].Split(new char[] {' ', ','}));
243             }
244             else if (tokens[0].Equals("\\clear"))
245             {
246                 if (this.doingPrivateChat)
247                 {
248                     this.chatClient.PrivateChannels.Remove(this.selectedChannelName);
249                 }
250                 else
251                 {
252                     ChatChannel channel;
253                     if (this.chatClient.TryGetChannel(this.selectedChannelName, this.doingPrivateChat, out channel))
254                     {
255                         channel.ClearMessages();
256                     }
257                 }
258             }
259             else if (tokens[0].Equals("\\msg") && !string.IsNullOrEmpty(tokens[1]))
260             {
261                 string[] subtokens = tokens[1].Split(new char[] {' ', ','}, 2);
262                 string targetUser = subtokens[0];
263                 string message = subtokens[1];
264                 this.chatClient.SendPrivateMessage(targetUser, message);
265             }
266         }
267         else
268         {
269             if (this.doingPrivateChat)
270             {
271                 this.chatClient.SendPrivateMessage(this.userIdInput, this.inputLine);
272             }
273             else
274             {
275                 this.chatClient.PublishMessage(this.selectedChannelName, this.inputLine);
276             }
277         }
278
279         this.inputLine = "";
280         GUI.FocusControl("");
281     }
File name: ChatGui.cs Copy
283     private void PostHelpToCurrentChannel()
284     {
285         ChatChannel channelForHelp = this.selectedChannel;
286         if (channelForHelp != null)
287         {
288             channelForHelp.Add("info", ChatGui.HelpText);
289         }
290         else
291         {
292             Debug.LogError("no channel for help");
293         }
294     }
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: GUICustomAuth.cs Copy
81     void OnGUI()
82     {
83         if (PhotonNetwork.connected)
84         {
85             GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
86             return;
87         }
88
89
90         GUILayout.BeginArea(GuiRect);
91         switch (guiState)
92         {
93             case GuiState.AuthFailed:
94                 GUILayout.Label("Authentication Failed");
95
96                 GUILayout.Space(10);
97
98                 GUILayout.Label("Error message:\n'" + this.authDebugMessage + "'");
99
100                 GUILayout.Space(10);
101
102                 GUILayout.Label("For this demo set the Authentication URL in the Dashboard to:\nhttp://photon.webscript.io/auth-demo-equals");
103                 GUILayout.Label("That authentication-service has no user-database. It confirms any user if 'name equals password'.");
104                 GUILayout.Label("The error message comes from that service and can be customized.");
105
106                 GUILayout.Space(10);
107
108                 GUILayout.BeginHorizontal();
109                 if (GUILayout.Button("Back"))
110                 {
111                     SetStateAuthInput();
112                 }
113                 if (GUILayout.Button("Help"))
114                 {
115                     SetStateAuthHelp();
116                 }
117                 GUILayout.EndHorizontal();
118                 break;
119
120             case GuiState.AuthHelp:
121
122                 GUILayout.Label("By default, any player can connect to Photon.\n'Custom Authentication' can be enabled to reject players without valid user-account.");
123
124                 GUILayout.Label("The actual authentication must be done by a web-service which you host and customize. Example sourcecode for these services is available on the docs page.");
125
126                 GUILayout.Label("For this demo set the Authentication URL in the Dashboard to:\nhttp://photon.webscript.io/auth-demo-equals");
127                 GUILayout.Label("That authentication-service has no user-database. It confirms any user if 'name equals password'.");
128
129                 GUILayout.Space(10);
130                 if (GUILayout.Button("Configure Authentication (Dashboard)"))
131                 {
132                     Application.OpenURL("https://cloud.exitgames.com/dashboard");
133                 }
134                 if (GUILayout.Button("Authentication Docs"))
135                 {
136                     Application.OpenURL("https://doc.exitgames.com/en/pun/current/tutorials/pun-and-facebook-custom-authentication");
137                 }
138
139
140                 GUILayout.Space(10);
141                 if (GUILayout.Button("Back to input"))
142                 {
143                     SetStateAuthInput();
144                 }
145                 break;
146
147             case GuiState.AuthInput:
148
149                 GUILayout.Label("Authenticate yourself");
150
151                 GUILayout.BeginHorizontal();
152                 this.authName = GUILayout.TextField(this.authName, GUILayout.Width(Screen.width/4 - 5));
153                 GUILayout.FlexibleSpace();
154                 this.authToken = GUILayout.TextField(this.authToken, GUILayout.Width(Screen.width/4 - 5));
155                 GUILayout.EndHorizontal();
156
157
158                 if (GUILayout.Button("Authenticate"))
159                 {
160                     PhotonNetwork.AuthValues = new AuthenticationValues();
161                     PhotonNetwork.AuthValues.SetAuthParameters(this.authName, this.authToken);
162                     PhotonNetwork.ConnectUsingSettings("1.0");
163                 }
164
165                 GUILayout.Space(10);
166
167                 if (GUILayout.Button("Help", GUILayout.Width(100)))
168                 {
169                     SetStateAuthHelp();
170                 }
171
172                 break;
173         }
174
175         GUILayout.EndArea();
176     }
File name: PunStartup.cs Copy
34     static void OnUpdate()
35     {
36         bool doneBefore = EditorPrefs.GetBool("PunDemosOpenedBefore");
37         if (doneBefore)
38         {
39             EditorApplication.update -= OnUpdate;
40             return;
41         }
42
43         if (String.IsNullOrEmpty(EditorApplication.currentScene) && EditorBuildSettings.scenes.Length == 0)
44         {
45             #if UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_5_1 || UNITY_5_2
46             if (EditorApplication.isUpdating) return;
47             #endif
48
49             LoadPunDemoHub();
50             SetPunDemoBuildSettings();
51             EditorPrefs.SetBool("PunDemosOpenedBefore", true);
52             Debug.Log("No scene was open. Loaded PUN Demo Hub Scene and added demos to build settings. Ready to go! This auto-setup is now disabled in this Editor.");
53         }
54     }
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: RPGMovement.cs Copy
85     void ResetSpeedValues()
86     {
87         m_CurrentMovement = Vector3.zero;
88         m_CurrentTurnSpeed = 0;
89     }
File name: RPGMovement.cs Copy
91     void ApplySynchronizedValues()
92     {
93         m_TransformView.SetSynchronizedValues( m_CurrentMovement, m_CurrentTurnSpeed );
94     }

Download file with original file name:Current

Current 181 lượt xem

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