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

Unity3D仿星露谷物语开发40之割草动画

1、目标

当Player选择Scythe后,鼠标悬浮在草上,会显示绿色光标。鼠标左击,会触发割草的动画。

2、优化Settings.cs脚本

添加以下两行代码:

// Reaping(收割)
public const int maxCollidersToTestPerReapSwing = 15; // 每次收割检测的最多的碰撞体数量
public const int maxTargetComponentsToDestroyPerReapSwing = 2; // 每次收割销毁的最多的组件数量

3、优化Player.cs脚本

1)添加一个变量:

2)Awake方法中添加新的定义

3)Start方法中添加新的定义

4)PlayerClickInput方法中增加一个if条件

5)ProcessPlayerClickInput方法增加一个case条件

6)ProcessPlayerClickInputTool方法增加case条件

7)添加判断角色方向的方法:

计算的方式如下:

private Vector3Int GetPlayerDirection(Vector3 cursorPosition, Vector3 playerPosition)
{if(cursorPosition.x > playerPosition.x&&cursorPosition.y < (playerPosition.y + cursor.ItemUseRadius / 2f)&&cursorPosition.y > (playerPosition.y - cursor.ItemUseRadius / 2f)){return Vector3Int.right;}else if(cursorPosition.x < playerPosition.x&&cursorPosition.y < (playerPosition.y + cursor.ItemUseRadius / 2f)&&cursorPosition.y > (playerPosition.y - cursor.ItemUseRadius / 2f)){return Vector3Int.left;}else if(cursorPosition.y > playerPosition.y){return Vector3Int.up;}else{return Vector3Int.down;}
}

8)添加ReapInPlayerDirectionAtCursor方法

private void ReapInPlayerDirectionAtCursor(ItemDetails itemDetails, Vector3Int playerDirection)
{StartCoroutine(ReapInPlayerDirectionAtCursorRoutine(itemDetails, playerDirection));
}

9)添加ReapInPlayerDirectionAtCursorRoutine方法

private IEnumerator ReapInPlayerDirectionAtCursorRoutine(ItemDetails itemDetails, Vector3Int playerDirection)
{PlayerInputIsDisabled = true;playerToolUseDisabled = true;// Set tool animation to scythe in override animationtoolCharacterAttribute.partVariantType = PartVariantType.scythe;characterAttributeCustomisationList.Clear();characterAttributeCustomisationList.Add(toolCharacterAttribute);animationOverrides.ApplyCharacterCustomisationParameters(characterAttributeCustomisationList);// Reap in player directionUseToolInPlayerDirection(itemDetails, playerDirection);yield return useToolAnimationPause;PlayerInputIsDisabled = false;playerToolUseDisabled = false;
}

10)添加UseToolInPlayerDirection方法

private void UseToolInPlayerDirection(ItemDetails equippedItemDetails, Vector3Int playerDirection)
{if (Input.GetMouseButton(0)){switch (equippedItemDetails.itemType){case ItemType.Reaping_tool:if(playerDirection == Vector3Int.right){isSwingToolRight = true;}else if(playerDirection == Vector3Int.left){isSwingToolLeft = true;}else if(playerDirection == Vector3Int.up){isSwingToolUp = true;}else if(playerDirection == Vector3Int.down){isSwingToolDown = true;}break;}// Define centre point of square which will be used for collision testing,检测碰撞的中心点位置Vector2 point = new Vector2(GetPlayerCentrePosition().x + playerDirection.x * (equippedItemDetails.itemUseRadius / 2f),GetPlayerCentrePosition().y + playerDirection.y * (equippedItemDetails.itemUseRadius / 2f));// Define size of the square which will be used for collision testingVector2 size = new Vector2(equippedItemDetails.itemUseRadius, equippedItemDetails.itemUseRadius);// Get Item components with 2D collider located in the square at the centre point defined (2d colliders tested limited to maxCollidersToTestPerReapSwing)Item[] itemArray = HelperMethods.GetComponentsAtBoxLocationNonAlloc<Item>(Settings.maxCollidersToTestPerReapSwing, point, size, 0f);int reapableItemCount = 0;// Loop through all items retrievedfor(int i = itemArray.Length - 1; i >= 0; i--){if(itemArray[i] != null){// Destory item game object if reapableif (InventoryManager.Instance.GetItemDetails(itemArray[i].ItemCode).itemType == ItemType.Reapable_scenary){// Effect positionVector3 effectPosition = new Vector3(itemArray[i].transform.position.x, itemArray[i].transform.position.y + Settings.gridCellSize / 2f,itemArray[i].transform.position.z);Destroy(itemArray[i].gameObject);reapableItemCount++;if (reapableItemCount >= Settings.maxTargetComponentsToDestroyPerReapSwing)break;}}}}
}

11)添加onEnable和onDisable方法

private void OnDisable()
{EventHandler.BeforeSceneUnloadFadeOutEvent -= DisablePlayerInputAndResetMovement;EventHandler.AfterSceneLoadFadeInEvent -= EnablePlayerInput;
}private void OnEnable()
{EventHandler.BeforeSceneUnloadFadeOutEvent += DisablePlayerInputAndResetMovement;EventHandler.AfterSceneLoadFadeInEvent += EnablePlayerInput;
}

