【unity框架开发9】序列化字典,场景,vector,color,Quaternion

news2024/10/11 22:46:14

文章目录

  • 前言
  • 一、可序列化字典类
    • 普通字典简单的使用
    • 可序列化字典简单的使用
  • 二、序列化场景
  • 三、序列化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 IDictionary

	public 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 IDeserializationCallback

	public void OnDeserialization(object sender)
	{
		((IDeserializationCallback)m_dict).OnDeserialization(sender);
	}

	#endregion

	#region ISerializable

	protected 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 -> Vector3
    public static implicit operator SerializedVector3(Vector3 vector3)
    {
        return new SerializedVector3(vector3.x, vector3.y, vector3.z);
    }

    // 隐式转换:Vector3 -> SerializedVector3
    public static implicit operator Vector3(SerializedVector3 vector3)
    {
        return new Vector3(vector3.x, vector3.y, vector3.z);
    }

    // 隐式转换:SerializedVector3 -> Vector3Int
    public static implicit operator SerializedVector3(Vector3Int vector3)
    {
        return new SerializedVector3(vector3.x, vector3.y, vector3.z);
    }

    // 隐式转换:Vector3Int -> SerializedVector3
    public 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 -> Vector2
    public static implicit operator SerializedVector2(Vector2 vector2)
    {
        return new SerializedVector2(vector2.x, vector2.y);
    }

    // 隐式转换:Vector2 -> SerializedVector2
    public static implicit operator Vector2(SerializedVector2 vector2)
    {
        return new Vector2(vector2.x, vector2.y);
    }

    // 隐式转换:SerializedVector2 -> Vector2Int
    public static implicit operator SerializedVector2(Vector2Int vector2)
    {
        return new SerializedVector2(vector2.x, vector2.y);
    }

    // 隐式转换:Vector2Int -> SerializedVector2
    public static implicit operator Vector2Int(SerializedVector2 vector2)
    {
        return new Vector2Int((int)vector2.x, (int)vector2.y);
    }
}

// 扩展方法类,用于转换向量
public static class SerializedVectorExtensions
{
    // 将SerializedVector3转换为Vector3
    public static Vector3 ConverToVector3(this SerializedVector3 sv3)
    {
        return new Vector3(sv3.x, sv3.y, sv3.z);
    }

    // 将Vector3转换为SerializedVector3
    public static SerializedVector3 ConverToSVector3(this Vector3 v3)
    {
        return new SerializedVector3(v3.x, v3.y, v3.z);
    }

    // 将SerializedVector3转换为Vector3Int
    public static Vector3Int ConverToVector3Int(this SerializedVector3 sv3)
    {
        return new Vector3Int((int)sv3.x, (int)sv3.y, (int)sv3.z);
    }

    // 将Vector3Int转换为SerializedVector3
    public static SerializedVector3 ConverToSVector3Int(this Vector3Int v3)
    {
        return new SerializedVector3(v3.x, v3.y, v3.z);
    }

    // 将SerializedVector2转换为Vector2
    public static Vector2 ConverToSVector2(this SerializedVector2 sv2)
    {
        return new Vector2(sv2.x, sv2.y);
    }

    // 将SerializedVector2转换为Vector2Int
    public static Vector2Int ConverToVector2Int(this SerializedVector2 sv2)
    {
        return new Vector2Int((int)sv2.x, (int)sv2.y);
    }

    // 将Vector2转换为SerializedVector2
    public static SerializedVector2 ConverToSVector2(this Vector2 v2)
    {
        return new SerializedVector2(v2.x, v2.y);
    }

    // 将Vector2Int转换为SerializedVector2
    public 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 -> SerializedColor
    public static implicit operator SerializedColor(Color color)
    {
        return new SerializedColor(color.r, color.g, color.b, color.a); // 从Unity的Color转换为SerializedColor
    }

    // 隐式转换:SerializedColor -> Color
    public 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的Color
    public static Color ConverToUnityColor(this SerializedColor color)
    {
        return new Color(color.r, color.g, color.b, color.a); // 创建并返回Unity的Color
    }

