583 lines
19 KiB
C#
583 lines
19 KiB
C#
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UnitSetUiCtrl : SingletonMonoBehaviour<UnitSetUiCtrl>
|
|
{
|
|
//스텟 정보 ui
|
|
[SerializeField] TMP_Text name;
|
|
[SerializeField] TMP_Text attribute;
|
|
[SerializeField] TMP_Text hp;
|
|
[SerializeField] TMP_Text defense;
|
|
[SerializeField] TMP_Text attack;
|
|
[SerializeField] TMP_Text defensePenetration;
|
|
[SerializeField] TMP_Text attackSpeed;
|
|
[SerializeField] TMP_Text moveSpeed;
|
|
[SerializeField] TMP_Text critical;
|
|
[SerializeField] TMP_Text criticalDamage;
|
|
[SerializeField] TMP_Text damageReduction;
|
|
|
|
[SerializeField] TMP_Text level;
|
|
[SerializeField] TMP_Text maxLevel;
|
|
|
|
//유닛 프리펩및 위치
|
|
[SerializeField] GameObject itemPrefab;
|
|
[SerializeField] Transform itemContent;
|
|
[SerializeField] GameObject unitPrefab;
|
|
[SerializeField] Transform unitContent;
|
|
|
|
//각종 세팅 ui
|
|
[SerializeField] GameObject objInfo;
|
|
[SerializeField] GameObject objItemView;
|
|
[SerializeField] GameObject objEquipment;
|
|
[SerializeField] GameObject objDeck;
|
|
|
|
//케릭터 카메라
|
|
[SerializeField] Transform CamContent;
|
|
GameObject UnitObject;
|
|
|
|
//아이템 정보
|
|
[SerializeField] GameObject itemInfo;
|
|
[SerializeField] Image itemImage;
|
|
[SerializeField] TMP_Text itemName;
|
|
[SerializeField] TMP_Text equipType;
|
|
[SerializeField] GameObject status0;
|
|
[SerializeField] TMP_Text status0Status;
|
|
[SerializeField] TMP_Text status0Value;
|
|
[SerializeField] GameObject status1;
|
|
[SerializeField] TMP_Text status1Status;
|
|
[SerializeField] TMP_Text status1Value;
|
|
[SerializeField] GameObject status2;
|
|
[SerializeField] TMP_Text status2Status;
|
|
[SerializeField] TMP_Text status2Value;
|
|
[SerializeField] GameObject status3;
|
|
[SerializeField] TMP_Text status3Status;
|
|
[SerializeField] TMP_Text status3Value;
|
|
|
|
//유닛 장착 아이템 정보
|
|
[SerializeField] Image[] equipItems;
|
|
|
|
GameObjectPool<ItemPrefab> itemPrefabList;
|
|
GameObjectPool<UnitPrefab> unitPrefabList;
|
|
|
|
List<ItemPrefab> onItemPrefabList;
|
|
List<UnitPrefab> onUnitPrefabList;
|
|
|
|
Equipment selectItem;
|
|
ItemPrefab selectItemPrefab;
|
|
DeckUnitInfo selectUnit;
|
|
UnitPrefab selectUnitPrefab;
|
|
|
|
//덱 유닛들
|
|
[SerializeField] DeckPrefab[] DeckPrefabs;
|
|
|
|
protected override void OnAwake()
|
|
{
|
|
maxLevel.text = Statics.dynamic["maxLevel"];
|
|
onItemPrefabList = new List<ItemPrefab>();
|
|
onUnitPrefabList = new List<UnitPrefab>();
|
|
itemPrefabList = new GameObjectPool<ItemPrefab>(5, () =>
|
|
{
|
|
var obj = Instantiate(itemPrefab, itemContent);
|
|
obj.SetActive(false);
|
|
var clone = obj.GetComponent<ItemPrefab>();
|
|
return clone;
|
|
});
|
|
unitPrefabList = new GameObjectPool<UnitPrefab>(5, () =>
|
|
{
|
|
var obj = Instantiate(unitPrefab, unitContent);
|
|
obj.SetActive(false);
|
|
var clone = obj.GetComponent<UnitPrefab>();
|
|
return clone;
|
|
});
|
|
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
ButtonStatus();
|
|
onItemPrefabList.Clear();
|
|
foreach (var item in Statics.equipment)
|
|
{
|
|
//장착된 아이템 스킵
|
|
if (item.equip_unit != 0)
|
|
continue;
|
|
ItemPrefab prefab = itemPrefabList.pop();
|
|
prefab.SetData(item);
|
|
prefab.gameObject.SetActive(true);
|
|
onItemPrefabList.Add(prefab);
|
|
}
|
|
|
|
foreach (var item in Statics.deckUnit)
|
|
{
|
|
UnitPrefab prefab = unitPrefabList.pop();
|
|
prefab.SetData(item.Value);
|
|
prefab.gameObject.SetActive(true);
|
|
onUnitPrefabList.Add(prefab);
|
|
}
|
|
onUnitPrefabList[0].SelectUnit();
|
|
|
|
for(int n = 0; n < DeckPrefabs.Length; n++)
|
|
{
|
|
DeckPrefabs[n].UnitSet();
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
foreach (var item in onItemPrefabList)
|
|
{
|
|
item.gameObject.SetActive(false);
|
|
itemPrefabList.push(item);
|
|
}
|
|
foreach (var item in onUnitPrefabList)
|
|
{
|
|
item.gameObject.SetActive(false);
|
|
unitPrefabList.push(item);
|
|
}
|
|
}
|
|
|
|
public void ButtonStatus()
|
|
{
|
|
objInfo.SetActive(true);
|
|
objItemView.SetActive(false);
|
|
objEquipment.SetActive(false);
|
|
objDeck.SetActive(false);
|
|
itemInfo.SetActive(false);
|
|
}
|
|
public void ButtonEquipment()
|
|
{
|
|
objInfo.SetActive(false);
|
|
objItemView.SetActive(true);
|
|
objEquipment.SetActive(true);
|
|
objDeck.SetActive(false);
|
|
itemInfo.SetActive(false);
|
|
}
|
|
public void ButtonDeck()
|
|
{
|
|
objInfo.SetActive(false);
|
|
objItemView.SetActive(false);
|
|
objEquipment.SetActive(false);
|
|
objDeck.SetActive(true);
|
|
itemInfo.SetActive(false);
|
|
}
|
|
public void ButtonHaracteristic()
|
|
{
|
|
objInfo.SetActive(false);
|
|
objItemView.SetActive(false);
|
|
objEquipment.SetActive(false);
|
|
objDeck.SetActive(false);
|
|
itemInfo.SetActive(false);
|
|
}
|
|
|
|
public void StatusSet(UnitPrefab unitPrefab, UnitData unitData, DeckUnitInfo deckUnitInfo, UnitCtrl unitCtrl)
|
|
{
|
|
this.selectUnitPrefab = unitPrefab;
|
|
this.selectUnit = deckUnitInfo;
|
|
level.text = deckUnitInfo.level.ToString();
|
|
name.text = unitData.name;
|
|
attribute.text = "None";
|
|
hp.text = (unitData.hp).ToString();
|
|
defense.text = (unitData.defense).ToString();
|
|
attack.text = (unitData.attack).ToString();
|
|
defensePenetration.text = "0%";
|
|
attackSpeed.text = (unitData.attack_speed).ToString();
|
|
moveSpeed.text = (unitData.move_speed).ToString();
|
|
critical.text = "0%";
|
|
criticalDamage.text = "50%";
|
|
damageReduction.text = "0%";
|
|
|
|
int index = -1;
|
|
|
|
if (deckUnitInfo.equip0_id == 0)
|
|
{
|
|
equipItems[0].color = Color.clear;
|
|
}
|
|
else
|
|
{
|
|
equipItems[0].color = Color.white;
|
|
index = Statics.equipment.FindIndex(n => (n.id == deckUnitInfo.equip0_id));
|
|
if (index == -1)
|
|
{
|
|
Debug.LogError("notData");
|
|
equipItems[2].color = Color.clear;
|
|
}
|
|
else
|
|
equipItems[0].sprite = Statics.stringIcons[Statics.excelDatas.equipmentData[Statics.equipment[index].equipment_data_id].name];
|
|
}
|
|
if (deckUnitInfo.equip1_id == 0)
|
|
{
|
|
equipItems[1].color = Color.clear;
|
|
}
|
|
else
|
|
{
|
|
equipItems[1].color = Color.white;
|
|
index = Statics.equipment.FindIndex(n => (n.id == deckUnitInfo.equip1_id));
|
|
if (index == -1)
|
|
{
|
|
Debug.LogError("notData");
|
|
equipItems[2].color = Color.clear;
|
|
}
|
|
else
|
|
equipItems[1].sprite = Statics.stringIcons[Statics.excelDatas.equipmentData[Statics.equipment[index].equipment_data_id].name];
|
|
}
|
|
if (deckUnitInfo.equip2_id == 0)
|
|
{
|
|
equipItems[2].color = Color.clear;
|
|
}
|
|
else
|
|
{
|
|
equipItems[2].color = Color.white;
|
|
index = Statics.equipment.FindIndex(n => (n.id == deckUnitInfo.equip2_id));
|
|
if(index == -1)
|
|
{
|
|
Debug.LogError("notData");
|
|
equipItems[2].color = Color.clear;
|
|
}
|
|
else
|
|
equipItems[2].sprite = Statics.stringIcons[Statics.excelDatas.equipmentData[Statics.equipment[index].equipment_data_id].name];
|
|
}
|
|
if (deckUnitInfo.equip3_id == 0)
|
|
{
|
|
equipItems[3].color = Color.clear;
|
|
}
|
|
else
|
|
{
|
|
equipItems[3].color = Color.white;
|
|
index = Statics.equipment.FindIndex(n => (n.id == deckUnitInfo.equip3_id));
|
|
if (index == -1)
|
|
{
|
|
Debug.LogError("notData : " + deckUnitInfo.equip3_id);
|
|
equipItems[2].color = Color.clear;
|
|
}
|
|
else
|
|
equipItems[3].sprite = Statics.stringIcons[Statics.excelDatas.equipmentData[Statics.equipment[index].equipment_data_id].name];
|
|
}
|
|
if (deckUnitInfo.equip4_id == 0)
|
|
{
|
|
equipItems[4].color = Color.clear;
|
|
}
|
|
else
|
|
{
|
|
equipItems[4].color = Color.white;
|
|
index = Statics.equipment.FindIndex(n => (n.id == deckUnitInfo.equip4_id));
|
|
if (index == -1)
|
|
{
|
|
Debug.LogError("notData");
|
|
equipItems[2].color = Color.clear;
|
|
}
|
|
else
|
|
equipItems[4].sprite = Statics.stringIcons[Statics.excelDatas.equipmentData[Statics.equipment[index].equipment_data_id].name];
|
|
}
|
|
if (deckUnitInfo.equip5_id == 0)
|
|
{
|
|
equipItems[5].color = Color.clear;
|
|
}
|
|
else
|
|
{
|
|
equipItems[5].color = Color.white;
|
|
index = Statics.equipment.FindIndex(n => (n.id == deckUnitInfo.equip5_id));
|
|
if (index == -1)
|
|
{
|
|
Debug.LogError("notData");
|
|
equipItems[2].color = Color.clear;
|
|
}
|
|
else
|
|
equipItems[5].sprite = Statics.stringIcons[Statics.excelDatas.equipmentData[Statics.equipment[index].equipment_data_id].name];
|
|
}
|
|
|
|
|
|
|
|
//카메라 유닛 생성
|
|
if (UnitObject != null)
|
|
Destroy(UnitObject);
|
|
|
|
UnitObject = Instantiate(unitCtrl.gameObject, CamContent);
|
|
UnitObject.GetComponent<UnitCtrl>().enabled = false;
|
|
}
|
|
|
|
public void ItemSet(ItemPrefab itemPrefab, Equipment equipment, EquipmentData equipmentData)
|
|
{
|
|
this.selectItemPrefab = itemPrefab;
|
|
this.selectItem = equipment;
|
|
equipType.text = "장착";
|
|
itemInfo.SetActive(true);
|
|
itemImage.sprite = Statics.stringIcons[equipmentData.name];
|
|
itemName.text = equipmentData.name;
|
|
|
|
status0.SetActive(true);
|
|
status0Status.text = StatusText(equipmentData.part, equipment.rand_stats);
|
|
status0Value.text = ValueText(equipmentData, equipment.rand_stats);
|
|
|
|
status1.SetActive(false);
|
|
status2.SetActive(false);
|
|
status3.SetActive(false);
|
|
}
|
|
|
|
public void ItemSet(ePart part)
|
|
{
|
|
Equipment equipment;
|
|
int index = -1;
|
|
switch (part)
|
|
{
|
|
case ePart.Weapon:
|
|
if ((index = Statics.equipment.FindIndex(n => n.id == selectUnit.equip0_id)) != -1)
|
|
equipment = Statics.equipment[index];
|
|
else return;
|
|
break;
|
|
case ePart.Armor:
|
|
if ((index = Statics.equipment.FindIndex(n => n.id == selectUnit.equip1_id)) != -1)
|
|
equipment = Statics.equipment[index];
|
|
else return;
|
|
break;
|
|
case ePart.Gloves:
|
|
if ((index = Statics.equipment.FindIndex(n => n.id == selectUnit.equip2_id)) != -1)
|
|
equipment = Statics.equipment[index];
|
|
else return;
|
|
break;
|
|
case ePart.Headpiece:
|
|
if ((index = Statics.equipment.FindIndex(n => n.id == selectUnit.equip3_id)) != -1)
|
|
equipment = Statics.equipment[index];
|
|
else return;
|
|
break;
|
|
case ePart.Shield:
|
|
if ((index = Statics.equipment.FindIndex(n => n.id == selectUnit.equip4_id)) != -1)
|
|
equipment = Statics.equipment[index];
|
|
else return;
|
|
break;
|
|
case ePart.Ring:
|
|
if ((index = Statics.equipment.FindIndex(n => n.id == selectUnit.equip5_id)) != -1)
|
|
equipment = Statics.equipment[index];
|
|
else return;
|
|
break;
|
|
default:
|
|
Debug.LogError("Not Data");
|
|
return;
|
|
}
|
|
|
|
EquipmentData equipmentData = Statics.excelDatas.equipmentData[equipment.equipment_data_id];
|
|
this.selectItem = equipment;
|
|
equipType.text = "해제";
|
|
itemInfo.SetActive(true);
|
|
itemImage.sprite = Statics.stringIcons[equipmentData.name];
|
|
itemName.text = equipmentData.name;
|
|
|
|
status0.SetActive(true);
|
|
status0Status.text = StatusText(equipmentData.part, equipment.rand_stats);
|
|
status0Value.text = ValueText(equipmentData, equipment.rand_stats);
|
|
|
|
status1.SetActive(false);
|
|
status2.SetActive(false);
|
|
status3.SetActive(false);
|
|
}
|
|
|
|
private string StatusText(ePart part, int randStats)
|
|
{
|
|
switch (part)
|
|
{
|
|
case ePart.Weapon: //무기
|
|
switch (randStats)
|
|
{
|
|
case 0:
|
|
return "공격력";
|
|
case 1:
|
|
return "방어 관통력";
|
|
case 2:
|
|
return "치명타 대미지";
|
|
default:
|
|
return "";
|
|
}
|
|
case ePart.Armor: //갑옷
|
|
switch (randStats)
|
|
{
|
|
case 0:
|
|
return "방어력";
|
|
case 1:
|
|
return "체력";
|
|
case 2:
|
|
return "대미지 감소";
|
|
default:
|
|
return "";
|
|
}
|
|
case ePart.Gloves: //장갑
|
|
switch (randStats)
|
|
{
|
|
case 0:
|
|
return "이동속도";
|
|
case 1:
|
|
return "공격속도";
|
|
case 2:
|
|
return "공격력";
|
|
default:
|
|
return "";
|
|
}
|
|
case ePart.Headpiece: //투구
|
|
switch (randStats)
|
|
{
|
|
case 0:
|
|
return "공격력";
|
|
case 1:
|
|
return "방어관통력";
|
|
case 2:
|
|
return "체력";
|
|
default:
|
|
return "";
|
|
}
|
|
case ePart.Shield: //보조장비
|
|
switch (randStats)
|
|
{
|
|
case 0:
|
|
return "방어력";
|
|
case 1:
|
|
return "대미지감소";
|
|
case 2:
|
|
return "체력";
|
|
default:
|
|
return "";
|
|
}
|
|
case ePart.Ring: //반지
|
|
switch (randStats)
|
|
{
|
|
case 0:
|
|
return "치명타확률";
|
|
case 1:
|
|
return "이동속도";
|
|
case 2:
|
|
return "공격속도";
|
|
default:
|
|
return "";
|
|
}
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
|
|
private string ValueText(EquipmentData equipmentData, int randStats)
|
|
{
|
|
switch (randStats)
|
|
{
|
|
case 1:
|
|
return equipmentData.stats1.ToString();
|
|
case 2:
|
|
return equipmentData.stats2.ToString();
|
|
case 3:
|
|
return equipmentData.stats3.ToString();
|
|
//case 4:
|
|
// return equipmentData.stats4.ToString();
|
|
default:
|
|
return "0";
|
|
}
|
|
}
|
|
|
|
public void equipItem()
|
|
{
|
|
itemInfo.SetActive(false);
|
|
EquipChangeResp request = new EquipChangeResp();
|
|
request.Request((data) =>
|
|
{
|
|
//신규 정보로 데이터 교체
|
|
for(int n = 0; n < Statics.equipment.Count; n++)
|
|
{
|
|
if (Statics.equipment[n].id == data.equipment.id)
|
|
{
|
|
Statics.equipment[n] = data.equipment;
|
|
break;
|
|
}
|
|
}
|
|
|
|
Statics.deckUnit.Remove(data.deck_unit_info.id);
|
|
Statics.deckUnit.Add(data.deck_unit_info.id, data.deck_unit_info);
|
|
|
|
//세팅되어있는 데이터 수정
|
|
selectUnitPrefab.SetData(data.deck_unit_info);
|
|
if(data.equipment.equip_unit == 0)
|
|
{
|
|
//생성
|
|
ItemPrefab prefab = itemPrefabList.pop();
|
|
prefab.SetData(data.equipment);
|
|
prefab.gameObject.SetActive(true);
|
|
onItemPrefabList.Add(prefab);
|
|
}
|
|
else
|
|
{
|
|
//삭제
|
|
for(int n = 0; n < onItemPrefabList.Count; n++)
|
|
{
|
|
if (onItemPrefabList[n].getId == data.equipment.id)
|
|
{
|
|
onItemPrefabList[n].gameObject.SetActive(false);
|
|
itemPrefabList.push(onItemPrefabList[n]);
|
|
onItemPrefabList.RemoveAt(n);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//추가 데이터 처리
|
|
if (data.change_equipment != null)
|
|
{
|
|
for (int n = 0; n < Statics.equipment.Count; n++)
|
|
{
|
|
if (Statics.equipment[n].id == data.change_equipment.id)
|
|
{
|
|
Statics.equipment[n] = data.change_equipment;
|
|
break;
|
|
}
|
|
}
|
|
//이곳은 장착 해제 여부밖에 나올수 없어 이렇게 작업됨.
|
|
ItemPrefab prefab = itemPrefabList.pop();
|
|
prefab.SetData(data.change_equipment);
|
|
prefab.gameObject.SetActive(true);
|
|
onItemPrefabList.Add(prefab);
|
|
}
|
|
|
|
selectUnitPrefab.SelectUnit();
|
|
}, selectUnit.id, selectItem.id, selectItem.equip_unit == 0);
|
|
}
|
|
|
|
public long DeckSwap(int index, long unit_id)
|
|
{
|
|
long selectUnitId = selectUnitPrefab.GetUnitId;
|
|
for (int n = 0; n < DeckPrefabs.Length; n++)
|
|
{
|
|
if (DeckPrefabs[n].GetIndex == index)
|
|
continue;
|
|
if (DeckPrefabs[n].GetUnitId == selectUnitId)//유닛정보가 들어와야함
|
|
{
|
|
DeckPrefabs[n].UnitChange(unit_id);
|
|
}
|
|
}
|
|
return selectUnitId;
|
|
}
|
|
|
|
public void DeckSaveButton()
|
|
{
|
|
//네트워크 통신 필요
|
|
DeckChangeResp request = new DeckChangeResp();
|
|
long[] deckUnits = new long[9];
|
|
for(int n = 0; n < DeckPrefabs.Length; n++)
|
|
{
|
|
deckUnits[n] = DeckPrefabs[n].GetUnitId;
|
|
}
|
|
request.Request((data) =>
|
|
{
|
|
int n = Statics.deck_info.FindIndex(n => n.id == data.deck_info.id);
|
|
if (n == -1)
|
|
{
|
|
Debug.LogError($"null Data id : {data.deck_info.id}");
|
|
return;
|
|
}
|
|
Statics.deck_info[n].newDataSet(data.deck_info);
|
|
|
|
}, Statics.deck_info[0].id, deckUnits);
|
|
}
|
|
public void DeckResetButton()
|
|
{
|
|
for (int n = 0; n < DeckPrefabs.Length; n++)
|
|
{
|
|
DeckPrefabs[n].UnitSet();
|
|
}
|
|
}
|
|
}
|