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

【制作100个unity游戏之26】unity2d横版卷轴动作类游13(附带项目源码)

最终效果

在这里插入图片描述

系列导航

文章目录

  • 最终效果
  • 系列导航
  • 前言
  • 存储点
  • 灯光
  • 后处理
  • 存储位置信息
  • 存储更多数据
  • 存储场景信息
  • 持久化存储数据
    • 引入Unity 的可序列化字典类
    • 调用
  • 游戏结束
  • 源码
  • 完结

前言

欢迎来到【制作100个Unity游戏】系列!本系列将引导您一步步学习如何使用Unity开发各种类型的游戏。在这第26篇中,我们将探索如何用unity制作一个unity2d横版卷轴动作类游戏,我会附带项目源码,以便你更好理解它。

本节主要实现灯光 后处理 存储和持久化存储

存储点

存储点的实现和宝箱类似

新增SavePoint

public class SavePoint : MonoBehaviour, IInteractable {private SpriteRenderer spriteRenderer;public Sprite darkSprite;public Sprite lightSprite;public bool isDone;private void Awake() {spriteRenderer = GetComponent<SpriteRenderer>();    }private void OnEnable() {spriteRenderer.sprite = isDone ? lightSprite : darkSprite;}public void TriggerAction(){if(!isDone){spriteRenderer.sprite = lightSprite;GetComponent<Collider2D>().enabled = false;isDone = true;Save();}}//存储数据private void Save(){Debug.Log("存储数据");}
}

配置
在这里插入图片描述

效果
在这里插入图片描述

灯光

具体可以查看文章:【实现100个unity特效之6】Unity2d光源的使用

调低全局灯光
在这里插入图片描述
石头添加点灯光
在这里插入图片描述
效果
在这里插入图片描述

后处理

后处理效果,我之前也做过不少,感兴趣的可以回头去看看
【用unity实现100个游戏之14】Unity2d做一个建造与防御类rts游戏
在这里插入图片描述
unity实战】3D水系统,游泳,潜水,钓鱼功能实现
在这里插入图片描述

为了方便测试,记得勾选显示后处理效果,默认都是勾选的
在这里插入图片描述
主相机勾选渲染后处理
在这里插入图片描述
添加一些简单的后处理效果

在这里插入图片描述
实现上面区域比下面区域亮
在这里插入图片描述
效果
在这里插入图片描述

存储位置信息

新增Data

public class Data
{/// <summary>/// 存储角色位置信息的字典,键为角色名称,值为对应的位置坐标(Vector3)。/// </summary>public Dictionary<string, Vector3> characterPosDict = new Dictionary<string, Vector3>();
}

新增DataManager,为了保证Data Manager可以优先其他代码执行,为它添加特性[DefaultExecutionOrder(-100)]。很多小伙伴没有留意后面会提到的这个内容,发现有ISaveable的注册报错。[DefaultExecutionOrder(-100)] 是 Unity 中的一个属性,用于指定脚本的默认执行顺序。参数 -100 表示该脚本的执行顺序优先级,数值越小,优先级越高,即越先执行。

