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
2
Question by LegionIsTaken · Jan 25, 2012 at 02:44 PM · c#classpublic

Defining a public class in C#

Hi, I am starting to really get my hands deep in regards of C#, but I really don't get how you define a class in C#(a class that is view-able in the Inspector)

In regards of JavaScript you define a class like this:

 class className{
 //Whatever
 }
 
 var CN : className; // This is what I dont get in C#

(That example is view-able and editable in the inspector)

In C# I currently got:

    public class className{
    //Whatever
    }

(This class won't show in the Inspector)

My question is; how can I make a class(in C#) show in the editor? I looked at the Microsoft C# reference, but it didn't help me that much.

Any help would be much appreciated.

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
6
Best Answer

Answer by syclamoth · Jan 25, 2012 at 02:50 PM

Simple- you need to tell the compiler that a given class should be able to be shown in the editor using the 'System.Serializable' attribute. In this case, use it like this-

 [System.Serializable]
 public class Foo
 {
     public string text;
     public int number;
     public float value;
 }
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 LegionIsTaken · Jan 25, 2012 at 04:17 PM 0
Share

Thank, you. It really seams legit, and I checked the Scripting Reference, but it wont "Serialize" or show the class in the editor. Even when just copying and pasting you script(or the one from the Scripting reference) it still won't show. I also tried [SerializeField], but that wont show the class either. Any help would be very appreciated.

avatar image karl_ · Jan 25, 2012 at 05:08 PM 2
Share

If your class only contains data and does not need to be attached to a gameobject, you can also inherit from ScriptableObject, which does essentially the same thing as the [System.Serializable] tag. Also, to get it to show in the inspector you need to create a variable for it. In Syclamoth's example, in your other class, create it like so:

public foo fooInstance;

avatar image LegionIsTaken · Jan 25, 2012 at 06:15 PM 0
Share

Thank you very much, both of you, it works!

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

6 People are following this question.

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

Related Questions

Field is never assigned to and will always have its default value. 0 Answers

Field is never assigned to, and will always have its default value 3 Answers

How to make classes/structs public to all scripts 0 Answers

an object reference is required to access non static member problem 0 Answers

Multiple Cars not working 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