Player.cs完整代码如下:

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;public class Player : SingletonMonobehaviour<Player>
{private WaitForSeconds afterUseToolAnimationPause;private WaitForSeconds useToolAnimationPause;private WaitForSeconds afterLiftToolAnimationPause;private WaitForSeconds liftToolAnimationPause;private bool playerToolUseDisabled = false;  // 如果玩家正在使用某个道具,其他道具将被禁用private AnimationOverrides animationOverrides;  // 动画重写控制器private GridCursor gridCursor;private Cursor cursor;private List<CharacterAttribute> characterAttributeCustomisationList;  // 目标动作列表[Tooltip("Should be populated in the prefab with the equippped item sprite renderer")][SerializeField] private SpriteRenderer equippedItemSpriteRenderer = null; // 武器的图片// Player attributes that can be swappedprivate CharacterAttribute armsCharacterAttribute;private CharacterAttribute toolCharacterAttribute;private float xInput;private float yInput;private bool isWalking;private bool isRunning;private bool isIdle;private bool isCarrying = false;private ToolEffect toolEffect = ToolEffect.none;private bool isUsingToolRight;private bool isUsingToolLeft;private bool isUsingToolUp;private bool isUsingToolDown;private bool isLiftingToolRight;private bool isLiftingToolLeft;private bool isLiftingToolUp;private bool isLiftingToolDown;private bool isPickingRight;private bool isPickingLeft;private bool isPickingUp;private bool isPickingDown;private bool isSwingToolRight;private bool isSwingToolLeft;private bool isSwingToolUp;private bool isSwingToolDown;private Camera mainCamera;private Rigidbody2D rigidbody2D;private Direction playerDirection;private float movementSpeed;private bool _playerInputIsDisabled = false;public bool PlayerInputIsDisabled { get => _playerInputIsDisabled; set => _playerInputIsDisabled = value; }protected override void Awake(){base.Awake();rigidbody2D = GetComponent<Rigidbody2D>();animationOverrides = GetComponentInChildren<AnimationOverrides>();// Initialise swappable character attributesarmsCharacterAttribute = new CharacterAttribute(CharacterPartAnimator.arms, PartVariantColour.none, PartVariantType.none);toolCharacterAttribute = new CharacterAttribute(CharacterPartAnimator.tool, PartVariantColour.none, PartVariantType.none);// Initialise character attribute listcharacterAttributeCustomisationList = new List<CharacterAttribute>();mainCamera = Camera.main;}private void OnDisable(){EventHandler.BeforeSceneUnloadFadeOutEvent -= DisablePlayerInputAndResetMovement;EventHandler.AfterSceneLoadFadeInEvent -= EnablePlayerInput;}private void OnEnable(){EventHandler.BeforeSceneUnloadFadeOutEvent += DisablePlayerInputAndResetMovement;EventHandler.AfterSceneLoadFadeInEvent += EnablePlayerInput;}private void Start(){gridCursor = FindObjectOfType<GridCursor>();cursor = FindObjectOfType<Cursor>();useToolAnimationPause = new WaitForSeconds(Settings.useToolAnimationPause);afterUseToolAnimationPause = new WaitForSeconds(Settings.afterUseToolAnimationPause);liftToolAnimationPause = new WaitForSeconds(Settings.liftToolAnimationPause);afterLiftToolAnimationPause = new WaitForSeconds(Settings.afterLiftToolAnimationPause);}private void Update(){#region  Player Inputif (!PlayerInputIsDisabled){ResetAnimationTrigger();PlayerMovementInput();PlayerWalkInput();PlayerClickInput();PlayerTestInput();// Send event to any listeners for player movement inputEventHandler.CallMovementEvent(xInput, yInput, isWalking, isRunning, isIdle, isCarrying, toolEffect,isUsingToolRight, isUsingToolLeft, isUsingToolUp, isUsingToolDown,isLiftingToolRight, isLiftingToolLeft, isLiftingToolUp, isLiftingToolDown,isPickingRight, isPickingLeft, isPickingUp, isPickingDown,isSwingToolRight, isSwingToolLeft, isSwingToolUp, isSwingToolDown,false, false, false, false);}#endregion Player Input}private void FixedUpdate(){PlayerMovement();}/// <summary>/// 展示拿东西的动画/// </summary>/// <param name="itemCode"></param>public void ShowCarriedItem(int itemCode){ItemDetails itemDetails = InventoryManager.Instance.GetItemDetails(itemCode);if(itemDetails != null){equippedItemSpriteRenderer.sprite = itemDetails.itemSprite;equippedItemSpriteRenderer.color = new Color(1f, 1f, 1f, 1f);// Apply 'carry' character arms customisationarmsCharacterAttribute.partVariantType = PartVariantType.carry;characterAttributeCustomisationList.Clear();characterAttributeCustomisationList.Add(armsCharacterAttribute);animationOverrides.ApplyCharacterCustomisationParameters(characterAttributeCustomisationList);isCarrying = true;}}public void ClearCarriedItem(){equippedItemSpriteRenderer.sprite = null;equippedItemSpriteRenderer.color = new Color(1f, 1f, 1f, 0f);// Apply base character arms customisationarmsCharacterAttribute.partVariantType = PartVariantType.none;characterAttributeCustomisationList.Clear();characterAttributeCustomisationList.Add(armsCharacterAttribute);animationOverrides.ApplyCharacterCustomisationParameters(characterAttributeCustomisationList);isCarrying = false;}private void PlayerMovement(){Vector2 move = new Vector2(xInput * movementSpeed * Time.deltaTime, yInput * movementSpeed * Time.deltaTime);rigidbody2D.MovePosition(rigidbody2D.position + move);}private void ResetAnimationTrigger(){toolEffect = ToolEffect.none;isUsingToolRight = false;isUsingToolLeft = false;isUsingToolUp = false;isUsingToolDown = false;isLiftingToolRight = false;isLiftingToolLeft = false;isLiftingToolUp = false;isLiftingToolDown = false;isPickingRight = false;isPickingLeft = false;isPickingUp = false;isPickingDown = false;isSwingToolRight = false;isSwingToolLeft = false;isSwingToolUp = false;isSwingToolDown = false;}private void PlayerMovementInput(){xInput = Input.GetAxisRaw("Horizontal");yInput = Input.GetAxisRaw("Vertical");// 斜着移动if (xInput != 0 && yInput != 0) {xInput = xInput * 0.71f;yInput = yInput * 0.71f;}// 在移动if (xInput != 0 || yInput != 0) {isRunning = true;isWalking = false;isIdle = false;movementSpeed = Settings.runningSpeed;// Capture player direction for save gameif (xInput < 0){playerDirection = Direction.left;}else if (xInput > 0){playerDirection = Direction.right;}else if (yInput < 0){playerDirection = Direction.down;}else{playerDirection = Direction.up;}}else if(xInput == 0 && yInput == 0){isRunning = false;isWalking = false;isIdle = true;}}// 按住Shift键移动为walkprivate void PlayerWalkInput(){if(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)){isRunning = false;isWalking = true;isIdle = false;movementSpeed = Settings.walkingSpeed;}else{isRunning = true;isWalking = false;isIdle = false;movementSpeed = Settings.runningSpeed;}}private void PlayerClickInput(){if (!playerToolUseDisabled){if (Input.GetMouseButton(0)){if (gridCursor.CursorIsEnabled || cursor.CursorIsEnable){// Get Cursor Grid PositionVector3Int cursorGridPosition = gridCursor.GetGridPositionForCursor();// Get Player Grid PositionVector3Int playerGridPosition = gridCursor.GetGridPositionForPlayer();ProcessPlayerClickInput(cursorGridPosition, playerGridPosition);}}}}private void ProcessPlayerClickInput(Vector3Int cursorGridPosition, Vector3Int playerGridPosition){ResetMovement();Vector3Int playerDirection = GetPlayerClickDirection(cursorGridPosition, playerGridPosition);// Get Selected item detailsItemDetails itemDetails = InventoryManager.Instance.GetSelectedInventoryItemDetails(InventoryLocation.player);// Get Grid property details at cursor position (the GridCursor validation routine ensures that grid property details are not null)GridPropertyDetails gridPropertyDetails = GridPropertiesManager.Instance.GetGridPropertyDetails(cursorGridPosition.x, cursorGridPosition.y);if(itemDetails != null){switch (itemDetails.itemType){case ItemType.Seed:if (Input.GetMouseButtonDown(0)){ProcessPlayerClickInputSeed(itemDetails);}break;case ItemType.Commodity:if (Input.GetMouseButtonDown(0)){ProcessPlayerClickInputCommodity(itemDetails);}break;case ItemType.Watering_tool:case ItemType.Hoeing_tool:case ItemType.Reaping_tool:ProcessPlayerClickInputTool(gridPropertyDetails, itemDetails, playerDirection);break;case ItemType.none:break;case ItemType.count:break;default:break;}}}private Vector3Int GetPlayerClickDirection(Vector3Int cursorGridPosition, Vector3Int playerGridPosition) {if(cursorGridPosition.x > playerGridPosition.x){return Vector3Int.right;}else if(cursorGridPosition.x < playerGridPosition.x){return Vector3Int.left;}else if(cursorGridPosition.y > playerGridPosition.y){return Vector3Int.up;}else{return Vector3Int.down;}}private Vector3Int GetPlayerDirection(Vector3 cursorPosition, Vector3 playerPosition){if(cursorPosition.x > playerPosition.x&&cursorPosition.y < (playerPosition.y + cursor.ItemUseRadius / 2f)&&cursorPosition.y > (playerPosition.y - cursor.ItemUseRadius / 2f)){return Vector3Int.right;}else if(cursorPosition.x < playerPosition.x&&cursorPosition.y < (playerPosition.y + cursor.ItemUseRadius / 2f)&&cursorPosition.y > (playerPosition.y - cursor.ItemUseRadius / 2f)){return Vector3Int.left;}else if(cursorPosition.y > playerPosition.y){return Vector3Int.up;}else{return Vector3Int.down;}}private void ProcessPlayerClickInputSeed(ItemDetails itemDetails){if(itemDetails.canBeDropped && gridCursor.CursorPositionIsValid){EventHandler.CallDropSelectedItemEvent();}}private void ProcessPlayerClickInputCommodity(ItemDetails itemDetails){if(itemDetails.canBeDropped && gridCursor.CursorPositionIsValid){EventHandler.CallDropSelectedItemEvent();}}private void ProcessPlayerClickInputTool(GridPropertyDetails gridPropertyDetails, ItemDetails itemDetails, Vector3Int playerDirection){// Switch on toolswitch (itemDetails.itemType){case ItemType.Hoeing_tool:if (gridCursor.CursorPositionIsValid){HoeGroundAtCursor(gridPropertyDetails, playerDirection);}break;case ItemType.Watering_tool:if (gridCursor.CursorPositionIsValid){WaterGroundAtCursor(gridPropertyDetails, playerDirection);}break;case ItemType.Reaping_tool:if (cursor.CursorPositionIsValid){playerDirection = GetPlayerDirection(cursor.GetWorldPositionForCursor(), GetPlayerCentrePosition());ReapInPlayerDirectionAtCursor(itemDetails, playerDirection);}break;default:break;}}private void ReapInPlayerDirectionAtCursor(ItemDetails itemDetails, Vector3Int playerDirection){StartCoroutine(ReapInPlayerDirectionAtCursorRoutine(itemDetails, playerDirection));}private IEnumerator ReapInPlayerDirectionAtCursorRoutine(ItemDetails itemDetails, Vector3Int playerDirection){PlayerInputIsDisabled = true;playerToolUseDisabled = true;// Set tool animation to scythe in override animationtoolCharacterAttribute.partVariantType = PartVariantType.scythe;characterAttributeCustomisationList.Clear();characterAttributeCustomisationList.Add(toolCharacterAttribute);animationOverrides.ApplyCharacterCustomisationParameters(characterAttributeCustomisationList);// Reap in player directionUseToolInPlayerDirection(itemDetails, playerDirection);yield return useToolAnimationPause;PlayerInputIsDisabled = false;playerToolUseDisabled = false;}private void UseToolInPlayerDirection(ItemDetails equippedItemDetails, Vector3Int playerDirection){if (Input.GetMouseButton(0)){switch (equippedItemDetails.itemType){case ItemType.Reaping_tool:if(playerDirection == Vector3Int.right){isSwingToolRight = true;}else if(playerDirection == Vector3Int.left){isSwingToolLeft = true;}else if(playerDirection == Vector3Int.up){isSwingToolUp = true;}else if(playerDirection == Vector3Int.down){isSwingToolDown = true;}break;}// Define centre point of square which will be used for collision testing,检测碰撞的中心点位置Vector2 point = new Vector2(GetPlayerCentrePosition().x + playerDirection.x * (equippedItemDetails.itemUseRadius / 2f),GetPlayerCentrePosition().y + playerDirection.y * (equippedItemDetails.itemUseRadius / 2f));// Define size of the square which will be used for collision testingVector2 size = new Vector2(equippedItemDetails.itemUseRadius, equippedItemDetails.itemUseRadius);// Get Item components with 2D collider located in the square at the centre point defined (2d colliders tested limited to maxCollidersToTestPerReapSwing)Item[] itemArray = HelperMethods.GetComponentsAtBoxLocationNonAlloc<Item>(Settings.maxCollidersToTestPerReapSwing, point, size, 0f);int reapableItemCount = 0;// Loop through all items retrievedfor(int i = itemArray.Length - 1; i >= 0; i--){if(itemArray[i] != null){// Destory item game object if reapableif (InventoryManager.Instance.GetItemDetails(itemArray[i].ItemCode).itemType == ItemType.Reapable_scenary){// Effect positionVector3 effectPosition = new Vector3(itemArray[i].transform.position.x, itemArray[i].transform.position.y + Settings.gridCellSize / 2f,itemArray[i].transform.position.z);Destroy(itemArray[i].gameObject);reapableItemCount++;if (reapableItemCount >= Settings.maxTargetComponentsToDestroyPerReapSwing)break;}}}}}private void WaterGroundAtCursor(GridPropertyDetails gridPropertyDetails, Vector3Int playerDirection) { // Trigger animationStartCoroutine(WaterGroundAtCursorRoutine(playerDirection, gridPropertyDetails));}private IEnumerator WaterGroundAtCursorRoutine(Vector3Int playerDirection, GridPropertyDetails gridPropertyDetails) {PlayerInputIsDisabled = true;playerToolUseDisabled = true;// Set tool animation to watering can in override animationtoolCharacterAttribute.partVariantType = PartVariantType.wateringCan;characterAttributeCustomisationList.Clear();characterAttributeCustomisationList.Add(toolCharacterAttribute);animationOverrides.ApplyCharacterCustomisationParameters(characterAttributeCustomisationList);toolEffect = ToolEffect.watering;if(playerDirection == Vector3Int.right){isLiftingToolRight = true;}else if(playerDirection == Vector3Int.left){isLiftingToolLeft = true;}else if(playerDirection == Vector3Int.up){isLiftingToolUp = true;}else if(playerDirection == Vector3Int.down){isLiftingToolDown = true;}yield return liftToolAnimationPause;// Set Grid property details for watered groundif(gridPropertyDetails.daysSinceWatered == -1){gridPropertyDetails.daysSinceWatered = 0;}// Set grid property to wateredGridPropertiesManager.Instance.SetGridPropertyDetails(gridPropertyDetails.gridX, gridPropertyDetails.gridY, gridPropertyDetails);// Display watered grid tilesGridPropertiesManager.Instance.DisplayWateredGround(gridPropertyDetails);// After animation pauseyield return afterLiftToolAnimationPause;PlayerInputIsDisabled = false;playerToolUseDisabled = false;}private void HoeGroundAtCursor(GridPropertyDetails gridPropertyDetails, Vector3Int playerDirection) {// Trigger animationStartCoroutine(HoeGroundAtCursorRoutine(playerDirection, gridPropertyDetails));}private IEnumerator HoeGroundAtCursorRoutine(Vector3Int playerDirection, GridPropertyDetails gridPropertyDetails){PlayerInputIsDisabled = true;playerToolUseDisabled = true;// Set tool animation to hoe in override animationtoolCharacterAttribute.partVariantType = PartVariantType.hoe;characterAttributeCustomisationList.Clear();characterAttributeCustomisationList.Add(toolCharacterAttribute);animationOverrides.ApplyCharacterCustomisationParameters(characterAttributeCustomisationList);if(playerDirection == Vector3Int.right){isUsingToolRight = true;}else if(playerDirection == Vector3Int.left){isUsingToolLeft = true;}else if(playerDirection == Vector3Int.up){isUsingToolUp = true;}else if(playerDirection == Vector3Int.down){isUsingToolDown = true;}yield return useToolAnimationPause;// Set Grid property details for dug groundif(gridPropertyDetails.daysSinceDug == -1){gridPropertyDetails.daysSinceDug = 0;}// Set grid property to dugGridPropertiesManager.Instance.SetGridPropertyDetails(gridPropertyDetails.gridX, gridPropertyDetails.gridY, gridPropertyDetails);// Display dug grid tilesGridPropertiesManager.Instance.DisplayDugGround(gridPropertyDetails);// After animation pauseyield return afterUseToolAnimationPause;PlayerInputIsDisabled = false;playerToolUseDisabled = false;}public Vector3 GetPlayerViewportPosition(){// Vector3 viewport position for player (0,0) viewport bottom left, (1,1) viewport top rightreturn mainCamera.WorldToViewportPoint(gameObject.transform.position);}public Vector3 GetPlayerCentrePosition(){return new Vector3(transform.position.x, transform.position.y + Settings.playerCentreYOffset, transform.position.z);}public void DisablePlayerInputAndResetMovement(){DisablePlayerInpupt();ResetMovement();// Send event to any listeners for player movement inputEventHandler.CallMovementEvent(xInput, yInput, isWalking, isRunning, isIdle, isCarrying, toolEffect,isUsingToolRight, isUsingToolLeft, isUsingToolUp, isUsingToolDown,isLiftingToolRight, isLiftingToolLeft, isLiftingToolUp, isLiftingToolDown,isPickingRight, isPickingLeft, isPickingUp, isPickingDown,isSwingToolRight, isSwingToolLeft, isSwingToolUp, isSwingToolDown,false, false, false, false);}private void ResetMovement(){// Reset movementxInput = 0f;yInput = 0f;isRunning = false;isWalking = false;isIdle = true;}public void DisablePlayerInpupt(){PlayerInputIsDisabled = true;}public void EnablePlayerInput(){PlayerInputIsDisabled = false;}/// <summary>/// Temp routine for test input/// </summary>private void PlayerTestInput(){// Trigger Advance Timeif (Input.GetKeyDown(KeyCode.T)){TimeManager.Instance.TestAdvanceGameMinute();}// Trigger Advance Dayif (Input.GetKeyDown(KeyCode.G)){TimeManager.Instance.TestAdvanceGameDay();}// Test scene unload / loadif (Input.GetKeyDown(KeyCode.L)){SceneControllerManager.Instance.FadeAndLoadScene(SceneName.Scene1_Farm.ToString(), transform.position);}}
}

