ParameterType
How do I use Parameter Type
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
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
100 break;
101 case PhotonAnimatorView.ParameterType.Int:
102 parameters += parameter.Name + " (" + m_AnimatorView.GetComponent
103 break;
104 case PhotonAnimatorView.ParameterType.Float:
105 parameters += parameter.Name + " (" + m_AnimatorView.GetComponent
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: PhotonAnimatorViewEditor.cs
Copy
179 private void DrawParameterInspector()
180 {
181 SerializedProperty foldoutProperty = serializedObject.FindProperty("ShowParameterInspector");
182 foldoutProperty.boolValue = PhotonGUI.ContainerHeaderFoldout("Synchronize Parameters", foldoutProperty.boolValue);
183
184 if (foldoutProperty.boolValue == false)
185 {
186 return;
187 }
188
189 float lineHeight = 20;
190 Rect containerRect = PhotonGUI.ContainerBody(GetParameterCount()*lineHeight);
191
192 for (int i = 0; i < GetParameterCount(); i++)
193 {
194 AnimatorControllerParameter parameter = null;
195
196#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
197 parameter = this.m_Controller.GetParameter(i);
198#else
199 parameter = m_Animator.parameters[ i ];
200#endif
201
202 string defaultValue = "";
203
204 if (parameter.type == AnimatorControllerParameterType.Bool)
205 {
206 defaultValue += parameter.defaultBool.ToString();
207 }
208 else if (parameter.type == AnimatorControllerParameterType.Float)
209 {
210 defaultValue += parameter.defaultFloat.ToString();
211 }
212 else if (parameter.type == AnimatorControllerParameterType.Int)
213 {
214 defaultValue += parameter.defaultInt.ToString();
215 }
216
217 if (this.m_Target.DoesParameterSynchronizeTypeExist(parameter.name) == false)
218 {
219 this.m_Target.SetParameterSynchronized(parameter.name, (PhotonAnimatorView.ParameterType) parameter.type, PhotonAnimatorView.SynchronizeType.Disabled);
220 EditorUtility.SetDirty(this.m_Target);
221 }
222
223 PhotonAnimatorView.SynchronizeType value = this.m_Target.GetParameterSynchronizeType(parameter.name);
224
225 Rect elementRect = new Rect(containerRect.xMin, containerRect.yMin + i*lineHeight, containerRect.width, lineHeight);
226
227 Rect labelRect = new Rect(elementRect.xMin + 5, elementRect.yMin + 2, EditorGUIUtility.labelWidth - 5, elementRect.height);
228 GUI.Label(labelRect, parameter.name + " (" + defaultValue + ")");
229
230 Rect popupRect = new Rect(elementRect.xMin + EditorGUIUtility.labelWidth, elementRect.yMin + 2, elementRect.width - EditorGUIUtility.labelWidth - 5, EditorGUIUtility.singleLineHeight);
231 value = (PhotonAnimatorView.SynchronizeType) EditorGUI.EnumPopup(popupRect, value);
232
233 if (i < GetParameterCount() - 1)
234 {
235 Rect splitterRect = new Rect(elementRect.xMin + 2, elementRect.yMax, elementRect.width - 4, 1);
236 PhotonGUI.DrawSplitter(splitterRect);
237 }
238
239 if (value != this.m_Target.GetParameterSynchronizeType(parameter.name))
240 {
241 Undo.RecordObject(target, "Modify Synchronize Parameter " + parameter.name);
242 this.m_Target.SetParameterSynchronized(parameter.name, (PhotonAnimatorView.ParameterType) parameter.type, value);
243
244 EditorUtility.SetDirty(this.m_Target);
245 }
246 }
247 }
File name: PhotonAnimatorView.cs
Copy
33 {
34 public ParameterType Type;
35 public SynchronizeType SynchronizeType;
36 public string Name;
37 }
File name: PhotonAnimatorView.cs
Copy
213 public void SetParameterSynchronized( string name, ParameterType type, SynchronizeType synchronizeType )
214 {
215 if( Application.isPlaying == true )
216 {
217 m_WasSynchronizeTypeChanged = true;
218 }
219
220 int index = m_SynchronizeParameters.FindIndex( item => item.Name == name );
221
222 if( index == -1 )
223 {
224 m_SynchronizeParameters.Add( new SynchronizedParameter { Name = name, Type = type, SynchronizeType = synchronizeType } );
225 }
226 else
227 {
228 m_SynchronizeParameters[ index ].SynchronizeType = synchronizeType;
229 }
230 }
File name: PhotonAnimatorView.cs
Copy
234 void SerializeDataContinuously()
235 {
236 if( m_Animator == null )
237 {
238 return;
239 }
240
241 for( int i = 0; i < m_SynchronizeLayers.Count; ++i )
242 {
243 if( m_SynchronizeLayers[ i ].SynchronizeType == SynchronizeType.Continuous )
244 {
245 m_StreamQueue.SendNext( m_Animator.GetLayerWeight( m_SynchronizeLayers[ i ].LayerIndex ) );
246 }
247 }
248
249 for( int i = 0; i < m_SynchronizeParameters.Count; ++i )
250 {
251 SynchronizedParameter parameter = m_SynchronizeParameters[ i ];
252
253 if( parameter.SynchronizeType == SynchronizeType.Continuous )
254 {
255
256 switch( parameter.Type )
257 {
258 case ParameterType.Bool:
259 m_StreamQueue.SendNext( m_Animator.GetBool( parameter.Name ) );
260 break;
261 case ParameterType.Float:
262 m_StreamQueue.SendNext( m_Animator.GetFloat( parameter.Name ) );
263 break;
264 case ParameterType.Int:
265 m_StreamQueue.SendNext( m_Animator.GetInteger( parameter.Name ) );
266 break;
267 case ParameterType.Trigger:
268
269 break;
270 }
271 }
272 }
273 }
File name: PhotonAnimatorView.cs
Copy
275 void DeserializeDataContinuously()
276 {
277 if( m_StreamQueue.HasQueuedObjects() == false )
278 {
279 return;
280 }
281
282 for( int i = 0; i < m_SynchronizeLayers.Count; ++i )
283 {
284 if( m_SynchronizeLayers[ i ].SynchronizeType == SynchronizeType.Continuous )
285 {
286 m_Animator.SetLayerWeight( m_SynchronizeLayers[ i ].LayerIndex, (float)m_StreamQueue.ReceiveNext() );
287 }
288 }
289
290 for( int i = 0; i < m_SynchronizeParameters.Count; ++i )
291 {
292 SynchronizedParameter parameter = m_SynchronizeParameters[ i ];
293
294 if( parameter.SynchronizeType == SynchronizeType.Continuous )
295 {
296 switch( parameter.Type )
297 {
298 case ParameterType.Bool:
299 m_Animator.SetBool( parameter.Name, (bool)m_StreamQueue.ReceiveNext() );
300 break;
301 case ParameterType.Float:
302 m_Animator.SetFloat( parameter.Name, (float)m_StreamQueue.ReceiveNext() );
303 break;
304 case ParameterType.Int:
305 m_Animator.SetInteger( parameter.Name, (int)m_StreamQueue.ReceiveNext() );
306 break;
307 case ParameterType.Trigger:
308
309 break;
310 }
311 }
312 }
313 }
File name: PhotonAnimatorView.cs
Copy
315 void SerializeDataDiscretly( PhotonStream stream )
316 {
317 for( int i = 0; i < m_SynchronizeLayers.Count; ++i )
318 {
319 if( m_SynchronizeLayers[ i ].SynchronizeType == SynchronizeType.Discrete )
320 {
321 stream.SendNext( m_Animator.GetLayerWeight( m_SynchronizeLayers[ i ].LayerIndex ) );
322 }
323 }
324
325 for( int i = 0; i < m_SynchronizeParameters.Count; ++i )
326 {
327 SynchronizedParameter parameter = m_SynchronizeParameters[ i ];
328
329 if( parameter.SynchronizeType == SynchronizeType.Discrete )
330 {
331 switch( parameter.Type )
332 {
333 case ParameterType.Bool:
334 stream.SendNext( m_Animator.GetBool( parameter.Name ) );
335 break;
336 case ParameterType.Float:
337 stream.SendNext( m_Animator.GetFloat( parameter.Name ) );
338 break;
339 case ParameterType.Int:
340 stream.SendNext( m_Animator.GetInteger( parameter.Name ) );
341 break;
342 case ParameterType.Trigger:
343
344 break;
345 }
346 }
347 }
348 }
File name: PhotonAnimatorView.cs
Copy
350 void DeserializeDataDiscretly( PhotonStream stream )
351 {
352 for( int i = 0; i < m_SynchronizeLayers.Count; ++i )
353 {
354 if( m_SynchronizeLayers[ i ].SynchronizeType == SynchronizeType.Discrete )
355 {
356 m_Animator.SetLayerWeight( m_SynchronizeLayers[ i ].LayerIndex, (float)stream.ReceiveNext() );
357 }
358 }
359
360 for( int i = 0; i < m_SynchronizeParameters.Count; ++i )
361 {
362 SynchronizedParameter parameter = m_SynchronizeParameters[ i ];
363
364 if( parameter.SynchronizeType == SynchronizeType.Discrete )
365 {
366 switch( parameter.Type )
367 {
368 case ParameterType.Bool:
369 if( stream.PeekNext() is bool == false )
370 {
371 return;
372 }
373
374 m_Animator.SetBool( parameter.Name, (bool)stream.ReceiveNext() );
375 break;
376 case ParameterType.Float:
377 if( stream.PeekNext() is float == false )
378 {
379 return;
380 }
381
382 m_Animator.SetFloat( parameter.Name, (float)stream.ReceiveNext() );
383 break;
384 case ParameterType.Int:
385 if( stream.PeekNext() is int == false )
386 {
387 return;
388 }
389
390 m_Animator.SetInteger( parameter.Name, (int)stream.ReceiveNext() );
391 break;
392 case ParameterType.Trigger:
393
394 break;
395 }
396 }
397 }
398 }
File name: NetworkingPeer.cs
Copy
1962 public void ExecuteRPC(Hashtable rpcData, PhotonPlayer sender)
1963 {
1964 if (rpcData == null || !rpcData.ContainsKey((byte)0))
1965 {
1966 Debug.LogError("Malformed RPC; this should never occur. Content: " + SupportClass.DictionaryToString(rpcData));
1967 return;
1968 }
1969
1970 // ts: updated with "flat" event data
1971 int netViewID = (int)rpcData[(byte)0]; // LIMITS PHOTONVIEWS&PLAYERS
1972 int otherSidePrefix = 0; // by default, the prefix is 0 (and this is not being sent)
1973 if (rpcData.ContainsKey((byte)1))
1974 {
1975 otherSidePrefix = (short)rpcData[(byte)1];
1976 }
1977
1978 string inMethodName;
1979 if (rpcData.ContainsKey((byte)5))
1980 {
1981 int rpcIndex = (byte)rpcData[(byte)5]; // LIMITS RPC COUNT
1982 if (rpcIndex > PhotonNetwork.PhotonServerSettings.RpcList.Count - 1)
1983 {
1984 Debug.LogError("Could not find RPC with index: " + rpcIndex + ". Going to ignore! Check PhotonServerSettings.RpcList");
1985 return;
1986 }
1987 else
1988 {
1989 inMethodName = PhotonNetwork.PhotonServerSettings.RpcList[rpcIndex];
1990 }
1991 }
1992 else
1993 {
1994 inMethodName = (string)rpcData[(byte)3];
1995 }
1996
1997 object[] inMethodParameters = null;
1998 if (rpcData.ContainsKey((byte)4))
1999 {
2000 inMethodParameters = (object[])rpcData[(byte)4];
2001 }
2002
2003 if (inMethodParameters == null)
2004 {
2005 inMethodParameters = new object[0];
2006 }
2007
2008 PhotonView photonNetview = this.GetPhotonView(netViewID);
2009 if (photonNetview == null)
2010 {
2011 int viewOwnerId = netViewID/PhotonNetwork.MAX_VIEW_IDS;
2012 bool owningPv = (viewOwnerId == this.mLocalActor.ID);
2013 bool ownerSent = (viewOwnerId == sender.ID);
2014
2015 if (owningPv)
2016 {
2017 Debug.LogWarning("Received RPC \"" + inMethodName + "\" for viewID " + netViewID + " but this PhotonView does not exist! View was/is ours." + (ownerSent ? " Owner called." : " Remote called.") + " By: " + sender.ID);
2018 }
2019 else
2020 {
2021 Debug.LogWarning("Received RPC \"" + inMethodName + "\" for viewID " + netViewID + " but this PhotonView does not exist! Was remote PV." + (ownerSent ? " Owner called." : " Remote called.") + " By: " + sender.ID + " Maybe GO was destroyed but RPC not cleaned up.");
2022 }
2023 return;
2024 }
2025
2026 if (photonNetview.prefix != otherSidePrefix)
2027 {
2028 Debug.LogError(
2029 "Received RPC \"" + inMethodName + "\" on viewID " + netViewID + " with a prefix of " + otherSidePrefix
2030 + ", our prefix is " + photonNetview.prefix + ". The RPC has been ignored.");
2031 return;
2032 }
2033
2034 // Get method name
2035 if (inMethodName == string.Empty)
2036 {
2037 Debug.LogError("Malformed RPC; this should never occur. Content: " + SupportClass.DictionaryToString(rpcData));
2038 return;
2039 }
2040
2041 if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
2042 Debug.Log("Received RPC: " + inMethodName);
2043
2044
2045 // SetReceiving filtering
2046 if (photonNetview.group != 0 && !allowedReceivingGroups.Contains(photonNetview.group))
2047 {
2048 return; // Ignore group
2049 }
2050
2051 Type[] argTypes = new Type[0];
2052 if (inMethodParameters.Length > 0)
2053 {
2054 argTypes = new Type[inMethodParameters.Length];
2055 int i = 0;
2056 for (int index = 0; index < inMethodParameters.Length; index++)
2057 {
2058 object objX = inMethodParameters[index];
2059 if (objX == null)
2060 {
2061 argTypes[i] = null;
2062 }
2063 else
2064 {
2065 argTypes[i] = objX.GetType();
2066 }
2067
2068 i++;
2069 }
2070 }
2071
2072 int receivers = 0;
2073 int foundMethods = 0;
2074 MonoBehaviour[] mbComponents = photonNetview.GetComponents
2075 for (int componentsIndex = 0; componentsIndex < mbComponents.Length; componentsIndex++)
2076 {
2077 MonoBehaviour monob = mbComponents[componentsIndex];
2078 if (monob == null)
2079 {
2080 Debug.LogError("ERROR You have missing MonoBehaviours on your gameobjects!");
2081 continue;
2082 }
2083
2084 Type type = monob.GetType();
2085
2086 // Get [RPC] methods from cache
2087 List
2088 if (this.monoRPCMethodsCache.ContainsKey(type))
2089 {
2090 cachedRPCMethods = this.monoRPCMethodsCache[type];
2091 }
2092
2093 if (cachedRPCMethods == null)
2094 {
2095 List
2096
2097 this.monoRPCMethodsCache[type] = entries;
2098 cachedRPCMethods = entries;
2099 }
2100
2101 if (cachedRPCMethods == null)
2102 {
2103 continue;
2104 }
2105
2106 // Check cache for valid methodname+arguments
2107 for (int index = 0; index < cachedRPCMethods.Count; index++)
2108 {
2109 MethodInfo mInfo = cachedRPCMethods[index];
2110 if (mInfo.Name == inMethodName)
2111 {
2112 foundMethods++;
2113 ParameterInfo[] pArray = mInfo.GetParameters();
2114 if (pArray.Length == argTypes.Length)
2115 {
2116 // Normal, PhotonNetworkMessage left out
2117 if (this.CheckTypeMatch(pArray, argTypes))
2118 {
2119 receivers++;
2120 object result = mInfo.Invoke((object)monob, inMethodParameters);
2121 if (mInfo.ReturnType == typeof(IEnumerator))
2122 {
2123 monob.StartCoroutine((IEnumerator)result);
2124 }
2125 }
2126 }
2127 else if ((pArray.Length - 1) == argTypes.Length)
2128 {
2129 // Check for PhotonNetworkMessage being the last
2130 if (this.CheckTypeMatch(pArray, argTypes))
2131 {
2132 if (pArray[pArray.Length - 1].ParameterType == typeof(PhotonMessageInfo))
2133 {
2134 receivers++;
2135
2136 int sendTime = (int)rpcData[(byte)2];
2137 object[] deParamsWithInfo = new object[inMethodParameters.Length + 1];
2138 inMethodParameters.CopyTo(deParamsWithInfo, 0);
2139 deParamsWithInfo[deParamsWithInfo.Length - 1] = new PhotonMessageInfo(sender, sendTime, photonNetview);
2140
2141 object result = mInfo.Invoke((object)monob, deParamsWithInfo);
2142 if (mInfo.ReturnType == typeof(IEnumerator))
2143 {
2144 monob.StartCoroutine((IEnumerator)result);
2145 }
2146 }
2147 }
2148 }
2149 else if (pArray.Length == 1 && pArray[0].ParameterType.IsArray)
2150 {
2151 receivers++;
2152 object result = mInfo.Invoke((object)monob, new object[] { inMethodParameters });
2153 if (mInfo.ReturnType == typeof(IEnumerator))
2154 {
2155 monob.StartCoroutine((IEnumerator)result);
2156 }
2157 }
2158 }
2159 }
2160 }
2161
2162 // Error handling
2163 if (receivers != 1)
2164 {
2165 string argsString = string.Empty;
2166 for (int index = 0; index < argTypes.Length; index++)
2167 {
2168 Type ty = argTypes[index];
2169 if (argsString != string.Empty)
2170 {
2171 argsString += ", ";
2172 }
2173
2174 if (ty == null)
2175 {
2176 argsString += "null";
2177 }
2178 else
2179 {
2180 argsString += ty.Name;
2181 }
2182 }
2183
2184 if (receivers == 0)
2185 {
2186 if (foundMethods == 0)
2187 {
2188 Debug.LogError("PhotonView with ID " + netViewID + " has no method \"" + inMethodName + "\" marked with the [RPC](C#) or @RPC(JS) property! Args: " + argsString);
2189 }
2190 else
2191 {
2192 Debug.LogError("PhotonView with ID " + netViewID + " has no method \"" + inMethodName + "\" that takes " + argTypes.Length + " argument(s): " + argsString);
2193 }
2194 }
2195 else
2196 {
2197 Debug.LogError("PhotonView with ID " + netViewID + " has " + receivers + " methods \"" + inMethodName + "\" that takes " + argTypes.Length + " argument(s): " + argsString + ". Should be just one?");
2198 }
2199 }
2200 }
File name: NetworkingPeer.cs
Copy
2208 private bool CheckTypeMatch(ParameterInfo[] methodParameters, Type[] callParameterTypes)
2209 {
2210 if (methodParameters.Length < callParameterTypes.Length)
2211 {
2212 return false;
2213 }
2214
2215 for (int index = 0; index < callParameterTypes.Length; index++)
2216 {
2217 Type type = methodParameters[index].ParameterType;
2218 //todo: check metro type usage
2219 if (callParameterTypes[index] != null && !type.Equals(callParameterTypes[index]))
2220 {
2221 return false;
2222 }
2223 }
2224
2225 return true;
2226 }
ParameterType 122 lượt xem
Gõ tìm kiếm nhanh...