Compare commits

...

5 Commits

Author SHA1 Message Date
taosuqi e16e5d4c09 修改工具面板 2024-08-15 21:28:36 +08:00
taosuqi bcb3764573 Merge branch 'main' of http://172.16.1.12/WangWeiZhi/YanCheng_Metrology into main 2024-08-15 20:38:50 +08:00
taosuqi 8e36bd262c 1 2024-08-15 20:38:45 +08:00
taosuqi b440a3f564 合并融合 2024-08-15 20:34:31 +08:00
taosuqi 2a27c3bf7a 融合 2024-08-15 20:33:25 +08:00
7 changed files with 101 additions and 70 deletions

View File

@ -144,11 +144,11 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalPosition.x
value: -1.134
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalPosition.y
value: 1.24
value: 1.5
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalPosition.z
@ -156,7 +156,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalRotation.w
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalRotation.x
@ -164,7 +164,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalRotation.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalRotation.z
@ -176,7 +176,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
value: 180
objectReference: {fileID: 0}
- target: {fileID: 2399593117452945566, guid: 86a8666f9623b6b46b8f4b860a11546f, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
@ -6201,6 +6201,10 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2557768358979172441, guid: f8a9676618f065446b3926269089375e, type: 3}
propertyPath: toolId
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2557768358979172441, guid: f8a9676618f065446b3926269089375e, type: 3}
propertyPath: _highlight
value:

View File

@ -8,14 +8,13 @@ using UnityEngine;
public class PacksackBagMgr : BaseManager<PacksackBagMgr>
{
//包里用了哪些工器具
private readonly Dictionary<string, ToolAndMaterialData> toolAndMaterialDic =
new Dictionary<string, ToolAndMaterialData>();
private readonly Dictionary<int, List<ItemInfo>> toolAndMaterialDic = new Dictionary<int, List<ItemInfo>>();
private PacksackBagMgr()
{
}
public Dictionary<string, ToolAndMaterialData> GetCurrentBagData()
public Dictionary<int, List<ItemInfo>> GetCurrentBagData()
{
return toolAndMaterialDic;
}
@ -25,20 +24,15 @@ public class PacksackBagMgr : BaseManager<PacksackBagMgr>
/// 添加一个工器具或材料
/// </summary>
/// <param name="name"></param>
public void AddOneToolOrMater(string name)
public void AddOneToolOrMater(ItemInfo itemInfo)
{
if (toolAndMaterialDic.ContainsKey(name))
if (toolAndMaterialDic.ContainsKey(itemInfo.toolId))
{
toolAndMaterialDic[name].count++;
toolAndMaterialDic[itemInfo.toolId].Add(itemInfo);
}
else
{
//从配置里得知是tool or Material
var tempToolOrMaterType = GameManager.ToolAndmaterialMgr.GetObjType(name);
if (tempToolOrMaterType == -1) return;
var tempToolAndMaterData = new ToolAndMaterialData()
{ count = 1, objName = name, type = tempToolOrMaterType };
toolAndMaterialDic.Add(name, tempToolAndMaterData);
toolAndMaterialDic.Add(itemInfo.toolId, new List<ItemInfo>() { itemInfo });
}
}
@ -46,14 +40,17 @@ public class PacksackBagMgr : BaseManager<PacksackBagMgr>
/// 移除一个工器具或材料
/// </summary>
/// <param name="name"></param>
public void RemoveOneToolOrMater(string name)
public void RemoveOneToolOrMater(ItemInfo itemInfo)
{
if (toolAndMaterialDic.ContainsKey(name))
if (toolAndMaterialDic.ContainsKey(itemInfo.toolId))
{
var toolAndMaterCount = toolAndMaterialDic[name].count--;
if (toolAndMaterCount <= 0)
if (toolAndMaterialDic[itemInfo.toolId].Count > 1)
{
toolAndMaterialDic.Remove(name);
toolAndMaterialDic[itemInfo.toolId].Remove(itemInfo);
}
else
{
toolAndMaterialDic.Remove(itemInfo.toolId);
}
}
}

View File

@ -1,65 +1,103 @@
using HighlightPlus;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using TMPro;
using UnityEditor;
using UnityEngine;
using UnityEngine.EventSystems;
[Serializable]
public class ItemInfo
{
public int toolId;
public int triggerID;
public string toolName;
public E_ToolOrDeviceOrMaterials toolOrDeviceOrMaterial;
// 你可以在这里添加更多的属性和方法
}
/// <summary>
/// 工具或者材料基类,此脚本必须挂在工具或者材料上
/// </summary>
public abstract class BaseToolOrDevice : MonoBehaviour
{
/// <summary>
/// 工具Id
/// </summary>
public int toolId;
public string toolName;
/// <summary>
/// 工器具类型 工具/材质/设备
/// </summary>
public E_ToolOrDeviceOrMaterials toolOrDeviceOrMaterial;
public ItemInfo itemInfo;
public HighlightEffect _highlight;
public bool IsClick = true;
private void Start()
{
_highlight = GetComponent<HighlightEffect>();
}
[ContextMenu("GetInfo")]
public void GetInfo()
public void GetInfo(string itemName)
{
//TODO:后续 根据英文名称去获取ID 中文名 和其它
}
//public void GetInfo(string itemName)
//{
// if (itemDatabase.ContainsKey(itemName))
// {
// ItemInfo info = itemDatabase[itemName];
// OnItemInfoReceived?.Invoke(info);
// }
//}
//public void GetInfo(GameObject Item,string ItemName,E_ToolOrDeviceOrMaterials E_Item)
//{
// Item.SetActive(false);
// if (itemDatabase.ContainsKey(ItemName))
// {
// // 获取物品信息
// ItemInfo info = itemDatabase[ItemName];
// // TODO: 后续处理例如更新UI或执行其他逻辑
// }
// else
// {
// Debug.LogWarning($"物品 '{ItemName}' 不存在于数据库中");
// }
// switch (E_Item)
// {
// case E_ToolOrDeviceOrMaterials.Tool:
// break;
// case E_ToolOrDeviceOrMaterials.Materials:
// break;
// }
// //TODO:后续 根据英文名称去获取ID 中文名 和其它
//}
private void OnMouseEnter()
{
if (GameManager.RunModelMgr.SceneType!= E_SceneType.ToolRoom) return;
if (GameManager.RunModelMgr.SceneType != E_SceneType.ToolRoom) return;
if (EventSystem.current.IsPointerOverGameObject()) return;
OnEnter();
//TODO: 这里写提示打开的代码
UIManager.Instance.ShowPanel<ItemTips>(E_UI_Layer.System, (panel) =>
{
panel.Init(gameObject.name);
//GetComponentInChildren<TextMeshProUGUI>().text = gameObject.name;
//transform.position = Input.mousePosition + new Vector3(10, 10, 0);
}); //提示面板
}
private void OnMouseDown()
{
if (GameManager.RunModelMgr.SceneType!= E_SceneType.ToolRoom) return;
if (GameManager.RunModelMgr.SceneType != E_SceneType.ToolRoom) return;
if (EventSystem.current.IsPointerOverGameObject()) return;
OnDown();
gameObject.SetActive(false);
//gameObject.SetActive(false);
}
private void OnMouseExit()
{
UIManager.Instance.HidePanel<ItemTips>();//提示面板
//TODO: 这里写提示关闭的代码
if (GameManager.RunModelMgr.SceneType!= E_SceneType.ToolRoom) return;
if (GameManager.RunModelMgr.SceneType != E_SceneType.ToolRoom) return;
if (EventSystem.current.IsPointerOverGameObject()) return;
OnExit();
}

View File

@ -19,7 +19,7 @@ public class Tool_SelectComponent : BaseToolOrDevice
if (IsClick)
{
//묏야츰냔뵨묏야렴흙묏야움
GameManager.PacksackBagMgr.AddOneToolOrMater(gameObject.name);
GameManager.PacksackBagMgr.AddOneToolOrMater(itemInfo);
this.gameObject.SetActive(false);
}
}

View File

@ -4,5 +4,8 @@ using UnityEngine;
public class UI_ToolAndMaterialsItem : BaseItem
{
public void Init(int count, string toolName)
{
}
}

View File

@ -87,14 +87,4 @@ public class UI_MainTitlePanel : BasePanel
}
}
[Button]
public void Test1()
{
GameManager.UIMgr.ShowPanel<UI_ToolAndMaterialPanel>();
}
[Button]
public void Test2()
{
GameManager.PacksackBagMgr.AddOneToolOrMater("万用表");
}
}

