- Home /
How to Call the default Editor of a ScriptableObject From the other ScriptableObject's OnInspectorGUI()?
Brief Description: There're some cases that I want a ScriptableObject A to Contain a reference to another ScriptableObject B. And want to Edit both of them by using the Editor of A (which has been customized by my self). But for ScriptableObject, it seems that the Editor of A will not call the default Editor of B. Is there any way to do this?
public class A: ScriptableObject
{
[SerializeField] private float aValue;
[SerializeField] private B b;
}
public class B: ScriptableObject
{
[SerializeField] private float bValue;
}
[CustomEditor( typeof(A) )]
public class EditorOfA : Editor
{
public override void OnInspectorGUI()
{
//Some Customized Info, Button implement here
base.OnInspectorGUI(); //This will Only show aValue in Inspector, but no bValue in class b...
}
}
Here is the Detail: Following is the reason why I want do this (It might not necessary to read the following to answer my question): Suppose I'm designing a Card game and it's not necessary for Cards to Update each frame (only be update in certain time that control by GameController) neither to have Transform. And since I also want to let other people to adjust the attributes, so I decide to use ScriptableObject for the Cards. Take the magic Cards for example, suppose it will recover the health Points of Character when some condition is matched.
public class MagicCard: ScriptableObject
{
[SerializeField] private float recoveredHealth;
[SerializeField] private ConditionInterface activateCondition;
[SerializeField] private EffectInterface recoverHealthEffect;
public void update(PlayerInfo playerStatus)
{
if( this.activateCondition.isActivated(playerStatus) )
recoverHealthEffect.Activate();
}
}
public abstract class ConditionInterface : ScriptableObject
{
public abstract void isActivated(PlayerInfo playerStatus);
}
public class DyingActivateCondition : ConditionInterface
{
[SerializeField] private float activateHealth; //want to be Edited by MagicCard Editor
public override void isActivated(PlayerInfo playerStatus)
{
if(playerStatus.Health < this.activateHealth)
return true;
else
return false;
}
}
There're many other condition and magic effect that can be switch to make different magic cards. So I declare the Condition and Effect to be interface. When I customize the Editor of Magic Card, I want its "base.OnInspectorGUI()" can Call the default editor of DyingActivateCondition, but it doesn't...
Is there a way other than customized all of the Magic Conditions myself? Or, are there some design that better than this? P.S. It should be very easy to use so that even people who know nothing about programing can edit the Cards. (In my case, the customized MagicCardEditor will provide a EnumMenu and a "Create" button so that other people can select the enum and hit "create" to create an Condition scriptableObject and attach it to the MagicCard.
Answer by SilentSin · Jan 14, 2015 at 12:53 PM
You probably want to look into making a property drawer for B.
If that doesn't work, I think you can create an instance of B's editor using:
Editor editor = Editor.CreateEditor(b);
Which you might be able to cast to your custom B editor class to call methods on it (or not cast it at all and just use the default OnInspectorGUI().
Your answer
Follow this Question
Related Questions
Custom Window with Hierarchy 1 Answer
Question About EditorGUILayout.BeginFadeGroup 1 Answer
Questions Regarding Images in Custom Inspector/Editor 1 Answer
Create a custom prefab stage 0 Answers