修改工具面板

This commit is contained in:
taosuqi 2024-08-15 21:28:36 +08:00
parent bcb3764573
commit e16e5d4c09
23 changed files with 342210 additions and 99 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9ea913af302bbdf42a9f003451c70e02
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,21 @@
fileFormatVersion: 2
guid: 4eae2d3f036a9f34e8b72ef95695be9d
TrueTypeFontImporter:
externalObjects: {}
serializedVersion: 4
fontSize: 16
forceTextureCase: -2
characterSpacing: 0
characterPadding: 1
includeFontData: 1
fontNames:
- Alimama ShuHeiTi
fallbackFontReferences: []
customCharacters:
fontRenderingMode: 0
ascentCalculationMode: 1
useLegacyBoundsCalculation: 0
shouldRoundAdvanceValue: 1
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f8ef5cb2ab4d4da4093d3fe60f978c99
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,21 @@
fileFormatVersion: 2
guid: 60b5d8dde4f509a4185ee4a54a236416
TrueTypeFontImporter:
externalObjects: {}
serializedVersion: 4
fontSize: 16
forceTextureCase: -2
characterSpacing: 0
characterPadding: 1
includeFontData: 1
fontNames:
- Source Han Sans CN
fallbackFontReferences: []
customCharacters:
fontRenderingMode: 0
ascentCalculationMode: 1
useLegacyBoundsCalculation: 0
shouldRoundAdvanceValue: 1
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1c4004df1d65ff944b6e23e3af757df7
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,21 @@
fileFormatVersion: 2
guid: 8af3ad854ddf42d4bad8563aff10a985
TrueTypeFontImporter:
externalObjects: {}
serializedVersion: 4
fontSize: 16
forceTextureCase: -2
characterSpacing: 0
characterPadding: 1
includeFontData: 1
fontNames:
- Source Han Sans CN
fallbackFontReferences: []
customCharacters:
fontRenderingMode: 0
ascentCalculationMode: 1
useLegacyBoundsCalculation: 0
shouldRoundAdvanceValue: 1
userData:
assetBundleName:
assetBundleVariant:

View File

@ -2,7 +2,7 @@ fileFormatVersion: 2
guid: f23cde0c3d86dad49bedc202ad993d21
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,21 @@
fileFormatVersion: 2
guid: 21e520e9f4216d64e86ecdad0d82df46
TrueTypeFontImporter:
externalObjects: {}
serializedVersion: 4
fontSize: 16
forceTextureCase: -2
characterSpacing: 0
characterPadding: 1
includeFontData: 1
fontNames:
- Source Han Sans CN
fallbackFontReferences: []
customCharacters:
fontRenderingMode: 0
ascentCalculationMode: 1
useLegacyBoundsCalculation: 0
shouldRoundAdvanceValue: 1
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 79e309f1e0c36e849a1766c6c66545ed
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -8,37 +8,31 @@ 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;
}
/// <summary>
/// 添加一个工器具或材料
/// </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

@ -2,72 +2,42 @@ 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
{
//public struct ItemInfo
//{
// public int toolId;
// public string toolName;
// public E_ToolOrDeviceOrMaterials toolOrDeviceOrMaterial;
//}
public class ItemInfo
{
public int toolId;
public string toolName;
public E_ToolOrDeviceOrMaterials toolOrDeviceOrMaterial;
public ItemInfo(int id, string Name, E_ToolOrDeviceOrMaterials itemType)
{
toolId = id;
toolName = Name;
toolOrDeviceOrMaterial = itemType;
}
// 你可以在这里添加更多的属性和方法
}
///// <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 SomeOtherClass otherClass = new SomeOtherClass();
private Dictionary<string, ItemInfo> itemDatabase = new Dictionary<string, ItemInfo>();
private void Start()
{
_highlight = GetComponent<HighlightEffect>();
//itemDatabase.Add("Screwdriver", new ItemInfo { toolId = 2, toolName = "螺丝刀", toolOrDeviceOrMaterial = E_ToolOrDeviceOrMaterials.Tool });
}
public class SomeOtherClass
{
public void ProcessItemInfo(ItemInfo itemInfo)
{
Debug.Log($"处理物品: ID={itemInfo.toolId}, 中文名={itemInfo.toolName}, 类型={itemInfo.toolOrDeviceOrMaterial}");
}
}
[ContextMenu("GetInfo")]
public void GetInfo(string itemName)
{
if (itemDatabase.ContainsKey(itemName))
{
ItemInfo info = itemDatabase[itemName];
otherClass.ProcessItemInfo(info); // 设置ItemInfo对象
}
}
//public void GetInfo(string itemName)
//{
@ -106,21 +76,18 @@ public abstract class BaseToolOrDevice : MonoBehaviour
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);
@ -130,7 +97,7 @@ public abstract class BaseToolOrDevice : MonoBehaviour
{
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(this.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

@ -86,15 +86,5 @@ public class UI_MainTitlePanel : BasePanel
break;
}
}
[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;
//}
}
}