    // 将Unity的Color转换为SerializedColor
    public 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类型转换为SerializedQuaternion
    public 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类型转换为SerializedQuaternion
    public 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.coloradmin.cn/o/2206118.html

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

相关文章

Android Framework默认授予app通知使用权限

安卓通知使用权限 在安卓系统中&#xff0c;应用程序需要获取通知使用权限才能向用户发送通知。以下是关于安卓通知使用权限的一些信息&#xff1a; 权限获取方式 当用户安装应用时&#xff0c;系统可能会在安装过程中提示用户授予应用通知权限。用户可以选择允许或拒绝。 应…

记录一些yolo-world训练数据集的报错

参考的这个文章 https://blog.csdn.net/ITdaka/article/details/138863017?spm1001.2014.3001.5501 openai快捷下载&#xff1a;https://download.csdn.net/download/qq_43767886/89876720 然后我打算训练coco数据集&#xff0c;遇到了以下的问题 问题一 原因&#xff1a;…

智慧农田新篇章:高标准农田灌区信息化的创新实践

在新时代的农业发展蓝图中&#xff0c;智慧农田已成为推动农业现代化、实现可持续发展目标的关键一环。高标准农田灌区信息化作为智慧农业的重要组成部分&#xff0c;正引领着一场深刻的农业技术革命&#xff0c;它不仅关乎粮食安全与资源高效利用&#xff0c;还深刻影响着农村…

writehelpAI论文写作,专业毕业论文救星

撰写专业毕业论文是每位学生学术旅程中的一个重要里程碑&#xff0c;它不仅检验了你对专业知识的掌握程度&#xff0c;还考验着研究能力、批判性思维以及书面表达技巧。在这个过程中&#xff0c;writehelpAI这样的智能写作助手可以成为你的得力伙伴&#xff0c;帮助解决从选题到…

功率检测和语音功能

INA226 INA226 High-Side or Low-Side Measurement, Bi-Directional Current and Power Monitor with I2C Compatible Interface datasheet (Rev. A) INA226功率监测模块原理 7.5 编程 INA226 器件的一个重要方面是它不一定测量电流或功率。该器件可测量施加在 IN 和 IN- 输入…

数据结构重点学习笔记教程——入门必看 数据结构心得

数据结构教程知识点 章节目录 一、数据结构概述二、线性表三、栈与队列四、数组与字符串五、树与二叉树六、图七、排序算法八、查找算法九、哈希表与散列法十、高级数据结构 总结简介 本数据结构教程知识点涵盖了从数据结构概述到高级数据结构的全方位内容&#xff0c;旨在帮…

河南省学籍管理员在校拍照采集学生证件照流程介绍

校园证件照采集是校园管理中一个重要的环节&#xff0c;它涉及为学生、教职工等校园成员拍摄并处理符合特定要求的证件照片。以下是针对河南省中小学生学籍照片集中拍摄采集的步骤指南&#xff0c;用于指导学籍管理员开展相关工作。 一、学籍照片采集的前期准备 &#xff08;1…

Java读取Excel文件_详细可执行_低内存占用

EasyExcel介绍&#xff1a;高效内存友好Java Excel处理工具&#xff0c;轻松应对大文件 EasyExcel是一个基于Java的、快速且简洁的Excel处理工具&#xff0c;专为解决大文件内存溢出问题设计。与传统的Excel处理框架如Apache POI和jxl相比&#xff0c;它显著降低了内存消耗。例…

linuxC高级_day5(完结)

目录 指针函数 1.概念 2.定义格式 3.函数内开辟空间 函数指针 1.概念 2.定义格式 2.1 格式 3.函数指针数组 3.1 概念 3.2 格式 3.3 赋值 条件编译 1.根据宏是否定义 根据宏值 3.防止头文件重复包含 指针函数 1.概念 本质是函数&#xff0c;函数返回值是指针。类…

C++系统教程004-数据类型(03)

一 .变量 变量是指在程序运行期间其值可以发生改变的量。每个变量都必须有一个名称作为唯一的标识&#xff0c;且具有一个特定的数据类型。变量使用之前&#xff0c;一定要先进行声明或定义。 1.变量的声明和定义 C中&#xff0c;变量声明是指为变量提供一个名称&#xff0c…

鸢尾花书实践和知识记录[6-23数据聚类]

文章目录 思维导图数据聚类和引例基于图论的聚类算法算法流程1构造数据构造距离矩阵相似度相似度矩阵创建图 拉普拉斯矩阵标准拉普拉斯矩阵(Combinatorial Laplacian)归一化拉普拉斯矩阵 (Normalized Laplacian)无标度拉普拉斯矩阵 (Signless Laplacian)归一化对称拉普拉斯矩阵…

这么好看的桌面时钟 怎么能不分享给大家

最近小编发现了非常好用的桌面时钟。桌面时钟顾名思义就是可以放在桌面上的时钟&#xff0c;这是一款界面优美,功能实用,易于操作的桌面时钟工具芝麻时钟&#xff08;下载地址&#xff1a;https://clock.zhimasoft.cn/&#xff09;。 1、首先来看下这些时钟的效果&#xff0c;…

Ping32企业加密软件:保护数据安全

在数字化时代&#xff0c;数据安全已成为每个企业不可忽视的重要课题。无论是客户信息、财务报表&#xff0c;还是商业机密&#xff0c;数据的安全性直接关系到企业的声誉与运营。为了应对不断变化的安全威胁&#xff0c;选择一款可靠的企业加密软件尤为重要。在这里&#xff0…

MFC的.rc 和.rc2文件【常见问题】

目录 一、介绍 .rc 文件 .rc2 文件 使用上的建议 二、实例 工程截图 rc文件 rc2文件 注意&#xff1a; 三、使用 能否删除&#xff1f; 一、介绍 在MFC项目中&#xff0c;.rc和.rc2文件都是资源脚本文件&#xff0c;但它们有不同的用途和管理方式。它们两指向的是同…

VS2022使用技巧

目录 如何打开资源管理器如何打开监视窗口 如何打开资源管理器 如何打开监视窗口 前提:必须先按f10 开始调试起来了

Typora+PicGo实现自动上传图片至图床

文章目录 前言图床选择图床去不图床 配置PicGo安装Typora对象存储七牛云又拍云 前言 使用过Typora的小伙伴应该已经发现&#xff0c;若是想分享给别人看不但需要发送md文件&#xff0c;还需要把对应的图片一起发给对方&#xff0c;否则图片无法显示。 但是每次都要打个压缩包发…

USIM 卡的鉴权原理

USIM 卡的一个重要功能是用来做鉴权。鉴权是移动通信中非常重要的概念&#xff0c;具体的实现需要很复杂的算法。 鉴权&#xff1a;就是鉴定你是否拥有访问网络的权利。用户在开卡后&#xff0c;手机的 USIM 卡里和运营商的核心网中都将存储一个密钥&#xff0c;或者说一个密码…

进程同步问题

在操作系统中引入进程后&#xff0c;一方面系统中多道程序可以并发进行&#xff0c;有效的改善了资源利用率&#xff0c;提高了系统的吞吐量。但另一方面&#xff0c;系统变得更加复杂了&#xff0c;如果不能通过有效措施对多个进程进行有效管理&#xff0c;那么必然会因为这些…

关于mac下的nvm设置淘宝镜像源

1. 进入配置文件修改镜像源 vim ~/.bash_profile增加下面内容 export NVM_NODEJS_ORG_MIRRORhttps://npmmirror.com/mirrors/node/2. 查看远程node镜像 nvm ls-remote3. 下载镜像 nvm install 14.17.64. 使用镜像 nvm use 14.17.6

Windows系统编程 - 目录操作、磁盘、卷信息

前言 各位师傅大家好&#xff0c;我是qmx_07&#xff0c;今天继续讲解Windows系统编程的相关知识:目录操作 目录 目录操作 创建目录 通过CreateDirectory函数创建目录 原型: BOOL CreateDirectoryA([in] LPCSTR lpPathName,//目录名称[in, opt…