【unity进阶知识9】序列化字典,场景,vector,color,Quaternion

文章目录

  • 前言
  • 一、可序列化字典类
    • 普通字典简单的使用
    • 可序列化字典简单的使用
  • 二、序列化场景
  • 三、序列化vector
  • 四、序列化color
  • 五、序列化旋转Quaternion
  • 完结

前言

自定义序列化的主要原因:

  1. 可读性:使数据结构更清晰,便于理解和维护。
  2. 优化 Inspector:提供更友好的用户界面,方便编辑和查看数据。
  3. 控制序列化:实现特定的序列化逻辑,灵活处理数据。比如在保存或加载时进行特定的转换或处理。
  4. 性能提升:减少内存占用,提高序列化和反序列化的效率。
  5. 易于扩展:根据项目需求灵活添加字段和功能。
  6. 类型安全:确保使用正确的数据类型,减少错误。

一、可序列化字典类

Unity 无法序列化标准词典。这意味着它们不会在检查器中显示或编辑,
也不会在启动时实例化。一个经典的解决方法是将键和值存储在单独的数组中,并在启动时构造字典。

我们使用gitthub大佬的源码即可,此项目提供了一个通用字典类及其自定义属性抽屉来解决此问题。
源码地址:https://github.com/azixMcAze/Unity-SerializableDictionary

你可以选择下载源码,也可以直接复制我下面的代码,我把主要代码提出来了
SerializableDictionary.cs