4、运行游戏

相关文章:

Unity3D仿星露谷物语开发40之割草动画

1、目标 当Player选择Scythe后&#xff0c;鼠标悬浮在草上&#xff0c;会显示绿色光标。鼠标左击&#xff0c;会触发割草的动画。 2、优化Settings.cs脚本 添加以下两行代码&#xff1a; // Reaping&#xff08;收割&#xff09; public const int maxCollidersToTestPerRe…...

量化交易之数学与统计学基础2.4——线性代数与矩阵运算 | 矩阵分解

量化交易之数学与统计学基础2.4——线性代数与矩阵运算 | 矩阵分解 第二部分&#xff1a;线性代数与矩阵运算 第4节&#xff1a;矩阵分解&#xff1a;奇异值分解&#xff08;SVD&#xff09;在数据压缩和风险分解的应用 一、奇异值分解&#xff08;SVD&#xff09;基础&#xf…...

ES使用之查询方式

文章目录 ES中的数据查询返回字段含义track_total_hits 精准匹配(term)单值匹配多值匹配 全文检索(match)range查询高级查询布尔查询 ES中的数据查询 返回字段含义 track_total_hits track_total_hits是 Elasticsearch 中用于 ‌控制匹配文档总数统计行为‌ 的关键参数。就算…...

