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 magnate · Nov 27, 2020 at 10:37 PM · c#inspectorcustom editor

Custom editor for inherited class but is not MonoBehaviour or ScriptableObject

Hi all, to begin, here's my code:

 [Serializable]
 public abstract class QuestTask
 {
     public string Description;
 }
 
 public enum QuestGoalType
 {
     Kill,
     Capture
 }
 
 [Serializable]
 public class KillQuestTask : QuestTask
 {
     public string Target;
     public int Amount;
 }
 
 [Serializable]
 public class CaptureQuestTask : QuestTask
 {
     public Item captureItem;
     public int Amount;
 }
 
 [Serializable]
 public class QuestGoal
 {
     public QuestGoalType questGoalType;
     public QuestTask questTask;
 }
 
 [Serializable]
 public class Quest
 {
     public string title;
     public string description;
     // .etc
     
     public List<QuestGoal> questGoalls = new List<QuestGoal>();
 }
 
 public class QuestGiver : MonoBehaviour
 {
     public Quest quests;
 }

How I should create an editor of QuestTask, in which I can change dynamically type of QuestGoalType and it will load the content of the inherited class. I mean, when I change the dropdown of enum on for example KillQuestTask, I should see all properties of KillQuestTask.

alt text

I want these classes to be serialized.

alt text

Or maybe there is some other way to achieve this effect? Easier way ...?

Thanks in advance to everyone guys.

img1.png (20.5 kB)
img2.png (25.4 kB)
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
0

Answer by ErikAndroid · Nov 28, 2020 at 08:28 AM

Have you tried using Scriptable Objects?

It will always be serialized and it gives us a more flexible way doing things.

alt text

Here is the changes (note that it is a demo):

 using System;
 using System.Collections.Generic;
 using UnityEngine;
 
  public class QuestTask : ScriptableObject
  {
      public string Description;
  }
  
  public enum QuestGoalType
  {
      Kill,
      Capture
  }
 
  [CreateAssetMenu]
  public class KillQuestTask : QuestTask
  {
      public string Target;
      public int Amount;
  }
  
  [CreateAssetMenu]
  public class CaptureQuestTask : QuestTask
  {
      public string captureItem;
      public int Amount;
  }
  
  [Serializable]
  public class QuestGoal
  {
      public QuestGoalType questGoalType;
      public QuestTask questTask;
  }
  
  [CreateAssetMenu]
  public class Quest : ScriptableObject
  {
      public string title;
      public string description;
      // .etc
      
      public List<QuestGoal> questGoals = new List<QuestGoal>();
  }
  
  public class QuestGiver : MonoBehaviour
  {
      public Quest quest;
  }
 



1.png (18.3 kB)
Comment
Add comment · Show 3 · 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 magnate · Nov 28, 2020 at 09:41 AM 0
Share

Yes, I tried Scriptable Objects, but I don't want to create every time separate new Quest Task. I would like to create all information dynamically in the Inspector.

avatar image ErikAndroid · Nov 28, 2020 at 12:45 PM 0
Share

You can try creating a CustomPropertyDrawer for the base class. Its worth trying.

avatar image magnate · Nov 28, 2020 at 01:19 PM 0
Share

@ErikAndroid, it is a good idea and I also tried this, but I think about an easier way. CustomPropertyDrawer is complicated. If I don't find any better solution, I will try again CustomPropertyDrawer. ;)

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

145 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Property Drawer SerializedProperty is null 2 Answers

Make a custom inspector that shows a group of variables in form of list 2 Answers

Multiple Cars not working 1 Answer

Show texture (image box) in inspector with custom editor [C#]? 3 Answers

Custom editor for the Unity Inspector 1 Answer


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