Extended Editor (11) _ the component cannot be edited

Source: Internet
Author: User

In unity, we can set the status for the component, such as the status that cannot be edited. Taking the transform component as an example, we can disable the original functions of the transform component. The Code is as follows:

Using unityengine; using unityeditor; using system. reflection; [customeditor (typeof (Transform)] The public class component cannot be edited: Editor {private editor m_editor; private void onenable () {m_editor = editor. createeditor (target, assembly. getassembly (typeof (editor )). getType ("unityeditor. transforminspector ", true);} public override void oninspectorgui () {If (guilayout. button ("Expand button") {} // start to Disable GUI. enabled = false; m_editor.oninspectorgui (); // Disable GUI termination. enabled = true; If (guilayout. button ("Expand button") {} // base. oninspectorgui ();}}

Similarly, use reflection to get the transform component, and disable the transform component by using gui. Enabled = false. The transform component cannot be edited. The effect is as follows:

In this case, the original functions of the transform component are disabled (gray indicates that the transform component cannot be edited), but this does not affect the two buttons that I expand up and down.

Can we choose whether to disable this component by ourselves? Of course, the Code is as follows:

Using unityengine; using unityeditor; Public Class components cannot be edited. 2 {[menuitem ("gameobject/3D object/lock", false, 0)] Static void lock () {If (selection. gameobjects! = NULL) {foreach (VAR gameobject in selection. gameobjects) {gameobject. hideflags = hideflags. noteditable ;}} [menuitem ("gameobject/3D object/lock/unlock", false, 1)] Static void unlock () {If (selection. gameobjects! = NULL) {foreach (VAR gameobject in selection. gameobjects) {gameobject. hideflags = hideflags. None ;}}}}

The effect is as follows:

In this case, you can select any game object and select 3d object> lock or unlock from the right-click menu ). The principle is to set hideflags for game objects. It should be noted that we do not have to set the hideflags of the game object, or we can set hideflags for a component separately. This will only affect one component, not all.

  PS:Hideflags can use bitwise OR (|) to maintain multiple attributes at the same time. The meaning of hideflags is quite understandable. You can enter your own code to debug it.

Hideflags. None clear status

Hideflags. dontsave setting object will not be saved (used only in edit mode and excluded during runtime)

Hideflags. dontsaveinbuild setting object will not be saved after building

Hideflags. dontunloadunuesdasset this object will not be detached when resources. unloadunusedasset () detaches useless Resources

Hideflags. hideanddontsave sets the object to be hidden and should not be saved

Hideflags. hideinhierarchy sets the object to be hidden in the hierarchical view.

Hideflags. hideininspector sets the object to be hidden in the control panel View

Hideflags. noteditable: the setting object cannot be edited.

Extended Editor (11) _ the component cannot be edited

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.