新输入系统获取键盘的输入,按下L按键读取一下进度。

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;//指定脚本的默认执行顺序,数值越小,优先级越高
[DefaultExecutionOrder(-100)]
public class DataManager : MonoBehaviour
{public static DataManager instance;[Header("事件监听")]public VoidEventSO saveDataEvent; // 保存数据事件/// <summary>/// 存储需要保存数据的 ISaveable 实例的列表。/// </summary>private List<ISaveable> saveableList = new List<ISaveable>();/// <summary>/// 保存数据到 Data 对象中。/// </summary>private Data saveData;private void Awake(){if (instance == null){instance = this;}else{Destroy(gameObject);}saveData = new Data();}private void Update(){// 按L 加载测试if(Keyboard.current.lKey.wasPressedThisFrame){Debug.Log("加载");Load();}}/// <summary>/// 注册需要保存数据的 ISaveable 实例。/// </summary>/// <param name="saveable">需要保存数据的 ISaveable 实例。</param>public void RegisterSaveData(ISaveable saveable){if (!saveableList.Contains(saveable)){saveableList.Add(saveable);}}public void UnRegisterSaveData(ISaveable saveable){if (saveableList.Contains(saveable)){// 如果在,就从列表中移除saveableList.Remove(saveable);}}private void OnEnable(){saveDataEvent.OnEventRaised += Save; // 监听保存数据事件}private void OnDisable(){saveDataEvent.OnEventRaised -= Save; // 取消监听保存数据事件}/// <summary>/// 保存数据。/// </summary>public void Save(){foreach (var saveable in saveableList){saveable.GetSaveData(saveData);}}/// <summary>/// 加载数据并应用到相应的 ISaveable 实例中。/// </summary>public void Load(){foreach (var saveable in saveableList){saveable.LoadData(saveData);}}
}

挂载配置
在这里插入图片描述

新增接口ISaveable

public interface ISaveable
{DataDefination GetDataID();/// <summary>/// 将该实例注册到数据管理器以便保存数据。/// </summary>void RegisterSaveData() => DataManager.instance.RegisterSaveData(this);/// <summary>/// 将该实例从数据管理器中注销,停止保存数据。/// </summary>void UnRegisterSaveData() => DataManager.instance.UnRegisterSaveData(this);/// <summary>/// 获取需要保存的数据并存储到指定的 Data 对象中。/// </summary>/// <param name="data">保存数据的 Data 对象。</param>void GetSaveData(Data data);/// <summary>/// 从指定的 Data 对象中加载数据并应用到该实例中。/// </summary>/// <param name="data">包含加载数据的 Data 对象。</param>void LoadData(Data data);
}

那么如果有三个野猪的名字完全一样,我们怎么区分每一只野猪具体存储的位置呢,所以接下来我们要创建一个唯一的标识,我们可以直接使用c#为我们设置好的全局唯一标识符,GUID就是个16位的串码,保证它的唯一性
在这里插入图片描述
新增枚举

/// <summary>
/// 指示数据定义的持久化类型。
/// </summary>
public enum PersistentType
{/// <summary>/// 可读写的持久化类型,数据会被持久化保存。/// </summary>ReadWrite,/// <summary>/// 不持久化类型,数据不会被持久化保存。/// </summary>DoNotPerst
}

新增DataDefination

public class DataDefination : MonoBehaviour
{/// <summary>/// 持久化类型,指示数据定义的持久化方式。/// </summary>public PersistentType persistentType;/// <summary>/// 数据定义的唯一标识符。/// </summary>public string ID;/// <summary>/// 当编辑器中的属性值发生更改时调用,用于自动设置默认的ID值。/// </summary>private void OnValidate(){if (persistentType == PersistentType.ReadWrite){if (ID == string.Empty){ID = System.Guid.NewGuid().ToString();}}else{ID = string.Empty;}}
}

配置挂载脚本,比如我们放在人物身上,生成唯一的UID
在这里插入图片描述
修改PlayerController,调用接口

public class PlayerController : MonoBehaviour, ISaveable
{//...private void OnEnable(){ISaveable saveable = this;saveable.RegisterSaveData();}private void OnDisable(){ISaveable saveable = this;saveable.UnRegisterSaveData();}// 获取数据ID,用于唯一标识当前对象的位置信息public DataDefination GetDataID(){return GetComponent<DataDefination>();}// 将对象的位置信息保存到数据中public void GetSaveData(Data data){// 检查数据中是否已经存在当前对象的位置信息if (data.characterPosDict.ContainsKey(GetDataID().ID)){// 如果已经存在,则更新位置信息data.characterPosDict[GetDataID().ID] = transform.position;}else{// 如果不存在,则添加新的位置信息data.characterPosDict.Add(GetDataID().ID, transform.position);}}// 从数据中加载对象的位置信息public void LoadData(Data data){// 检查数据中是否存在当前对象的位置信息if (data.characterPosDict.ContainsKey(GetDataID().ID)){// 如果存在,则将位置信息设置为对应的数值transform.position = data.characterPosDict[GetDataID().ID];}}
}

