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.