近期回顾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. CF734B Anton and Digits 题解

    Content 有 \(k_2\) 个 \(2\).\(k_3\) 个 \(3\).\(k_5\) 个 \(5\) 和 \(k_6\) 个 \(6\),你可以用这里面的数字来组成 \(256,32\) ...

  2. java 数据类型String 【正则表达式】匹配工具 Pattern和Matcher

    Pattern和Matcher的介绍: Pattern对象是正则表达式编译后在内存中的表示形式,因此正则表达式宇符串必须先被编译为Pattern对象,然后再用该Pattern对象创建对应的Matche ...

  3. react 实现tab切换 三角形筛选样式

    ​ ​ 这次使用的是react的class 类组件 import React, { Component } from 'react' import { LeftOutline, SearchOutli ...

  4. JAVA中CountDownLatch的简单示例

    public static void main(String[] args) throws InterruptedException { CountDownLatch latch =new Count ...

  5. mysql导入文件 日期时间报错:[Err] 1067 - Invalid default value for 'active_time'

    报错原因意思是说:mysql5.7版本中有了一个STRICT mode(严格模式),而在此模式下默认是不允许设置日期时间的值为全0值的,所以想要  解决这个问题,就需要修改sql_mode的值. 修改 ...

  6. MySQL数据导入报错:Got a packet bigger than‘max_allowed_packet’bytes的问题

    修改my.cnf,需重启mysql. 在 [MySQLd] 部分添加一句(如果存在,调整其值就可以): max_allowed_packet=512M 查找MySql的配置文件my.cnf所在路径参考 ...

  7. JAVA获取当前日期指定天数之后的日期

    /** * 获取day天之后的日期 * @param day 天数 * @return */ public static String getDate(int day){ Calendar calen ...

  8. 【LeetCode】1041. Robot Bounded In Circle 解题报告(Python)

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

  9. 【LeetCode】982. Triples with Bitwise AND Equal To Zero 解题报告(C++)

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

  10. 【LeetCode】563. Binary Tree Tilt 解题报告(Java & Python)

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