GetArrayElementAtIndex









How do I use Get Array Element At Index
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: PhotonViewInspector.cs Copy
258     void DrawObservedComponentsList()
259     {
260         GUILayout.Space( 5 );
261         SerializedProperty listProperty = serializedObject.FindProperty( "ObservedComponents" );
262
263         if( listProperty == null )
264         {
265             return;
266         }
267
268         float containerElementHeight = 22;
269         float containerHeight = listProperty.arraySize * containerElementHeight;
270
271         bool isOpen = PhotonGUI.ContainerHeaderFoldout( "Observed Components (" + GetObservedComponentsCount() + ")", serializedObject.FindProperty( "ObservedComponentsFoldoutOpen" ).boolValue );
272         serializedObject.FindProperty( "ObservedComponentsFoldoutOpen" ).boolValue = isOpen;
273
274         if( isOpen == false )
275         {
276             containerHeight = 0;
277         }
278
279         //Texture2D statsIcon = AssetDatabase.LoadAssetAtPath( "Assets/Photon Unity Networking/Editor/PhotonNetwork/PhotonViewStats.png", typeof( Texture2D ) ) as Texture2D;
280
281         Rect containerRect = PhotonGUI.ContainerBody( containerHeight );
282         bool wasObservedComponentsEmpty = m_Target.ObservedComponents.FindAll( item => item != null ).Count == 0;
283         if( isOpen == true )
284         {
285             for( int i = 0; i < listProperty.arraySize; ++i )
286             {
287                 Rect elementRect = new Rect( containerRect.xMin, containerRect.yMin + containerElementHeight * i, containerRect.width, containerElementHeight );
288                 {
289                     Rect texturePosition = new Rect( elementRect.xMin + 6, elementRect.yMin + elementRect.height / 2f - 1, 9, 5 );
290                     ReorderableListResources.DrawTexture( texturePosition, ReorderableListResources.texGrabHandle );
291
292                     Rect propertyPosition = new Rect( elementRect.xMin + 20, elementRect.yMin + 3, elementRect.width - 45, 16 );
293                     EditorGUI.PropertyField( propertyPosition, listProperty.GetArrayElementAtIndex( i ), new GUIContent() );
294
295                     //Debug.Log( listProperty.GetArrayElementAtIndex( i ).objectReferenceValue.GetType() );
296                     //Rect statsPosition = new Rect( propertyPosition.xMax + 7, propertyPosition.yMin, statsIcon.width, statsIcon.height );
297                     //ReorderableListResources.DrawTexture( statsPosition, statsIcon );
298
299                     Rect removeButtonRect = new Rect( elementRect.xMax - PhotonGUI.DefaultRemoveButtonStyle.fixedWidth,
300                                                         elementRect.yMin + 2,
301                                                         PhotonGUI.DefaultRemoveButtonStyle.fixedWidth,
302                                                         PhotonGUI.DefaultRemoveButtonStyle.fixedHeight );
303
304                     GUI.enabled = listProperty.arraySize > 1;
305                     if( GUI.Button( removeButtonRect, new GUIContent( ReorderableListResources.texRemoveButton ), PhotonGUI.DefaultRemoveButtonStyle ) )
306                     {
307                         listProperty.DeleteArrayElementAtIndex( i );
308                     }
309                     GUI.enabled = true;
310
311                     if( i < listProperty.arraySize - 1 )
312                     {
313                         texturePosition = new Rect( elementRect.xMin + 2, elementRect.yMax, elementRect.width - 4, 1 );
314                         PhotonGUI.DrawSplitter( texturePosition );
315                     }
316                 }
317             }
318         }
319
320         if( PhotonGUI.AddButton() )
321         {
322             listProperty.InsertArrayElementAtIndex( Mathf.Max( 0, listProperty.arraySize - 1 ) );
323         }
324
325         serializedObject.ApplyModifiedProperties();
326
327         bool isObservedComponentsEmpty = m_Target.ObservedComponents.FindAll( item => item != null ).Count == 0;
328
329         if( wasObservedComponentsEmpty == true && isObservedComponentsEmpty == false && m_Target.synchronization == ViewSynchronization.Off )
330         {
331             m_Target.synchronization = ViewSynchronization.UnreliableOnChange;
332             EditorUtility.SetDirty( m_Target );
333             serializedObject.Update();
334         }
335
336         if( wasObservedComponentsEmpty == false && isObservedComponentsEmpty == true )
337         {
338             m_Target.synchronization = ViewSynchronization.Off;
339             EditorUtility.SetDirty( m_Target );
340             serializedObject.Update();
341         }
342
343     }

GetArrayElementAtIndex 138 lượt xem

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