修改SavePoint,调用存储数据

public class SavePoint : MonoBehaviour, IInteractable {private SpriteRenderer spriteRenderer;public Sprite darkSprite;public Sprite lightSprite;public bool isDone;public VoidEventSO saveDataEvent; // 保存数据事件private void Awake() {spriteRenderer = GetComponent<SpriteRenderer>();    }private void OnEnable() {spriteRenderer.sprite = isDone ? lightSprite : darkSprite;}public void TriggerAction(){if(!isDone){Save();spriteRenderer.sprite = lightSprite;GetComponent<Collider2D>().enabled = false;isDone = true;}}//存储数据private void Save(){Debug.Log("存储数据");saveDataEvent.RaiseEvent();}
}

效果,按L测试读取数据,角色回到存储的位置
在这里插入图片描述

存储更多数据

修改Data,定义通用的float的类型,所有和float相关的类型都可用它保存

public class Data
{//...public Dictionary<string, float> floatSaveData = new Dictionary<string, float>();
}

但是如何区分是人物的血条还是能量呢?我们可以加入不同的后缀,修改PlayerController

// 将对象的位置信息保存到数据中
public void GetSaveData(Data data)
{// 检查数据中是否已经存在当前对象的位置信息if (data.characterPosDict.ContainsKey(GetDataID().ID)){// 如果已经存在,则更新位置信息data.characterPosDict[GetDataID().ID] = transform.position;data.floatSaveData[GetDataID().ID + "Health"] = GetComponent<Character>().currentHealth;data.floatSaveData[GetDataID().ID + "Power"] = GetComponent<Character>().currentPower;}else{// 如果不存在,则添加新的位置信息data.characterPosDict.Add(GetDataID().ID, transform.position);//存储玩家血量和能量data.floatSaveData.Add(GetDataID().ID + "Health", GetComponent<Character>().currentHealth);data.floatSaveData.Add(GetDataID().ID + "Power", GetComponent<Character>().currentPower);}
}// 从数据中加载对象的位置信息
public void LoadData(Data data)
{// 检查数据中是否存在当前对象的位置信息if (data.characterPosDict.ContainsKey(GetDataID().ID)){// 如果存在,则将位置信息设置为对应的数值transform.position = data.characterPosDict[GetDataID().ID];GetComponent<Character>().currentHealth = data.floatSaveData[GetDataID().ID + "Health"];GetComponent<Character>().currentPower = data.floatSaveData[GetDataID().ID + "Power"];//更新血条能量UIGetComponent<Character>().OnHealthChanged?.Invoke(GetComponent<Character>());}
}

效果
在这里插入图片描述
同理你可以存储其他的比如宝箱,野猪等信息

存储场景信息

修改Data,将场景信息转为json数据进行存取

public string sceneToSave;public void SaveGameScene(SceneField savedScene){sceneToSave = JsonUtility.ToJson(savedScene);
}public SceneField GetSavedScene(){SceneField loadedData = JsonUtility.FromJson<SceneField>(sceneToSave);return loadedData;
}

修改SavePoint,存储场景信息

public SceneField currentLoadedScene;public class SavePoint : MonoBehaviour, IInteractable, ISaveable
{//...public DataDefination GetDataID(){return null;}public void GetSaveData(Data data){data.SaveGameScene(currentLoadedScene);//存储场景}public void LoadData(Data data){}
}

配置当前场景
在这里插入图片描述

修改DataManager,我们希望加载存储场景完成后,再进行其他的LoadData操作,所以加载存储场景的操作我们就不放在LoadData里执行了。可以加入场景过渡渐变,让效果更好,这里我就不加了