using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using UnityEngine;public abstract class SerializableDictionaryBase
{public abstract class Storage {}protected class Dictionary<TKey, TValue> : System.Collections.Generic.Dictionary<TKey, TValue>{public Dictionary() {}public Dictionary(IDictionary<TKey, TValue> dict) : base(dict) {}public Dictionary(SerializationInfo info, StreamingContext context) : base(info, context) {}}
}[Serializable]
public abstract class SerializableDictionaryBase<TKey, TValue, TValueStorage> : SerializableDictionaryBase, IDictionary<TKey, TValue>, IDictionary, ISerializationCallbackReceiver, IDeserializationCallback, ISerializable
{Dictionary<TKey, TValue> m_dict;[SerializeField]TKey[] m_keys;[SerializeField]TValueStorage[] m_values;public SerializableDictionaryBase(){m_dict = new Dictionary<TKey, TValue>();}public SerializableDictionaryBase(IDictionary<TKey, TValue> dict){	m_dict = new Dictionary<TKey, TValue>(dict);}protected abstract void SetValue(TValueStorage[] storage, int i, TValue value);protected abstract TValue GetValue(TValueStorage[] storage, int i);public void CopyFrom(IDictionary<TKey, TValue> dict){m_dict.Clear();foreach (var kvp in dict){m_dict[kvp.Key] = kvp.Value;}}public void OnAfterDeserialize(){if(m_keys != null && m_values != null && m_keys.Length == m_values.Length){m_dict.Clear();int n = m_keys.Length;for(int i = 0; i < n; ++i){m_dict[m_keys[i]] = GetValue(m_values, i);}m_keys = null;m_values = null;}}public void OnBeforeSerialize(){int n = m_dict.Count;m_keys = new TKey[n];m_values = new TValueStorage[n];int i = 0;foreach(var kvp in m_dict){m_keys[i] = kvp.Key;SetValue(m_values, i, kvp.Value);++i;}}#region IDictionary<TKey, TValue>public ICollection<TKey> Keys {	get { return ((IDictionary<TKey, TValue>)m_dict).Keys; } }public ICollection<TValue> Values { get { return ((IDictionary<TKey, TValue>)m_dict).Values; } }public int Count { get { return ((IDictionary<TKey, TValue>)m_dict).Count; } }public bool IsReadOnly { get { return ((IDictionary<TKey, TValue>)m_dict).IsReadOnly; } }public TValue this[TKey key]{get { return ((IDictionary<TKey, TValue>)m_dict)[key]; }set { ((IDictionary<TKey, TValue>)m_dict)[key] = value; }}public void Add(TKey key, TValue value){((IDictionary<TKey, TValue>)m_dict).Add(key, value);}public bool ContainsKey(TKey key){return ((IDictionary<TKey, TValue>)m_dict).ContainsKey(key);}public bool Remove(TKey key){return ((IDictionary<TKey, TValue>)m_dict).Remove(key);}public bool TryGetValue(TKey key, out TValue value){return ((IDictionary<TKey, TValue>)m_dict).TryGetValue(key, out value);}public void Add(KeyValuePair<TKey, TValue> item){((IDictionary<TKey, TValue>)m_dict).Add(item);}public void Clear(){((IDictionary<TKey, TValue>)m_dict).Clear();}public bool Contains(KeyValuePair<TKey, TValue> item){return ((IDictionary<TKey, TValue>)m_dict).Contains(item);}public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex){((IDictionary<TKey, TValue>)m_dict).CopyTo(array, arrayIndex);}public bool Remove(KeyValuePair<TKey, TValue> item){return ((IDictionary<TKey, TValue>)m_dict).Remove(item);}public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator(){return ((IDictionary<TKey, TValue>)m_dict).GetEnumerator();}IEnumerator IEnumerable.GetEnumerator(){return ((IDictionary<TKey, TValue>)m_dict).GetEnumerator();}#endregion#region IDictionarypublic bool IsFixedSize { get { return ((IDictionary)m_dict).IsFixedSize; } }ICollection IDictionary.Keys { get { return ((IDictionary)m_dict).Keys; } }ICollection IDictionary.Values { get { return ((IDictionary)m_dict).Values; } }public bool IsSynchronized { get { return ((IDictionary)m_dict).IsSynchronized; } }public object SyncRoot { get { return ((IDictionary)m_dict).SyncRoot; } }public object this[object key]{get { return ((IDictionary)m_dict)[key]; }set { ((IDictionary)m_dict)[key] = value; }}public void Add(object key, object value){((IDictionary)m_dict).Add(key, value);}public bool Contains(object key){return ((IDictionary)m_dict).Contains(key);}IDictionaryEnumerator IDictionary.GetEnumerator(){return ((IDictionary)m_dict).GetEnumerator();}public void Remove(object key){((IDictionary)m_dict).Remove(key);}public void CopyTo(Array array, int index){((IDictionary)m_dict).CopyTo(array, index);}#endregion#region IDeserializationCallbackpublic void OnDeserialization(object sender){((IDeserializationCallback)m_dict).OnDeserialization(sender);}#endregion#region ISerializableprotected SerializableDictionaryBase(SerializationInfo info, StreamingContext context) {m_dict = new Dictionary<TKey, TValue>(info, context);}public void GetObjectData(SerializationInfo info, StreamingContext context){((ISerializable)m_dict).GetObjectData(info, context);}#endregion
}public static class SerializableDictionary
{public class Storage<T> : SerializableDictionaryBase.Storage{public T data;}
}[Serializable]
public class SerializableDictionary<TKey, TValue> : SerializableDictionaryBase<TKey, TValue, TValue>
{public SerializableDictionary() {}public SerializableDictionary(IDictionary<TKey, TValue> dict) : base(dict) {}protected SerializableDictionary(SerializationInfo info, StreamingContext context) : base(info, context) {}protected override TValue GetValue(TValue[] storage, int i){return storage[i];}protected override void SetValue(TValue[] storage, int i, TValue value){storage[i] = value;}
}[Serializable]
public class SerializableDictionary<TKey, TValue, TValueStorage> : SerializableDictionaryBase<TKey, TValue, TValueStorage> where TValueStorage : SerializableDictionary.Storage<TValue>, new()
{public SerializableDictionary() {}public SerializableDictionary(IDictionary<TKey, TValue> dict) : base(dict) {}protected SerializableDictionary(SerializationInfo info, StreamingContext context) : base(info, context) {}protected override TValue GetValue(TValueStorage[] storage, int i){return storage[i].data;}protected override void SetValue(TValueStorage[] storage, int i, TValue value){storage[i] = new TValueStorage();storage[i].data = value;}
}

