Hiya folks,
So, let me see if i can cut this short.
I have a class which I used a custom inspector for. It is ripped(i.e. less code shown)
Assume proper namespacing is used and the following work.
TLDR: I need some way to inserting a custom inspector into my window when selecting an item(which is cached). How can I do this? Below scripts, I want a fill in for “DrawCustomInpsector” spot below.
[System.Serializable]
public class BaseItem : ScriptableObject
{
public string name;
public int cost;
}
and custom editor below
[CustomEditor(typeof(BaseItem))]
[CanEditMultipleObjects]
public class EditorBaseItem : Editor
{
public override void OnInspectorGUI ()
{
BaseItem item = (BaseItem)this.target;
EditorGUILayout.TextField ("Item name<custom>:", item.name);
// Opens up the window with the asset info
if(GUILayout.Button("Modify"))
{
CreateItemWindow.ShowWindowWithProperties(item);
}
}
}
Now standard custom window script
[MenuItem("Window/Item Database Management")]
public static void ShowWindow()
{
EditorWindow.GetWindow<BaseItemDatabaseWindow>();
void OnGUI()
{
// SO, I have a scroll view on the left hand side. This contains my list of items.
_item_selection_scroll_pos = GUI.BeginScrollView(new Rect(0f, 0f, position.width/3.5f, position.height), _item_selection_scroll_pos, new Rect(0f, 0f, position.width/4f, position.height*2));
// Now, what I would like is when I select an item from the list. On the right hand side, the custom script appears.
int i = 0;
foreach(BaseItem item in BaseItemDataBaseInstance.instance.main_data.data)
{
if(GUI.Button(new Rect(0, _height_offset * i++, position.width/3.5f, 20f), item.name))
{
// Store select item some how
// _current_item = new SerializedObject(item);
//_item = item;
}
}
Rect right_side = new Rect(position.width/3.5f, 0.0f, position.width - position.width/3.5f, position.height);
GUI.BeginGroup(right_side);
if(/* we have the selected item */)
{
//DrawCustomInpsector<EditorBaseItem>(item) // I wish....
}
GUI.EndGroup();
this.Repaint();