力扣-数组-41缺失的第一个正数

思路 关键有两点 原地哈希 把1-len的数分别映射到下标为0 - len-1的地方中 交换后&#xff0c;接着查看下标i被交换过来的数&#xff0c;直到他到了该到的位置或者超出范围 使用while&#xff0c;把不满足映射关系的点一直交换&#xff0c;直到下标指向的位置符合要求 代…...

Nginx — http、server、location模块下配置相同策略优先级问题

一、配置优先级简述 在 Nginx 中&#xff0c;http、server、location 模块下配置相同策略时是存在优先级的&#xff0c;一般遵循 “范围越小&#xff0c;优先级越高” 的原则&#xff0c;下面为你详细介绍&#xff1a; 1. 配置继承关系 http 块&#xff1a;作为全局配置块&…...

管家婆易指开单如何设置零售开单

一&#xff0c;零售设置 1&#xff0c;登录管理员账号-基本信息--职员信息-新建职员及其属于哪个门店。 2&#xff0c;系统维护-系统管理-用户配置-系统配置-切换为“触摸屏模式或者普通零售模式” 3&#xff0c;用户及权限设置-给该员工开通零售及开单等相关的权限 4&#xff…...

深入浅出循环神经网络(RNN):原理、应用与实战

1、引言 在深度学习领域&#xff0c;循环神经网络&#xff08;Recurrent Neural Network, RNN&#xff09;是一种专门用于处理**序列数据**的神经网络架构。与传统的前馈神经网络不同&#xff0c;RNN 具有**记忆能力**&#xff0c;能够捕捉数据中的时间依赖性&#xff0c;广泛应…...