/// <summary>
/// 加载数据并应用到相应的 ISaveable 实例中。
/// </summary>
public void Load()
{//获取存储的场景var scence = saveData.GetSavedScene();if (scence != null){// 获取当前活动的场景Scene activeScene = SceneManager.GetActiveScene();// 获取所有加载的场景for (int i = 0; i < SceneManager.sceneCount; i++){Scene loadedScene = SceneManager.GetSceneAt(i);Debug.Log("Loaded Scene " + i + ": " + loadedScene.name);if (activeScene.name != loadedScene.name) SceneManager.UnloadSceneAsync(loadedScene.name); // 异步卸载所有非主场景}//加载scence场景SceneManager.LoadSceneAsync(scence.SceneName, LoadSceneMode.Additive).completed += operation =>{if (operation.isDone){//获取相机边界方法cameraControl.GetNewCameraBounds();//加载其他数据foreach (var saveable in saveableList){saveable.LoadData(saveData);}}};//控制按钮的显示隐藏sceneLoadTrigger.StartMenu();}
}

效果
在这里插入图片描述

持久化存储数据

具体可以看我这篇文章:【unity小技巧】Unity存储存档保存——PlayerPrefs、JsonUtility和MySQL数据库的使用

需要注意的是,Dictionary 类型不能直接序列化为 JSON 字符串,因为 JsonUtility.ToJson() 方法只能序列化 Unity 引擎内置支持的类型。解决这个问题的一种方法是创建一个自定义类。其实我在之前的文章早就有用到这种方法:【用unity实现100个游戏之12】unity制作一个俯视角2DRPG《类星露谷物语、浮岛物语》资源收集游戏(附项目源码)

引入Unity 的可序列化字典类

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;}
}

调用

修改Data,Dictionary 全部改为SerializableDictionary

public class Data
{/// <summary>/// 存储角色位置信息的字典,键为角色名称,值为对应的位置坐标(Vector3)。/// </summary>public SerializableDictionary <string, Vector3> characterPosDict = new SerializableDictionary <string, Vector3>();public SerializableDictionary <string, float> floatSaveData = new SerializableDictionary <string, float>();public SerializableDictionary <string, bool> boolSaveData = new SerializableDictionary <string, bool>();public string sceneToSave;public void SaveGameScene(SceneField savedScene){sceneToSave = JsonUtility.ToJson(savedScene);}public SceneField GetSavedScene(){SceneField loadedData = JsonUtility.FromJson<SceneField>(sceneToSave);return loadedData;}
}

修改DataManager

String savePath = "test.json";/// <summary>
/// 保存数据。
/// </summary>
public void Save()
{//。。。//持久化存储数据String jsonData = JsonUtility.ToJson(saveData);File.WriteAllText(savePath, jsonData);
}/// <summary>
/// 加载数据并应用到相应的 ISaveable 实例中。
/// </summary>
public void Load()
{//读取数据string jsonData = File.ReadAllText(savePath);//将JSON数据反序列化为游戏数据对象Data saveData = JsonUtility.FromJson<Data>(jsonData);//。。。
}

查看存储的test.json数据
在这里插入图片描述
在这里插入图片描述

效果
在这里插入图片描述

游戏结束

比如触碰水死亡,我们直接加个Attack脚本就可以了,把伤害设置很高
在这里插入图片描述
人物死亡,返回菜单,修改PlayerController

//死亡
public void PlayerDead()
{AudioManager.Instance.PlaySFX("人物死亡");isDead = true;inputControl.Player.Disable();//多少秒后重新加载场景Invoke("RestartGame", 1.5f);
}//重新开始
public void RestartGame()
{SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}

效果
在这里插入图片描述

源码

源码不出意外的话我会放在最后一节

完结

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

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

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

在这里插入图片描述

相关文章:

【制作100个unity游戏之26】unity2d横版卷轴动作类游13(附带项目源码)

