Unity3d SerializeField and serializefield

Source: Internet
Author: User

Unity3d SerializeField and serializefield

First, Unity will automatically serialize the Public variable. serialization means that the serialized variable has a value when it is read again. You do not need to assign a value again, because it has been saved. Then, what values will be displayed on the panel? The value already serialized, but not marked by HideInInspector. [HideInInspector] indicates hiding serialized values originally displayed on the panel. [SerializeField] indicates that private variables and protection variables that will not be serialized can be serialized, so they will be the value you assigned last time for the next read. 1. If a is a public serialization variable. 1.1 if you want to see a in the panel, use: public int a; 1.2 if you do not want to see a in the panel, use: [HideInInspector] public int; // In this way, a can be assigned a value by the code in the program, but it is not displayed on the panel and is set manually. 2. If a is a private serialization variable and you want to read and save it in the panel, use [SerializeField] private int a; 3. if a is a private serialized variable and you want to read it in the Panel but do not save it, use [HideInInspector] [SerializedField] private int; public int B {get {return a ;}}then displayed in the Editor, EditorGUILayout. labelField ("value", game. b. toString (); 4 if a is a private serialized variable, you do not want to perform any operations in the panel (do not want to see it or write it), but you want to assign a value to it in the program, so use. [HideInInspector] [SerializedField] private int a; public int B {get {return a;} set {a = value ;}}
 
For details about 4th, set and get, see the next article.

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.