装备系统做了很多
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 21557314f50e3bf4db9d860c5adfc61c, type: 3}
|
||||
m_Name: EquipmentUpdateSO
|
||||
m_EditorClassIdentifier:
|
||||
upgradeMaterial: {fileID: 11400000, guid: 4b7d886fc44e4cbe9db602da8c2f9c11, type: 2}
|
||||
breakthroughMaterial: {fileID: 11400000, guid: 6b403344b9414dbba95b7311c3ff57fa, type: 2}
|
||||
upgradeMaterialBase: 3
|
||||
upgradeMaterialGrowth: 3
|
||||
upgradeCoinsBase: 3
|
||||
upgradeCoinsGrowth: 3
|
||||
upgradeMemoryFragmentBase: 3
|
||||
upgradeMemoryFragmentGrowth: 3
|
||||
breakthroughStageCosts:
|
||||
- materialRequired: 30
|
||||
coinRequired: 1000
|
||||
- materialRequired: 75
|
||||
coinRequired: 2500
|
||||
- materialRequired: 125
|
||||
coinRequired: 4000
|
||||
- materialRequired: 200
|
||||
coinRequired: 10000
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8efade7387483747a7baf2668a9674b
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,113 @@
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(fileName = "EquipmentUpdateSO", menuName = "Equipment/EquipmentUpdateSO")]
|
||||
public class eUpdate_mtrSO : ScriptableObject
|
||||
{
|
||||
[System.Serializable]
|
||||
public class BreakthroughStageCost
|
||||
{
|
||||
[Tooltip("breakthroughMaterial required count")]
|
||||
public int materialRequired;
|
||||
[Tooltip("coin required count")]
|
||||
public int coinRequired;
|
||||
}
|
||||
|
||||
[Header("Material Definitions")]
|
||||
[Tooltip("Fixed equipment upgrade consumable definition: 78101")]
|
||||
public equipmentConsumableSO upgradeMaterial;
|
||||
[Tooltip("Fixed equipment breakthrough consumable definition: 78111")]
|
||||
public equipmentConsumableSO breakthroughMaterial;
|
||||
|
||||
[Header("Upgrade Cost")]
|
||||
[Tooltip("Upgrade material required count = base + level * growth")]
|
||||
public int upgradeMaterialBase = 1;
|
||||
public int upgradeMaterialGrowth;
|
||||
[Tooltip("Upgrade coin required count = base + level * growth")]
|
||||
public int upgradeCoinsBase;
|
||||
public int upgradeCoinsGrowth;
|
||||
[Tooltip("Upgrade memory fragment required count = base + level * growth")]
|
||||
public int upgradeMemoryFragmentBase;
|
||||
public int upgradeMemoryFragmentGrowth;
|
||||
|
||||
[Header("Breakthrough Cost")]
|
||||
[Tooltip("Index 0-3 -> level 4/9/14/19")]
|
||||
public BreakthroughStageCost[] breakthroughStageCosts = new BreakthroughStageCost[4];
|
||||
|
||||
public int GetUpgradeMaterialRequired(int level)
|
||||
{
|
||||
return Mathf.Max(0, upgradeMaterialBase + Mathf.Max(0, level) * upgradeMaterialGrowth);
|
||||
}
|
||||
|
||||
public int GetBreakthroughMaterialRequired(int level)
|
||||
{
|
||||
int stageIndex = GetBreakthroughStageIndex(level);
|
||||
if (stageIndex < 0 || breakthroughStageCosts == null || stageIndex >= breakthroughStageCosts.Length || breakthroughStageCosts[stageIndex] == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Mathf.Max(0, breakthroughStageCosts[stageIndex].materialRequired);
|
||||
}
|
||||
|
||||
public int GetUpgradeCoinsRequired(int level)
|
||||
{
|
||||
return Mathf.Max(0, upgradeCoinsBase + Mathf.Max(0, level) * upgradeCoinsGrowth);
|
||||
}
|
||||
|
||||
public int GetUpgradeMemoryFragmentRequired(int level)
|
||||
{
|
||||
return Mathf.Max(0, upgradeMemoryFragmentBase + Mathf.Max(0, level) * upgradeMemoryFragmentGrowth);
|
||||
}
|
||||
|
||||
public int GetBreakthroughCoinsRequired(int level)
|
||||
{
|
||||
int stageIndex = GetBreakthroughStageIndex(level);
|
||||
if (stageIndex < 0 || breakthroughStageCosts == null || stageIndex >= breakthroughStageCosts.Length || breakthroughStageCosts[stageIndex] == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Mathf.Max(0, breakthroughStageCosts[stageIndex].coinRequired);
|
||||
}
|
||||
|
||||
public int GetBreakthroughStageIndex(int level)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case 4:
|
||||
return 0;
|
||||
case 9:
|
||||
return 1;
|
||||
case 14:
|
||||
return 2;
|
||||
case 19:
|
||||
return 3;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
if (breakthroughStageCosts == null || breakthroughStageCosts.Length != 4)
|
||||
{
|
||||
var resized = new BreakthroughStageCost[4];
|
||||
if (breakthroughStageCosts != null)
|
||||
{
|
||||
for (int i = 0; i < Mathf.Min(breakthroughStageCosts.Length, resized.Length); i++)
|
||||
{
|
||||
resized[i] = breakthroughStageCosts[i];
|
||||
}
|
||||
}
|
||||
|
||||
breakthroughStageCosts = resized;
|
||||
}
|
||||
|
||||
for (int i = 0; i < breakthroughStageCosts.Length; i++)
|
||||
{
|
||||
breakthroughStageCosts[i] ??= new BreakthroughStageCost();
|
||||
breakthroughStageCosts[i].materialRequired = Mathf.Max(0, breakthroughStageCosts[i].materialRequired);
|
||||
breakthroughStageCosts[i].coinRequired = Mathf.Max(0, breakthroughStageCosts[i].coinRequired);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21557314f50e3bf4db9d860c5adfc61c
|
||||
@@ -0,0 +1,673 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class equipUpdate : MonoBehaviour
|
||||
{
|
||||
[Header("so")]
|
||||
public Player_SO playerSO;
|
||||
public equipmentSO eqp_p_SO;
|
||||
public eUpdate_mtrSO need_mtrSO;
|
||||
|
||||
[Header("state objects")]
|
||||
public GameObject beforeObj;
|
||||
public GameObject toObj;
|
||||
public GameObject nextObj;
|
||||
|
||||
[Header("dragging")]
|
||||
public GameObject dragPrev;
|
||||
|
||||
[Header("transforms")]
|
||||
public Transform prevLevelEquip;
|
||||
public Transform nextLevelEquip;
|
||||
public GameObject eip;
|
||||
|
||||
[Header("texts")]
|
||||
public Text prevLevelText;
|
||||
public Text nextLevelText;
|
||||
public Text reasonWhy;
|
||||
|
||||
[Header("materials")]
|
||||
public GameObject mtrPrefab;
|
||||
public Transform mtrParent;
|
||||
public Text mtrInfo;
|
||||
|
||||
[Header("sprites")]
|
||||
public Sprite MemoryFragmentSprite;
|
||||
public Sprite coinSprite;
|
||||
|
||||
[Header("buttons")]
|
||||
public Button yesUpdateButton;
|
||||
|
||||
private GameObject spawnedPrevLevelInstance;
|
||||
private GameObject spawnedNextLevelInstance;
|
||||
private equipmentSO nextLevelPreviewSO;
|
||||
private readonly List<GameObject> spawnedMaterialItems = new List<GameObject>();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InitializeBindings();
|
||||
SetDragPreviewVisible(false);
|
||||
ResetInitialSelectionState();
|
||||
RefreshAll();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
InitializeBindings();
|
||||
SetDragPreviewVisible(false);
|
||||
ResetInitialSelectionState();
|
||||
RefreshAll();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (yesUpdateButton != null)
|
||||
{
|
||||
yesUpdateButton.onClick.RemoveListener(HandleYesUpdateClicked);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeBindings()
|
||||
{
|
||||
if (playerSO != null)
|
||||
{
|
||||
PlayerEconomyLedger.EnsureInstance().AttachPlayerData(playerSO);
|
||||
}
|
||||
|
||||
if (yesUpdateButton != null)
|
||||
{
|
||||
yesUpdateButton.onClick.RemoveListener(HandleYesUpdateClicked);
|
||||
yesUpdateButton.onClick.AddListener(HandleYesUpdateClicked);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDragPreviewVisible(bool visible)
|
||||
{
|
||||
if (dragPrev == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gameObject.activeInHierarchy)
|
||||
{
|
||||
dragPrev.SetActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dragPrev != null)
|
||||
{
|
||||
dragPrev.SetActive(visible);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsPointerOverDropArea(Vector2 screenPoint, Camera eventCamera)
|
||||
{
|
||||
if (dragPrev == null || !dragPrev.activeInHierarchy)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
RectTransform rectTransform = dragPrev.transform as RectTransform;
|
||||
if (rectTransform == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return RectTransformUtility.RectangleContainsScreenPoint(rectTransform, screenPoint, eventCamera);
|
||||
}
|
||||
|
||||
public void AcceptDraggedEquipment(equipmentSO equipment)
|
||||
{
|
||||
if (equipment == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
eqp_p_SO = equipment;
|
||||
RefreshAll();
|
||||
}
|
||||
|
||||
private void RefreshAll()
|
||||
{
|
||||
RefreshPrevLevelPreview();
|
||||
RefreshNextLevelPreview();
|
||||
RefreshSelectionState();
|
||||
RefreshPrevLevelText();
|
||||
RefreshNextLevelText();
|
||||
RefreshMaterialRequirements();
|
||||
RefreshActionState();
|
||||
}
|
||||
|
||||
public void RefreshPrevLevelPreview()
|
||||
{
|
||||
DestroyPrevLevelPreview();
|
||||
|
||||
if (eqp_p_SO == null || eip == null || prevLevelEquip == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject instance = Instantiate(eip, prevLevelEquip);
|
||||
instance.name = $"{eqp_p_SO.name}_PrevLevel";
|
||||
instance.SetActive(true);
|
||||
spawnedPrevLevelInstance = instance;
|
||||
|
||||
equipItemPrefab item = instance.GetComponent<equipItemPrefab>();
|
||||
if (item != null)
|
||||
{
|
||||
item.Bind(eqp_p_SO);
|
||||
item.SetInteractionOptions(false, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshNextLevelPreview()
|
||||
{
|
||||
DestroyNextLevelPreview();
|
||||
|
||||
if (!CanShowNextPreview())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
nextLevelPreviewSO = Instantiate(eqp_p_SO);
|
||||
nextLevelPreviewSO.level = Mathf.Clamp(eqp_p_SO.level + 1, 0, 20);
|
||||
|
||||
GameObject instance = Instantiate(eip, nextLevelEquip);
|
||||
instance.name = $"{eqp_p_SO.name}_NextLevel";
|
||||
instance.SetActive(true);
|
||||
spawnedNextLevelInstance = instance;
|
||||
|
||||
equipItemPrefab item = instance.GetComponent<equipItemPrefab>();
|
||||
if (item != null)
|
||||
{
|
||||
item.Bind(nextLevelPreviewSO);
|
||||
item.SetInteractionOptions(false, false);
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanShowNextPreview()
|
||||
{
|
||||
if (eqp_p_SO == null || eip == null || nextLevelEquip == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int level = eqp_p_SO.level;
|
||||
if (level < 0 || level >= 20)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return !RequiresTour(level);
|
||||
}
|
||||
|
||||
private void RefreshSelectionState()
|
||||
{
|
||||
bool hasSelection = eqp_p_SO != null && spawnedPrevLevelInstance != null;
|
||||
bool requiresTour = hasSelection && RequiresTour(eqp_p_SO.level);
|
||||
bool isMaxLevel = hasSelection && eqp_p_SO.level >= 20;
|
||||
bool isInvalidLevel = hasSelection && !IsLegalLevel(eqp_p_SO.level);
|
||||
|
||||
if (beforeObj != null)
|
||||
{
|
||||
beforeObj.SetActive(true);
|
||||
}
|
||||
|
||||
bool showProgressObjects = hasSelection && !requiresTour && !isMaxLevel && !isInvalidLevel;
|
||||
|
||||
if (toObj != null)
|
||||
{
|
||||
toObj.SetActive(showProgressObjects);
|
||||
}
|
||||
|
||||
if (nextObj != null)
|
||||
{
|
||||
nextObj.SetActive(showProgressObjects);
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshPrevLevelText()
|
||||
{
|
||||
if (prevLevelText == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (eqp_p_SO == null)
|
||||
{
|
||||
prevLevelText.text = "选择一个记忆";
|
||||
prevLevelText.color = Color.black;
|
||||
return;
|
||||
}
|
||||
|
||||
prevLevelText.text = $"{Mathf.Max(0, eqp_p_SO.level)}追忆等级";
|
||||
prevLevelText.color = ResolveEquipmentColor(GetQualityColorIndex(eqp_p_SO.level));
|
||||
}
|
||||
|
||||
private void RefreshNextLevelText()
|
||||
{
|
||||
if (nextLevelText == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CanShowNextPreview() || nextLevelPreviewSO == null)
|
||||
{
|
||||
nextLevelText.text = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
nextLevelText.text = $"{Mathf.Max(0, nextLevelPreviewSO.level)}追忆等级";
|
||||
nextLevelText.color = ResolveEquipmentColor(GetQualityColorIndex(nextLevelPreviewSO.level));
|
||||
}
|
||||
|
||||
private void RefreshMaterialRequirements()
|
||||
{
|
||||
ClearSpawnedMaterialItems();
|
||||
|
||||
if (mtrInfo != null)
|
||||
{
|
||||
mtrInfo.text = "需要指定记忆";
|
||||
}
|
||||
|
||||
if (eqp_p_SO == null || need_mtrSO == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int level = eqp_p_SO.level;
|
||||
if (!IsLegalLevel(level))
|
||||
{
|
||||
if (mtrInfo != null)
|
||||
{
|
||||
mtrInfo.text = "装备不合法";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (level == 20)
|
||||
{
|
||||
if (mtrInfo != null)
|
||||
{
|
||||
mtrInfo.text = "<color=#FF69B4>梦醒装备已满级</color>";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (RequiresTour(level))
|
||||
{
|
||||
if (mtrInfo != null)
|
||||
{
|
||||
mtrInfo.text = "需要巡演";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (mtrInfo != null)
|
||||
{
|
||||
mtrInfo.text = string.Empty;
|
||||
}
|
||||
|
||||
SpawnUpgradeMaterialItems(level);
|
||||
}
|
||||
|
||||
private void SpawnUpgradeMaterialItems(int level)
|
||||
{
|
||||
if (mtrPrefab == null || mtrParent == null || need_mtrSO == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int upgradeMaterialRequired = need_mtrSO.GetUpgradeMaterialRequired(level);
|
||||
int upgradeCoinsRequired = need_mtrSO.GetUpgradeCoinsRequired(level);
|
||||
int upgradeMemoryRequired = need_mtrSO.GetUpgradeMemoryFragmentRequired(level);
|
||||
|
||||
if (upgradeMaterialRequired > 0 && need_mtrSO.upgradeMaterial != null)
|
||||
{
|
||||
SpawnMaterialItem(
|
||||
need_mtrSO.upgradeMaterial.consumableSprite,
|
||||
need_mtrSO.upgradeMaterial.consumableName,
|
||||
upgradeMaterialRequired.ToString());
|
||||
}
|
||||
|
||||
if (upgradeCoinsRequired > 0)
|
||||
{
|
||||
SpawnMaterialItem(
|
||||
coinSprite,
|
||||
"Coins",
|
||||
upgradeCoinsRequired.ToString());
|
||||
}
|
||||
|
||||
if (upgradeMemoryRequired > 0)
|
||||
{
|
||||
SpawnMaterialItem(
|
||||
MemoryFragmentSprite,
|
||||
"记忆碎片",
|
||||
upgradeMemoryRequired.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnMaterialItem(Sprite sprite, string displayName, string amountText)
|
||||
{
|
||||
GameObject instance = Instantiate(mtrPrefab, mtrParent);
|
||||
instance.SetActive(true);
|
||||
spawnedMaterialItems.Add(instance);
|
||||
|
||||
materialPrefab item = instance.GetComponent<materialPrefab>();
|
||||
if (item != null)
|
||||
{
|
||||
item.Bind(sprite, displayName, amountText, true, false, null);
|
||||
item.SetSelected(true);
|
||||
if (item.materialButton != null)
|
||||
{
|
||||
item.materialButton.interactable = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshActionState()
|
||||
{
|
||||
string failureReason = GetUpgradeFailureReason();
|
||||
|
||||
if (reasonWhy != null)
|
||||
{
|
||||
reasonWhy.text = string.IsNullOrEmpty(failureReason) ? string.Empty : failureReason;
|
||||
}
|
||||
|
||||
if (yesUpdateButton == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
yesUpdateButton.interactable = string.IsNullOrEmpty(failureReason);
|
||||
}
|
||||
|
||||
private bool CanUpgradeCurrent()
|
||||
{
|
||||
return string.IsNullOrEmpty(GetUpgradeFailureReason());
|
||||
}
|
||||
|
||||
private string GetUpgradeFailureReason()
|
||||
{
|
||||
if (eqp_p_SO == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (need_mtrSO == null)
|
||||
{
|
||||
return "未配置升级规则";
|
||||
}
|
||||
|
||||
int level = eqp_p_SO.level;
|
||||
if (!IsLegalLevel(level))
|
||||
{
|
||||
return "装备不合法";
|
||||
}
|
||||
|
||||
if (level >= 20)
|
||||
{
|
||||
return "梦醒装备已满级";
|
||||
}
|
||||
|
||||
if (RequiresTour(level))
|
||||
{
|
||||
return "当前等级需要巡演";
|
||||
}
|
||||
|
||||
int upgradeMaterialRequired = need_mtrSO.GetUpgradeMaterialRequired(level);
|
||||
int upgradeCoinsRequired = need_mtrSO.GetUpgradeCoinsRequired(level);
|
||||
int upgradeMemoryRequired = need_mtrSO.GetUpgradeMemoryFragmentRequired(level);
|
||||
|
||||
if (upgradeMaterialRequired > 0)
|
||||
{
|
||||
if (need_mtrSO.upgradeMaterial == null)
|
||||
{
|
||||
return "未配置升级材料";
|
||||
}
|
||||
|
||||
int ownedConsumable = EquipmentConsumableLedger.EnsureInstance().GetCount(need_mtrSO.upgradeMaterial.consumableKind);
|
||||
if (ownedConsumable < upgradeMaterialRequired)
|
||||
{
|
||||
return "升级材料不足";
|
||||
}
|
||||
}
|
||||
|
||||
if (!PlayerEconomyLedger.EnsureInstance().HasEnoughCoins(upgradeCoinsRequired))
|
||||
{
|
||||
return "硬币不足";
|
||||
}
|
||||
|
||||
if (!PlayerEconomyLedger.EnsureInstance().HasEnoughMaterial(upgradeMemoryRequired))
|
||||
{
|
||||
return "记忆碎片不足";
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private void HandleYesUpdateClicked()
|
||||
{
|
||||
if (!CanUpgradeCurrent())
|
||||
{
|
||||
RefreshActionState();
|
||||
return;
|
||||
}
|
||||
|
||||
int currentLevel = eqp_p_SO.level;
|
||||
int upgradeMaterialRequired = need_mtrSO.GetUpgradeMaterialRequired(currentLevel);
|
||||
int upgradeCoinsRequired = need_mtrSO.GetUpgradeCoinsRequired(currentLevel);
|
||||
int upgradeMemoryRequired = need_mtrSO.GetUpgradeMemoryFragmentRequired(currentLevel);
|
||||
|
||||
if (upgradeMaterialRequired > 0)
|
||||
{
|
||||
if (need_mtrSO.upgradeMaterial == null || !EquipmentConsumableLedger.EnsureInstance().TryConsume(need_mtrSO.upgradeMaterial.consumableKind, upgradeMaterialRequired))
|
||||
{
|
||||
RefreshAll();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (upgradeCoinsRequired > 0 && !PlayerEconomyLedger.EnsureInstance().TrySpendCoins(upgradeCoinsRequired))
|
||||
{
|
||||
if (upgradeMaterialRequired > 0 && need_mtrSO.upgradeMaterial != null)
|
||||
{
|
||||
EquipmentConsumableLedger.EnsureInstance().Add(need_mtrSO.upgradeMaterial.consumableKind, upgradeMaterialRequired);
|
||||
}
|
||||
RefreshAll();
|
||||
return;
|
||||
}
|
||||
|
||||
if (upgradeMemoryRequired > 0 && !PlayerEconomyLedger.EnsureInstance().TrySpendMaterial(upgradeMemoryRequired))
|
||||
{
|
||||
if (upgradeCoinsRequired > 0)
|
||||
{
|
||||
PlayerEconomyLedger.EnsureInstance().AddCoins(upgradeCoinsRequired);
|
||||
}
|
||||
if (upgradeMaterialRequired > 0 && need_mtrSO.upgradeMaterial != null)
|
||||
{
|
||||
EquipmentConsumableLedger.EnsureInstance().Add(need_mtrSO.upgradeMaterial.consumableKind, upgradeMaterialRequired);
|
||||
}
|
||||
RefreshAll();
|
||||
return;
|
||||
}
|
||||
|
||||
eqp_p_SO.level = Mathf.Clamp(eqp_p_SO.level + 1, 0, 20);
|
||||
PersistEquipmentLevel(eqp_p_SO);
|
||||
RefreshAllEquipBags();
|
||||
RefreshAll();
|
||||
}
|
||||
|
||||
private static void PersistEquipmentLevel(equipmentSO equipment)
|
||||
{
|
||||
if (equipment == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorUtility.SetDirty(equipment);
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void RefreshAllEquipBags()
|
||||
{
|
||||
equipBag[] bags = FindObjectsOfType<equipBag>(true);
|
||||
for (int i = 0; i < bags.Length; i++)
|
||||
{
|
||||
if (bags[i] != null)
|
||||
{
|
||||
bags[i].Rebuild();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Color ResolveEquipmentColor(int colorIndex)
|
||||
{
|
||||
if (eip == null)
|
||||
{
|
||||
return Color.white;
|
||||
}
|
||||
|
||||
equipItemPrefab itemPrefab = eip.GetComponent<equipItemPrefab>();
|
||||
if (itemPrefab == null || itemPrefab.itemBtmColors == null || itemPrefab.itemBtmColors.Length == 0)
|
||||
{
|
||||
return Color.white;
|
||||
}
|
||||
|
||||
int safeIndex = Mathf.Clamp(colorIndex, 0, itemPrefab.itemBtmColors.Length - 1);
|
||||
return itemPrefab.itemBtmColors[safeIndex];
|
||||
}
|
||||
|
||||
private static int GetQualityColorIndex(int level)
|
||||
{
|
||||
if (level >= 20)
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
if (level >= 15)
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
if (level >= 10)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (level >= 5)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static bool IsLegalLevel(int level)
|
||||
{
|
||||
return level >= 0 && level <= 20;
|
||||
}
|
||||
|
||||
private static bool RequiresTour(int level)
|
||||
{
|
||||
return level == 4 || level == 9 || level == 14 || level == 19;
|
||||
}
|
||||
|
||||
private void ResetInitialSelectionState()
|
||||
{
|
||||
DestroyPrevLevelPreview();
|
||||
DestroyNextLevelPreview();
|
||||
ClearSpawnedMaterialItems();
|
||||
eqp_p_SO = null;
|
||||
}
|
||||
|
||||
private void ClearSpawnedMaterialItems()
|
||||
{
|
||||
if (mtrParent != null)
|
||||
{
|
||||
for (int i = mtrParent.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
Transform child = mtrParent.GetChild(i);
|
||||
if (child == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
Object.DestroyImmediate(child.gameObject);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
Object.Destroy(child.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
spawnedMaterialItems.Clear();
|
||||
}
|
||||
|
||||
private void DestroyPrevLevelPreview()
|
||||
{
|
||||
if (spawnedPrevLevelInstance == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
Object.DestroyImmediate(spawnedPrevLevelInstance);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
Object.Destroy(spawnedPrevLevelInstance);
|
||||
}
|
||||
|
||||
spawnedPrevLevelInstance = null;
|
||||
}
|
||||
|
||||
private void DestroyNextLevelPreview()
|
||||
{
|
||||
if (spawnedNextLevelInstance != null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
Object.DestroyImmediate(spawnedNextLevelInstance);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
Object.Destroy(spawnedNextLevelInstance);
|
||||
}
|
||||
|
||||
spawnedNextLevelInstance = null;
|
||||
}
|
||||
|
||||
if (nextLevelPreviewSO != null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
Object.DestroyImmediate(nextLevelPreviewSO);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
Object.Destroy(nextLevelPreviewSO);
|
||||
}
|
||||
|
||||
nextLevelPreviewSO = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0233fcfb8bdea5045a2cfdcddad7dd7f
|
||||
Reference in New Issue
Block a user