unity, SerializedObject.FindProperty不要写在Editor的OnEnable里,要写在OnInspectorGUI里
如果像下面这样写:
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
using UnityEngine.Assertions.Must;
[CustomEditor(typeof(xxxControl))]
public class xxxControlEditor : Editor
{
SerializedProperty m_a;
void OnEnable(){
m_a=serializedObject.FindProperty ("m_a");
}
public override void OnInspectorGUI()
{
/////DrawDefaultInspector();
serializedObject.Update ();
EditorGUILayout.PropertyField(m_a,true);
serializedObject.ApplyModifiedProperties ();
}
}
则在其它Editor或EditorWindow脚本的中调用
Editor _editor=Editor.CreateEditor(xxxObj.GetComponent<xxxControl>());
就会报如下错误:
NullReferenceException: (null)
UnityEditor.SerializedObject..ctor (UnityEngine.Object[] objs) (at C:/buildslave/unity/build/artifacts/generated/common/editor/SerializedPropertyBindings.gen.cs:72)
UnityEditor.Editor.GetSerializedObjectInternal () (at C:/buildslave/unity/build/artifacts/generated/common/editor/EditorBindings.gen.cs:151)
UnityEditor.Editor.get_serializedObject () (at C:/buildslave/unity/build/artifacts/generated/common/editor/EditorBindings.gen.cs:144)
xxxControlEditor.OnEnable () (at Assets/??/Editor/xxxControlEditor.cs:??)
如果将SerializedObject.FindProperty从OnEnable中改到OnInspectorGUI中,即:
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
using UnityEngine.Assertions.Must;
[CustomEditor(typeof(xxxControl))]
public class xxxControlEditor : Editor
{
SerializedProperty m_a;
void OnEnable(){
}
public override void OnInspectorGUI()
{
/////DrawDefaultInspector();
m_a=serializedObject.FindProperty ("m_a");//serializedObject.FindProperty should be called in OnInspectorGUI() instead of OnEnable()
serializedObject.Update ();
EditorGUILayout.PropertyField(m_a,true);
serializedObject.ApplyModifiedProperties ();
}
}
则不会出现上述错误。
unity, SerializedObject.FindProperty不要写在Editor的OnEnable里,要写在OnInspectorGUI里的更多相关文章
- 关于python命令在editor里编写与在interpreter里的编写的不同之处
关于python命令在editor里编写与在interpreter里的编写的不同之处 其实用这个标题,我心里还是有点胆怯的.作为一个python入门的小白,不,编程入门的小白,我还不太确定我对edit ...
- CSS规范--春风十里不如写好CSS
先吟几句: 最近看了看春风十里不如你,本来很少看剧的,暑假有点闲就看了,感觉不错,挺喜欢这部剧,就套了个名字,嘿嘿嘿.剧里面印象深刻的是<致橡树>这首诗,念几句: 我如果爱你,绝不像攀援的 ...
- react 生命周期钩子里不要写逻辑,否则不生效
react 生命周期钩子里不要写逻辑,否则不生效,要把逻辑写在函数里,然后在钩子里调用函数,否则会出现问题.
- HBase的写事务,MVCC及新的写线程模型
MVCC是实现高性能数据库的关键技术,主要为了读不影响写.几乎所有数据库系统都用这技术,比如Spanner,看这里.Percolator,看这里.当然还有mysql.本文说HBase的MVCC和0.9 ...
- 我最近用Python写了一个算法,不需要写任何规则就能自动识别一个网页的内容
我最近用Python写了一个算法,不需要写任何规则就能自动识别一个网页的内容,目前测试了300多个新闻网站的新闻页,都能准确识别
- 郑晔谈 Moco 框架的开发:写一个好的内部 DSL ,写一个表达性好的程序
作者:张龙 出处:http://www.infoq.com/cn/news/2013/07/zhengye-on-moco 郑晔谈Moco框架的开发:写一个好的内部DSL,写一个表达性好的程序 作者 ...
- [golang]写了一个可以用 go 来写脚本的工具:gosl
转自:https://golangtc.com/t/53cca103320b52060a000030 写了一个可以用 go 来写脚本的工具:gosl 代码和使用说明可以看这里: http://gith ...
- ProjectTool写白包工具,秒级别写H5游戏壳包,可视化操作,极易使用,支持Swift、Objecive-C双语言
这是自动写白包工具,秒级别写H5游戏壳包,可视化操作,极易使用,支持Swift.Objecive-C双语言 扣扣交流群:811715780 [ 官网下载 ] 这是一个白包目录示例 ProjectToo ...
- Unity扩展编辑器--类型1:Editor Windows
Extending the Editor Unity允许你使用自己定制的inspectors和Editor Windows扩展编辑器,并且你可以使用定制的Property Drawers定义属性集在i ...
随机推荐
- 算法(第4版)-1.1.7 API
总结:本小姐讲述了API的定义.作用以及一些Java库的举例. 重点: 1.API的目的是将调用和实现分离:除了API中给出的信息,调用者不需要知道实现的其他细节,而实现也不应考虑特殊的应用场景.
- 关于Android Studio里的Gradle,你所需要知道的都在这里了
Gradle介绍 Gradle是一个先进的build toolkit,可以方便的管理依赖包和定义自己的build逻辑.到底有多先进,Android Studio官方集成Gradle,Google还专门 ...
- My97DatePicker日期控件用法
用法很简单,主要演示都在myDate.html <meta http-equiv="content-type" content="text/html; chars ...
- 101+ Manual and Automation Software Testing Interview Questions and Answers
101+ Manual and Automation Software Testing Interview Questions and Answers http://www.softwaretesti ...
- php中将文中关键词高亮显示,快捷方式可以用正则
php将文中关键词高亮显示,可以用正则表达式 $text = "Sample sentence from AnsonCheung.tk, regular expression has bec ...
- Customize R initiallization in Mac
First, we need to find a "Rprofile" document. locate Rprofile Then we find Rprofile docume ...
- Java-->一个只能运行十次的程序
--> 感觉没什么营养的样子啊... package com.dragon.java.tensoftware; import java.io.BufferedReader; import jav ...
- ZSDR101-跑成品MRP
*&---------------------------------------------------------------------**& Report ZSDR101*&a ...
- Codeforces Round #303 (Div. 2) D 贪心
D. Queue time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- jQuery弹出层始终垂直居中相对于屏幕或当前窗口
把弹出层的位置设为fixed,设置top:50%,然后获取当前元素的整体的高度height,用获取的高度height/2,设置margin-top:-height/2.即可把当前的弹出层始终垂直居中于 ...