View File

@ -21,28 +21,27 @@ public class UI_ToolAndMaterialPanel : BasePanel
private void CreatItem(int type)
{
var bagData = GameManager.PacksackBagMgr.GetCurrentBagData();
Dictionary<int, List<ItemInfo>> bagDatas = GameManager.PacksackBagMgr.GetCurrentBagData();
foreach (var toolAndMaterialData in bagData.Values)
foreach (var toolAndMaterialData in bagDatas.Values)
{
if (toolAndMaterialData.type != type)
foreach (var item in toolAndMaterialData)
{
continue;
}
//string iconName = GameManager.ToolAndmaterialMgr.GetIconSpriteName(toolAndMaterialData.objName);
//if (iconName != null)
//{
// var toolAndMaterItem = GameManager.ResourcesMgr.Load<GameObject>(Const.UI_Item +
// "UI_ToolAndMaterialPanel/" +s
// "ToolAndMeterialItem");
string iconName = GameManager.ToolAndmaterialMgr.GetIconSpriteName(toolAndMaterialData.objName);
if (iconName != null)
{
var toolAndMaterItem = GameManager.ResourcesMgr.Load<GameObject>(Const.UI_Item +
"UI_ToolAndMaterialPanel/" +
"ToolAndMeterialItem");
// toolAndMaterItem.GetComponent<Image>().sprite =
// GameManager.ResourcesMgr.Load<Sprite>(Const.TitleSpritePath + iconName);
// toolAndMaterItem.GetComponentInChildren<Text>().text = toolAndMaterialData.count.ToString();
toolAndMaterItem.GetComponent<Image>().sprite =
GameManager.ResourcesMgr.Load<Sprite>(Const.TitleSpritePath + iconName);
toolAndMaterItem.GetComponentInChildren<Text>().text = toolAndMaterialData.count.ToString();
toolAndMaterItem.transform.parent = GetControl<ScrollRect>("itemScrollView").content;
}
// toolAndMaterItem.transform.parent = GetControl<ScrollRect>("itemScrollView").content;
//}
}
}