最终效果 系列导航 文章目录 最终效果系列导航前言存储点灯光后处理存储位置信息存储更多数据存储场景信息持久化存储数据引入Unity 的可序列化字典类调用 游戏结束源码完结 前言 欢迎来到【制作100个Unity游戏】系列&#xff01;本系列将引导您一步步学习如何使用Unity开发各…...

Golang使用HTTP框架zdpgo_resty实现文件下载

核心代码 代码解析&#xff1a; client.SetOutputDirectory("Downloads") 设置下载目录client.R().SetOutput("test.go").Get("http://127.0.0.1:3333/download 指定下载文件名并进行下载 // 设置输出目录路径&#xff0c;如果目录不存在&#xff…...

提取COCO 数据集的部分类

1.python提取COCO数据集中特定的类 安装pycocotools github地址&#xff1a;https://github.com/philferriere/cocoapi pip install githttps://github.com/philferriere/cocoapi.git#subdirectoryPythonAPI若报错&#xff0c;pip install githttps://github.com/philferriere…...

高刚性滚柱直线导轨有哪些优势?

滚柱导轨是机械传动系统中用于支持和引导滑块或导轨的装置&#xff0c;承载能力较高、刚性强及高精度等特点。特别适用于大负载和高刚性的工业设备&#xff0c;如机床、数控机床等设备&#xff0c;这些优势使其在工业生产和机械设备中得到了广泛的应用。 1、高精度&#xff1a;…...

KNN及降维预处理方法LDA|PCA|MDS

文章目录 基本原理模型介绍模型分析 python代码实现降维处理维数灾难 curse of dimensionality线性变换 Linear TransformationLDA - 线性判别分析LDA python 实现PCA - 主成分分析PCA最近重构性PCA最大可分性PCA求解及说明PCA python实现 多维缩放 Multiple Dimensional Scali…...

论文精读-SwinIR Image Restoration Using Swin Transformer

论文精读-SwinIR: Image Restoration Using Swin Transformer SwinIR:使用 Swin Transformer进行图像恢复 参数量&#xff1a;SR 11.8M、JPEG压缩伪影 11.5M、去噪 12.0M 优点&#xff1a;1、提出了新的网络结构。它采用分块设计。包括浅层特征提取&#xff1a;cnn提取&#…...

解释Spring Bean的生命周期

Spring Bean的生命周期涉及到Bean的创建、配置、使用和销毁的各个阶段。理解这个生命周期对于编写高效的Spring应用和充分利用框架的功能非常重要。下面是Spring Bean生命周期的主要步骤&#xff1a; 1. 实例化Bean Spring容器首先将使用Bean的定义&#xff08;无论是XML、注…...

CTF网络安全大赛web题目:字符?正则?

题目来源于&#xff1a;bugku 题目难度&#xff1a;难 题目描  述: 字符&#xff1f;正则&#xff1f; 题目htmnl源代码&#xff1a; <code><span style"color: #000000"> <span style"color: #0000BB"><?php <br />highl…...

Linux——Docker容器虚拟化平台

安装docker 安装 Docker | Docker 从入门到实践https://vuepress.mirror.docker-practice.com/install/ 不需要设置防火墙 docker命令说明 docker images #查看所有本地主机的镜像 docker search 镜像名 #搜索镜像 docker pull 镜像名 [标签] #下载镜像&…...

Transformer详解(3)-多头自注意力机制

attention multi-head attention pytorch代码实现 import math import torch from torch import nn import torch.nn.functional as Fclass MultiHeadAttention(nn.Module):def __init__(self, heads8, d_model128, droput0.1):super().__init__()self.d_model d_model # 12…...

运用HTML、CSS设计Web网页——“西式甜品网”图例及代码

目录 一、效果展示图 二、设计分析 1.整体效果分析 2.头部header模块效果分析 3.导航及banner模块效果分析 4.分类classify模块效果分析 5.产品展示show模块效果分析 6.版权banquan模块效果分析 三、HTML、CSS代码分模块展示 1. 头部header模块代码 2.导航及bann…...

大语言模型是通用人工智能的实现路径吗?【文末有福利】

