Unity3D仿星露谷物语开发32之地面属性决定角色动作

1、目标

根据地面属性(diggable, canDropItem, canPlaceFurniture, isPath, isNPCObstacle)决定角色进行何种操作。比如没有canDropItem属性的地面,则不能放置物体。

2、优化保存Item数据

PS:这个是对已有代码的优化,与本节的主题无关。

打开Assets -> Scripts -> SaveSystem -> SceneSave.cs,

已有的代码如下:

public class SceneSave
{// string key is an identifier name we choose for this listpublic Dictionary<string, List<SceneItem>> listSceneItemDictionary;
}

已有的数据如下:

sceneSave.listSceneItemDictionary.Add("sceneItemList", sceneItemList);

因为当前只有一个itemList,所以不需要存储为字典,可以直接存储为List。

调整后代码如下:

using System.Collections.Generic;[System.Serializable]public class SceneSave
{// string key is an identifier name we choose for this listpublic List<SceneItem> listSceneItem;
}

然后打开Assets -> Scripts -> Scene -> SceneItemsManager.cs做相应的调整。

调整后的代码如下:


using System.Collections;
using System.Collections.Generic;
using UnityEngine;[RequireComponent(typeof(GenerateGUID))]
public class SceneItemsManager : SingletonMonobehaviour<SceneItemsManager>, ISaveable
{private Transform parentItem;[SerializeField] private GameObject itemPrefab = null;private string _iSaveableUniqueID;private GameObjectSave _gameObjectSave;public string ISaveableUniqueID { get { return _iSaveableUniqueID; } set { _iSaveableUniqueID = value; } }public GameObjectSave GameObjectSave { get { return _gameObjectSave; } set { _gameObjectSave = value; } }private void AfterSceneLoad(){parentItem = GameObject.FindGameObjectWithTag(Tags.ItemsParentTransform).transform;}protected override void Awake(){base.Awake();ISaveableUniqueID = GetComponent<GenerateGUID>().GUID;GameObjectSave = new GameObjectSave();}private void OnEnable(){ISaveableRegister();EventHandler.AfterSceneLoadEvent += AfterSceneLoad;}private void OnDisable(){ISaveableDeregister();EventHandler.AfterSceneLoadEvent -= AfterSceneLoad;}public void ISaveableDeregister(){SaveLoadManager.Instance.iSaveableObjectList.Remove(this);}public void ISaveableRegister(){// 将当前对象添加到iSaveableObjectList中SaveLoadManager.Instance.iSaveableObjectList.Add(this);}// 恢复场景public void ISaveableRestoreScene(string sceneName){if(GameObjectSave.sceneData.TryGetValue(sceneName, out SceneSave sceneSave)){if(sceneSave.listSceneItem != null){// scene list items found - destroy existing items in sceneDestroySceneItems();// new instantiate the list of scene itemsInstantiateSceneItems(sceneSave.listSceneItem);}}}private void InstantiateSceneItems(List<SceneItem> sceneItemList){GameObject itemGameObject;foreach(SceneItem sceneItem in sceneItemList){itemGameObject = Instantiate(itemPrefab, new Vector3(sceneItem.position.x, sceneItem.position.y, sceneItem.position.z), Quaternion.identity, parentItem);Item item = itemGameObject.GetComponent<Item>();item.ItemCode = sceneItem.itemCode;item.name = sceneItem.itemName;}}// Destroy items currently in the sceneprivate void DestroySceneItems(){// Get all items in the sceneItem[] itemsInScene = GameObject.FindObjectsOfType<Item>();// Loop through all scene items and destroy themfor(int i = itemsInScene.Length - 1; i > -1; i--){Destroy(itemsInScene[i].gameObject);}}// 保存场景public void ISaveableStoreScene(string sceneName){// Remove old scene save for gameObject if existsGameObjectSave.sceneData.Remove(sceneName);// Get all items in the sceneList<SceneItem> sceneItemList = new List<SceneItem>();Item[] itemsInScene = FindObjectsOfType<Item>();// Loop through all scene itemsforeach(Item item in itemsInScene){SceneItem sceneItem = new SceneItem();sceneItem.itemCode = item.ItemCode;sceneItem.position = new Vector3Serializable(item.transform.position.x, item.transform.position.y,item.transform.position.z);sceneItem.itemName = item.name;// Add scene item to listsceneItemList.Add(sceneItem);}// Create list scene items dictionary in scene save and add to itSceneSave sceneSave = new SceneSave();sceneSave.listSceneItem = sceneItemList;// Add scene save to gameobjectGameObjectSave.sceneData.Add(sceneName, sceneSave);}
}

改动点是:

// 恢复场景
    public void ISaveableRestoreScene(string sceneName)
    {
        if(GameObjectSave.sceneData.TryGetValue(sceneName, out SceneSave sceneSave))
        {
            if(sceneSave.listSceneItem != null)  // 精简了这块的代码
            {
                // scene list items found - destroy existing items in scene
                DestroySceneItems();

                // new instantiate the list of scene items
                InstantiateSceneItems(sceneSave.listSceneItem);
            }
        }
    }

3、优化SceneSave.cs

增加保存地面属性信息。

using System.Collections.Generic;[System.Serializable]public class SceneSave
{// string key is an identifier name we choose for this listpublic List<SceneItem> listSceneItem;public Dictionary<string, GridPropertyDetails> gridPropertyDetailsDictionary; // key是坐标信息,value是地面属性信息
}

public Dictionary<string, GridPropertyDetails> gridPropertyDetailsDictionary;中,string会保存网格的坐标信息。

4、创建GridPropertyDetails.cs

在Assets -> Scripts -> Map下新增GridPropertyDetails.cs脚本。


[System.Serializable]
public class GridPropertyDetails
{public int gridX;public int gridY;public bool isDiggable = false;public bool canDropItem = false;public bool canPlaceFurniture = false;public bool isPath = false;public bool isNPCObstacle = false;public int daysSinceDug = -1;public int daysSinceWatered = -1;public int seedItemCode = -1;public int growthDays = -1;public int daysSinceLastHarvest = -1;public GridPropertyDetails() { }
}

其中上半部分的属性是已知的,下半部分的信息是在运行中赋值的。

5、创建GridPropertiesManager.cs脚本

在Assets -> Scripts -> Map下新增GridPropertiesManager.cs脚本。

该类会读取Assets -> Scriptable Object Assets -> Maps下的3个so_xxx资源文件,然后写到SceneSave的gridPropertyDetailsDictionary中去。

using System.Collections;
using System.Collections.Generic;
using JetBrains.Annotations;
using UnityEngine;[RequireComponent(typeof(GenerateGUID))]
public class GridPropertiesManager : SingletonMonobehaviour<GridPropertiesManager>, ISaveable
{public Grid grid;private Dictionary<string, GridPropertyDetails> gridPropertyDictionary;[SerializeField] private SO_GridProperties[] so_gridPropertiesArray = null;private string _iSaveableUniqueID;private GameObjectSave _gameObjectSave;public string ISaveableUniqueID { get { return _iSaveableUniqueID; } set { _iSaveableUniqueID = value; } }public GameObjectSave GameObjectSave { get { return _gameObjectSave; } set { _gameObjectSave = value; } }protected override void Awake(){base.Awake();ISaveableUniqueID = GetComponent<GenerateGUID>().GUID;GameObjectSave = new GameObjectSave();}private void OnEnable(){ISaveableRegister();EventHandler.AfterSceneLoadEvent += AfterSceneLoaded;}private void OnDisable() {ISaveableDeregister();EventHandler.AfterSceneLoadEvent -= AfterSceneLoaded;}private void AfterSceneLoaded(){// Get Gridgrid = GameObject.FindObjectOfType<Grid>();}public void ISaveableDeregister(){SaveLoadManager.Instance.iSaveableObjectList.Remove(this);}public void ISaveableRegister(){SaveLoadManager.Instance.iSaveableObjectList.Add(this);}public void ISaveableRestoreScene(string sceneName){// Get sceneSave for scene - it exists since we created it in initialiseif(GameObjectSave.sceneData.TryGetValue(sceneName, out SceneSave sceneSave)){// get grid property details dictionary - it exists since we created it in initialiseif(sceneSave.gridPropertyDetailsDictionary != null){gridPropertyDictionary = sceneSave.gridPropertyDetailsDictionary;}}}public void ISaveableStoreScene(string sceneName){// Remove sceneSave for sceneGameObjectSave.sceneData.Remove(sceneName);// Create sceneSave for sceneSceneSave sceneSave = new SceneSave();// create & add dict grid property details dictionarysceneSave.gridPropertyDetailsDictionary = gridPropertyDictionary;// Add scene save to game object scene dataGameObjectSave.sceneData.Add(sceneName, sceneSave);}private void Start(){InitialiseGridProperties();}/// <summary>/// This initialises the grid property dictionary with the values from the SO_GridProperties assets and stores the values for each scene in/// GameObjectSave sceneData/// </summary>private void InitialiseGridProperties(){// loop through all gridproperties in the arrayforeach(SO_GridProperties so_GridProperties in so_gridPropertiesArray){// Create dictionary of grid property detailsDictionary<string, GridPropertyDetails> gridPropertyDictionary = new Dictionary<string, GridPropertyDetails>();// Populate grid property dictionary - Iterate through all the grid properties in the so gridproperties listforeach(GridProperty gridProperty in so_GridProperties.gridPropertyList){GridPropertyDetails gridPropertyDetails;gridPropertyDetails = GetGridPropertyDetails(gridProperty.gridCoordinate.x, gridProperty.gridCoordinate.y, gridPropertyDictionary);if(gridPropertyDetails == null){gridPropertyDetails = new GridPropertyDetails();}switch (gridProperty.gridBoolProperty){case GridBoolProperty.diggable:gridPropertyDetails.isDiggable = gridProperty.gridBoolValue;break;case GridBoolProperty.canDropItem:gridPropertyDetails.canDropItem = gridProperty.gridBoolValue;break;case GridBoolProperty.canPlaceFurniture:gridPropertyDetails.canPlaceFurniture = gridProperty.gridBoolValue;break;case GridBoolProperty.isPath:gridPropertyDetails.isPath = gridProperty.gridBoolValue;break;case GridBoolProperty.isNPCObstacle:gridPropertyDetails.isNPCObstacle = gridProperty.gridBoolValue;break;default:break; }SetGridPropertyDetails(gridProperty.gridCoordinate.x, gridProperty.gridCoordinate.y, gridPropertyDetails, gridPropertyDictionary);}// Create scene save for this gameobjectSceneSave sceneSave = new SceneSave();// Add grid property dictionary to scene save datasceneSave.gridPropertyDetailsDictionary = gridPropertyDictionary;// If starting scene set the griProertyDictionary member variable to the current iterationif(so_GridProperties.sceneName.ToString() == SceneControllerManager.Instance.startingSceneName.ToString()){this.gridPropertyDictionary = gridPropertyDictionary;}// Add scene save to game object scene dataGameObjectSave.sceneData.Add(so_GridProperties.sceneName.ToString(), sceneSave);}}/// <summary>/// Returns the gridPropertyDetails at the gridlocation fro the supplied dictionary,/// or null if no properties exist at that location/// </summary>/// <param name="gridX"></param>/// <param name="gridY"></param>/// <param name="gridPropertyDictionary"></param>/// <returns></returns>public GridPropertyDetails GetGridPropertyDetails(int gridX, int gridY, Dictionary<string, GridPropertyDetails> gridPropertyDictionary){// Construct key from coordinatestring key = "x" + gridX + "y" + gridY;GridPropertyDetails gridPropertyDetails;// Check if grid property details exist for coordinate and retrieveif (!gridPropertyDictionary.TryGetValue(key, out gridPropertyDetails)){// if not foundreturn null;}else{return gridPropertyDetails;}}public GridPropertyDetails GetGridPropertyDetails(int gridX, int gridY){return GetGridPropertyDetails(gridX, gridY, gridPropertyDictionary);}/// <summary>/// Set the grid property details to gridPropertyDetails fro the tile at (gridX, gridY) for current scene/// </summary>/// <param name="gridX"></param>/// <param name="gridY"></param>/// <param name="gridPropertyDetails"></param>public void SetGridPropertyDetails(int gridX, int gridY, GridPropertyDetails gridPropertyDetails){SetGridPropertyDetails(gridX, gridY, gridPropertyDetails, gridPropertyDictionary);}/// <summary>/// Set the grid property details to gridPropertyDetails for the title at (gridX, gridY) for the gridPropertyDictionary./// </summary>/// <param name="gridX"></param>/// <param name="gridY"></param>/// <param name="gridPropertyDetails"></param>/// <param name="gridPropertyDictionary"></param>public void SetGridPropertyDetails(int gridX, int gridY, GridPropertyDetails gridPropertyDetails, Dictionary<string, GridPropertyDetails> gridPropertyDictionary){// Construct key from coordinatestring key = "x" + gridX + "y" + gridY;gridPropertyDetails.gridX = gridX;gridPropertyDetails.gridY = gridY;// Set value gridPropertyDictionary[key] = gridPropertyDetails;}}

6、优化Settings.cs

Assets -> Scripts -> Misc -> Settings.cs文件。

增加如下代码:

 // Tilemappublic const float gridCellSize = 1f; // grid cell size in unity units

7、优化UIInventorySlot.cs

Assets -> Scripts -> UI -> UIInventory -> UIInventorySlot.cs

经过前面几步的准备,现在我们在Drop Item时可以做一层判断。

调整DropSelectedItemAtMousePosition函数如下:

  private void DropSelectedItemAtMousePosition(){if(itemDetails != null && isSelected){Vector3 worldPosition = mainCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -mainCamera.transform.position.z));// If can drop item hereVector3Int gridPosition = GridPropertiesManager.Instance.grid.WorldToCell(worldPosition);GridPropertyDetails gridPropertyDetails = GridPropertiesManager.Instance.GetGridPropertyDetails(gridPosition.x, gridPosition.y);if(gridPropertyDetails != null && gridPropertyDetails.canDropItem){// Create item from prefab at mouse positionGameObject itemGameObject = Instantiate(itemPrefab, new Vector3(worldPosition.x, worldPosition.y - Settings.gridCellSize/2f, worldPosition.z), Quaternion.identity, parentItem);Item item = itemGameObject.GetComponent<Item>();item.ItemCode = itemDetails.itemCode;// Remove item from player's inventoryInventoryManager.Instance.RemoveItem(InventoryLocation.player, item.ItemCode);// If no more of item then clear selectedif (InventoryManager.Instance.FindItemInInventory(InventoryLocation.player, item.ItemCode) == -1){ClearSelectedItem();}}}}

因为Item的中心在pivot(底部),如果不调整item的中心位置,每次放置Item到地面时都会导致Item的y轴上的落地点比鼠标位置高一点。

所以我们通过new Vector3(worldPosition.x, worldPosition.y - Settings.gridCellSize/2f, worldPosition.z),适当调整y的位置。

UIInventorySlot.cs完整代码如下:

using UnityEngine;
using TMPro;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System;public class UIInventorySlot : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
{private Camera mainCamera;private Transform parentItem; // 场景中的物体父类private GameObject draggedItem; // 被拖动的物体private Canvas parentCanvas;public Image inventorySlotHighlight;public Image inventorySlotImage;public TextMeshProUGUI textMeshProUGUI;[SerializeField] private UIInventoryBar inventoryBar = null;[SerializeField] private GameObject itemPrefab = null;[SerializeField] private int slotNumber = 0; // 插槽的序列号[SerializeField] private GameObject inventoryTextBoxPrefab = null;[HideInInspector] public ItemDetails itemDetails;[HideInInspector] public int itemQuantity;[HideInInspector] public bool isSelected = false;private void Awake(){parentCanvas = GetComponentInParent<Canvas>();}private void OnDisable(){EventHandler.AfterSceneLoadEvent -= SceneLoaded;}private void OnEnable(){EventHandler.AfterSceneLoadEvent += SceneLoaded;}public void SceneLoaded(){parentItem = GameObject.FindGameObjectWithTag(Tags.ItemsParentTransform).transform;}private void Start(){mainCamera = Camera.main;//parentItem = GameObject.FindGameObjectWithTag(Tags.ItemsParentTransform).transform;}public void OnBeginDrag(PointerEventData eventData){if(itemDetails != null) {// Disable keyboard inputPlayer.Instance.DisablePlayerInputAndResetMovement();// Instatiate gameobject as dragged itemdraggedItem = Instantiate(inventoryBar.inventoryBarDraggedItem, inventoryBar.transform);// Get image for dragged itemImage draggedItemImage = draggedItem.GetComponentInChildren<Image>();draggedItemImage.sprite = inventorySlotImage.sprite;SetSelectedItem();}}public void OnDrag(PointerEventData eventData){// move game object as dragged itemif(!draggedItem != null){draggedItem.transform.position = Input.mousePosition;}}public void OnEndDrag(PointerEventData eventData){// Destroy game object as dragged itemif (draggedItem != null) {Destroy(draggedItem);// if drag ends over inventory bar, get item drag is over and swap thenif (eventData.pointerCurrentRaycast.gameObject != null && eventData.pointerCurrentRaycast.gameObject.GetComponent<UIInventorySlot>() != null) {// get the slot number where the drag endedint toSlotNumber = eventData.pointerCurrentRaycast.gameObject.GetComponent<UIInventorySlot>().slotNumber;// Swap inventory items in inventory listInventoryManager.Instance.SwapInventoryItems(InventoryLocation.player, slotNumber, toSlotNumber);// Destroy inventory text boxDestroyInventoryTextBox();// Clear selected itemClearSelectedItem();}else{// else attemp to drop the item if it can be droppedif (itemDetails.canBeDropped){DropSelectedItemAtMousePosition();}}// Enable player inputPlayer.Instance.EnablePlayerInput();}}/// <summary>/// Drops the item(if selected) at the current mouse position. called by the DropItem event/// </summary>private void DropSelectedItemAtMousePosition(){if(itemDetails != null && isSelected){Vector3 worldPosition = mainCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -mainCamera.transform.position.z));// If can drop item hereVector3Int gridPosition = GridPropertiesManager.Instance.grid.WorldToCell(worldPosition);GridPropertyDetails gridPropertyDetails = GridPropertiesManager.Instance.GetGridPropertyDetails(gridPosition.x, gridPosition.y);if(gridPropertyDetails != null && gridPropertyDetails.canDropItem){// Create item from prefab at mouse positionGameObject itemGameObject = Instantiate(itemPrefab, new Vector3(worldPosition.x, worldPosition.y - Settings.gridCellSize/2f, worldPosition.z), Quaternion.identity, parentItem);Item item = itemGameObject.GetComponent<Item>();item.ItemCode = itemDetails.itemCode;// Remove item from player's inventoryInventoryManager.Instance.RemoveItem(InventoryLocation.player, item.ItemCode);// If no more of item then clear selectedif (InventoryManager.Instance.FindItemInInventory(InventoryLocation.player, item.ItemCode) == -1){ClearSelectedItem();}}}}public void OnPointerEnter(PointerEventData eventData){// Populate text box with item detailsif(itemQuantity != 0){// Instantiate inventory text boxinventoryBar.inventoryTextBoxGameobject = Instantiate(inventoryTextBoxPrefab, transform.position, Quaternion.identity);inventoryBar.inventoryTextBoxGameobject.transform.SetParent(parentCanvas.transform, false);UIInventoryTextBox inventoryTextBox = inventoryBar.inventoryTextBoxGameobject.GetComponent<UIInventoryTextBox>();// Set item type descriptionstring itemTypeDescription = InventoryManager.Instance.GetItemTypeDescription(itemDetails.itemType);// Populate text boxinventoryTextBox.SetTextboxText(itemDetails.itemDescription, itemTypeDescription, "", itemDetails.itemLongDescription, "", "");// Set text box position according to inventory bar positionif (inventoryBar.IsInventoryBarPositionBottom){inventoryBar.inventoryTextBoxGameobject.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0f);inventoryBar.inventoryTextBoxGameobject.transform.position = new Vector3(transform.position.x, transform.position.y + 50f, transform.position.z);}else{inventoryBar.inventoryTextBoxGameobject.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 1f);inventoryBar.inventoryTextBoxGameobject.transform.position = new Vector3(transform.position.x, transform.position.y - 50f, transform.position.z);}}}public void OnPointerExit(PointerEventData eventData){DestroyInventoryTextBox();}private void DestroyInventoryTextBox(){if (inventoryBar.inventoryTextBoxGameobject != null) {Destroy(inventoryBar.inventoryTextBoxGameobject);}}public void OnPointerClick(PointerEventData eventData){// if left clickif (eventData.button == PointerEventData.InputButton.Left){// if inventory slot currently selected then deselectif (isSelected == true){ClearSelectedItem();}else  // 未被选中且有东西则显示选中的效果{if(itemQuantity > 0){SetSelectedItem();}}}}/// <summary>/// Set this inventory slot item to be selected/// </summary>private void SetSelectedItem(){// Clear currently highlighted itemsinventoryBar.ClearHighlightOnInventorySlots();// Highlight item on inventory barisSelected = true;// Set highlighted inventory slotsinventoryBar.SetHighlightedInventorySlots();// Set item selected in inventoryInventoryManager.Instance.SetSelectedInventoryItem(InventoryLocation.player, itemDetails.itemCode);if (itemDetails.canBeCarried == true){// Show player carrying itemPlayer.Instance.ShowCarriedItem(itemDetails.itemCode);}else {Player.Instance.ClearCarriedItem();}}private void ClearSelectedItem(){// Clear currently highlighted iteminventoryBar.ClearHighlightOnInventorySlots();isSelected = false;// set no item selected in inventoryInventoryManager.Instance.ClearSelectedInventoryItem(InventoryLocation.player);// Clear player carrying itemPlayer.Instance.ClearCarriedItem();}
}

8、创建GridPropertiesManager对象

在Hierarchy -> PersistentScene下创建空物体命名为:GridPropertiesManager。

添加组件GridPropertiesManager如下(同时会自动创建Generate GUID组件):

然后,锁定面板,将3个so_xxx 文件拖到So_grid Properties Array中:

保存后执行程序:将采集的corn拖到地板位置,无法放置。

9、绘制CanDropItem区域

点击Scene1_Farm的GridProperties对象,在Inspector勾选组件启用。

点击BoolCanDropItem对象,点击Tile Palette面板,使用tile在scene界面中放置瓦片。

然后进入Inspector面板,反勾选Tilemap Render组件。

接着点击GridProperties对象,反勾选GridProperties组件。此时点击Assets -> Scriptable Object Assets的So_Grid_Properties_Scene1_Farm文件,可以看到Grid Property List有2000+个元素。

接下来,针对Scene2和Scene3进行同样的操作。

Scene2:

Scene3:

10、效果演示

如上所示,草地位置是有CanDropItem属性的,所以可以放置南瓜;而屋顶位置没有CanDropItem属性,所以无法放置南瓜。

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

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

相关文章

031-valgrind

valgrind 以下是从原理到代码实现、参数优化及结果分析的Valgrind技术调研报告&#xff0c;结合C示例和可视化工具使用说明&#xff1a; 一、Valgrind核心原理与架构 1.1 系统架构 #mermaid-svg-xIgV3fg90dGhEEq4 {font-family:"trebuchet ms",verdana,arial,sans-…

C/C++蓝桥杯算法真题打卡(Day12)

一、P8752 [蓝桥杯 2021 省 B2] 特殊年份 - 洛谷 算法代码&#xff1a; #include<bits/stdc.h> using namespace std; int cnt;int main() {int i1;while(i<5){int num;cin>>num;string string_numto_string(num);if(string_num[0]string_num[2]&&str…

MySQL 复制与主从架构(Master-Slave)

MySQL 复制与主从架构&#xff08;Master-Slave&#xff09; MySQL 复制与主从架构是数据库高可用和负载均衡的重要手段。通过复制数据到多个从服务器&#xff0c;既可以实现数据冗余备份&#xff0c;又能分担查询压力&#xff0c;提升系统整体性能与容错能力。本文将详细介绍…

《大模型部署》——ollama下载及大模型本地部署(详细快速部署)

ollama Ollama 是一款开源跨平台的大语言模型&#xff08;LLM&#xff09;运行工具&#xff0c;旨在简化本地部署和管理 AI 模型的流程。 下载ollama 进入官网下载https://ollama.com/ 选择需要的系统下载 下载完成后直接进行安装 下载大模型 选择想要部署的模型&#…

Java关于包和final

什么是包&#xff1f; 包就是文件夹。用来管理等各种不同功能的java类&#xff0c;方便后期代码维护 包名的规则&#xff1a;公司域名反写包的作用&#xff0c;需要全部英文小写&#xff0c;见名知意。例如&#xff1a;com.pdsu.domain package com.pdsu.demain;public class…

数据层的基本操作

1.数据层的更名: Arcmap内容列表中,数据框所包含的每个图层及每个图层所包含的一系列地理要素,都有相应的描述字符与之对应.默认情况下,添加进地图的图层是以其数据源的名字命名的,而地理要素的描述就是要素类型字段取值.由于这些命名影响到用户对数据的理解和地图输出时的图例…

Vue舞台剧

Vue 的舞台剧比喻 &#x1f3ad;&#xff08;完整表格版&#xff09; Vue 结构及路由管理 Vue 结构比喻&#xff08;舞台剧&#xff09;&#x1f3ad;作用index.html空白场地 &#x1f3df;️Vue 负责填充内容&#xff0c;提供 #app 容器&#xff0c;等待演出开始。main.js导…

【Windows】win10系统安装.NET Framework 3.5(包括.NET 2.0和3.0)失败 错误代码:0×80240438

一、.NET3.5(包括.NET 2.0和3.0)安装方式 1.1 联网安装(需要联网,能访问微软,简单,很可能会失败) 1.2 离线安装-救急用(需要操作系统iso镜像文件,复杂,成功几率大) 二、联网安装 通过【控制面板】→【程序】→【程序和功能】→【启用或关闭Windows功能】 下载过程…

Android学习总结之RecyclerView补充篇

在 Android 开发中&#xff0c;列表数据更新的性能一直是关键痛点。传统的 notifyDataSetChanged() 会触发全量刷新&#xff0c;导致不必要的界面重绘。而 DiffUtil 作为 Android 提供的高效差异计算工具&#xff0c;能精准识别数据变化&#xff0c;实现局部更新&#xff0c;成…

Miniforge3高效管理 Python环境:2025年最新实践指南

Miniforge3 高效管理 Python 环境:2025 年最新实践指南 在现代开发中,灵活高效地管理 Python 环境至关重要。Miniforge3 作为一款轻量级 Conda 管理工具,不仅默认采用更新更快的 conda-forge 软件源,还对 ARM 架构(例如 Apple M1/M2/M3)有着出色的适配性。相比于传统的 …

山东大学软件学院项目创新实训开发日志(4)之中医知识问答数据存储、功能结构、用户界面初步设计

目录 数据库设计&#xff1a; 功能设计&#xff1a; 用户界面: 数据库设计&#xff1a; --对话表 (1个对话包含多条消息) CREATE TABLE conversations ( conv_id VARCHAR(36) PRIMARY KEY, -- 对话ID user_id VARCHAR(36) NOT NULL, -- 所属用户 title VARCHAR(100), -- 对话…

交换机、路由器、VLAN、单臂路由、三层交换、STP

华为模拟安装 1.依次安装wincap 2.wireshark 3.virtual box 4.ensp 一、设置 1.virtual box设置 2.计算机防火墙允许以上程序 3.eNSP设置 路由器&#xff1a;AR2240 交换机&#xff1a;S5700、CE12800 防火墙USG6000V 交换机 一、交换机工作原理 1、回顾 二层交换机…

【蓝桥杯】每日练习 Day15

目录 前言 奶牛选美 分析 代码 大臣的旅费 分析 代码 飞机降落 分析 代码 母亲的牛奶 分析 代码 扫雷 分析 代码 前言 虽为诞辰&#xff0c;但也不忘完成每日的训练。 今天给大家带来五道dfs的题目&#xff0c;包括组合数&#xff0c;连通块&#xff0c;数的…

ipconfig、ping、ipconfig/all 4个常用 **Windows终端(CMD)命令** 的详细解释

ipconfig、ping、ipconfig/all 4个常用 Windows终端&#xff08;CMD&#xff09;命令 的详细解释、用途分析和使用示例 1. ipconfig 作用 快速查看本地网络连接的 IP地址、子网掩码、默认网关 等基础信息。 示例输出 Windows IP 配置无线局域网适配器 WLAN:IPv4 地址 . . .…

@emotion/css + react+动态主题切换

1.下载插件 npm install --save emotion/css 2.创建ThemeContext.tsx // src/ThemeContext.tsx import React, { createContext, useContext, useState } from "react";// 定义主题类型 export type Theme "light" | "dark";// 定义主题上下…

【信奥一本通提高篇】基础算法之贪心算法

原文 https://bbs.fmcraft.top/blog/index.php/archives/22/ 贪心算法 概述 近年来的信息学竞赛试题&#xff0c;经常出现求一个问题的可行解或最优解的题目。这类问题就是我们通常所说的最优化问题。贪心算法是求解这类问题的一种常用算法。在众多的算法中&#xff0c;贪心…

CentOS-7.0系统基础操作

配置ip地址 编辑网卡文件&#xff1a; vi etc/sysconfig/network-scripts/ifcfg-ens33 在网卡文件里参照如下设置&#xff1a; BOOTPROTO"static" IPADDR192.168.61.233 GATEWAY192.168.61.2 NETMASK255.255.255.0 ONBOOT"yes" 防火墙管理 开启防火墙&am…

【大模型应用】信息抽取的调研

老规矩&#xff0c;先占坑&#xff0c;后续更新。 关键词&#xff1a; Pydantic functioncal 参考文献&#xff1a;小白学大模型&#xff1a;自定义信息抽取Agent-CSDN博客

MySQL内存使用率高问题排查与解决方案:

目录标题 **一、问题现象****二、核心排查步骤****1. 参数检查****2. 内存使用分析****3. 存储过程/函数/视图检查****4. 操作系统级检查** **三、解决方案****1. 调整MySQL配置****2. 关闭透明大页&#xff08;THP&#xff09;****3. 优化查询与存储过程****4. 硬件与环境优化…

华为GaussDB数据库的手动备份与还原操作介绍

数据库的备份以A机上的操作为例。 1、使用linux的root用户登录到GaussDB服务器。 2、用以下命令切换到 GaussDB 管理员用户&#xff0c;其中&#xff0c;omm 为当前数据库的linux账号。 su - omm 3、执行gs_dump命令进行数据库备份&#xff1a; 这里使用gs_dump命令进行备…