171 lines
4.3 KiB
C#
171 lines
4.3 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Games.Item;
|
|
|
|
public class PopCanSelectItemPanelCtr : MonoBehaviour {
|
|
|
|
|
|
public GameObject m_ItemPrefab;
|
|
public Transform m_Parent;
|
|
private List<int> m_AllItem = new List<int>();
|
|
private List<GameObject> m_AutoMedicItemList = new List<GameObject>();
|
|
public List<GameObject> AutoMedicItemList
|
|
{
|
|
get
|
|
{
|
|
return m_AutoMedicItemList;
|
|
}
|
|
}
|
|
|
|
public static PopCanSelectItemPanelCtr Instance;
|
|
|
|
public GameObject posObj;
|
|
|
|
public Transform _posOne;
|
|
public Transform _posTwo;
|
|
|
|
private void OnEnable()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
Instance = null;
|
|
m_AllItem.Clear();
|
|
}
|
|
|
|
public void SetMyShowList(List<int> m_List, int Type) //1.面板快捷使用药品 2.界面快捷药
|
|
{
|
|
m_AllItem.Clear();
|
|
foreach (var item in m_List)
|
|
{
|
|
m_AllItem.Add(item);
|
|
}
|
|
|
|
StartCoroutine(InitMyItem(Type));
|
|
posObj.transform.localPosition = Type == 1 ? _posOne.localPosition : _posTwo.localPosition;
|
|
}
|
|
|
|
|
|
|
|
//初始化当前可以点击设置的Item
|
|
IEnumerator InitMyItem(int Type)
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
if (m_AutoMedicItemList.Count < m_AllItem.Count)
|
|
{
|
|
var _NeedCreateCount = m_AllItem.Count - m_AutoMedicItemList.Count;
|
|
for (int index = 0; index < _NeedCreateCount; index++)
|
|
{
|
|
GameObject m_PrefabItem = GameObject.Instantiate(m_ItemPrefab);
|
|
|
|
//设置父节点以及缩放位置
|
|
m_PrefabItem.transform.parent = m_Parent;
|
|
m_PrefabItem.transform.localPosition = Vector3.zero;//????
|
|
m_PrefabItem.transform.localRotation = Quaternion.Euler(Vector3.zero);
|
|
m_PrefabItem.transform.localScale = Vector3.one;
|
|
m_PrefabItem.SetActive(false);
|
|
|
|
m_AutoMedicItemList.Add(m_PrefabItem);
|
|
}
|
|
}
|
|
|
|
//隐藏多余的
|
|
for (int index = m_AllItem.Count; index < m_AutoMedicItemList.Count; index++)
|
|
{
|
|
m_AutoMedicItemList[index].SetActive(false);
|
|
}
|
|
|
|
//初始化可以显示的
|
|
for (int index = 0; index < m_AllItem.Count; index++)
|
|
{
|
|
m_AutoMedicItemList[index].SetActive(true);
|
|
m_AutoMedicItemList[index].GetComponent<MyAutoMedicItem>().InitMyItem(m_AllItem[index], Type);
|
|
}
|
|
|
|
yield break;
|
|
}
|
|
|
|
|
|
public int sortMyItemList(int a_Id, int b_Id)
|
|
{
|
|
GameItemContainer BackPack = GameManager.gameManager.PlayerDataPool.BackPack;
|
|
List<GameItem> itemList = ItemTool.ItemFilter(BackPack, 0); //过滤背包中所有物品 存储在ItemList中
|
|
|
|
bool hasA = false;
|
|
bool hasB = false;
|
|
|
|
int levelA = -1;
|
|
int levelB = -1;
|
|
for(int index = 0; index < itemList.Count; index++)
|
|
{
|
|
if(itemList[index].DataID == a_Id)
|
|
{
|
|
levelA = itemList[index].GetMinLevelRequire();
|
|
hasA = true;
|
|
continue;
|
|
}
|
|
if(itemList[index].DataID == b_Id)
|
|
{
|
|
levelB = itemList[index].GetMinLevelRequire();
|
|
hasB = true;
|
|
continue;
|
|
}
|
|
|
|
if (hasB && hasA)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
if((hasA && hasB) || (!hasA && !hasB))
|
|
{
|
|
if(levelA < levelB)
|
|
{
|
|
return -1;
|
|
}else if(levelA == levelB)
|
|
{
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
else if(hasA && !hasB)
|
|
{
|
|
return -1;
|
|
}
|
|
else if(!hasA && hasB)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void closeMyPopCanSelectItemPanel()
|
|
{
|
|
//先清除?
|
|
//for(int index = 0; index < m_AutoMedicItemList.Count; index++)
|
|
//{
|
|
// Destroy(m_AutoMedicItemList[index]);
|
|
//}
|
|
////置为false
|
|
//// this.gameObject.SetActive(false);
|
|
UIManager.CloseUI(UIInfo.PopCanSelectItemPanel);
|
|
}
|
|
|
|
|
|
|
|
}
|