【Java】打印运行环境中某个类引用的jar版本路径

背景 正式环境出现jar版本不匹配问题&#xff0c;不知道正式环境用的哪个jar版本。通过一下可以打印出类调用的jar // 获取 POIFSFileSystem 类的加载器并打印其来源路径 ClassLoader classloaderPOIFS org.apache.poi.poifs.filesystem.POIFSFileSystem.class.getClassLoade…...

【效率提升】Vibe Coding时代如何正确使用输入法:自定义短语实现Prompt快捷输入

AI时代的效率神器&#xff1a;用搜狗拼音自定义短语实现Prompt快捷输入 在日益依赖AI工具的今天&#xff0c;我们经常需要输入各种复杂的prompt来指导AI完成特定任务。有些同学完全忽视了这一层工作的意义&#xff0c;实际上不同质量的prompt对模型的表现影响是巨大的。&#…...

C# 类的基本概念(从类的内部访问成员和从类的外部访问成员)

本章内容&#xff1a; 类的概述 程序和类&#xff1a;一个简单的示例 声明类 类成员 创建变量和类的实例 为数据分配内存 实例成员 访问修饰符 从类的内部访问成员 从类的外部访问成员 综合应用 从类的内部访问成员 如前所述&#xff0c;类的成员仅用其他类成员的名称就可以访…...

