class UIPanelTypeJson
{
public List<UIPanelInfo> List;
}
void UIPAnalysis()//构造一个UIPanel的解析方法
{
panelTypepath = new Dictionary<UIPanelType, string>();
TextAsset ta=Resources.Load<TextAsset>("UIPanelTyep");
UIPanelTypeJson gameObjectInfo= JsonUtility.FromJson<UIPanelTypeJson>(ta.text);//运行程序报这个为永远为空
foreach (UIPanelInfo info in gameObjectInfo.List)
{
panelTypepath.Add(info.panelTyep, info.path);
}
}
运行前Unity警告内部类UIPanelTyepJson中定义的List为空
运行后报JsonUtility.FromJson解析方法得到的为空
UIPanelInfo代码如下:
[NonSerialized]
public UIPanelType panelTyep;//枚举类型
public string panelstring;
public string path;//字符串类型
public void OnAfterDeserialize()
{
Debug.Log(panelstring);
UIPanelType type = (UIPanelType)System.Enum.Parse(typeof(UIPanelType), panelstring);
panelTyep = type;
}
public void OnBeforeSerialize()
{
throw new NotImplementedException();
}
Json代码
{
"List": [
{
"panelstring": "Bag",
"path": "UIPanel/BagPanel"
},
{
"panelstring": "System",
"path": "UIPanel/SystemPanel"
},
{
"panelstring": "Shop",
"path": "UIPanel/ShopPanel"
},
{
"panelstring": "Sikll",
"path": "UIPanel/SikllPanel"
},
{
"panelstring": "Task",
"path": "UIPanel/TaskPanel"
},
{
"panelstring": "MainMeun",
"path": "UIPanel/MainMeunPanel"
}
]
}