Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 VesmirPendel · Feb 16, 2016 at 09:02 AM · unity 5databaseinheritanceinventory systemitems

Working with Items and Class Inheritance for an RPG Item Database

So I've been coming up with a plan on making an item database, and that is to make it a List of type Item.

public List<Item> items = new List<Item>();

I want to place all of my items, whether it is a weapon, a consumable, or a quest item onto a single database. I am using a serializable Item class to hold the common data, and then I have a Weapon, Consumable, and Quest class (which are all inherited to Item) so that they have their own individual variables.

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 [System.Serializable]
 public class Item
 {
     public int itemID;
     public string itemName;
     public string itemDesc;
     public Image itemImage;
 
     public enum ItemType
     {
         None,
         Consumable,
         Quest
     }
     public ItemType itemType;
 }

And then a sample for the Consumable class would be

 using UnityEngine;
 using System.Collections;
 
 public class ItemConsumable : Item 
 {
     public int addHP;
     public int addMP;
 }

With the Item class serialized, I can edit each object in the database list via the inspector, but I am only able to edit variables in the Item class, and not on the child classes.

I was thinking of placing an enum to determine if the item is a weapon, a consumable, or etc,. Pop up an if statement and make Item as someItemType or whatever. This is probably wrong and I've done my research on attempting that.

Is there any other way for this?

NOTE: I will not be using XML.

Comment
Add comment · Show 1
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 Salmjak · Feb 16, 2016 at 02:13 PM 0
Share

You could try using a scriptableobject ins$$anonymous$$d. Here is a forum thread that will get you started if you choose to do it this way, and the tutorial referred to in the thread.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by phil_me_up · Feb 16, 2016 at 01:56 PM

As you've seen, there are limitations to what can be achieved simply by making the class serialisable. However, thankfully we can write our own inspectors for these things so you can totally customise not only what you can and can't see in the inspector, but also how they appear and how you can interact with them.

Do some reading up on: http://docs.unity3d.com/ScriptReference/Editor.OnInspectorGUI.html as a starting point.

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Visual Studio Code Mac (1.29.1) problem with class inheritance Unity (2018.2.17f1) 0 Answers

MongoDB C# authentication exception 0 Answers

Inventory with Upgradable Items and Varying Stats 2 Answers

Class inheritance for Item system question: Instance needs to be both Weapon and Ammo subclass 2 Answers

get_version can only be called from the main thread. 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