Unity属性(Attributes)
Unity3d中的属性(Attributes)
Attributes属性属于U3D的RunTimeClass,所以加上以下的命名空间是必须的了。
using UnityEngine;
using System.Collections;
0.Property Attributes变量属性(放在方括号内变量申明前)(常用)
1/ Range(min,max)
如: [SerializeField, Range(0, 5)]
int count;
如: [SerializeField, Range(0,5)]
int[] counts;
2/ Multiline 多行
如: [Multiline]
public string b;
3/ TextArea 文本区域
可以设置的最大值和最小值的行数
如: [TextArea]
public string c;
4/ ContextMenu上下文菜单
如: [ContextMenu("Hello World!")]
void HelloWorld()
{
Debug.Log("Hello World!");
}
5/ ContextMenuItem(右击变量调用方法)
如:[ContextMenuItem("Resetvalue","resetValue")]
public int e=100;
public void resetValue(){
e=50;
}
6/ Head("This is a variable") 头显示
7/ Space(5)
设置字段与字段之间的空间
8/ [Tooltip("this is a nasha!")]
如果鼠标光标是在字段上,显示的说明文本。
1.AddComponentMenu 添加组件菜单
这函数只是起方便用,原本的脚本(组建)都会在“Component/Script”菜单下,在类之前声明一下这个,它便可以出现在"Componet"菜单下的任何位置。说明指的是要重启U3D才能显示,不过测试貌似直接可以显示。
[AddComponentMenu("MyPhysic/PhysicType")]
public class PhysicType: MonoBehaviour
{
}
2.ContextMenu 上下文菜单
这个译名我觉得很不自然,其实上下文算是啥东西……这个函数是在Inspector的脚本中加一个触发事件,就是删除脚本重置脚本按钮的那个小拉菜单中,具体很难说清位置,所以我截了个图。
public class Attributes : MonoBehaviour {
[ContextMenu("Hello World!")]
void HelloWorld()
{
Debug.Log("Hello World!");
}
}
3.ExecuteInEditMode 在Editor模式下运行
跟名字一样,在编辑器中运行。不过有三种函数的调用方式。
a- "Update()" is only called when something in the scene changed.
b- "OnGUI()" is called when the Game View recieves an Event.
c- "OnRenderObject()" and the other rendering callback functions are called on every repaint of the Scene View or Game View.
[ExecuteInEditMode]
public class ExecuteInEditModeTest: MonoBehaviour
{
private Vector3 vec_Rotation = new Vector3(0.0f, 0.5f, 0.0f);
//Rotate all the time
void OnRenderObject()
{
transform.Rotate(vec_Rotation);
}
}
4.HideInInspector 在检视面板中隐藏
public class HideInspectorTest : MonoBehaviour
{
[HideInInspector]
public Transform m_Target;
void Start()
{
m_Target = GameObject.Find("test").transform;
}
}
5.RequireComponent 必须要有相应的组建
加入一个组建之前必须存在另一个相应的组建,若没有则自动创建。这个在项目中非常有必要用到,尤其是项目人员比较多的时候(大于三四个)。
[RequireComponent (typeof (Rigidbody))]
public class RequireComponentTest : MonoBehaviour {
void FixedUpdate() {
rigidbody.AddForce(Vector3.up);
}
}
6.NonSerialized 不被序列化
不被序列化该变量,且不显示在检视面板中。
public class Test {
[System.NonSerialized]
public int i_Helloword = 5;
}
7.Serializable 可序列化
这个属性可以让子类(继承类)的变量属性显示在检视面板中,也能序列化它。(JS的话完全不需要这个属性。)
//SerializableTest.cs
[System.Serializable]
public class SerializableTest
{
public int p = 5;
public Color c = Color.white;
}
//SerializableTest2.cs
public class SerializableTest2 : MonoBehaviour
{
public SerializableTest test;
}
8.SerializeField 序列化域(强制序列化)
这里写得比较清楚,可以将私有变量序列化,将U3D的内建变量序列化等。
Unity属性(Attributes)的更多相关文章
- 给iOS开发新手送点福利,简述文本属性Attributes的用法
给iOS开发新手送点福利,简述文本属性Attributes的用法 文本属性Attributes 1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSF ...
- IOS开发UI基础文本属性Attributes
文本属性Attributes 1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSFontAttributeName : [UIFont systemFo ...
- Unity属性的封装、继承、方法隐藏
(一)Unity属性封装.继承.方法隐藏的学习和总结 一.属性的封装 1.属性封装的定义:通过对属性的读和写来保护类中的域. 2.格式例子: private string departname; // ...
- iOS- 详解文本属性Attributes(转)
iOS- 详解文本属性Attributes 1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSFontAttributeName : [UIFont s ...
- (转)Unity3d中的属性(Attributes)整理
Attributes属性属于U3D的RunTimeClass,所以加上以下的命名空间是必须的了.其它倒没什么需要注意的.本文将所有运行属性过一遍罢了. using UnityEngine; using ...
- Unity3d中的属性(Attributes)整理
Attributes属性属于U3D的RunTimeClass,所以加上以下的命名空间是必须的了.其它倒没什么需要注意的.本文将所有运行属性过一遍罢了. using UnityEngine; using ...
- (转载)Unity3d中的属性(Attributes)整理
附加: float字段检视面板修改:[Range(1,10)] 对属性进行分组:[Header("xxx")] 工具栏中调用方法,类文件需在Editor文件夹中:[MenuIte( ...
- zencart批量插入TEXT文本属性attributes
有时候上传的产品与多级分类比较多,在后台添加文本属性如Name,Number等需要顾客自定义的内容就比较费神了.现在只需将以下代码保存为insert_attributes.php,变量$options ...
- 文本属性Attributes
1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSFontAttributeName : [UIFont systemFontOfSize:_fontS ...
随机推荐
- 项目结构的设计(iOS篇)
项目结构的设计(iOS篇) 本文附带源码:YoungHeart-Chapter-02.zip 在设计任何一个框架之前,都应规划好项目结构. 假定Git作为我们的项目管理工具.我们要建立两个仓库,一个用 ...
- VPN pptp on linuxmint13/ubuntu12.04/debian VPS
VPN is a great thing when you are forced to be stuck somewhere. on ubuntu, you need to check out whe ...
- 学习OpenCV:滤镜系列(15)——羽化(模糊边缘)
============================================== 版权所有:小熊不去实验室CSDN博客 ================================== ...
- Windows 8.1 Preview的新功能和新API
http://msdn.microsoft.com/en-us/library/windows/apps/bg182410 App打包 新的App程序包将使App的提交更简单.资源包可以让你提供附加的 ...
- php设计模式----工厂模式
工厂模式主要是为了代码执行的时候更灵活地new对象,就像工厂流水线一样,批量生产出产品. 目的:简化对象生成过程,更加灵活. 例子如下: <?php /** * User: freephp * ...
- java中的public,protected,private权限修饰
public和private基本没问题,主要是默认的和protected之间的区别 同一包中默认的和protected一样,所以来看看不同包的情况 看下如下代码,两个类位于不同包: public cl ...
- Python学习笔记---形式参数(parameter)和实际参数(argument)
def mydemo(name): '函数定义过程中的name是叫形参' #因为它只是一个形式,表示占据一个参数位置 print('传递进来的' + name + '叫做实参,因为它是具体的参数值!' ...
- Linux下的暴力密码在线破解工具Hydra安装及其组件安装-使用
Linux下的暴力密码在线破解工具Hydra安装及其组件安装-使用 hydra可以破解: http://www.thc.org/thc-hydra,可支持AFP, Cisco AAA, Cisco a ...
- 使用Gradle编译release apk报错:Please correct the above warnings first
在开发SDK的过程中,遇到了一个研发,使用了自己的SDK之后遇到了各种问题,于是我们自己帮忙接入. 所有代码都接入完成之后,准备export出一个release包,但是此时却报错: 此时出现了很多的w ...
- 关于对HandlerThread的了解
在Android中经常需要创建一个循环线程,有耗时操作时候,放到里面去操作,如果没有耗时操作,就让该线程处于等待,但是不要杀死它, 最好不要一旦有耗时任务,就立刻创建一个新线程,因为会有性能问题. H ...