Parameters









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

Featured Snippets


File name: ClassBLL.cs Copy
275         public bool Proc_Insert(string proc,string test)
276         {
277             SqlConnection con = da.GetConnect();
278             con.Open();
279             SqlCommand cmd = new SqlCommand(proc, con);
280             cmd.CommandType = CommandType.StoredProcedure;
281             cmd.Parameters.Add("@test", SqlDbType.NVarChar).Value = test;
282             SqlDataReader dr = cmd.ExecuteReader();
283             if (dr.Read())
284             {
285                 return false;
286             }
287             return true;
288         }
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: 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: DemoMecanimGUI.cs Copy
61     public void OnGUI()
62     {
63         GUI.skin = Skin;
64
65         string[] synchronizeTypeContent = new string[] { "Disabled", "Discrete", "Continuous" };
66
67         GUILayout.BeginArea( new Rect( Screen.width - 200 * m_FoundPlayerSlideIn - 400 * m_SlideIn, 0, 600, Screen.height ), GUI.skin.box );
68         {
69             GUILayout.Label( "Mecanim Demo", GUI.skin.customStyles[ 0 ] );
70
71             GUI.color = Color.white;
72             string label = "Settings";
73
74             if( m_IsOpen == true )
75             {
76                 label = "Close";
77             }
78
79             if( GUILayout.Button( label, GUILayout.Width( 110 ) ) )
80             {
81                 m_IsOpen = !m_IsOpen;
82             }
83
84             string parameters = "";
85
86             if( m_AnimatorView != null )
87             {
88                 parameters += "Send Values:\n";
89
90                 for( int i = 0; i < m_AnimatorView.GetSynchronizedParameters().Count; ++i )
91                 {
92                     PhotonAnimatorView.SynchronizedParameter parameter = m_AnimatorView.GetSynchronizedParameters()[ i ];
93
94                     try
95                     {
96                         switch( parameter.Type )
97                         {
98                         case PhotonAnimatorView.ParameterType.Bool:
99                             parameters += parameter.Name + " (" + ( m_AnimatorView.GetComponent().GetBool( parameter.Name ) ? "True" : "False" ) + ")\n";
100                             break;
101                         case PhotonAnimatorView.ParameterType.Int:
102                             parameters += parameter.Name + " (" + m_AnimatorView.GetComponent().GetInteger( parameter.Name ) + ")\n";
103                             break;
104                         case PhotonAnimatorView.ParameterType.Float:
105                             parameters += parameter.Name + " (" + m_AnimatorView.GetComponent().GetFloat( parameter.Name ).ToString( "0.00" ) + ")\n";
106                             break;
107                         }
108                     }
109                     catch
110                     {
111                         Debug.Log( "derrrr for " + parameter.Name );
112                     }
113                 }
114             }
115
116             if( m_RemoteAnimator != null )
117             {
118                 parameters += "\nReceived Values:\n";
119
120                 for( int i = 0; i < m_AnimatorView.GetSynchronizedParameters().Count; ++i )
121                 {
122                     PhotonAnimatorView.SynchronizedParameter parameter = m_AnimatorView.GetSynchronizedParameters()[ i ];
123
124                     try
125                     {
126                         switch( parameter.Type )
127                         {
128                         case PhotonAnimatorView.ParameterType.Bool:
129                             parameters += parameter.Name + " (" + ( m_RemoteAnimator.GetBool( parameter.Name ) ? "True" : "False" ) + ")\n";
130                             break;
131                         case PhotonAnimatorView.ParameterType.Int:
132                             parameters += parameter.Name + " (" + m_RemoteAnimator.GetInteger( parameter.Name ) + ")\n";
133                             break;
134                         case PhotonAnimatorView.ParameterType.Float:
135                             parameters += parameter.Name + " (" + m_RemoteAnimator.GetFloat( parameter.Name ).ToString( "0.00" ) + ")\n";
136                             break;
137                         }
138                     }
139                     catch
140                     {
141                         Debug.Log( "derrrr for " + parameter.Name );
142                     }
143                 }
144             }
145
146             GUIStyle style = new GUIStyle( GUI.skin.label );
147             style.alignment = TextAnchor.UpperLeft;
148
149             GUI.color = new Color( 1f, 1f, 1f, 1 - m_SlideIn );
150             GUI.Label( new Rect( 10, 100, 600, Screen.height ), parameters, style );
151
152             if( m_AnimatorView != null )
153             {
154                 GUI.color = new Color( 1f, 1f, 1f, m_SlideIn );
155
156                 GUILayout.Space( 20 );
157                 GUILayout.Label( "Synchronize Parameters" );
158
159                 for( int i = 0; i < m_AnimatorView.GetSynchronizedParameters().Count; ++i )
160                 {
161                     GUILayout.BeginHorizontal();
162                     {
163                         PhotonAnimatorView.SynchronizedParameter parameter = m_AnimatorView.GetSynchronizedParameters()[ i ];
164
165                         GUILayout.Label( parameter.Name, GUILayout.Width( 100 ), GUILayout.Height( 36 ) );
166
167                         int selectedValue = (int)parameter.SynchronizeType;
168                         int newValue = GUILayout.Toolbar( selectedValue, synchronizeTypeContent );
169
170                         if( newValue != selectedValue )
171                         {
172                             m_AnimatorView.SetParameterSynchronized( parameter.Name, parameter.Type, (PhotonAnimatorView.SynchronizeType)newValue );
173                         }
174                     }
175                     GUILayout.EndHorizontal();
176                 }
177             }
178         }
179         GUILayout.EndArea();
180     }
File name: WorkerMenu.cs Copy
234     public void OnFailedToConnectToPhoton(object parameters)
235     {
236         this.connectFailed = true;
237         Debug.Log("OnFailedToConnectToPhoton. StatusCode: " + parameters + " ServerAddress: " + PhotonNetwork.networkingPeer.ServerAddress);
238     }
File name: PhotonAnimatorViewEditor.cs Copy
18     public override void OnInspectorGUI()
19     {
20         //base.OnInspectorGUI();
21
22         if (this.m_Animator == null)
23         {
24             GUILayout.BeginVertical(GUI.skin.box);
25             GUILayout.Label("GameObject doesn't have an Animator component to synchronize");
26             GUILayout.EndVertical();
27             return;
28         }
29
30         DrawWeightInspector();
31
32         if (this.m_Animator.layerCount == 0)
33         {
34             GUILayout.BeginVertical(GUI.skin.box);
35             GUILayout.Label("Animator doesn't have any layers setup to synchronize");
36             GUILayout.EndVertical();
37         }
38
39         DrawParameterInspector();
40
41         if (GetParameterCount() == 0)
42         {
43             GUILayout.BeginVertical(GUI.skin.box);
44             GUILayout.Label("Animator doesn't have any parameters setup to synchronize");
45             GUILayout.EndVertical();
46         }
47
48         serializedObject.ApplyModifiedProperties();
49
50         //GUILayout.Label( "m_SynchronizeLayers " + serializedObject.FindProperty( "m_SynchronizeLayers" ).arraySize );
51         //GUILayout.Label( "m_SynchronizeParameters " + serializedObject.FindProperty( "m_SynchronizeParameters" ).arraySize );
52     }
File name: PhotonAnimatorViewEditor.cs Copy
54     private void OnEnable()
55     {
56         this.m_Target = (PhotonAnimatorView) target;
57         this.m_Animator = this.m_Target.GetComponent();
58
59#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
60         this.m_Controller = AnimatorController.GetEffectiveAnimatorController(this.m_Animator);
61#endif
62
63         CheckIfStoredParametersExist();
64     }
File name: PhotonAnimatorViewEditor.cs Copy
113     private int GetParameterCount()
114     {
115#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
116         if (this.m_Controller == null)
117         {
118             return 0;
119         }
120
121         return this.m_Controller.parameterCount;
122#else
123         if( m_Animator == null )
124         {
125             return 0;
126         }
127
128         return m_Animator.parameters.Length;
129#endif
130     }
File name: PhotonAnimatorViewEditor.cs Copy
132     private bool DoesParameterExist(string name)
133     {
134#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
135         for (int i = 0; i < this.m_Controller.parameterCount; ++i)
136         {
137             if (this.m_Controller.GetParameter(i).name == name)
138             {
139                 return true;
140             }
141         }
142
143         return false;
144#else
145         for( int i = 0; i < m_Animator.parameters.Length; ++i )
146         {
147             if( m_Animator.parameters[ i ].name == name )
148             {
149                 return true;
150             }
151         }
152
153         return false;
154#endif
155     }
File name: PhotonAnimatorViewEditor.cs Copy
157     private void CheckIfStoredParametersExist()
158     {
159         for (int i = 0; i < this.m_Target.GetSynchronizedParameters().Count; ++i)
160         {
161             string parameterName = this.m_Target.GetSynchronizedParameters()[i].Name;
162             if (DoesParameterExist(parameterName) == false)
163             {
164                 Debug.LogWarning("Parameter '" + this.m_Target.GetSynchronizedParameters()[i].Name +
165                                  "' doesn't exist anymore. Removing it from the list of synchronized parameters");
166                 int numberOfRemovedElements = this.m_Target.GetSynchronizedParameters().RemoveAll(item => item.Name == parameterName);
167                 EditorUtility.SetDirty(this.m_Target);
168
169                 i -= numberOfRemovedElements;
170
171                 if (i < 0)
172                 {
173                     break;
174                 }
175             }
176         }
177     }

Parameters 131 lượt xem

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