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 ...
随机推荐
- My_Python的常用函数.
范围生成函数 class range(object) | range(stop) -> range object | range(start, stop[, step]) -> range ...
- BZOJ 1954 The xor-longest Path
问题转化为一些数里面选两个数异或和最大. #include<iostream> #include<cstdio> #include<cstring> #includ ...
- css3控制内容的可选择性
<!doctype html><html> <head> <meta charset="UTF-8"> <meta name= ...
- 著名的安装制作软件InnoSetup的源码及示例源码-The installation of a well-known software s source code and sample InnoSetup source
@echo off rem Inno Setup rem Copyright (C) 1997-2007 Jordan Russell rem Portions by Martijn Laan rem ...
- 双系统安装要点 - imsoft.cnblogs
1.用磁盘工具 取消当前激活分区,并隐藏当前激活分区2.按照普通的形式安装系统 Ghost安装和简单安装都可以3用修复启动项工具 修复之前处隐藏的系统启动项 OK,再就不会看到烦人的蓝屏了!
- hdu 5187 zhx's contest
题目分析如果n=1,答案是1,否则答案是2n−2. 证明:ai肯定是最小的或者最大的.考虑另外的数,如果它们的位置定了的话,那么整个序列是唯一的. 那么ai是最小或者最大分别有2n−1种情况,而整个序 ...
- linux死锁检测的一种思路
前言: 上一篇博文讲述了pstack的使用和原理. 和jstack一样, pstack能获取进程的线程堆栈快照, 方便检验和性能评估. 但jstack功能更加的强大, 它能对潜在的死锁予以提示, 而p ...
- ZPPR032-批量展BOM
*-----------------------------------------------------------------------REPORT zppr032 NO STANDARD P ...
- cdoj 482 优先队列+bfs
Charitable Exchange Time Limit: 4000/2000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Othe ...
- leetcode之反转链表
原文链接:点击打开链接 Reverse a singly linked list A linked list can be reversed either iteratively or recursi ...