简介: 今日工作中又遇到了一个奇葩问题,在给一个MonoBehaviour 的属性key帧的时候,自定义类型 class 的字段无法被 key 帧,struct的字段类型是可以key 帧的
unity版本:20222.1.7fc1
我们有一个MonoBehaviour 类 TTT ,一个可序列化的纯类 BBB
TTT
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TTTT : MonoBehaviour
{
public BBB b=new BBB();
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
BBB
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class BBB
{
public int x=0;
public int y=0;
}
这个时候 TTT 内的BBB 对象是无法在物体上key帧的
![](https://img.haomeiwen.com/i19189157/ada53e7c1d8b7f29.gif)
我们来一个 struct 对象 CCC
[System.Serializable]
public struct CCC
{
public int z ;
public int w;
}
TTT 类进行添加 CCC 字段
public class TTTT : MonoBehaviour
{
public BBB b=new BBB();
public CCC c;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
![](https://img.haomeiwen.com/i19189157/bd71825d5bd1d526.gif)
网友评论