端到端观测分析:从前端负载均衡到后端服务

前言 我们在做系统运维保障的时候&#xff0c;关注从前端负载均衡到后端服务的流量情况是很有必要的&#xff0c;可以了解每个后端服务实例接收的流量大小&#xff0c;这有助于确定资源分配是否合理&#xff0c;能够帮助找出后端服务中的性能瓶颈。同时&#xff0c;当系统出现…...

Axure疑难杂症:全局变量跨页面赋值、中继器交互(玩转全局变量)

亲爱的小伙伴,在您浏览之前,烦请关注一下,在此深表感谢! Axure产品经理精品视频课已登录CSDN可点击学习https://edu.csdn.net/course/detail/40420 课程主题:全局变量高级交互 主要内容:数据跨页面传递、赋值、中继器交互 应用场景:页面间值的传递、赋值 案例展示:…...

css 数字从0开始增加的动画效果

项目场景&#xff1a; 提示&#xff1a;这里简述项目相关背景&#xff1a; 在有些时候比如在做C端项目的时候&#xff0c;页面一般需要一些炫酷效果&#xff0c;比如数字会从小值自动加到数据返回的值 css 数字从0开始增加的动画效果 分析&#xff1a; 提示&#xff1a;这里填…...

【MongoDB篇】MongoDB的索引操作!

目录 引言第一节&#xff1a;天生的“索引小能手”——_id 索引 &#x1f194;第二节&#xff1a;自己动手&#xff0c;丰衣足食——创建索引 &#x1f511;&#x1f6e0;️第三节&#xff1a;索引的“类型”——因“材”施“索”&#xff01;&#x1f333;&#x1f511;第四节…...

写劳动节前的 跨系统 文件传输

功能说明&#xff1a; 协议隐身&#xff1a;流量伪装为HTTPS图片传输 动态混淆&#xff1a;每个数据包添加随机填充 军用级擦除&#xff1a;临时文件三次覆写清除 抗分析&#xff1a;随机传输时间间隔和端口跳跃 隐蔽通道&#xff1a;ALTSHIFTC触发隐藏控制台 网络架构建…...

腾讯元宝桌面客户端:基于Tauri的开源技术解析

2025年3月,腾讯元宝宣布上线电脑客户端版本,支持Windows和macOS系统。作为腾讯旗下的AI助手产品,腾讯元宝桌面端采用了Tauri而非传统的Electron作为其跨平台开发框架,这一技术选择体现了腾讯对应用性能、安全性和用户体验的重视。本文将依据腾讯元宝桌面客户端的用户规则中…...

重塑驾乘体验!哈曼Ready系列引爆「人车交互革命」

AI定义汽车趋势下&#xff0c;AI加速赋能整车辅助驾驶、智能座舱、智能底盘等各域。 以智能座舱为例&#xff0c;AI大模型的快速应用与迭代&#xff0c;推动智能座舱加速迈入“多模交互”阶段&#xff0c;融合视觉、听觉、触觉等感知技术&#xff0c;智能座舱向着终极形态演进…...

第二章-科学计算库NumPy

第二章-科学计算库NumPy Numpy 作为高性能科学计算和数据分析的基础包,是其他重要数据分析工具的基础, 掌握 NumPy 的功能及其用法, 将有助于后续其他数据分析工具的学习. 2.1 认识 NumPy 数组对象 NumPy 中最重要的一个特点就是其 N 维数组对象, 即 ndarray(别名 array) 对象…...

3.2goweb框架GORM

GORM 是 Go 语言中功能强大的 ORM&#xff08;对象关系映射&#xff09;框架&#xff0c;支持 MySQL、PostgreSQL、SQLite、SQL Server 等主流数据库。以下是 GORM 的核心概念和用法详解&#xff1a; ​​一、基础入门​​ 1. 安装 go get -u gorm.io/gorm go get -u gorm.io…...

KUKA机器人不同的用户权限详细介绍

对于KUKA机器人&#xff0c;主菜单里有一个“用户组”的登录&#xff0c;不同的用户组对应不同的权限。 一、KUKA示教器正常开机后显示以下界面&#xff0c;对于8.5及以上的系统&#xff0c;增加了快捷登录用户组的符号 &#xff0c;直接点击即可打开。在 smartHMI 上&…...

AI对IT行业的重塑:挑战与机遇并存的技术革命

一、必要性&#xff1a;AI成为IT行业的基础设施 在云计算、大数据和物联网构成的数字生态中&#xff0c;AI技术已成为IT行业的"水电煤"。以微软Azure为例&#xff0c;其AI云服务支撑着全球超过85%的《财富》500强企业&#xff0c;通过机器学习模型自动优化服务器集群…...

利用IEEE异常机制优化Fortran浮点数计算

利用IEEE异常机制优化Fortran浮点数计算 在Fortran程序中&#xff0c;IEEE浮点异常机制可以帮助你检测和优化浮点数计算&#xff0c;提高数值稳定性和程序健壮性。以下是几种利用IEEE异常机制优化浮点数计算的方法&#xff1a; 1. 启用和检测IEEE异常 现代Fortran&#xff0…...

构建网页版IPFS去中心化网盘

