gameplay手游触屏支持,一些小优化和修复
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public static class AllyHeroSkillSelectionValidator
|
||||
{
|
||||
public static IEnumerator ValidateAllHeroesAsync(int heroesPerFrame = 2, Action<bool> onCompleted = null)
|
||||
{
|
||||
AllyHero_SO[] heroes = RuntimeResourcesCache.LoadAllAllyHeroes();
|
||||
bool anyChanged = false;
|
||||
int processedThisFrame = 0;
|
||||
int batchSize = Mathf.Max(1, heroesPerFrame);
|
||||
|
||||
for (int i = 0; i < heroes.Length; i++)
|
||||
{
|
||||
AllyHero_SO hero = heroes[i];
|
||||
if (hero != null && hero.ValidateEquippedSkillSelections())
|
||||
{
|
||||
anyChanged = true;
|
||||
}
|
||||
|
||||
processedThisFrame++;
|
||||
if (processedThisFrame >= batchSize)
|
||||
{
|
||||
processedThisFrame = 0;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
onCompleted?.Invoke(anyChanged);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aebb9d085d6f9c14fa7ff27d1b4e6e03
|
||||
@@ -189,6 +189,77 @@ public class AllyHero_SO : ScriptableObject
|
||||
return EquipmentSkillGroupLibrary.ResolveSkillGroup(groupID);
|
||||
}
|
||||
|
||||
public bool ValidateEquippedSkillSelections(bool persistIfChanged = true)
|
||||
{
|
||||
LoadEquippedSkillsFromLocal();
|
||||
LoadEquippedEquipmentFromLocal();
|
||||
|
||||
if (equippedSkillGroupIDs == null)
|
||||
{
|
||||
equippedSkillGroupIDs = Array.Empty<int>();
|
||||
}
|
||||
|
||||
int currentLevelId = GetEffectiveLevelForCurrentEXP()?.levelID ?? 0;
|
||||
int maxSkillSlots = Mathf.Max(0, GetEffectiveSkillSlotLimit());
|
||||
List<int> validatedGroupIds = new List<int>(Mathf.Min(equippedSkillGroupIDs.Length, maxSkillSlots));
|
||||
HashSet<int> seenGroupIds = new HashSet<int>();
|
||||
|
||||
for (int i = 0; i < equippedSkillGroupIDs.Length; i++)
|
||||
{
|
||||
int groupId = equippedSkillGroupIDs[i];
|
||||
if (groupId <= 0 || !seenGroupIds.Add(groupId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (validatedGroupIds.Count >= maxSkillSlots)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
SkillGroup group = GetOwnedSkillGroupByID(groupId);
|
||||
if (group == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int requiredLevelId = Mathf.Clamp(group.thisSkill_levelLimit, 1, 4);
|
||||
if (currentLevelId < requiredLevelId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
validatedGroupIds.Add(groupId);
|
||||
}
|
||||
|
||||
int[] validatedArray = validatedGroupIds.ToArray();
|
||||
bool changed = !AreSkillGroupIdArraysEqual(equippedSkillGroupIDs, validatedArray);
|
||||
if (!changed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
equippedSkillGroupIDs = validatedArray;
|
||||
|
||||
if (persistIfChanged)
|
||||
{
|
||||
SaveEquippedSkillsToLocal();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
EditorUtility.SetDirty(this);
|
||||
if (persistIfChanged)
|
||||
{
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int[] GetEffectiveEquippedSkillGroupIDs()
|
||||
{
|
||||
var result = new List<int>();
|
||||
@@ -365,6 +436,45 @@ public class AllyHero_SO : ScriptableObject
|
||||
result.Add(groupId);
|
||||
}
|
||||
|
||||
private static bool AreSkillGroupIdArraysEqual(int[] left, int[] right)
|
||||
{
|
||||
int leftLength = left != null ? left.Length : 0;
|
||||
int rightLength = right != null ? right.Length : 0;
|
||||
if (leftLength != rightLength)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < leftLength; i++)
|
||||
{
|
||||
if (left[i] != right[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private SkillGroup GetOwnedSkillGroupByID(int groupId)
|
||||
{
|
||||
if (skillGroups == null || skillGroups.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int i = 0; i < skillGroups.Length; i++)
|
||||
{
|
||||
SkillGroup group = skillGroups[i];
|
||||
if (group != null && group.skillGroupID == groupId)
|
||||
{
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int GetUnlockedLevelIndex()
|
||||
{
|
||||
List<AllyLevelInfo> sorted = BuildSortedLevelStats();
|
||||
|
||||
Reference in New Issue
Block a user