Controlling Object Visibility and Editability in Unity Using HideFlags
来源:互联网 发布:微信一键转发软件代理 编辑:程序博客网 时间:2024/06/04 18:59
Unity game objects and components have an interesting feature called HideFlags. This allows you to control whether a game object or component is visible, editable, persistent, or any combination thereof.
Both GameObject and MonoBehaviour inherit from the Object class which contains the hideFlags property. This property can be set to any of the valid values in the HideFlags enumeration. By default it is set to HideFlags.None. Below are some examples and explanations of various options.
To run these examples, I've created a script that allows you to choose a HideFlags
value and whether to set it on the game object or component. It sets the hideFlags
property in OnEnable, so it will run when the game starts, or you can use it in combination with ExecuteInEditMode to run it while in the editor.
using UnityEngine;public class HideFlagsSetter : MonoBehaviour{ public HideFlags customHideFlags; public enum Mode { GameObject, Component } public Mode setOn = Mode.GameObject; private void OnEnable() { if (setOn == Mode.GameObject) { gameObject.hideFlags = customHideFlags; } else if (setOn == Mode.Component) { hideFlags = customHideFlags; } }}
HideFlags.HideInHierarchy
This option hides your game object in the hierarchy view, and makes it not selectable in the scene view. This has no effect if set on a component.
HideFlags.HideInInspector
If set on a game object, this option hides all the components in the inspector.
If set on a component, this option only hides the component in the inspector.
HideFlags.NotEditable
If set on a game object, no components will be editable. The object will also not be selectable in the scene.
If set on a component, only that component will not be editable.
Other options include HideFlags.DontSaveInEditor, HideFlags.DontUnloadUnusedAsset, HideFlags.DontSaveInBuild,HideFlags.DontSave, and HideFlags.HideAndDontSave that mainly relate to scene and build persistence that I won't go into detail about here. More information about these can be found in the HideFlags Documentation.
You can download the example project to experiment with HideFlags using the script and example scene used in this post.
- Controlling Object Visibility and Editability in Unity Using HideFlags
- Using OBJECT, EMBED and APPLET Tags in Java Plug-in
- Object.hideFlags 隐藏标识
- unity中HideFlags~
- UNITY 5.2 HideFlags
- Using JPA and JAXB Annotations in the Same Object
- Unity学习 - Masking and clipping textures using shaders in NGUI
- Controlling servos using Ubuntu (linux server) and Python
- Unity 解决 An asset is marked with HideFlags.DontSave but is included in the build 问题。
- Using ActiveX Object in Qt
- HideFlags
- unity 项目build 的时候后报错An asset is marked with HideFlags.DontSave but is included in the build:
- unity 项目build 的时候后报错An asset is marked with HideFlags.DontSave but is included in the build:
- 【Unity】《Unity_API解析》 第四章 HideFlags类
- Using C object files in Delphi
- Business Object Validation Using Attributes in C#
- Object Oriented Analysis and Design Using UML
- Installing and Using the Torque Object Mapper
- uva 325 Identifying Legal Pascal Real Constants
- Python入门之循环分支
- 图像处理、计算机视觉、算法相关资源
- 文件系统使用总结
- C++常见内存错误汇总
- Controlling Object Visibility and Editability in Unity Using HideFlags
- vb.net 教程 3-2 窗体编程之窗体 4
- java-记录一个子串在整串中出现的次数
- C++ STL常用容器删除操作注意事項
- 穿衣的搭配--装饰模式
- 使用工厂方法模式实现各种不同分润规则
- 【BZOJ】1293 [SCOI2009]生日礼物 (这题有多种解法)
- gcc编译器的使用
- Js_面向对象_canvas_02