- Home /
Custom Inspector when Selecting from Project Tree?
I have created a custom editor that can create a special asset. It is meant to be a blueprint / predefined asset that you can assign to the characters in my game. (Not a component because you edit them visually.) It is created from the Menu as follows:
// Create a new Behavior Tree
[MenuItem("GameObject/Create Other/Behavior Tree")]
static void CreateTree()
{
Init();
BehaviorTree newTree = new BehaviorTree();
m_behaviorTrees.Add(newTree);
m_selectedTree = newTree;
Selection.activeObject = newTree;
AssetDatabase.CreateAsset(newTree, "Assets/TestTree.tree.asset");// <-- .asset
}
When you select a script in the editor or a texture it brings up a special Inspector for those types. How can I make my custom asset respond with a custom inspector when you select it from the Project Tree (the tree with Scripts.)
Here is my custom Inspector:
[CustomEditor(typeof(BehaviorTree))]
public class BehaviorTreeInspector : Editor
{
SerializedProperty m_nodes;
public void OnEnable()
{
m_nodes = serializedObject.FindProperty("Nodes");
}
// Implement this function to make a custom inspector.
public override void OnInspectorGUI()
{
if (GUILayout.Button("Add Node"))
{
Debug.Log("New node added!");
BehaviorTree tree = target as BehaviorTree;
tree.AddNode();
}
GUILayout.TextArea("Yes!");
}
}
Answered this one myself! Apparently, all assets $$anonymous$$UST end with the .asset extension in order for this to work. I've highlighted the edited line above.
Works like a charm now.
Your answer
Follow this Question
Related Questions
Unity editor and inspector header 0 Answers
ReImport in c# of GameObjects only for Scene Objects, not assets? 1 Answer
How can I add a new "Inspector" type? 1 Answer
Call inspector on custom window editor 4 Answers
Custom Asset Files 2 Answers