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 WhisperXD · Apr 29, 2019 at 05:47 AM · listchangenameelement

change the name of List elements in the inspector

I tried to do it here

but not work, i make a script : NamedArrayAttribute:

 using UnityEngine;
  
 public class NamedArrayAttribute : PropertyAttribute
 {
     public readonly string[] names;
     public NamedArrayAttribute(string[] names) { this.names = names; }
 }

PropertyDrawer:

 using UnityEngine;
 using UnityEditor;
  
 [CustomPropertyDrawer (typeof(NamedArrayAttribute))]public class NamedArrayDrawer : PropertyDrawer
 {
     public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
     {
         try {
             int pos = int.Parse(property.propertyPath.Split('[', ']')[1]);
             EditorGUI.ObjectField(rect, property, new GUIContent(((NamedArrayAttribute)attribute).names[pos]));
         } catch {
             EditorGUI.ObjectField(rect, property, label);
         }
     }
 }

but namespace name "NamedArrayAttribute" could not be found alt text

cannot-find.png (11.6 kB)
Comment
Add comment · Show 2
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 Hellium · Apr 29, 2019 at 06:42 AM 0
Share

Do you have multiple assemblies in your project? Have you tried to use [NamedArray] attribute ins$$anonymous$$d of [NamedArrayAttribute]?

avatar image WhisperXD Hellium · Apr 29, 2019 at 07:35 AM 0
Share

yeah, still not find it alt text

alt text

1 Reply

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

Answer by Bunny83 · Apr 29, 2019 at 12:17 PM

Make sure you declared your "NamedArrayAttribute" inside a runtime class, not inside an editor file. The attribute need to be part of the runtime. If you declare it inside an editor script it is not available for your runtime scripts. So you can not declare the attribute definition inside the same file as your propertydrawer.


It's best practise to place the attribute definition in a seperate file that has the filename matching with the defined type. So create a "NamedArrayAttribute.cs" file somewhere inside your assets folder but not inside an editor folder.

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 Bunny83 · Apr 29, 2019 at 12:23 PM 0
Share

ps: you may want to change the attribute constructor to take a params array so the initialization is simpler. Without the params keyword you have to do

 [NamedArray(new string[] {"str1", "str2", "str3", "str4"})]

with the params keyword you can simply do

 [NamedArray("str1", "str2", "str3", "str4")]

Even the the effect is the same it's simpler to use. The params keyword is essentially syntactic sugar for the first variant. So the array creation is done by the compiler for you.

avatar image WhisperXD · Apr 30, 2019 at 04:49 AM 0
Share

thanks,, ^_^

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

109 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

Related Questions

A node in a childnode? 1 Answer

Explanation on how to use LIST<> in UnityScript 2 Answers

How to see what element is the current one 2 Answers

how can i check if there is a blanc spot in my list 3 Answers

Linq OrderBy GameObject's name Numerical 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