养成基本完毕,新UI,修bug,装备初步,
This commit is contained in:
@@ -0,0 +1,313 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Bansonic;
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
public class idolSkillsHub : MonoBehaviour
|
||||
{
|
||||
[Header("objects")]
|
||||
public GameObject deSkillPrefab;
|
||||
public Transform deSkillContainer;
|
||||
|
||||
[Header("fallbacks")]
|
||||
public Sprite unlock_sprite;
|
||||
|
||||
[Header("displaying")]
|
||||
public Material disgot_grayMtr;
|
||||
public Color enabled_btmColor = Color.white;
|
||||
public Color disabled_btmColor = Color.white;
|
||||
public Color unlock_btmColor = Color.gray;
|
||||
|
||||
[Header("bool")]
|
||||
public bool display_ungotten = true;
|
||||
|
||||
[Header("runtime")]
|
||||
public AllyHero_SO currentHero;
|
||||
private int selectedDetailSkillGroupId = -1;
|
||||
|
||||
public void SetHero(AllyHero_SO hero)
|
||||
{
|
||||
bool heroChanged = currentHero == null || hero == null || currentHero.ally_heroID != hero.ally_heroID;
|
||||
currentHero = hero;
|
||||
if (currentHero != null)
|
||||
{
|
||||
currentHero.LoadEquippedSkillsFromLocal();
|
||||
}
|
||||
|
||||
if (heroChanged)
|
||||
{
|
||||
selectedDetailSkillGroupId = GetDefaultDetailSkillGroupId(currentHero);
|
||||
}
|
||||
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
public void Rebuild()
|
||||
{
|
||||
ClearItems();
|
||||
|
||||
if (currentHero == null || deSkillPrefab == null || deSkillContainer == null || currentHero.skillGroups == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
currentHero.LoadEquippedSkillsFromLocal();
|
||||
|
||||
int currentTierNumber = GetCurrentTierNumber(currentHero);
|
||||
AllyHero_SO.AllyLevelInfo currentLevelInfo = currentHero.GetEffectiveLevelForCurrentEXP();
|
||||
int maxSkillSlots = currentLevelInfo != null ? Mathf.Max(0, currentLevelInfo.skill_slot_limited) : 0;
|
||||
|
||||
for (int i = 0; i < currentHero.skillGroups.Length; i++)
|
||||
{
|
||||
SkillGroup group = currentHero.skillGroups[i];
|
||||
if (group == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool unlocked = currentTierNumber >= Mathf.Clamp(group.thisSkill_levelLimit, 1, 4);
|
||||
bool equipped = IsEquipped(group.skillGroupID);
|
||||
bool slotAvailable = equipped || GetEquippedCount() < maxSkillSlots;
|
||||
|
||||
string enableText;
|
||||
bool enableToggleValue;
|
||||
if (!unlocked)
|
||||
{
|
||||
enableText = "\u9700\u8981\u7b49\u7ea7" + GetTierName(group.thisSkill_levelLimit);
|
||||
enableToggleValue = false;
|
||||
}
|
||||
else if (!slotAvailable)
|
||||
{
|
||||
enableText = "\u6280\u80fd\u69fd\u4f4d\u5df2\u6ee1";
|
||||
enableToggleValue = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
enableText = "\u6280\u80fd\u53ef\u7528";
|
||||
enableToggleValue = true;
|
||||
}
|
||||
|
||||
string equipText = equipped ? "\u5df2\u88c5\u914d\u6b64\u6280\u80fd" : "\u6280\u80fd\u672a\u88c5\u914d";
|
||||
bool equipToggleValue = equipped;
|
||||
|
||||
bool hideLockedIdentity = !unlocked && !display_ungotten;
|
||||
Sprite displaySprite = unlocked
|
||||
? group.groupIcon
|
||||
: (display_ungotten ? group.groupIcon : unlock_sprite);
|
||||
string displayName = hideLockedIdentity ? "\u672a\u89e3\u9501\u6280\u80fd" : (group.groupName ?? string.Empty);
|
||||
string detailName = displayName;
|
||||
string detailDescription = hideLockedIdentity ? "\u6b64\u6280\u80fd\u5c1a\u672a\u89e3\u9501\u3002" : (group.skillDescriptionsText ?? string.Empty);
|
||||
Color bottomColor = equipped ? enabled_btmColor : (unlocked ? disabled_btmColor : unlock_btmColor);
|
||||
Material iconMaterial = unlocked ? null : disgot_grayMtr;
|
||||
|
||||
GameObject instance = Instantiate(deSkillPrefab, deSkillContainer);
|
||||
deSkillPrefab item = instance.GetComponent<deSkillPrefab>();
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool hoverToShowDetails = item.display_DP_ungotten;
|
||||
bool allowDetailsHover = item.display_DP_ungotten;
|
||||
bool showDetailsNow = !item.display_DP_ungotten && unlocked && selectedDetailSkillGroupId == group.skillGroupID;
|
||||
|
||||
item.Bind(
|
||||
displaySprite,
|
||||
displaySprite,
|
||||
displayName,
|
||||
detailName,
|
||||
detailDescription,
|
||||
bottomColor,
|
||||
iconMaterial,
|
||||
enableToggleValue,
|
||||
enableText,
|
||||
equipToggleValue,
|
||||
equipText,
|
||||
equipped,
|
||||
true,
|
||||
showDetailsNow,
|
||||
hoverToShowDetails,
|
||||
allowDetailsHover,
|
||||
() => HandleSkillClicked(group));
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleSkillClicked(SkillGroup group)
|
||||
{
|
||||
if (currentHero == null || group == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int currentTierNumber = GetCurrentTierNumber(currentHero);
|
||||
if (currentTierNumber < Mathf.Clamp(group.thisSkill_levelLimit, 1, 4))
|
||||
{
|
||||
selectedDetailSkillGroupId = -1;
|
||||
Rebuild();
|
||||
gNotice.warning.display("\u9700\u8981\u7b49\u7ea7" + GetTierName(group.thisSkill_levelLimit));
|
||||
return;
|
||||
}
|
||||
|
||||
selectedDetailSkillGroupId = group.skillGroupID;
|
||||
|
||||
List<int> equipped = new List<int>(currentHero.equippedSkillGroupIDs ?? Array.Empty<int>());
|
||||
equipped.RemoveAll(id => id == 0);
|
||||
|
||||
if (equipped.Contains(group.skillGroupID))
|
||||
{
|
||||
equipped.Remove(group.skillGroupID);
|
||||
ApplyEquippedSkillGroupIds(equipped);
|
||||
Rebuild();
|
||||
return;
|
||||
}
|
||||
|
||||
AllyHero_SO.AllyLevelInfo currentLevelInfo = currentHero.GetEffectiveLevelForCurrentEXP();
|
||||
int maxSkillSlots = currentLevelInfo != null ? Mathf.Max(0, currentLevelInfo.skill_slot_limited) : 0;
|
||||
if (equipped.Count >= maxSkillSlots)
|
||||
{
|
||||
Rebuild();
|
||||
gNotice.warning.display("\u6280\u80fd\u69fd\u4f4d\u5df2\u6ee1");
|
||||
return;
|
||||
}
|
||||
|
||||
equipped.Add(group.skillGroupID);
|
||||
ApplyEquippedSkillGroupIds(equipped);
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
private void ApplyEquippedSkillGroupIds(List<int> equippedIds)
|
||||
{
|
||||
currentHero.equippedSkillGroupIDs = equippedIds != null ? equippedIds.ToArray() : Array.Empty<int>();
|
||||
currentHero.SaveEquippedSkillsToLocal();
|
||||
currentHero.LoadEquippedSkillsFromLocal();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
EditorUtility.SetDirty(currentHero);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private bool IsEquipped(int skillGroupId)
|
||||
{
|
||||
if (currentHero == null || currentHero.equippedSkillGroupIDs == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < currentHero.equippedSkillGroupIDs.Length; i++)
|
||||
{
|
||||
if (currentHero.equippedSkillGroupIDs[i] == skillGroupId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private int GetEquippedCount()
|
||||
{
|
||||
if (currentHero == null || currentHero.equippedSkillGroupIDs == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (int i = 0; i < currentHero.equippedSkillGroupIDs.Length; i++)
|
||||
{
|
||||
if (currentHero.equippedSkillGroupIDs[i] != 0)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private int GetDefaultDetailSkillGroupId(AllyHero_SO hero)
|
||||
{
|
||||
if (hero == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
hero.LoadEquippedSkillsFromLocal();
|
||||
if (hero.equippedSkillGroupIDs != null)
|
||||
{
|
||||
for (int i = 0; i < hero.equippedSkillGroupIDs.Length; i++)
|
||||
{
|
||||
int groupId = hero.equippedSkillGroupIDs[i];
|
||||
if (groupId == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
SkillGroup group = hero.GetSkillGroupByID(groupId);
|
||||
if (group != null && GetCurrentTierNumber(hero) >= Mathf.Clamp(group.thisSkill_levelLimit, 1, 4))
|
||||
{
|
||||
return groupId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static int GetCurrentTierNumber(AllyHero_SO hero)
|
||||
{
|
||||
if (hero == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return Mathf.Clamp(hero.ally_growthUnlockedTierIndex + 1, 1, 4);
|
||||
}
|
||||
|
||||
private static string GetTierName(int tierNumber)
|
||||
{
|
||||
switch (Mathf.Clamp(tierNumber, 1, 4))
|
||||
{
|
||||
case 1: return "C";
|
||||
case 2: return "B";
|
||||
case 3: return "A";
|
||||
case 4: return "S";
|
||||
default: return "C";
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearItems()
|
||||
{
|
||||
if (deSkillContainer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = deSkillContainer.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
Transform child = deSkillContainer.GetChild(i);
|
||||
if (child == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
DestroyImmediate(child.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
#else
|
||||
Destroy(child.gameObject);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user