前言&#xff1a;我把它命名为无限网盘 Unlimited network disks&#xff08;ULND&#xff09;&#xff0c;可以实现简单的去中心化存储&#xff0c;其实实现起来并不难&#xff0c;还是依靠强大的IPFS&#xff0c;跟着我一步一步做就可以了。 第一步&#xff1a;准备开发环境…...

【solidity基础】一文说清楚合约函数的大小事

在 Solidity 里,函数是合约的关键构成部分,用于执行特定任务或操作的代码块,可以包含逻辑、访问状态变量、进行计算,并且可以接受参数和返回值。 但是solidity 的函数与其他语言不太一样,经常会有同学搞混,这里开一篇文章完整介绍一下 solidity 函数的用法。 1. 函数定…...

用Python构建自动驾驶传感器融合算法:从理论到实践

用Python构建自动驾驶传感器融合算法:从理论到实践 随着自动驾驶技术的飞速发展,传感器在自动驾驶系统中的作用愈发重要。传感器不仅是车辆感知外部环境的“眼睛”,它们提供的信息也是自动驾驶决策系统的基础。然而,单一传感器的感知能力是有限的。为了提升自动驾驶系统的…...

PLC与工业电脑:有什么区别?

随着工业部门的快速发展&#xff0c;自动化已经从奢侈品转变为绝对必需品。世界各地的工业越来越多地采用工业自动化来提高效率、提高精度并最大限度地减少停机时间。这场自动化革命的核心是两项关键技术&#xff1a;可编程逻辑控制器&#xff08;PLC&#xff09;和电脑&#x…...

机器学习:在虚拟环境中使用 Jupyter Lab

机器学习&#xff1a;在虚拟环境中使用 Jupyter Lab 第一步&#xff1a;激活虚拟环境 打开终端&#xff08;CMD/PowerShell&#xff09;并执行&#xff1a; $cmd #激活虚拟环境 $conda activate D:\conda_envs\mll_env 激活后&#xff0c;终端提示符前会显示环境名称&…...

Arduino项目实战与编程技术详解

一、智能避障小车:超声波传感器与PWM电机控制 1.1 硬件需求与工作原理 智能避障小车的核心在于超声波传感器与电机驱动模块的协同工作。超声波传感器(HC-SR04)通过发射高频声波并接收回波来测量距离,而L298N电机驱动模块则负责控制两个直流电机的转向与速度。 1.1.1 超声…...

AI数字人:人类身份与意识的终极思考(10/10)

文章摘要&#xff1a;AI数字人技术正在引发从"像素复刻"到"意识投射"的范式革命&#xff0c;多模态交互、神经辐射场等技术突破推动数字人从工具属性迈向虚拟主体。其发展伴随身份认同危机、伦理困境&#xff0c;促使人类重新思考自我认知与"人之为人…...

【单例模式】简介

目录 概念理解使用场景优缺点实现方式 概念理解 单例模式要保证一个类在整个系统运行期间&#xff0c;无论创建多少次该类的对象&#xff0c;始终只会有一个实例存在。就像操作系统中的任务管理器&#xff0c;无论何时何地调用它&#xff0c;都是同一个任务管理器在工作&#…...

安凯微以创新之芯,赋能万物智能互联新时代

在全球半导体产业步入深度调整期的当下&#xff0c;安凯微用一份“技术浓度”远超“财务数字”的年报&#xff0c;向市场传递出其作为物联网智能硬件核心SoC芯片领军者的战略定力。面对行业短期波动&#xff0c;公司选择以技术纵深突破与生态价值重构为锚点&#xff0c;在逆势中…...

TIME_WAIT状态+UDP概念及模拟实现服务器和客户端收发数据

目录 一、TIME_WAIT状态存在的原因 二、TIME_WAIT状态存在的意义 三、TIME_WAIT状态的作用 四、UDP的基本概念 4.1 概念 4.2 特点 五、模拟实现UDP服务器和客户端收发数据 5.1 服务器udpser 5.2 客户端udpcil 一、TIME_WAIT状态存在的原因 1.可靠的终止TCP连接。 2.…...

高并发内存池(五):性能测试与性能优化

前言 在前几期的实现中&#xff0c;我们完成了tcmalloc基础的内存管理功能&#xff0c;但还存在两个关键问题&#xff1a; 未处理超过256KB的大内存申请。 前期测试覆盖不足&#xff0c;导致多线程场景下隐藏了一些bug。 本文将修复这些问题&#xff0c;并实现三个目标&…...

景联文科技牵头起草的《信息技术 可扩展的生物特征识别数据交换格式 第4部分:指纹图像数据》国家标准正式发布

2025年3月28日&#xff0c;由景联文科技作为第一起草单位主导编制的国家标准GB/T 45284.4-2025 《信息技术 可扩展的生物特征识别数据交换格式 第4部分&#xff1a;指纹图像数据》正式获批发布&#xff0c;将于2025年10月1日开始实施。该标准的制定标志着我国生物特征识别领域标…...

完美解决 mobile-ffmpeg Not overwriting - exiting

在使用ffmpeg库 &#xff0c;有pcm转换到 aac的过程中报错 mobile-ffmpeg Not overwriting - exiting终于在网上翻到&#xff0c;在output 输出文件的地方加 -y, 重复覆盖的意思&#xff0c;完美解决。...

4:QT联合HALCON编程—机器人二次程序抓取开发(九点标定)

判断文件是否存在 //判断文件在不在 int HandEyeCalib::AnsysFileExists(QString FileAddr) {QFile File1(FileAddr);if(!File1.exists()){QMessageBox::warning(this,QString::fromLocal8Bit("提示"),FileAddrQString::fromLocal8Bit("文件不存在"));retu…...

C语言之操作符

