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 /
  • Help Room /
avatar image
0
Question by LT23Live · Dec 19, 2015 at 06:29 PM · arraycustom-inspectoritemmonobehavior

Custom Editor from a Non-Monobehavior Script

So I am new to a custom editor, but the system I want to write is big for my production. I am essentially working on an item library for the random drops when enemies die, or what a chest/pickup box should be filled with.

I have a simple item script (below) using UnityEngine; using System.Collections;

 public enum ItemType
 {
     Junk,
     Quest,
     Weapon,
     Trap,
     Health,
     AntiVirus,
     Armor
 }
 
 public enum WeaponType
 {
     Ranged,
     Melee,
     Thrown
 }
 
 public enum HandRequirements
 {
     OneHanded,
     TwoHanded
 }
 
 public enum ArmorType
 {
     Head,
     Torso,
     Hands,
     Legs,
     Feet
 }
     
 [System.Serializable]
 public class Item: MonoBehaviour
 {
     //ItemInfo itemInfo;
     public ItemType itemType;
     public string itemName;
     public string itemDescription;
     public int weight;
     public int value;
     public int hpValue {get;set;}
     public int avValue {get;set;}
     public int tier {get;set;}
     public int questID {get;set;}
     public Vector2 attackValue {get;set;}
     public WeaponType weaponType {get;set;}
     public HandRequirements handRequirements {get;set;}
     public Vector2 defenseValue {get;set;}
     public ArmorType armorType {get;set;}
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }
 

and a custom editor, which so far works pretty fine. (below)

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 
 [CanEditMultipleObjects]
 [CustomEditor (typeof(Item)), CanEditMultipleObjects]
 public class ItemEditor : Editor 
 {
     public override void OnInspectorGUI ()
     {
         Item myItem = (Item)target;
         DrawDefaultInspector();
 
         switch (myItem.itemType)
         {
             case ItemType.AntiVirus:
                 myItem.avValue = EditorGUILayout.IntField ("AntiVirus Effectiveness",myItem.avValue);
                 if (myItem.tier > 4)
                 {
                     myItem.tier = 4;
                 }
                 
                 if (myItem.tier < 1)
                 {
                     myItem.tier = 1;
                 }
                 break;
 
         case ItemType.Armor:
             //myItem.armorType = EditorGUILayout.EnumPopup ("Armor Type", myItem.armorType);
             myItem.defenseValue = EditorGUILayout.Vector2Field ("Defense Value", myItem.defenseValue);
             break;
 
         case ItemType.Health:
             myItem.tier = EditorGUILayout.IntField("Class", myItem.tier);
             myItem.hpValue = EditorGUILayout.IntField ("AntiVirus Effectiveness",myItem.hpValue);
             if (myItem.tier > 4)
             {
                 myItem.tier = 4;
             }
             
             if (myItem.tier < 1)
             {
                 myItem.tier = 1;
             }
             break;
 
         case ItemType.Quest:
             myItem.questID = EditorGUILayout.IntField ("Class",myItem.questID);
             break;
 
         case ItemType.Trap:
             myItem.tier = EditorGUILayout.IntField ("Trap Tier",myItem.tier);
             myItem.attackValue = EditorGUILayout.Vector2Field ("Trap Damage", myItem.attackValue);
             break;
 
         case ItemType.Weapon:
             myItem.attackValue = EditorGUILayout.Vector2Field ("Attack Value",myItem.attackValue);
             break;
         }
     }
 }
 

The problem is, I want to turn the item script into a non-monobehavior class and have it accessed as an array of "Item" from another script. When i do that the editor script throws an error that I do not know how to fix. (below)

Cannot convert type UnityEngine.Object' to Item'

If anyone knows how to fix my problem and/or a better way to go about writing this please let me know. I appreciate your time!

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 LT23Live · Dec 26, 2015 at 06:15 AM 0
Share

Nobody can help me?!

0 Replies

· Add your reply
  • Sort: 

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

34 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

Related Questions

How can I modify 'SerializedProperty' that contain 'Array' in Custom inspector? 0 Answers

Need help checking if an item slot is filled 1 Answer

PropertyDrawer for Array 2 Answers

Inventory System with Randomly Generated Loot 2 Answers

Array index is out of range? 4 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