相关说明 这篇文章的大部分内容参考自我的新书《解构大语言模型&#xff1a;从线性回归到通用人工智能》&#xff0c;欢迎有兴趣的读者多多支持。 关于大语言模型的内容&#xff0c;推荐参考这个专栏。 内容大纲 相关说明一、哲学与人工智能二、内容简介三、书籍简介与福利粉…...

c语言——宏offsetof

1.介绍 &#xff01;&#xff01;&#xff01; offsetof 是一个宏 2.使用举例 结构体章节的计算结构体占多少字节需要先掌握&#xff08;本人博客结构体篇章中已经讲解过&#xff09; 计算结构体中某变量相对于首地址的偏移&#xff0c;并给出说明 首先&#xff0c;结构体首个…...

C#串口通信-串口相关参数介绍

串口通讯(Serial Communication)&#xff0c;是指外设和计算机间&#xff0c;通过数据信号线、地线等&#xff0c;按位进行传输数据的一种双向通讯方式。 串口是一种接口标准&#xff0c;它规定了接口的电气标准&#xff0c;没有规定接口插件电缆以及使用的通信协议&#xff0c…...

节省时间与精力:用BAT文件和任务计划器自动执行重复任务

文章目录 1.BAT文件详解2. 经典BAT文件及使用场景3. 使用方法4. 如何设置BAT文件为定时任务5. 实例应用&#xff1a;自动清理临时文件 BAT文件&#xff0c;也就是批处理文件&#xff0c;是一种在Windows操作系统中自动执行一系列命令的文本文件。这些文件的扩展名为 .bat。通过…...

一年前的Java作业,模拟游戏玩家战斗

说明&#xff1a;一年前写的作业&#xff0c;感觉挺有意思的&#xff0c;将源码分享给大家。 刚开始看题也觉得很难&#xff0c;不过写着写着思路更加清晰&#xff0c;发现也没有想象中的那么难。 一、作业题目描述&#xff1a; 题目&#xff1a;模拟游戏玩家战斗 1.1 基础功…...

C++ 学习 关于引用

&#x1f64b;本文主要讲讲C的引用 是基础入门篇~ 本文是阅读C Primer 第五版的笔记 &#x1f308; 关于引用 几个比较重要的点 &#x1f33f;引用相当于为一个已经存在的对象所起的另外一个名字 &#x1f31e; 定义引用时&#xff0c;程序把引用和它的初始值绑定&#xff08;b…...

BERT ner 微调参数的选择

针对批大小和学习率的组合进行收敛速度测试&#xff0c;结论&#xff1a; 相同轮数的条件下&#xff0c;batchsize-32 相比 batchsize-256 的迭代步数越多&#xff0c;收敛更快批越大的话&#xff0c;学习率可以相对设得大一点 画图代码&#xff08;deepseek生成&#xff09;…...

【MySQL精通之路】系统变量-持久化系统变量

MySQL服务器维护用于配置其操作的系统变量。 系统变量可以具有影响整个服务器操作的全局值&#xff0c;也可以具有影响当前会话的会话值&#xff0c;或者两者兼而有之。 许多系统变量是动态的&#xff0c;可以在运行时使用SET语句进行更改&#xff0c;以影响当前服务器实例的…...

fdk-aac将aac格式转为pcm数据

int sampleRate 44100; // 采样率int sampleSizeInBits 16; // 采样位数&#xff0c;通常是16int channels 2; // 通道数&#xff0c;单声道为1&#xff0c;立体声为2FILE *m_fd NULL;FILE *m_fd2 NULL;HANDLE_AACDECODER decoder aacDecoder_Open(TT_MP4_ADTS, 1);if (!…...

KubeSphere 容器平台高可用:环境搭建与可视化操作指南

Linux_k8s篇 欢迎来到Linux的世界&#xff0c;看笔记好好学多敲多打&#xff0c;每个人都是大神&#xff01; 题目&#xff1a;KubeSphere 容器平台高可用&#xff1a;环境搭建与可视化操作指南 版本号: 1.0,0 作者: 老王要学习 日期: 2025.06.05 适用环境: Ubuntu22 文档说…...

