Unity in Hideininspector and Serializefield and serializable

Source: Internet
Author: User

First, Unity automatically serializes the public variable, which means that the serialized variable is valued when it reads unity again, and does not require you to assign a value again because it has been saved.
Then, what value will be displayed on the panel? The
has been serialized, but there is no value marked with Hideininspector.

[Hideininspector] means that the serialized values that were originally displayed on the panel are hidden.

[Serializefield] means that private variables and protection variables that would not otherwise be serialized can be serialized, so that they will be the value of your last assignment at the next read.

1 If name is a public serialization variable.
1.1 If you want to see the name in the panel, then use:
public int name;

1.2 If you do not want to see the name in the panel, then use:
[hideininspector]
public int name;
This way, name can be assigned to code in the program, but it will not be seen in the panel and set to the assigned value manually.

2 If name is a private serialization variable that you want to read and save in the panel, then use:
[Serializefield]
Private int name;

3. If name is a private serialization variable and you want to read it in the panel, but do not save it, then use:
[Hideininspector][serializedfield]
Private int name;
public int name{
    Get{return Name;}
}
is then displayed in editor,
Editorguilayout.labelfield ("value", game. Name.tostring ());

4 If name is a private serialization variable, you do not want to do anything in the panel (you do not want to see it, you do not want to write it), but you want to assign a value to it in the program.
[Hideininspector][serializedfield]
Private int name;
public int name{
    Get{return Name;}
    set{name = value;}
}

You can also mark a class as [Serializable]

[Serializable]

public class Person
{
[Serializefield]
private string name;
public string Name
{
get {return name;}
set {name = value;}
}
public string age;
}

And then:

[Serializefield]
Private person P = new person ();

Both name and age are displayed in the Unity panel

Unity in Hideininspector and Serializefield and serializable

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.