Unity琐碎(1) 编辑器参数修改
2017-03-19 16:35
399 查看
今天在写编辑器面板的时候,突然发现如果面板参数变化的时候,不能实时修改表现效果(参数没有生效)。
就像上面的代码,只在启动的时候的会修改变量的数值,运行中修改编辑器中参数不会再去执行Awake的....
his function is called when the script is loaded or a value is changed in the inspector (Called in the editor only).
Use this function to validate the data of your MonoBehaviours. This can be used to ensure that when you modify date in an editor that the data stays within a certain range.
(2) 自定义编辑器
在自定义编辑器中访问更新数据相关的接口(代码不准确,意思表达清晰即可)
有些代码逻辑在Awake中不实现的,也可以尝试定义[[ExecuteInEditMode ]]解决(https://docs.unity3d.com/ScriptReference/ExecuteInEditMode.html)解决编辑器下的问题。
public int monsterCount ; void Awake() { monsterCount = Mathf.Clamp(monsterCount, 0, 1000); }
就像上面的代码,只在启动的时候的会修改变量的数值,运行中修改编辑器中参数不会再去执行Awake的....
解决思路
(1) MonoBehavior.OnValidate()his function is called when the script is loaded or a value is changed in the inspector (Called in the editor only).
Use this function to validate the data of your MonoBehaviours. This can be used to ensure that when you modify date in an editor that the data stays within a certain range.
(2) 自定义编辑器
在自定义编辑器中访问更新数据相关的接口(代码不准确,意思表达清晰即可)
public int monsterCount ; public int MonsterCount { set{monsterCount = value ; UpdateParam() ;} } void Awake() { monsterCount = Mathf.Clamp(monsterCount, 0, 1000); } void UpdateParam() { monsterCount = Mathf.Clamp(monsterCount, 0, 1000); }
附加
有些代码逻辑在Awake中不实现的,也可以尝试定义[[ExecuteInEditMode ]]解决(https://docs.unity3d.com/ScriptReference/ExecuteInEditMode.html)解决编辑器下的问题。
相关文章推荐
- Unity 琐碎5 : 利用反射设置编辑器参数
- Unity 控制面板transform3个参数的获得和修改
- 巧妙地批量修改unity本地文件的参数
- Unity编辑器下获取动画的根运动状态并修改
- Unity编辑器 - 资源修改立即写入磁盘AssetDataBase.SaveAssets()
- unity 2017.3 动态修改粒子特效参数
- Unity中动态修改游戏中任意参数的框架
- unity 编辑器扩展 修改代码的值
- UnityProject面板中右键创建新的Lua脚本以及修改文件默认打开方式的编辑器
- Unity-【编辑器扩展】一键批量修改预设UGUI Text字体
- unity 扩展编辑器一(修改编辑器名称)
- Unity 3D - 编辑器扩展之修改PackingTag
- Unity编辑器拓展之五:修改脚本icon
- Unity一键修改NGUI字体的编辑器脚本
- Unity2017.1.0f3 问题记录(动态修改ParticleSystem中的相关参数)
- dedecms修改后台编辑器参数GetEditor
- Unity编辑器扩展之修改扩展脚本的成员变量
- unity编辑器拓展六——不实例化的情况下修改Assets下面的文件
- unity 修改编辑器
- pligg9.7beta搭起后HTML编辑器插件的安装(-fckeditor的配置与修改变相支持中文文件名:默认上传后不能正常调用-)就像csdn的这个编辑器