IExposedPropertyTable与ExposedReference的使用
近期回顾Dead of the Book demo时,看见了它们的运用。感觉主要是用于ScriptableObject资源和Scene资源解耦;
并将这类做法规范化。
做一个小测试,IExposedPropertyTable做容器,存放具体目标对象:
public class ExposeTableObj : MonoBehaviour, IExposedPropertyTable
{
[System.Serializable]
public struct Info
{
public PropertyName id;
public Object value;
} [SerializeField] private Info[] infos; public void ClearReferenceValue(PropertyName id)
{
infos = System.Array.Empty<Info>();
} public Object GetReferenceValue(PropertyName id, out bool idValid)
{
idValid = false; for (int i = 0; i < infos.Length; i++)
{
var info = infos[i];
if (info.id == id)
{
idValid = true;
return info.value;
}
} return null;
} public void SetReferenceValue(PropertyName id, Object value)
{
}
}
使用者:
public class ExposeTableUser : MonoBehaviour
{public ExposeTableObj exposeTable; private void Start()
{
ExposedReference<GameObject> myReference = new ExposedReference<GameObject>();
myReference.exposedName = "myGoObj";
GameObject go = myReference.Resolve(exposeTable);
Debug.Log(go);
}
}
这里直接动态创建了myReference,如果作为成员字段也可以被序列化,但是unity不会初始化匹配的exposedName。
然后在Start里,通过exposedName匹配了对应的对象。Unity用Guid作为exposedName,当然这个测试用了常规字符串也没问题。
面板配置:

IExposedPropertyTable与ExposedReference的使用的更多相关文章
- Book of the Dead 死者之书Demo工程回顾与学习
1.前言 一转眼离Book of the Dead Environment Demo开放下载已过去多年,当时因为技术力有限,以及对HDRP理解尚浅, 所以这篇文章一直搁浅到了现在.如今工作重心已转向U ...
- Timeline扩展功能实践指南
转载于http://forum.china.unity3d.com/forum.php?mod=viewthread&tid=32842,介绍了timeline的轨道扩展 Timeline功能 ...
随机推荐
- java 、abstract修饰的【抽象类】【比如几何图形类】
现实中问题引入 现实中一类具有共同特征的类,但是无法具体实现.,比如我们定义了一个几何类,叫做Shape,我们有一个方法要计算周长,直接在每个子类实现虽然可以,但是无法通过Shape定义的实例来访问到 ...
- libevent源码学习(13):事件主循环event_base_loop
目录开启事件主循环执行事件主循环校对时间 阻塞/非阻塞处理激活队列中的event事件主循环的退出event_base_loopexitevent_base_loopbreak开启事件主循环 ...
- JAVA获取六位随机数
public static String getSixNum() { String str = "0123456789"; StringBuilder sb = new Strin ...
- MySQL查找数据中相同的数据,并进行删除
查找表中多余的重复记录,重复记录是根据某个字段来判断 select * from 表名 where 字段 in (select 字段 from 表名 group by 字段 having count( ...
- Vue总结第五天:vue-router (使用模块化(创建Vue组件)机制编程)、router-link 标签的属性、路由代码跳转、懒加载、路由嵌套(子路由)、路由传递数据、导航守卫)
Vue总结第五天:vue-router ✿ 路由(器)目录: □ vue中路由作用 □ vue-router基本使用 □ vue-router嵌套路由 □ vue-router参数传递 □ ...
- Qt之使用qss设置Qwidget背景色无效解决
如题 解决方案 添加头文件 #include <QStyleOption> 重写函数paintEvent 内容如下 void statistics_assistant::paintEven ...
- 【LeetCode】210. Course Schedule II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 拓扑排序,BFS 拓扑排序,DFS 参考资料 日期 ...
- 【LeetCode】855. Exam Room 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/exam-roo ...
- (数据科学学习手札133)利用geopandas绘制拓扑着色地图
本文示例代码及文件已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 我们在绘制某些地图时,为了凸显出每个独立的 ...
- 理解HTTP协议中的multipart/form-data
前提 之前在写一个通用HTTP组件的时候遇到过媒体(Media)类型multipart/form-data的封装问题,这篇文章主要简单介绍一下HTTP协议中媒体类型multipart/form-dat ...