惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Vercel News
Vercel News
博客园_首页
Y
Y Combinator Blog
美团技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
阮一峰的网络日志
阮一峰的网络日志
aimingoo的专栏
aimingoo的专栏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MyScale Blog
MyScale Blog
GbyAI
GbyAI
人人都是产品经理
人人都是产品经理
T
Tailwind CSS Blog
MongoDB | Blog
MongoDB | Blog
D
DataBreaches.Net
博客园 - Franky
Engineering at Meta
Engineering at Meta
量子位
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
酷 壳 – CoolShell
酷 壳 – CoolShell
N
Netflix TechBlog - Medium

博客园 - kingBook

git patch git 修改最后一次提交的日期 Win10 修改特定格式文件的右键快捷菜单 TypeScript async、 await、Promise LayaAir3.x 侦听程序退出 旋转力学例子 旋转力学公式 凹多边形碰撞检测 LayaAir3.x 侦听键盘事件 URP 阴影 TypeScript 里的 override TypeScript 类的自身类型 C# 匿名对象、动态属性 Cocos Creator 安卓模拟器中无法运行 Unity Editor 保存图片、缩放纹理 LayaAir3.2.0-beta.2 设置2d刚体线性速度,在不同设备(分辨率)下,表现不一致的问题 LayaAir3.x 物理2D碰撞事件 TypeScirpt 声明Map类型变量 TypeScript 声明函数类型变量
Unity 二维数组序列化
kingBook · 2024-10-07 · via 博客园 - kingBook

unity 中,二维以上的数量是不支持序列化的,如:

using System.Collections.Generic;
using UnityEngine;
public class TestArray : MonoBehaviour {
    // 不支持序列化(在Inspector面板无法显示)
    public Rect[][] rect2Ds;
    // 不支持序列化(在Inspector面板无法显示)
    //public List<List<Rect>> rect2Ds;
}

可以使用以下方式代替:

using UnityEngine;
public class TestArray : MonoBehaviour {
    public RectArray[] rectArrays;

    private void Awake() {
        var rectArray1 = new RectArray(2);
        rectArray1[0] = new Rect(0, 0, 0, 0);
        rectArray1[1] = new Rect(1, 1, 1, 1);

        rectArrays = new RectArray[1];
        rectArrays[0] = rectArray1;
    }
}

[System.Serializable]
public class RectArray {

    public Rect[] rects;

    public RectArray(int length) {
        rects = new Rect[length];
    }

    public Rect this[int index] {
        get { return rects[index]; }
        set { rects[index] = value; }
    }
}