347 lines
11 KiB
C#
347 lines
11 KiB
C#
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using static UnityEditor.Progress;
|
|
|
|
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;
|
|
[SerializeField] GameObject UnitObject;
|
|
|
|
//아이템 정보
|
|
[SerializeField] GameObject itemInfo;
|
|
[SerializeField] Image itemImage;
|
|
[SerializeField] TMP_Text itemName;
|
|
[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;
|
|
|
|
GameObjectPool<ItemPrefab> itemPrefabList;
|
|
GameObjectPool<UnitPrefab> unitPrefabList;
|
|
|
|
List<ItemPrefab> onItemPrefabList;
|
|
List<UnitPrefab> onUnitPrefabList;
|
|
|
|
Equipment selectItem;
|
|
ItemPrefab selectItemPrefab;
|
|
DeckUnitInfo selectUnit;
|
|
UnitPrefab selectUnitPrefab;
|
|
|
|
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();
|
|
}
|
|
|
|
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 ButtoncHaracteristic()
|
|
{
|
|
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%";
|
|
|
|
|
|
//카메라 유닛 생성
|
|
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;
|
|
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.unit_id != 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;
|
|
}
|
|
}
|
|
}
|
|
}, selectUnit.id, selectItem.id);
|
|
}
|
|
}
|