ReorderableList









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

Featured Snippets


File name: PhotonGUI.cs Copy
11     {
12         get
13         {
14             if( m_DefaultTitleStyle == null )
15             {
16                 m_DefaultTitleStyle = new GUIStyle();
17                 m_DefaultTitleStyle.border = new RectOffset( 2, 2, 2, 1 );
18                 m_DefaultTitleStyle.margin = new RectOffset( 5, 5, 5, 0 );
19                 m_DefaultTitleStyle.padding = new RectOffset( 5, 5, 0, 0 );
20                 m_DefaultTitleStyle.alignment = TextAnchor.MiddleLeft;
21                 m_DefaultTitleStyle.normal.background = ReorderableListResources.texTitleBackground;
22                 m_DefaultTitleStyle.normal.textColor = EditorGUIUtility.isProSkin
23                     ? new Color( 0.8f, 0.8f, 0.8f )
24                     : new Color( 0.2f, 0.2f, 0.2f );
25             }
26
27             return m_DefaultTitleStyle;
28         }
29     }
File name: PhotonGUI.cs Copy
33     {
34         get
35         {
36             if( m_DefaultContainerStyle == null )
37             {
38                 m_DefaultContainerStyle = new GUIStyle();
39                 m_DefaultContainerStyle.border = new RectOffset( 2, 2, 1, 2 );
40                 m_DefaultContainerStyle.margin = new RectOffset( 5, 5, 5, 5 );
41                 m_DefaultContainerStyle.padding = new RectOffset( 1, 1, 2, 2 );
42                 m_DefaultContainerStyle.normal.background = ReorderableListResources.texContainerBackground;
43             }
44
45             return m_DefaultContainerStyle;
46         }
47     }
File name: PhotonGUI.cs Copy
51     {
52         get
53         {
54             if( m_DefaultAddButtonStyle == null )
55             {
56                 m_DefaultAddButtonStyle = new GUIStyle();
57                 m_DefaultAddButtonStyle.fixedWidth = 30;
58                 m_DefaultAddButtonStyle.fixedHeight = 16;
59                 m_DefaultAddButtonStyle.normal.background = ReorderableListResources.texAddButton;
60                 m_DefaultAddButtonStyle.active.background = ReorderableListResources.texAddButtonActive;
61             }
62
63             return m_DefaultAddButtonStyle;
64         }
65     }
File name: PhotonGUI.cs Copy
69     {
70         get
71         {
72             if( m_DefaultRemoveButtonStyle == null )
73             {
74                 m_DefaultRemoveButtonStyle = new GUIStyle();
75                 m_DefaultRemoveButtonStyle.fixedWidth = 30;
76                 m_DefaultRemoveButtonStyle.fixedHeight = 20;
77                 m_DefaultRemoveButtonStyle.active.background = ReorderableListResources.CreatePixelTexture( "Dark Pixel (List GUI)", new Color32( 18, 18, 18, 255 ) );
78                 m_DefaultRemoveButtonStyle.imagePosition = ImagePosition.ImageOnly;
79                 m_DefaultRemoveButtonStyle.alignment = TextAnchor.MiddleCenter;
80             }
81
82             return m_DefaultRemoveButtonStyle;
83         }
84     }
File name: PhotonGUI.cs Copy
88     {
89         get
90         {
91             if( m_DefaultContainerRowStyle == null )
92             {
93                 m_DefaultContainerRowStyle = new GUIStyle();
94                 m_DefaultContainerRowStyle.border = new RectOffset( 2, 2, 2, 2 );
95
96                 m_DefaultContainerRowStyle.margin = new RectOffset( 5, 5, 5, 5 );
97                 m_DefaultContainerRowStyle.padding = new RectOffset( 1, 1, 2, 2 );
98                 m_DefaultContainerRowStyle.normal.background = ReorderableListResources.texContainerBackground;
99             }
100
101             return m_DefaultContainerRowStyle;
102         }
103     }
File name: PhotonGUI.cs Copy
186     public static void DrawSplitter( Rect position )
187     {
188         ReorderableListResources.DrawTexture( position, ReorderableListResources.texItemSplitter );
189     }
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     }
File name: ReorderableListResources.cs Copy
19         static ReorderableListResources()
20         {
21             GenerateSpecialTextures();
22             LoadResourceAssets();
23         }
File name: ReorderableListResources.cs Copy
168         private static void LoadResourceAssets()
169         {
170             var skin = EditorGUIUtility.isProSkin ? s_DarkSkin : s_LightSkin;
171             s_Cached = new Texture2D[ skin.Length ];
172
173             for( int i = 0; i < s_Cached.Length; ++i )
174             {
175                 // Get image data (PNG) from base64 encoded strings.
176                 byte[] imageData = Convert.FromBase64String( skin[ i ] );
177
178                 // Gather image size from image data.
179                 int texWidth, texHeight;
180                 GetImageSize( imageData, out texWidth, out texHeight );
181
182                 // Generate texture asset.
183                 var tex = new Texture2D( texWidth, texHeight, TextureFormat.ARGB32, false, true );
184                 tex.hideFlags = HideFlags.HideAndDontSave;
185                 tex.name = "(Generated) ReorderableList:" + i;
186                 tex.filterMode = FilterMode.Point;
187                 tex.LoadImage( imageData );
188
189                 s_Cached[ i ] = tex;
190             }
191
192             s_LightSkin = null;
193             s_DarkSkin = null;
194         }

Download file with original file name:ReorderableList

ReorderableList 132 lượt xem

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