Hi all,
I know its allot of trouble to try and use reflection, but i was just wondering if its possible
to show the Preferences Window and select a specific Section to be displayed?
if( GUILayout.Button( "Show 9 Slice Preferences" ) )
{
Assembly asm = Assembly.GetAssembly( typeof(EditorWindow) );
Type T = asm.GetType( "UnityEditor.PreferencesWindow" );
MethodInfo M = T.GetMethod( "ShowPreferencesWindow", BindingFlags.NonPublic | BindingFlags.Static );
M.Invoke( null, null );
BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
FieldInfo field_m_Sections = T.GetField("m_Sections", flags);
int nCount = 0;
PropertyInfo piCount = field_m_Sections.GetType().GetProperty( "Count" );
if (piCount != null)
{
object values = piCount.GetValue( T, null );
if (values != null)
{
PropertyInfo valuesCountProperty = values.GetType().GetProperty("Count");
//if (countProperty != null)
//{
nCount = (int)valuesCountProperty.GetValue( T, null );
//}
}
}
for (int i = 0; i < nCount; i++)
{
object section = (object) field_m_Sections.GetType().GetGenericArguments()[i];
FieldInfo fi_content = section.GetType().GetField( "content" );
GUIContent c = (GUIContent) fi_content.GetValue( null );
if( c.text == "9 Slice" )
{
FieldInfo fi_m_SelectedSectionIndex = T.GetField( "m_SelectedSectionIndex", flags );
fi_m_SelectedSectionIndex.SetValue( i, null );
//this.m_RefreshCustomPreferences = true;
break;
}
}
}