欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
實(shí)現Unity對Dictionary的序列化

若有嘗試過(guò)想在unity的inspector檢視面板中像List或者數組那樣可以編輯Dictionary變量的童鞋應該知道,Dictionary變量不會(huì )出現在inspector中,unity并不會(huì )直接序列化Dictionary類(lèi)型,但實(shí)際上unity有提供接口使之可能:

unity doc: http://docs.unity3d.com/ScriptReference/ISerializationCallbackReceiver.OnBeforeSerialize.html。

注意其中的This interface should be used very carefully. Unity's serializer usually runs on the non main thread, while most of the Unity API can only be called from the main thread.

請慎用該方法,它不是線(xiàn)程安全的。

 1 using UnityEngine; 2 using System.Collections.Generic; 3  4 /// Usage: 5 ///  6 /// [System.Serializable] 7 /// class MyDictionary : SerializableDictionary<int, GameObject> {} 8 /// public MyDictionary dic; 9 ///10 [System.Serializable]11 public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, ISerializationCallbackReceiver12 {13     // We save the keys and values in two lists because Unity does understand those.14     [SerializeField]15     private List<TKey> _keys;16     [SerializeField]17     private List<TValue> _values;18 19     // Before the serialization we fill these lists20     public void OnBeforeSerialize()21     {      //官方例子有誤,去掉     
    }30 31 // After the serialization we create the dictionary from the two lists32 public void OnAfterDeserialize()33 {34 this.Clear();35 int count = Mathf.Min(_keys.Count, _values.Count);36 for (int i = 0; i < count; ++i)37 {38 this.Add(_keys[i], _values[i]);39 }40 }41 }

 

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
泛型與反射
C#泛型字典類(lèi)比較
《Shuttler.Net東寫(xiě)西讀之一》BCL里Dictionary的緣分算法
U3d內存優(yōu)化(二)之Dictonary
WorkflowRuntime.CreateWorkflow 方法 (System.Wor...
C#高手之路詳解解析Hashtable、Dictionary、SortedDictiona...
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久