RestClient

什么是RestClient RestClient 是 Elasticsearch 官方提供的 Java 低级 REST 客户端&#xff0c;它允许HTTP与Elasticsearch 集群通信&#xff0c;而无需处理 JSON 序列化/反序列化等底层细节。它是 Elasticsearch Java API 客户端的基础。 RestClient 主要特点 轻量级&#xff…...

云启出海,智联未来|阿里云网络「企业出海」系列客户沙龙上海站圆满落地

借阿里云中企出海大会的东风&#xff0c;以**「云启出海&#xff0c;智联未来&#xff5c;打造安全可靠的出海云网络引擎」为主题的阿里云企业出海客户沙龙云网络&安全专场于5.28日下午在上海顺利举办&#xff0c;现场吸引了来自携程、小红书、米哈游、哔哩哔哩、波克城市、…...

Java 加密常用的各种算法及其选择

在数字化时代&#xff0c;数据安全至关重要&#xff0c;Java 作为广泛应用的编程语言&#xff0c;提供了丰富的加密算法来保障数据的保密性、完整性和真实性。了解这些常用加密算法及其适用场景&#xff0c;有助于开发者在不同的业务需求中做出正确的选择。​ 一、对称加密算法…...

基于TurtleBot3在Gazebo地图实现机器人远程控制

1. TurtleBot3环境配置 # 下载TurtleBot3核心包 mkdir -p ~/catkin_ws/src cd ~/catkin_ws/src git clone -b noetic-devel https://github.com/ROBOTIS-GIT/turtlebot3.git git clone -b noetic https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git git clone -b noetic-dev…...

Web后端基础(基础知识)

BS架构&#xff1a;Browser/Server&#xff0c;浏览器/服务器架构模式。客户端只需要浏览器&#xff0c;应用程序的逻辑和数据都存储在服务端。 优点&#xff1a;维护方便缺点&#xff1a;体验一般 CS架构&#xff1a;Client/Server&#xff0c;客户端/服务器架构模式。需要单独…...

归并排序:分治思想的高效排序

目录 基本原理 流程图解 实现方法 递归实现 非递归实现 演示过程 时间复杂度 基本原理 归并排序(Merge Sort)是一种基于分治思想的排序算法&#xff0c;由约翰冯诺伊曼在1945年提出。其核心思想包括&#xff1a; 分割(Divide)&#xff1a;将待排序数组递归地分成两个子…...

CTF show 数学不及格

拿到题目先查一下壳&#xff0c;看一下信息 发现是一个ELF文件&#xff0c;64位的 ​ 用IDA Pro 64 打开这个文件 ​ 然后点击F5进行伪代码转换 可以看到有五个if判断&#xff0c;第一个argc ! 5这个判断并没有起太大作用&#xff0c;主要是下面四个if判断 ​ 根据题目…...

EasyRTC音视频实时通话功能在WebRTC与智能硬件整合中的应用与优势

一、WebRTC与智能硬件整合趋势​ 随着物联网和实时通信需求的爆发式增长&#xff0c;WebRTC作为开源实时通信技术&#xff0c;为浏览器与移动应用提供免插件的音视频通信能力&#xff0c;在智能硬件领域的融合应用已成必然趋势。智能硬件不再局限于单一功能&#xff0c;对实时…...

Qwen系列之Qwen3解读:最强开源模型的细节拆解

文章目录 1.1分钟快览2.模型架构2.1.Dense模型2.2.MoE模型 3.预训练阶段3.1.数据3.2.训练3.3.评估 4.后训练阶段S1: 长链思维冷启动S2: 推理强化学习S3: 思考模式融合S4: 通用强化学习 5.全家桶中的小模型训练评估评估数据集评估细节评估效果弱智评估和民间Arena 分析展望 如果…...