loudixvmuniu/Assets/_Scripts/Application/UI/SelectToolsPanel.cs

83 lines
3.7 KiB
C#
Raw Normal View History

2025-01-02 12:15:45 +08:00
using CG.Framework;
using CG.UTility;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/*******************************************************************************
*Create By CG
*Function
*******************************************************************************/
namespace ZXK.LouDiXvMuNiu
{
public class SelectToolsPanel : UIBase
{
private Transform _toolsContent = null;
private GameObject _toolItemPrefab = null;
private List<GameObject> _toolBtnArray = new List<GameObject>();
protected override void Awake()
{
base.Awake();
_toolsContent = GetWedage("ToolsItemContent_N").transform;
_toolItemPrefab = GetWedage("SelectToolsPanel_ToolsItem_N");
CreateTool();
}
private void OnEnable()
{
for (int i = 0; i < _toolBtnArray.Count; i++)
{
_toolBtnArray[i].transform.Find("BeUseImg/ChoseRight").gameObject.SetActive(false);
_toolBtnArray[i].transform.Find("BeUseImg/ChoseError").gameObject.SetActive(false);
}
}
private void CreateTool()
{
for (int i = 0; i < GameManager.Instance._DataNiuHandler.NiuDataArray.Count; i++)
{
string itemTools = GameManager.Instance._DataNiuHandler.NiuDataArray[i].ToolsName;
if (string.IsNullOrEmpty(itemTools)) continue;
string[] tools = itemTools.Split("|");
for (int j = 0; j < tools.Length; j++)
{
GameObject toolItemGeo = Instantiate(_toolItemPrefab, _toolsContent);
toolItemGeo.name = tools[j];
toolItemGeo.transform.Find("NoUseImg/Text").GetComponent<Text>().text = tools[j];
Sprite sprite = Resources.Load<Sprite>("ToolsLogo/" + tools[j]);
//UtilitiesMng.LoadSpriteByURL(ItemInfo[i].picURL, (sprite) =>
//{
//DataBJCJHandler._BJCZSpriteArray.Add(ItemInfo[i].partName, sprite);
toolItemGeo.transform.Find("ToolsConnet").GetComponent<Image>().sprite = sprite;
//});
toolItemGeo.GetComponent<Button>().onClick.AddListener(() =>
{
NiuData curStep = GameManager.Instance._DataNiuHandler.CurNiuHandler.Value;
if (!curStep.TaskType.Equals(ConstCtrl.TASKTYPE_ShowGeo)) return;
toolItemGeo.GetComponent<Button>().interactable = false;
string[] curTools = curStep.ToolsName.Split("|");
bool rightSelect = false;
for (int i = 0; i < curTools.Length; i++)
{
if (curTools[i].Equals(toolItemGeo.name)) rightSelect = true;
}
if (rightSelect)
{
toolItemGeo.transform.Find("BeUseImg/ChoseRight").gameObject.SetActive(true);
GameManager.Instance._EventManager.Raise(new ClickToolArgs() { SelectTool = toolItemGeo.name });
GameManager.Instance._DataNiuHandler.AddScore(curStep.ModuleName, curStep.ThreeTaskName, 1);
}
else
{
toolItemGeo.transform.Find("BeUseImg/ChoseError").gameObject.SetActive(true);
}
});
toolItemGeo.SetActive(true);
_toolBtnArray.Add(toolItemGeo);
}
}
}
}
}