目录 1. 操作符的分类 2. 移位操作符 2.1 左移操作符 << 2.2 右移操作符 >> 3. 位操作符 3.1 按位与 & 3.2 按位或 | 3.3 按位异或 ^ 3.4 按位取反 ~ 3.5 例题 3.5.1 按位异或 ^ 拓展公式 3.5.2 不能创建临时变量&#xff08;第三个变量&#xff…...

【优选算法 | 前缀和】前缀和算法:高效解决区间求和问题的关键

算法相关知识点可以通过点击以下链接进行学习一起加油&#xff01;双指针滑动窗口二分查找 在本篇文章中&#xff0c;我们将深入解析前缀和算法的原理。从基础概念到实际应用&#xff0c;带你了解如何通过前缀和高效解决数组求和、区间查询等问题。无论你是刚接触算法的新手&am…...

『深夜_MySQL』详解数据库 探索数据库是如何存储的

1. 数据库基础 1.1 什么是数据库 存储数据用文件就可以了&#xff0c;那为什么还要弄个数据库&#xff1f; 一般的文件缺失提供了数据的存储功能&#xff0c;但是文件并没有提供非常好的数据管理能力&#xff08;用户角度&#xff0c;内容方面&#xff09; 文件保存数据有以…...

Microsoft Entra ID 免费版管理云资源详解

Microsoft Entra ID(原 Azure AD)免费版为企业提供了基础的身份管理功能,适合小型团队或预算有限的组织。以下从功能解析到实战配置,全面展示如何利用免费版高效管理云资源。 1. 免费版核心功能与限制 1.1 功能概览 功能免费版支持情况基础用户与组管理✔️ 支持创建、删除…...

k8s -hpa

hpa定义弹性自动伸缩 1、横向伸缩,当定义的cpu、mem指标达到hpa值时,会触发pods伸展 2、安装metrics-server 收集pods的cpu。mem信息供hpa参照 安装helm curl -fsSl -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 用helm安装metr…...

Web应用开发指南

一、引言 随着互联网的迅猛发展&#xff0c;Web应用已深度融入日常生活的各个方面。为满足用户对性能、交互与可维护性的日益增长的需求&#xff0c;开发者需要一整套高效、系统化的解决方案。在此背景下&#xff0c;前端框架应运而生。不同于仅提供UI组件的工具库&#xff0c…...

Vue3 + TypeScript 实现 PC 端鼠标横向拖动滚动

功能说明 ​​拖动功能​​&#xff1a; 鼠标按下时记录初始位置和滚动位置拖动过程中计算移动距离并更新滚动位置松开鼠标后根据速度实现惯性滚动 ​​滚动控制​​&#xff1a; 支持鼠标滚轮横向滚动&#xff08;通过 wheel 事件&#xff09;自动边界检测防止滚动超出内容…...

MyBatis的SQL映射文件中,`#`和`$`符号的区别

在MyBatis的SQL映射文件中,#和$符号用于处理SQL语句中的参数替换,但它们的工作方式和使用场景有所不同。 #{} 符号 预编译参数:#{} 被用来作为预编译SQL语句的占位符。这意味着MyBatis会将你传入的参数设置为PreparedStatement的参数,从而防止SQL注入攻击,并允许MyBatis对…...

Python----卷积神经网络(池化为什么能增强特征)

一、什么是池化 池化&#xff08;Pooling&#xff09;是卷积神经网络&#xff08;CNN&#xff09;中的一种关键操作&#xff0c;通常位于卷积层之后&#xff0c;用于对特征图&#xff08;Feature Map&#xff09;进行下采样&#xff08;Downsampling&#xff09;。其核心目的是…...

React Native 从零开始完整教程(环境配置 → 国内镜像加速 → 运行项目)

React Native 从零开始完整教程&#xff08;环境配置 → 国内镜像加速 → 运行项目&#xff09; 本教程将从 环境配置 开始&#xff0c;到 国内镜像加速&#xff0c;最后成功运行 React Native 项目&#xff08;Android/iOS&#xff09;&#xff0c;适合新手和遇到网络问题的开…...

SNR8016语音模块详解(STM32)

目录 一、介绍 二、传感器原理 1.原理图 2.引脚描述 三、程序设计 main文件 usart.h文件 usart.c文件 四、实验效果 五、资料获取 项目分享 一、介绍 SNR8016语音模块是智纳捷科技生产的一种离线语音识别模块&#xff0c;设计适合用于DIY领域&#xff0c;开放用户设…...

驱动开发系列54 - Linux Graphics QXL显卡驱动代码分析(一)设备初始化

一&#xff1a;概述 QXL 是QEMU支持的一种虚拟显卡&#xff0c;用于虚拟化环境中的图形加速&#xff0c;旨在提高虚拟机的图形显示和远程桌面的用户体验&#xff1b;QEMU 也称 Quick Emulator&#xff0c;快速仿真器&#xff0c;是一个开源通用的仿真和虚拟化工具&#xff0c;可…...

通过IP计算分析归属地

在产品中可能存在不同客户端&#xff0c;请求同一个服务端接口的场景。 例如小程序和App或者浏览器中&#xff0c;如果需要对请求的归属地进行分析&#xff0c;前提是需要先获取请求所在的国家或城市&#xff0c;这种定位通常需要主动授权&#xff0c;而用户一般是不愿意提供的…...

【网络原理】从零开始深入理解HTTP的报文格式(二)

本篇博客给大家带来的是网络HTTP协议的知识点, 续上篇文章,接着介绍HTTP的报文格式. &#x1f40e;文章专栏: JavaEE初阶 &#x1f680;若有问题 评论区见 ❤ 欢迎大家点赞 评论 收藏 分享 如果你不知道分享给谁,那就分享给薯条. 你们的支持是我不断创作的动力 . 王子,公主请阅…...