像标题一样,我没有为ScriptableObject创建自定义检查器,而我用谷歌搜索,大多数答案都使用SetDirty(object),但是它没有用。当我在项目和Unity中修改任何代码时将重构C#代码,一些ScriptableObjects将显示在“检查器”面板中,不是所有SO而是全部显示,而是部分显示,我检查了这些显示的SO,数据没有丢失;当我再次打开项目时,然后单击SO项目面板,检查器面板什么都没有;
如您所见,从上次我打开Unity时创建的MouseModuleData不会显示,从这次创建的MouseModuleData1开始创建;所以我认为我的数据结构是否有问题。
/// <summary>
/// Base Class of Module Data
/// </summary>
public abstract class PitchModuleBaseData : ScriptableObject, IEnumerable
{
public abstract IEnumerator GetEnumerator();
}
/// <summary>
/// Face Module Data
/// </summary>
[System.Serializable, CreateAssetMenu(fileName = "MouseModuleData", menuName = "AvatarData/MouseModuleData")]
public class MouthModuleData : PitchModuleBaseData
{
public BoneData MouthCornerLeft;
public BoneData MouthCornerRight;
public BoneData LeapUp;
public BoneData LeapMiddle;
public BoneData LeapDown;
public BoneData MouseRoot;
public MouthModuleData()
{
MouthCornerLeft = new BoneData(PitchFaceConst.Mouth_CornerL, PitchFaceConst.Mouth_CornerR);
MouthCornerRight = new BoneData(PitchFaceConst.Mouth_CornerR, PitchFaceConst.Mouth_CornerL);
LeapDown = new BoneData(PitchFaceConst.Mouth_LeapDown);
LeapMiddle = new BoneData(PitchFaceConst.Mouth_LeapMiddle);
LeapUp = new BoneData(PitchFaceConst.Mouth_LeapUp);
MouseRoot = new BoneData(PitchFaceConst.Mouth_Root);
}
public override IEnumerator GetEnumerator()
{
BoneData[] arr = new BoneData[6];
arr[0] = MouthCornerLeft;
arr[1] = MouthCornerRight;
arr[2] = LeapUp;
arr[3] = LeapDown;
arr[4] = MouseRoot;
arr[5] = LeapMiddle;
return new DataEnumerator(arr);
}
}
所以我做了一个测试;我创建了类似于上面的数据。
public abstract class ABData : ScriptableObject, IEnumerable
{
public abstract IEnumerator GetEnumerator();
}
[System.Serializable, CreateAssetMenu(fileName = "TestData", menuName = "Create/TestData")]
public class TestData : ABData
{
public TestData()
{
data = new BoneData();
Middle = new BoneData(PitchFaceConst.Eye_Mid);
Left = new BoneData(PitchFaceConst.Eye_Left, PitchFaceConst.Eye_Right);
Right = new BoneData(PitchFaceConst.Eye_Right, PitchFaceConst.Eye_Left);
EyeLeft1 = new BoneData(PitchFaceConst.Eye_L1, PitchFaceConst.Eye_R1);
EyeLeft2 = new BoneData(PitchFaceConst.Eye_L2, PitchFaceConst.Eye_R2);
EyeLeft3 = new BoneData(PitchFaceConst.Eye_L3, PitchFaceConst.Eye_R3);
EyeLeft4 = new BoneData(PitchFaceConst.Eye_L4, PitchFaceConst.Eye_R4);
EyeRight1 = new BoneData(PitchFaceConst.Eye_R1, PitchFaceConst.Eye_L1);
EyeRight2 = new BoneData(PitchFaceConst.Eye_R2, PitchFaceConst.Eye_L2);
EyeRight3 = new BoneData(PitchFaceConst.Eye_R3, PitchFaceConst.Eye_L3);
EyeRight4 = new BoneData(PitchFaceConst.Eye_R4, PitchFaceConst.Eye_L4);
}
public BoneData data;
public BoneData Middle;
public BoneData Left;
public BoneData Right;
public BoneData EyeLeft1;
public BoneData EyeLeft2;
public BoneData EyeLeft3;
public BoneData EyeLeft4;
public BoneData EyeRight1;
public BoneData EyeRight2;
public BoneData EyeRight3;
public BoneData EyeRight4;
public override IEnumerator GetEnumerator()
{
throw new System.NotImplementedException();
}
}
然后让我发疯,发生了一些事。TestData显示为正常状态无论是否重新打开,它都像正常的OS一样工作。
请帮助我,让我走上正确的轨道。
答案 0 :(得分:0)
已解决: 我将所有ScriptableObject代码放在一个.cs文件中,重新加载项目后,Unity找不到ScriptableObject脚本实例ID,您可以让Inspector进入DEBUG模式进行检查! 答案是每个ScriptableObject都应该带有一个参考.cs文件;