Unity MonoBehaviour 和ScriptableObject序列化字典Dictionary

官方文档有个MonoBehaviour的字典序列化,但不能用。
​​​​​​UnityEngine.ISerializationCallbackReceiver - Unity 脚本 API

using UnityEngine;
using System;
using System.Collections.Generic;

public class SerializationCallbackScript : MonoBehaviour, ISerializationCallbackReceiver
{
    public List _keys = new List { 3, 4, 5 };
    public List _values = new List { "I", "Love", "Unity" };

    //Unity doesn't know how to serialize a Dictionary
    public Dictionary  _myDictionary = new Dictionary();

    public void OnBeforeSerialize()
    {
        _keys.Clear();
        _values.Clear();

        foreach (var kvp in _myDictionary)
        {
            _keys.Add(kvp.Key);
            _val

你可能感兴趣的:(Unity3D.杂项,unity,c#,序列化字典)