ObjectField
How do I use Object Field
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PhotonViewInspector.cs
Copy
209 void DrawOldObservedItem()
210 {
211 EditorGUILayout.BeginHorizontal();
212
213 // Using a lower version then 3.4? Remove the TRUE in the next line to fix an compile error
214 string typeOfObserved = string.Empty;
215 if( m_Target.observed != null )
216 {
217 int firstBracketPos = m_Target.observed.ToString().LastIndexOf( '(' );
218 if( firstBracketPos > 0 )
219 {
220 typeOfObserved = m_Target.observed.ToString().Substring( firstBracketPos );
221 }
222 }
223
224
225 Component componenValue = (Component)EditorGUILayout.ObjectField( "Observe: " + typeOfObserved, m_Target.observed, typeof( Component ), true );
226 if( m_Target.observed != componenValue )
227 {
228 if( m_Target.observed == null )
229 {
230 m_Target.synchronization = ViewSynchronization.UnreliableOnChange; // if we didn't observe anything yet. use unreliable on change as default
231 }
232 if( componenValue == null )
233 {
234 m_Target.synchronization = ViewSynchronization.Off;
235 }
236
237 m_Target.observed = componenValue;
238 }
239
240 EditorGUILayout.EndHorizontal();
241 }
File name: SpriterEntityInspector.cs
Copy
13 public override void OnInspectorGUI()
14 {
15 var myTarget = (SpriterEntity)target;
16
17 myTarget.SpriteMaterial = (Material)EditorGUILayout.ObjectField("Sprite Material", myTarget.SpriteMaterial, typeof(Material), false);
18
19 if(GUILayout.Button("Assign Material"))
20 {
21 myTarget.ApplyMaterial();
22 }
23
24 EditorUtility.SetDirty(target);
25 }
ObjectField 133 lượt xem
Gõ tìm kiếm nhanh...