185 lines
5.7 KiB
C#
185 lines
5.7 KiB
C#
using GCGame.Table;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class ChildSkillPanel : MonoBehaviour {
|
|
public bool _IsCanSelect = false; //是否可以被选中
|
|
public List<ChildSkillDescItem> _ChildSkillItemList;
|
|
[Serializable]
|
|
public class ChildSkillItemClickEvent : UnityEvent<int>
|
|
{
|
|
public ChildSkillItemClickEvent() { }
|
|
}
|
|
[SerializeField]
|
|
public ChildSkillItemClickEvent _SkillClickEvent;
|
|
|
|
[HideInInspector]
|
|
private int _CurSelectIndex;
|
|
public void InitSkillItem(int childIndex, int curSelecSkillType = 1)
|
|
{
|
|
_CurSelectIndex = childIndex;
|
|
if (ChildData.GetChildByIndex(childIndex) == null)
|
|
{
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
gameObject.SetActive(true);
|
|
|
|
for(int index = 0; index < _ChildSkillItemList.Count; index++)
|
|
{
|
|
_ChildSkillItemList[index].InitSkillDescItem(GetSkillExIdByType(index + 1), GetCurSkillLevelByType(index + 1));
|
|
}
|
|
|
|
if (curSelecSkillType == -1)
|
|
curSelecSkillType = 1;//重置一些初始默认是-1的情况
|
|
|
|
ShowDefaultFirst(curSelecSkillType);
|
|
}
|
|
|
|
public int GetSkillExIdByType(int type)
|
|
{
|
|
var childSkillParamTab = TableManager.GetChildrenSkillParam();
|
|
foreach (var tab in childSkillParamTab)
|
|
{
|
|
if (tab.Value.Type == type)
|
|
return tab.Value.Id;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
public void ShowDefaultFirst(int curSelecSkillType = 1)
|
|
{
|
|
if(_IsCanSelect)
|
|
OnSKillItemClick(curSelecSkillType);
|
|
}
|
|
|
|
private int GetCurSkillLevelByType(int type)
|
|
{
|
|
if (ChildData.GetChildByIndex(_CurSelectIndex) == null)
|
|
return 0;
|
|
switch (type)
|
|
{
|
|
case 1:
|
|
return ChildData.GetChildByIndex(_CurSelectIndex).study.curLvlMath;
|
|
case 2:
|
|
return ChildData.GetChildByIndex(_CurSelectIndex).study.curLvlArt;
|
|
case 3:
|
|
return ChildData.GetChildByIndex(_CurSelectIndex).study.curLvlWarcraft;
|
|
case 4:
|
|
return ChildData.GetChildByIndex(_CurSelectIndex).study.curLvlStamina;
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
private int _CurSelectStudyType = -1;
|
|
private int _CurSelectSkillIndex = -1;
|
|
public void OnSKillItemClick(int studyType)
|
|
{
|
|
if (studyType == -1)
|
|
{
|
|
Debug.LogError("studyType is -1");
|
|
return;
|
|
}
|
|
|
|
_CurSelectStudyType = studyType;
|
|
var pos = Vector3.zero;
|
|
for (int index = 0; index < _ChildSkillItemList.Count; index++)
|
|
{
|
|
if (_ChildSkillItemList[index]._CurSkillType == studyType)
|
|
{
|
|
_CurSelectSkillIndex = index;
|
|
pos = _ChildSkillItemList[index].transform.position;
|
|
}
|
|
_ChildSkillItemList[index].ShowMark(_IsCanSelect ? _ChildSkillItemList[index]._CurSkillType == studyType : false);
|
|
}
|
|
|
|
if(!_IsCanSelect)
|
|
{
|
|
var curTypeId = GetCurTypeId();
|
|
var nextLevelId = GetCurTypeNextLevelId();
|
|
UIManager.ShowUI(UIInfo.ChildSkillTips, (bool bSucess, object param) => {
|
|
if(bSucess)
|
|
{
|
|
ChildSkillTips.Instance.InitSkillInfoTips(curTypeId, nextLevelId, pos);
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (_SkillClickEvent != null)
|
|
_SkillClickEvent.Invoke(GetCurTypeId());
|
|
}
|
|
|
|
Dictionary<int, List<Tab_ChildrenStudyLevelUp>> _ChildStudyTypeAndIdListDic= null;
|
|
public int GetCurTypeId()
|
|
{
|
|
if(_ChildStudyTypeAndIdListDic == null)
|
|
SetStudyTypeAndIdListDic();
|
|
|
|
if(_ChildStudyTypeAndIdListDic.ContainsKey(_CurSelectStudyType))
|
|
{
|
|
var idList = _ChildStudyTypeAndIdListDic[_CurSelectStudyType];
|
|
var curSelectTypeSkillLevel = GetCurSkillLevelByType(_CurSelectStudyType);
|
|
for (int index = 0; index < idList.Count; index++)
|
|
{
|
|
if(idList[index].Level == curSelectTypeSkillLevel)
|
|
return idList[index].Id;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("_ChildStudyTypeAndIdListDic don't contain type : " + _CurSelectStudyType);
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
public int GetCurTypeNextLevelId()
|
|
{
|
|
if (_ChildStudyTypeAndIdListDic == null)
|
|
SetStudyTypeAndIdListDic();
|
|
|
|
if (_ChildStudyTypeAndIdListDic.ContainsKey(_CurSelectStudyType))
|
|
{
|
|
var idList = _ChildStudyTypeAndIdListDic[_CurSelectStudyType];
|
|
for (int index = 0; index < idList.Count; index++)
|
|
{
|
|
if (idList[index].Level == GetCurSkillLevelByType(_CurSelectStudyType))
|
|
{
|
|
if (index == idList.Count - 1)
|
|
return -1;
|
|
return idList[index + 1].Id;
|
|
}
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
void SetStudyTypeAndIdListDic()
|
|
{
|
|
_ChildStudyTypeAndIdListDic = new Dictionary<int, List<Tab_ChildrenStudyLevelUp>>();
|
|
var allTab = TableManager.GetChildrenStudyLevelUp();
|
|
|
|
foreach(var tab in allTab)
|
|
{
|
|
if (_ChildStudyTypeAndIdListDic.ContainsKey(tab.Value.StudyType))
|
|
{
|
|
_ChildStudyTypeAndIdListDic[tab.Value.StudyType].Add(tab.Value);
|
|
}
|
|
else
|
|
{
|
|
List<Tab_ChildrenStudyLevelUp> list = new List<Tab_ChildrenStudyLevelUp>();
|
|
list.Add(tab.Value);
|
|
_ChildStudyTypeAndIdListDic.Add(tab.Value.StudyType, list);
|
|
}
|
|
}
|
|
}
|
|
}
|