普通字典简单的使用

public class SerializedTest : MonoBehaviour {//普通字典public Dictionary<string, string> dictionary;private void Start() {//实例化字典dictionary = new Dictionary<string, string>();//添加键值对dictionary.Add("name1", "小明");dictionary["name2"] = "小红";//检查是否包含指定的键string key = "name1";Debug.Log($"是否包含键为{key}{dictionary.ContainsKey(key)}");//检查是否包含指定的值string value = "小红";Debug.Log($"是否包含值为{value}{dictionary.ContainsValue(value)}");//获取指定键的值Debug.Log($"获取键为name2的值:{dictionary["name2"]}");//移除键值对dictionary.Remove("name1");//获取键值对数量Debug.Log($"获取键值对数量:{dictionary.Count}");//清空字典dictionary.Clear();}
}

结果
在这里插入图片描述

可序列化字典简单的使用

和普通字典的使用方法一样,只需要把Dictionary换成SerializableDictionary,并且使用时不需要先实例化了

public class SerializedTest : MonoBehaviour {//可序列化字典public SerializableDictionary<string, string> serializableDictionary;private void Start() {//添加键值对serializableDictionary.Add("name1", "小明");serializableDictionary["name2"] = "小红";//检查是否包含指定的键string key = "name1";Debug.Log($"是否包含键为{key}{serializableDictionary.ContainsKey(key)}");//获取指定键的值Debug.Log($"获取键为name2的值:{serializableDictionary["name2"]}");//移除键值对serializableDictionary.Remove("name1");//获取键值对数量Debug.Log($"获取键值对数量:{serializableDictionary.Count}");//清空字典//serializableDictionary.Clear();}
}

结果
在这里插入图片描述
运行时,在挂载的脚本上也可以直接显示字典的值
在这里插入图片描述

二、序列化场景

正常我们都是按场景名称或者索引去跟踪我们的场景吗,这里其实有一个更好的方法,之后在所有的项目中我们都可以去使用它

灵感来源于一篇Unity论坛的SceneField代码:
https://discussions.unity.com/t/inspector-field-for-scene-asset/40763
在这里插入图片描述
解释:这是代码通过使用SceneField类和SceneFieldPropertyDrawer属性绘制器,开发者可以在自定义的脚本中方便地引用和管理场景对象,并在Inspector面板中进行编辑和选择操作。这对于需要频繁切换场景或者处理多个场景的情况非常有用。

新增SerializableScene.cs脚本,如下

