Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Joshua P. R. Pan · Jan 14, 2015 at 12:33 PM · custom editorcustom-inspector

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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().

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Baste · Jan 14, 2015 at 01:33 PM 0
Share

Did not know about CreateEditor. Thanks a bunch!

avatar image Joshua P. R. Pan · Jan 15, 2015 at 08:56 AM 0
Share

Thanks, that help a lot!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Custom Window with Hierarchy 1 Answer

Custom Inspector: Making Individual Vertical Containers and Dynamically Adding & Removing Child Elements 1 Answer

Question About EditorGUILayout.BeginFadeGroup 1 Answer

Questions Regarding Images in Custom Inspector/Editor 1 Answer

Create a custom prefab stage 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges