近期回顾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. LuoguP5238 整数校验器 题解

    Content 给定两个整数 \(l,r\),再给定 \(T\) 个整数,请判断对于每个整数 \(x\),是否满足以下要求: \(x\in[l,r]\). \(x\) 格式合法. 数据范围:\(-2^ ...

  2. nginx配置文件简析

    https://blog.csdn.net/wangbin_0729/article/details/82109693 #运行用户 user www-data; #启动进程,通常设置成和cpu的数量相 ...

  3. 优雅的按键模块-----Multi-button

    优雅的按键模块-----Multi-button ​ 在我们日常开发和使用的过程中常常使用了一些按键,利用按键实现不同的功能,比如长按,短按,双击等等.但是每次都是采用标志等等来实现信息的读取,是否有 ...

  4. AcWing 1204. 错误票据

    题目: 某涉密单位下发了某种票据,并要在年终全部收回. 每张票据有唯一的ID号. 全年所有票据的ID号是连续的,但ID的开始数码是随机选定的. 因为工作人员疏忽,在录入ID号的时候发生了一处错误,造成 ...

  5. nim_duilib(18)之xml控件关联优化

    方法1 直接调用函数FindControl函数,返回Control*类型,对返回的类型强制转换 ui::CheckBox* pcheckbox = (ui::CheckBox*)(FindContro ...

  6. 1036 - A Refining Company

    1036 - A Refining Company   PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 ...

  7. D. Puzzles(Codeforces Round #362 (Div. 2))

    D. Puzzles Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 ...

  8. Rikka with Graph(hdu5631)

    Rikka with Graph  Accepts: 123  Submissions: 525  Time Limit: 2000/1000 MS (Java/Others)  Memory Lim ...

  9. .NET Core 实现动态代理做AOP(面向切面编程)

    1.介绍 1.1 动态代理作用 用动态代理可以做AOP(面向切面编程),进行无入侵式实现自己的扩展业务,调用者和被调用者之间的解耦,提高代码的灵活性和可扩展性,比如:日志记录.性能统计.安全控制.事务 ...

  10. [opencv]二维码识别率提升方案-resize调整

    这里采用循环resize的方式,对二维码图像进行放缩. 识别到name(二维码结果)不为空,则立即退出循环 //循环识别 for (int i = 1;name.empty(); i++){ resi ...