近期回顾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的使用的更多相关文章

  1. Book of the Dead 死者之书Demo工程回顾与学习

    1.前言 一转眼离Book of the Dead Environment Demo开放下载已过去多年,当时因为技术力有限,以及对HDRP理解尚浅, 所以这篇文章一直搁浅到了现在.如今工作重心已转向U ...

  2. Timeline扩展功能实践指南

    转载于http://forum.china.unity3d.com/forum.php?mod=viewthread&tid=32842,介绍了timeline的轨道扩展 Timeline功能 ...

随机推荐

  1. Django modules模块

    http://www.cnblogs.com/wupeiqi/articles/5246483.html

  2. ligerUI问题

    1.checkboxColWidth:990,Grid的复选框的宽度设置为什么不起作用. 2.当grid出现横线不对齐时,可以设置detailColWidth:90,属性进行设置.此属性好像只是针对复 ...

  3. axiso 高级封装

    ​ import axios from 'axios'; import qs from 'qs'; const Unit = { async getApi(ajaxCfg){ let data = a ...

  4. JS中使用reconnecting-websocket实现websocket断开自动重新连接

    这里用了第三方的js 官方地址:https://github.com/joewalnes/reconnecting-websocket 引入js reconnecting-websocket.min. ...

  5. 【LeetCode】1438. 绝对差不超过限制的最长连续子数组 Longest Continuous Subarray With Absolute Diff Less Than or Equal t

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 滑动窗口 日期 题目地址:https://leetco ...

  6. 【LeetCode】663. Equal Tree Partition 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcode ...

  7. 【LeetCode】246. Strobogrammatic Number 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcode ...

  8. 【LeetCode】623. Add One Row to Tree 解题报告(Python)

    [LeetCode]623. Add One Row to Tree 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problem ...

  9. Atcoder ABC137D:Summer Vacation(贪心)

    D - Summer Vacation Time Limit: 2 sec / Memory Limit: 1024 MB Score : 400 points Problem Statement T ...

  10. Chapter 3 Observational Studies

    目录 概 3.1 3.2 Exchangeability 3.3 Positivity 3.4 Consistency First Second Fine Point 3.1 Identifiabil ...