完成编队 增加多个细节和小功能
This commit is contained in:
@@ -6,6 +6,7 @@ public class AllyHero_SO : ScriptableObject
|
||||
{
|
||||
[Header("友方英雄基本信息")]
|
||||
public string ally_heroName;
|
||||
public string ally_heroDesignation;
|
||||
public int ally_heroID;
|
||||
|
||||
[Header("英雄立绘")]
|
||||
@@ -18,6 +19,8 @@ public class AllyHero_SO : ScriptableObject
|
||||
public Sprite ally_heroIcon;
|
||||
[Header("英雄编队界面海报")]
|
||||
public Sprite ally_heroPoster;
|
||||
[Header("角色带通道立绘")]
|
||||
public Sprite ally_hero_HD_image;
|
||||
|
||||
[Header("英雄简介")]
|
||||
[TextArea(3, 10)]
|
||||
@@ -49,6 +52,7 @@ public class AllyHero_SO : ScriptableObject
|
||||
[Tooltip("得分效率")]
|
||||
public float scoreEfficiency = 1f;
|
||||
|
||||
[Header("升到本等级所需经验")]
|
||||
[Tooltip("升到本等级所需经验")]
|
||||
public int requiredEXP;
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ public class CharacterCardView : MonoBehaviour, IBeginDragHandler, IDragHandler,
|
||||
img.SetNativeSize();
|
||||
var cg = dragGhost.AddComponent<CanvasGroup>();
|
||||
cg.blocksRaycasts = false;
|
||||
cg.alpha = 0.5f; // Set transparency to half
|
||||
|
||||
UpdateGhostPosition(eventData);
|
||||
}
|
||||
|
||||
@@ -5,12 +5,21 @@ using System.Collections;
|
||||
|
||||
public class newTeamSelector : MonoBehaviour
|
||||
{
|
||||
public static newTeamSelector Instance { get; private set; }
|
||||
|
||||
[Header("等级图片CBAS")]
|
||||
public Sprite levelIcon_sprite_C;
|
||||
public Sprite levelIcon_sprite_B;
|
||||
public Sprite levelIcon_sprite_A;
|
||||
public Sprite levelIcon_sprite_S;
|
||||
|
||||
[Header("已选择的队伍")]
|
||||
public int selected_heroSlot01_heroID;
|
||||
public int selected_heroSlot02_heroID;
|
||||
public int selected_heroSlot03_heroID;
|
||||
public int selected_heroSlot04_heroID;
|
||||
public int selected_heroSlot05_heroID;
|
||||
|
||||
[Tooltip("Prefab for a single hero slot. Must contain slots_heroSlots component.")]
|
||||
public GameObject slotPrefab;
|
||||
|
||||
@@ -28,10 +37,23 @@ public class newTeamSelector : MonoBehaviour
|
||||
|
||||
private readonly List<slots_heroSlots> createdSlots = new List<slots_heroSlots>();
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (instantiateOnStart)
|
||||
CreateSlots();
|
||||
LoadSelectedHeroes();
|
||||
}
|
||||
|
||||
void Update() { }
|
||||
@@ -137,4 +159,92 @@ public class newTeamSelector : MonoBehaviour
|
||||
}
|
||||
|
||||
public List<slots_heroSlots> GetCreatedSlots() => createdSlots;
|
||||
|
||||
public void UpdateAndSaveSelectedHeroes()
|
||||
{
|
||||
if (createdSlots.Count > 0) selected_heroSlot01_heroID = createdSlots[0].heroSlot_heroID;
|
||||
if (createdSlots.Count > 1) selected_heroSlot02_heroID = createdSlots[1].heroSlot_heroID;
|
||||
if (createdSlots.Count > 2) selected_heroSlot03_heroID = createdSlots[2].heroSlot_heroID;
|
||||
if (createdSlots.Count > 3) selected_heroSlot04_heroID = createdSlots[3].heroSlot_heroID;
|
||||
if (createdSlots.Count > 4) selected_heroSlot05_heroID = createdSlots[4].heroSlot_heroID;
|
||||
|
||||
PlayerPrefs.SetInt("selected_heroSlot01_heroID", selected_heroSlot01_heroID);
|
||||
PlayerPrefs.SetInt("selected_heroSlot02_heroID", selected_heroSlot02_heroID);
|
||||
PlayerPrefs.SetInt("selected_heroSlot03_heroID", selected_heroSlot03_heroID);
|
||||
PlayerPrefs.SetInt("selected_heroSlot04_heroID", selected_heroSlot04_heroID);
|
||||
PlayerPrefs.SetInt("selected_heroSlot05_heroID", selected_heroSlot05_heroID);
|
||||
PlayerPrefs.Save();
|
||||
|
||||
Debug.Log("已保存当前队伍到PlayerPrefs");
|
||||
}
|
||||
|
||||
public void LoadSelectedHeroes()
|
||||
{
|
||||
if (createdSlots.Count == 0) return;
|
||||
|
||||
selected_heroSlot01_heroID = PlayerPrefs.GetInt("selected_heroSlot01_heroID", 0);
|
||||
selected_heroSlot02_heroID = PlayerPrefs.GetInt("selected_heroSlot02_heroID", 0);
|
||||
selected_heroSlot03_heroID = PlayerPrefs.GetInt("selected_heroSlot03_heroID", 0);
|
||||
selected_heroSlot04_heroID = PlayerPrefs.GetInt("selected_heroSlot04_heroID", 0);
|
||||
selected_heroSlot05_heroID = PlayerPrefs.GetInt("selected_heroSlot05_heroID", 0);
|
||||
|
||||
// Set the slots
|
||||
if (createdSlots.Count > 0) createdSlots[0].heroSlot_heroID = selected_heroSlot01_heroID;
|
||||
if (createdSlots.Count > 1) createdSlots[1].heroSlot_heroID = selected_heroSlot02_heroID;
|
||||
if (createdSlots.Count > 2) createdSlots[2].heroSlot_heroID = selected_heroSlot03_heroID;
|
||||
if (createdSlots.Count > 3) createdSlots[3].heroSlot_heroID = selected_heroSlot04_heroID;
|
||||
if (createdSlots.Count > 4) createdSlots[4].heroSlot_heroID = selected_heroSlot05_heroID;
|
||||
|
||||
// Update each slot's UI
|
||||
for (int i = 0; i < createdSlots.Count; i++)
|
||||
{
|
||||
var slot = createdSlots[i];
|
||||
if (slot.heroSlot_heroID != 0)
|
||||
{
|
||||
// Find the hero SO
|
||||
AllyHero_SO hero = FindHeroById(slot.heroSlot_heroID);
|
||||
if (hero != null)
|
||||
{
|
||||
slot.SetSlot(slot.heroSlot_heroID, hero.ally_heroName, hero.ally_heroPoster);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Clear slot logic
|
||||
slot.heroSlot_heroID = 0;
|
||||
if (slot.heroSlot_heroName != null) slot.heroSlot_heroName.text = "空置";
|
||||
if (slot.heroImage != null)
|
||||
{
|
||||
// revert to default sprite if provided, otherwise keep transparent
|
||||
if (slot.defaultHeroSprite != null)
|
||||
{
|
||||
slot.heroImage.sprite = slot.defaultHeroSprite;
|
||||
slot.heroImage.color = new Color(slot.heroImage.color.r, slot.heroImage.color.g, slot.heroImage.color.b, 1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.heroImage.sprite = null;
|
||||
slot.heroImage.color = new Color(slot.heroImage.color.r, slot.heroImage.color.g, slot.heroImage.color.b, 0f);
|
||||
}
|
||||
}
|
||||
if (slot.heroLevelImage != null)
|
||||
{
|
||||
slot.heroLevelImage.sprite = null;
|
||||
slot.heroLevelImage.color = new Color(1f, 1f, 1f, 0f);
|
||||
}
|
||||
// Update skill list
|
||||
slot.UpdateSkillList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AllyHero_SO FindHeroById(int id)
|
||||
{
|
||||
var arr = Resources.LoadAll<AllyHero_SO>("");
|
||||
foreach (var a in arr)
|
||||
{
|
||||
if (a != null && a.ally_heroID == id) return a;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace Utils
|
||||
private static GameObject ghost;
|
||||
private static Image ghostImage;
|
||||
private static Canvas parentCanvas;
|
||||
private static CanvasGroup ghostCanvasGroup;
|
||||
|
||||
// Ensure ghost exists under given canvas
|
||||
public static void Show(Canvas canvas, Sprite sprite)
|
||||
@@ -21,8 +22,9 @@ namespace Utils
|
||||
ghost.transform.SetParent(parentCanvas.transform, false);
|
||||
ghostImage = ghost.AddComponent<Image>();
|
||||
ghostImage.raycastTarget = false;
|
||||
var cg = ghost.AddComponent<CanvasGroup>();
|
||||
cg.blocksRaycasts = false;
|
||||
ghostCanvasGroup = ghost.AddComponent<CanvasGroup>();
|
||||
ghostCanvasGroup.blocksRaycasts = false;
|
||||
ghostCanvasGroup.alpha = 0.5f; // Set transparency to half
|
||||
}
|
||||
ghostImage.sprite = sprite;
|
||||
// set size to sprite rect (avoid SetNativeSize to reduce layout work)
|
||||
|
||||
Reference in New Issue
Block a user