当前位置: 首页 > news >正文

网站项目建设策划方案超级外链发布

网站项目建设策划方案,超级外链发布,设计网站汇总,网站开发需要多少钱Unity中将字典序列化,在预制体上能够看到字典的内容,也可以直接在预制体上拖拽给字典赋值 直接上代码 using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine;public class SerializableD…

Unity中将字典序列化,在预制体上能够看到字典的内容,也可以直接在预制体上拖拽给字典赋值

直接上代码

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;public class SerializableDic
{
}[Serializable]
public class SerializableDic<TKey, TValue> :SerializableDic,ISerializationCallbackReceiver,IDictionary<TKey, TValue>{[SerializeField] private List<SerializableKeyValuePair> list = new List<SerializableKeyValuePair>();[Serializable]private struct SerializableKeyValuePair{public TKey Key;public TValue Value;public SerializableKeyValuePair(TKey key, TValue value){Key = key;Value = value;}}#region key indexprivate Dictionary<TKey, int> KeyPositions{get { return _keyPositions.Value; }}private Lazy<Dictionary<TKey, int>> _keyPositions;public SerializableDic(){_keyPositions = new Lazy<Dictionary<TKey, int>>(MakeKeyPositions);}#endregionprivate Dictionary<TKey, int> MakeKeyPositions(){Dictionary<TKey, int> dictionary = new Dictionary<TKey, int>(list.Count);for (var i = 0; i < list.Count; i++){dictionary[list[i].Key] = i;}return dictionary;}public void OnBeforeSerialize(){}public void OnAfterDeserialize(){_keyPositions = new Lazy<Dictionary<TKey, int>>(MakeKeyPositions);}#region IDictionary<TKey, TValue>/// <summary>///  array[index]   dic[key]/// </summary>/// <param name="key"></param>public TValue this[TKey key]{get => list[KeyPositions[key]].Value;set{SerializableKeyValuePair pair = new SerializableKeyValuePair(key, value);if (KeyPositions.ContainsKey(key)){list[KeyPositions[key]] = pair;}else{KeyPositions[key] = list.Count;list.Add(pair);}}}public ICollection<TKey> Keys{get { return list.Select(tuple => tuple.Key).ToArray(); }}public ICollection<TValue> Values{get { return list.Select(tuple => tuple.Value).ToArray(); }}public void Add(TKey key, TValue value){if (KeyPositions.ContainsKey(key))throw new ArgumentException("An element with the same key already exists in the dictionary.");else{KeyPositions[key] = list.Count;list.Add(new SerializableKeyValuePair(key, value));}}public bool ContainsKey(TKey key){return KeyPositions.ContainsKey(key);}public bool Remove(TKey key){if (KeyPositions.TryGetValue(key, out var index)){KeyPositions.Remove(key);list.RemoveAt(index);for (var i = index; i < list.Count; i++)KeyPositions[list[i].Key] = i;return true;}elsereturn false;}public bool TryGetValue(TKey key, out TValue value){if (KeyPositions.TryGetValue(key, out var index)){value = list[index].Value;return true;}else{value = default;return false;}}#endregion#region ICollection <KeyValuePair<TKey, TValue>>public int Count{get { return list.Count; }}public bool IsReadOnly{get { return false; }}public void Add(KeyValuePair<TKey, TValue> kvp){Add(kvp.Key, kvp.Value);}public void Clear(){list.Clear();}public bool Contains(KeyValuePair<TKey, TValue> kvp){return KeyPositions.ContainsKey(kvp.Key);}public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex){var numKeys = list.Count;if (array.Length - arrayIndex < numKeys)throw new ArgumentException("arrayIndex");for (var i = 0; i < numKeys; i++, arrayIndex++){var entry = list[i];array[arrayIndex] = new KeyValuePair<TKey, TValue>(entry.Key, entry.Value);}}public bool Remove(KeyValuePair<TKey, TValue> kvp){return Remove(kvp.Key);}#endregion#region IEnumerable <KeyValuePair<TKey, TValue>>public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator(){return list.Select(ToKeyValuePair).GetEnumerator();}static KeyValuePair<TKey, TValue> ToKeyValuePair(SerializableKeyValuePair skvp){return new KeyValuePair<TKey, TValue>(skvp.Key, skvp.Value);}IEnumerator IEnumerable.GetEnumerator(){return GetEnumerator();}#endregion
}

直接将该类替换为原字典类Dictionary即可!

http://www.dtcms.com/a/426723.html

相关文章:

  • 使用 Lens连接阿里云k8s集群
  • UNIX下C语言编程与实践24-UNIX 标准文件编程库:无格式读写函数族(字符、行、块)的使用
  • mysql中的日志
  • Spring Cloud Nacos 配置中心详解:从基础使用到 MyBatis 整合(含多文档配置)
  • 去出海做产品吧,亚马逊爆款产品 属于电子类的消费产品。用全志A733完胜--
  • 设计配色网站租房合同范本下载word
  • 安卓生态进化史:从手机系统到全场景智能
  • 自适应网站开发工具网站优化排名提升
  • 中国建材网:重构建材行业生态的数字力量
  • 【有源码】基于Hadoop+Spark的豆瓣电影数据分析与可视化系统-基于大数据的电影评分趋势分析与可视化系统
  • 模板匹配算法原理
  • Matplotlib子图布局与响应式设计实战:GridSpec与CSS框架深度结合
  • 【图像处理进阶】边缘检测算法深度优化与复杂场景实战
  • yolov12 onnx导出tensorrt
  • 【Java学习】定时器Timer(源码详解)
  • 【数据结构】二叉树的数组表示推导
  • 前端版本更新,错误监控,解决方案 error / unhandledrejection,同步异步错误监控方案
  • 2023 美赛C Predicting Wordle Results(上)
  • 微退休(Micro-retirement)介绍
  • LeetCode热题100(1-7)
  • 想让图片可以在Word和WPS文档中自由移动?修改文字环绕
  • 连云港网站设计北京seo优化分析
  • PostgreSQL WAL 日志发展史 - pg9
  • 企业自有网站全国加盟网站大全
  • 做金融网站看那些素材怎样联系自己建设网站
  • Java的任务调度框架之 Quartz 以及 CronTrigger,CronScheduleBuilder 和 Cron表达式 笔记250930
  • 联想乐享重构智能搜索生态:ThinkPad T14p 2025升级信息首触“企业智能双胞胎”
  • 明远智睿 SSD2351 核心板:64 位四核含税不足 50 元,批量采购新选择
  • Flutter 自定义 View 权威指引
  • AWS | Linux 硬盘挂载综合教程