using UnityEngine;#if UNITY_EDITOR
using UnityEditor;
#endif[System.Serializable]
public class SerializableScene
{[SerializeField]private Object m_SceneAsset;[SerializeField]private string m_SceneName = "";public string SceneName{get { return m_SceneName; }}// 使其与现有的Unity方法(LoadLevel / LoadScene)兼容public static implicit operator string(SerializableScene sceneField){return sceneField.SceneName;}
}#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(SerializableScene))]
public class SceneFieldPropertyDrawer : PropertyDrawer
{public override void OnGUI(Rect _position, SerializedProperty _property, GUIContent _label){EditorGUI.BeginProperty(_position, GUIContent.none, _property);SerializedProperty sceneAsset = _property.FindPropertyRelative("m_SceneAsset");SerializedProperty sceneName = _property.FindPropertyRelative("m_SceneName");_position = EditorGUI.PrefixLabel(_position, GUIUtility.GetControlID(FocusType.Passive), _label);if (sceneAsset != null){// 显示场景选择器,让用户选择一个场景sceneAsset.objectReferenceValue = EditorGUI.ObjectField(_position, sceneAsset.objectReferenceValue, typeof(SceneAsset), false);// 如果已经选择了场景,则将场景名称保存在场景名称变量中if (sceneAsset.objectReferenceValue != null){sceneName.stringValue = (sceneAsset.objectReferenceValue as SceneAsset).name;}}EditorGUI.EndProperty();}
}
#endif

测试调用

public class SerializedTest : MonoBehaviour {//可序列化场景public SerializableScene scene1;public SerializableScene scene2;private void Start() {SceneManager.LoadScene(scene1);//跳转场景}
}

绑定数据
在这里插入图片描述

三、序列化vector

新增SerializedVector.cs代码

using System;
using UnityEngine;/// <summary>
/// 定义一个可序列化的Vector3结构
/// </summary>
[Serializable]
public struct SerializedVector3 : IEquatable<SerializedVector3>
{public float x, y, z; // 向量的x、y、z分量// 构造函数,用于初始化向量public SerializedVector3(float x, float y, float z){this.x = x;this.y = y;this.z = z;}// 判断当前向量是否与其他向量相等public bool Equals(SerializedVector3 other){return this.x == other.x && this.y == other.y && this.z == other.z;}// 重写ToString方法,返回向量的字符串表示public override string ToString(){return $"({x},{y},{z})";}// 重写GetHashCode方法,生成哈希值public override int GetHashCode(){return x.GetHashCode() ^ (y.GetHashCode() << 2) ^ (z.GetHashCode() >> 2);}// 隐式转换:SerializedVector3 -> Vector3public static implicit operator SerializedVector3(Vector3 vector3){return new SerializedVector3(vector3.x, vector3.y, vector3.z);}// 隐式转换:Vector3 -> SerializedVector3public static implicit operator Vector3(SerializedVector3 vector3){return new Vector3(vector3.x, vector3.y, vector3.z);}// 隐式转换:SerializedVector3 -> Vector3Intpublic static implicit operator SerializedVector3(Vector3Int vector3){return new SerializedVector3(vector3.x, vector3.y, vector3.z);}// 隐式转换:Vector3Int -> SerializedVector3public static implicit operator Vector3Int(SerializedVector3 vector3){return new Vector3Int((int)vector3.x, (int)vector3.y, (int)vector3.z);}
}/// <summary>
/// 定义一个可序列化的Vector2结构
/// </summary>
[Serializable]
public struct SerializedVector2 : IEquatable<SerializedVector2>
{public float x, y; // 向量的x、y分量// 构造函数,用于初始化向量public SerializedVector2(float x, float y){this.x = x;this.y = y;}// 判断当前向量是否与其他向量相等public bool Equals(SerializedVector2 other){return this.x == other.x && this.y == other.y;}// 重写ToString方法,返回向量的字符串表示public override string ToString(){return $"({x},{y})";}// 重写GetHashCode方法,生成哈希值public override int GetHashCode(){return x.GetHashCode() ^ (y.GetHashCode() << 2);}// 隐式转换:SerializedVector2 -> Vector2public static implicit operator SerializedVector2(Vector2 vector2){return new SerializedVector2(vector2.x, vector2.y);}// 隐式转换:Vector2 -> SerializedVector2public static implicit operator Vector2(SerializedVector2 vector2){return new Vector2(vector2.x, vector2.y);}// 隐式转换:SerializedVector2 -> Vector2Intpublic static implicit operator SerializedVector2(Vector2Int vector2){return new SerializedVector2(vector2.x, vector2.y);}// 隐式转换:Vector2Int -> SerializedVector2public static implicit operator Vector2Int(SerializedVector2 vector2){return new Vector2Int((int)vector2.x, (int)vector2.y);}
}// 扩展方法类,用于转换向量
public static class SerializedVectorExtensions
{// 将SerializedVector3转换为Vector3public static Vector3 ConverToVector3(this SerializedVector3 sv3){return new Vector3(sv3.x, sv3.y, sv3.z);}// 将Vector3转换为SerializedVector3public static SerializedVector3 ConverToSVector3(this Vector3 v3){return new SerializedVector3(v3.x, v3.y, v3.z);}// 将SerializedVector3转换为Vector3Intpublic static Vector3Int ConverToVector3Int(this SerializedVector3 sv3){return new Vector3Int((int)sv3.x, (int)sv3.y, (int)sv3.z);}// 将Vector3Int转换为SerializedVector3public static SerializedVector3 ConverToSVector3Int(this Vector3Int v3){return new SerializedVector3(v3.x, v3.y, v3.z);}// 将SerializedVector2转换为Vector2public static Vector2 ConverToSVector2(this SerializedVector2 sv2){return new Vector2(sv2.x, sv2.y);}// 将SerializedVector2转换为Vector2Intpublic static Vector2Int ConverToVector2Int(this SerializedVector2 sv2){return new Vector2Int((int)sv2.x, (int)sv2.y);}// 将Vector2转换为SerializedVector2public static SerializedVector2 ConverToSVector2(this Vector2 v2){return new SerializedVector2(v2.x, v2.y);}// 将Vector2Int转换为SerializedVector2public static SerializedVector2 ConverToSVector2(this Vector2Int v2){return new SerializedVector2(v2.x, v2.y);}
}

测试调用

//普通Vector
public Vector3 vector3;
public Vector2 vector2;
//可序列化Vector
public SerializedVector3 serializedVector3;
public SerializedVector2 serializedVector2;//Vector3和SerializedVector3可以随意转换
Debug.Log(vector3);
vector3 = serializedVector3;
Debug.Log(vector3);
serializedVector3 = Vector3.zero;
Debug.Log(serializedVector3);

配置
在这里插入图片描述
结果
在这里插入图片描述

四、序列化color

新增SerializableColor.cs

using UnityEngine;
using System;/// <summary>
/// 可序列化的颜色结构
/// </summary>
[Serializable]
public struct SerializedColor
{public float r, g, b, a; // 颜色的红、绿、蓝和透明度分量// 构造函数,用于初始化颜色public SerializedColor(float r, float g, float b, float a){this.r = r; // 红色分量this.g = g; // 绿色分量this.b = b; // 蓝色分量this.a = a; // 透明度分量}// 重写ToString方法,返回颜色的字符串表示public override string ToString(){return $"({r},{g},{b},{a})"; // 格式化输出颜色分量}// 重写GetHashCode方法,返回颜色的哈希值public override int GetHashCode(){return this.ConverToUnityColor().GetHashCode(); // 使用Unity的颜色哈希值}// 隐式转换:Color -> SerializedColorpublic static implicit operator SerializedColor(Color color){return new SerializedColor(color.r, color.g, color.b, color.a); // 从Unity的Color转换为SerializedColor}// 隐式转换:SerializedColor -> Colorpublic static implicit operator Color(SerializedColor color){return new Color(color.r, color.g, color.b, color.a); // 从SerializedColor转换为Unity的Color}
}/// <summary>
/// 颜色序列化扩展方法类
/// </summary>
public static class Serialization_ColorExtensions
{// 将SerializedColor转换为Unity的Colorpublic static Color ConverToUnityColor(this SerializedColor color){return new Color(color.r, color.g, color.b, color.a); // 创建并返回Unity的Color}// 将Unity的Color转换为SerializedColorpublic static SerializedColor ConverToSerializationColor(this Color color){return new SerializedColor(color.r, color.g, color.b, color.a); // 创建并返回SerializedColor}
}

测试调用

//颜色
public Color color;
//可序列化的颜色
public SerializedColor serializedColor;color = new Color(1.0f, 0.5f, 0.0f, 1.0f);
Debug.Log(color);
serializedColor = new SerializedColor(0.0f, 1.0f, 0.0f, 1.0f);
Debug.Log(serializedColor);
color = serializedColor;
Debug.Log(color);

配置
在这里插入图片描述

在这里插入图片描述

五、序列化旋转Quaternion

新增SerializedQuaternion.cs,这个其实和vector序列号类似

using System;
using UnityEngine;/// <summary>
/// 定义一个可序列化的Quaternion结构
/// </summary>
[Serializable]
public struct SerializedQuaternion : IEquatable<SerializedQuaternion>
{public float x, y, z, w; // 四元数的x、y、z、w分量// 构造函数,用于初始化四元数public SerializedQuaternion(float x, float y, float z, float w){this.x = x;this.y = y;this.z = z;this.w = w;}// 判断当前四元数是否与其他四元数相等public bool Equals(SerializedQuaternion other){return this.x == other.x && this.y == other.y && this.z == other.z && this.w == other.w;}// 重写ToString方法,返回四元数的字符串表示public override string ToString(){return $"({x}, {y}, {z}, {w})";}// 重写GetHashCode方法,生成四元数的哈希值public override int GetHashCode(){return x.GetHashCode() ^ (y.GetHashCode() << 2) ^ (z.GetHashCode() >> 2) ^ (w.GetHashCode() << 1);}// 隐式转换:从Unity的Quaternion类型转换为SerializedQuaternionpublic static implicit operator SerializedQuaternion(Quaternion quaternion){return new SerializedQuaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w);}// 隐式转换:从SerializedQuaternion转换为Unity的Quaternion类型public static implicit operator Quaternion(SerializedQuaternion quaternion){return new Quaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w);}
}// 扩展方法类,用于转换四元数
public static class SerializedQuaternionExtensions
{// 将SerializedQuaternion转换为Unity的Quaternion类型public static Quaternion ConvertToQuaternion(this SerializedQuaternion sq){return new Quaternion(sq.x, sq.y, sq.z, sq.w);}// 将Unity的Quaternion类型转换为SerializedQuaternionpublic static SerializedQuaternion ConvertToSQuaternion(this Quaternion q){return new SerializedQuaternion(q.x, q.y, q.z, q.w);}
}

测试调用

//旋转
public Quaternion quaternion;
//可序列化旋转
public SerializedQuaternion serializedQuaternion;// 定义一个欧拉角(绕X、Y、Z轴的旋转)    
Vector3 eulerAngles = new Vector3(30f, 45f, 60f); 
// 将欧拉角转换为四元数
quaternion = Quaternion.Euler(eulerAngles);
// 将四元数转换为欧拉角
eulerAngles = quaternion.eulerAngles;
Debug.Log(eulerAngles);//直接赋值
serializedQuaternion = Quaternion.Euler(eulerAngles);
serializedQuaternion = quaternion;//互相转换
serializedQuaternion = quaternion.ConvertToSQuaternion();
quaternion = serializedQuaternion.ConvertToQuaternion();

完结

赠人玫瑰,手有余香!如果文章内容对你有所帮助,请不要吝啬你的点赞评论和关注,你的每一次支持都是我不断创作的最大动力。当然如果你发现了文章中存在错误或者有更好的解决方法,也欢迎评论私信告诉我哦!

好了,我是向宇,https://xiangyu.blog.csdn.net

一位在小公司默默奋斗的开发者,闲暇之余,边学习边记录分享,站在巨人的肩膀上,通过学习前辈们的经验总是会给我很多帮助和启发!如果你遇到任何问题,也欢迎你评论私信或者加群找我, 虽然有些问题我也不一定会,但是我会查阅各方资料,争取给出最好的建议,希望可以帮助更多想学编程的人,共勉~
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/1556899.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

字符编码发展史5 — UTF-16和UTF-32

上一篇《字符编码发展史4 — Unicode与UTF-8》我们讲解了Unicode字符集与UTF-8编码。本篇我们将继续讲解字符编码的第三个发展阶段中的UTF-16和UTF-32。 2.3. 第三个阶段 国际化 2.3.2. Unicode的编码方式 2.3.2.2. UTF-16 UTF-16也是一种变长编码&#xff0c;对于一个Unic…

第Y2周:训练自己的数据集

&#x1f368; 本文为&#x1f517;365天深度学习训练营 中的学习记录博客&#x1f356; 原作者&#xff1a;K同学啊 在上一次体验yolov5s的为基础上&#xff0c;这次将训练自己的数据集。 在YOLO目标检测算法中常用的三种标签格式&#xff1a;voc(xml)、coco(json)和yolo(txt…

【多线程】详解 CAS 机制

&#x1f970;&#x1f970;&#x1f970;来都来了&#xff0c;不妨点个关注叭&#xff01; &#x1f449;博客主页&#xff1a;欢迎各位大佬!&#x1f448; 文章目录 1. CAS 是什么1.1 CAS 具体步骤1.2 CAS 伪代码 2. CAS 的应用2.1 实现原子类2.1.1 AtomInteger 类2.1.2 伪代…

Rspamd:开源垃圾邮件过滤系统

Rspamd 是一个开源垃圾邮件过滤和电子邮件处理框架&#xff0c;旨在根据各种规则评估消息&#xff0c;包括正则表达式、统计分析以及与 URL 黑名单等自定义服务的集成。 系统会分析每封邮件并做出判定&#xff0c;MTA可据此采取进一步行动&#xff0c;例如拒绝邮件或添加垃圾邮…

低照度图像增强网络——EnlightenGAN

系列文章目录 GAN生成对抗网络介绍https://blog.csdn.net/m0_58941767/article/details/142704354?spm1001.2014.3001.5501 循环生成对抗网络——CycleGANhttps://blog.csdn.net/m0_58941767/article/details/142704671?spm1001.2014.3001.5501 目录 系列文章目录 前言 …

SSM社区慢性病管理系统—计算机毕业设计源码37572

摘 要 社区慢性病管理是社区卫生服务的主要内容&#xff0c;发展社区卫生服务是提供基本卫生服务、满足人民群众日益增长的卫生服务需求&#xff0c;也是提高人民健康水平的重要保障。为迎接慢性病防治的挑战我国进行了社区卫生服务改革&#xff0c;但由于社区卫生存在的诸多问…

OJ在线评测系统 微服务 OpenFeign调整后端下 nacos注册中心配置 不给前端调用的代码 全局引入负载均衡器

OpenFeign内部调用二 4.修改各业务服务的调用代码为feignClient 开启nacos注册 把Client变成bean 该服务仅内部调用&#xff0c;不是给前端的 将某个服务标记为“内部调用”的目的主要有以下几个方面&#xff1a; 安全性: 内部API通常不对外部用户公开&#xff0c;这样可以防止…

【CF2021E】Digital Village(All Version)

题目 给你一张 n n n 个点 m m m 条边的无向图&#xff0c;有 p p p 个关键点。你需要选择 k k k 个点染黑&#xff0c;使得这 p p p 个关键点到这 k k k 个黑点的代价和最小。定义代价为两点之间边权最大的边的最小值。 你需要求出 k 1,2,…,n 的所有答案 E1 n,m,p&l…

fiddler抓包20_弱网模拟

课程大纲 ① 打开CustomRules.js文件&#xff1a;Fiddler快捷键“CtrlR”(或鼠标点击&#xff0c;菜单栏 - Rules - Customize Rules)。 ② 设置速率&#xff1a;“CtrlF”&#xff0c;搜索 “m_SimulateModem”&#xff0c;定位至函数。在函数里设置上传、下载速率&#xff0c…

乔斯编程——P3283 通信救援

说明 众所周知&#xff0c;在同一平面内到定点的距离等于定长的点的集合叫做圆。这个定点叫做圆的圆心&#xff0c;定长即圆的半径。 同时用圆心的坐标和圆的半径&#xff0c;就可以确定圆在平面内的位置&#xff0c; 在本题当中&#xff0c;我们根据圆在平面覆盖的区域来描述…

全面解析大型模型Agent智能体原理及实践案例

1 什么是大模型 Agent &#xff1f; 大模型 Agent&#xff0c;作为一种人工智能体&#xff0c;是具备环境感知能力、自主理解、决策制定及执行行动能力的智能实体。简而言之&#xff0c;它是构建于大模型之上的计算机程序&#xff0c;能够模拟独立思考过程&#xff0c;灵活调…

动态规划10:174. 地下城游戏

动态规划解题步骤&#xff1a; 1.确定状态表示&#xff1a;dp[i]是什么 2.确定状态转移方程&#xff1a;dp[i]等于什么 3.初始化&#xff1a;确保状态转移方程不越界 4.确定填表顺序&#xff1a;根据状态转移方程即可确定填表顺序 5.确定返回值 题目链接&#xff1a;174.…

【FPGA】面试八股

1.FPGA的底层资源有哪些 &#xff08;1&#xff09;可编程的逻辑资源 可编程的逻辑单元由查找表&#xff08;LUT&#xff09;,数据选择器&#xff08;MUX&#xff09;,进位链&#xff08;Carry Chain&#xff09;和触发器&#xff08;Flip-Flop&#xff09; &#xff08;2&…

毕业设计——物联网设备管理系统后台原型设计

作品详情 主要功能&#xff1a; 通过构建数字化综合体&#xff0c;利用物联网技术、设备监控技术采集生产线设备等物对象的实时数据&#xff0c;加强信息汇聚管理和服务&#xff0c;多系统维度、多层次的清楚地掌握设施各系统的状态&#xff0c;提高厂房服务的可控性、安全性&…

算法剖析:双指针

文章目录 双指针算法一、 移动零1. 题目2. 算法思想3. 代码实现 二、 复写零1. 题目2. 算法思想3. 代码实现 三、 快乐数1. 题目2. 算法思想3. 代码实现 四、 盛水最多的容器1. 题目2. 算法思想3. 代码实现 五、有效三角形的个数1. 题目2. 算法思想3. 代码实现 六、 和为 s 的两…

出国必备神器!这5款中英翻译工具让你秒变外语达人

在这个全球化的时代&#xff0c;中英互译已然成为我们日常生活和工作中不可或缺的一环。面对众多的翻译工具&#xff0c;如何选择一款既高效又人性化的翻译助手呢&#xff1f;今天&#xff0c;就让我为大家揭秘几款热门的中英互译工具&#xff0c;并分享我的使用感受。 一、福昕…

中广核CGN25届校招网申SHL测评题库、面试流程、招聘对象,内附人才测评认知能力真题

​中国广核集团校园招聘在线测评攻略&#x1f680; &#x1f393; 校园招聘对象 2024届、2025届海内外全日制应届毕业生&#xff0c;大专、本科、硕士、博士&#xff0c;广核集团等你来&#xff01; &#x1f4c8; 招聘流程 投递简历 简历筛选 在线测评&#xff08;重点来啦…

用java编写飞机大战

游戏界面使用JFrame和JPanel构建。背景图通过BG类绘制。英雄机和敌机在界面上显示并移动。子弹从英雄机发射并在屏幕上移动。游戏有四种状态&#xff1a;READY、RUNNING、PAUSE、GAMEOVER。状态通过鼠标点击进行切换&#xff1a;点击开始游戏&#xff08;从READY变为RUNNING&am…

详解Redis分布式锁在SpringBoot的@Async方法中没锁住的坑

背景 Redis分布式锁很有用处&#xff0c;在秒杀、抢购、订单、限流特别是一些用到异步分布式并行处理任务时频繁的用到&#xff0c;可以说它是一个BS架构的应用中最高频使用的技术之一。 但是我们经常会碰到这样的一个问题&#xff0c;那就是我们都按照标准做了但有时运行着、…

JavaEE之多线程进阶-面试问题

一.常见的锁策略 锁策略不是指某一个具体的锁&#xff0c;所有的锁都可以往这些锁策略中套 1.悲观锁与乐观锁 预测所冲突的概率是否高&#xff0c;悲观锁为预测锁冲突的概率较高&#xff0c;乐观锁为预测锁冲突的概率更低。 2.重量级锁和轻量级锁 从加锁的开销角度判断&am…