编队系统重置 选角页面基本完成 等待存入playerprefs

This commit is contained in:
FloatGaming
2025-12-07 12:04:21 +08:00
parent 941b294fce
commit c0a822b958
134 changed files with 14796 additions and 198 deletions
+66 -3
View File
@@ -3,8 +3,9 @@ using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class CharacterCardView : MonoBehaviour
public class CharacterCardView : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
public int characterID;
public string currentBoundaryLevel;
@@ -14,10 +15,16 @@ public class CharacterCardView : MonoBehaviour
public Image occupationIcon;
public bool isSelected=false;
// drag
private GameObject dragGhost;
private Canvas rootCanvas;
private CanvasGroup canvasGroup;
void Start()
{
charactCard = gameObject;
rootCanvas = GetComponentInParent<Canvas>();
canvasGroup = GetComponent<CanvasGroup>() ?? gameObject.AddComponent<CanvasGroup>();
}
/// <summary>
/// 未在队中的卡点击后进入被操纵状态。若在队伍中默认进入已经入队状态
@@ -40,6 +47,62 @@ public class CharacterCardView : MonoBehaviour
TeamManager.Instance.removeTeamCharacter(characterID);
characterImage.color = new Color(1f, 1f, 1f,1);
}
// Drag handlers: create ghost based on characterImage.sprite
public void OnBeginDrag(PointerEventData eventData)
{
Debug.Log($"CharacterCardView OnBeginDrag: {gameObject.name}");
if (characterImage == null || characterImage.sprite == null) return;
if (rootCanvas == null) rootCanvas = GetComponentInParent<Canvas>();
if (rootCanvas == null) return;
// prevent the original from blocking raycasts so drop targets can receive events
if (canvasGroup == null) canvasGroup = GetComponent<CanvasGroup>() ?? gameObject.AddComponent<CanvasGroup>();
canvasGroup.blocksRaycasts = false;
// ensure pointerDrag references this object for drop handlers
eventData.pointerDrag = gameObject;
dragGhost = new GameObject("_RoleDragGhost");
dragGhost.transform.SetParent(rootCanvas.transform, false);
var img = dragGhost.AddComponent<Image>();
img.raycastTarget = false;
img.sprite = characterImage.sprite;
img.SetNativeSize();
var cg = dragGhost.AddComponent<CanvasGroup>();
cg.blocksRaycasts = false;
UpdateGhostPosition(eventData);
}
public void OnDrag(PointerEventData eventData)
{
if (dragGhost == null) return;
UpdateGhostPosition(eventData);
}
public void OnEndDrag(PointerEventData eventData)
{
Debug.Log($"CharacterCardView OnEndDrag: {gameObject.name}");
if (dragGhost != null)
{
Destroy(dragGhost);
dragGhost = null;
}
// restore raycast blocking on the original
if (canvasGroup != null)
canvasGroup.blocksRaycasts = true;
}
private void UpdateGhostPosition(PointerEventData eventData)
{
if (rootCanvas == null) return;
RectTransformUtility.ScreenPointToLocalPointInRectangle(
rootCanvas.transform as RectTransform,
eventData.position,
eventData.pressEventCamera,
out Vector2 localPoint);
if (dragGhost != null)
dragGhost.transform.localPosition = localPoint;
}
}
+14 -1
View File
@@ -106,6 +106,10 @@ public class TeamManager : MonoBehaviour
// {
// teamSettingPanelInstance = teamSettingPanel.Instance;
// }
// Ensure we have a reference to the UI panel instance if available
if (teamSettingPanelInstance == null && teamSettingPanel.Instance != null)
teamSettingPanelInstance = teamSettingPanel.Instance;
testTeamSetting();//接入玩家存档后请注释掉此行
}
void saveTeamSetting()
@@ -227,7 +231,16 @@ public class TeamManager : MonoBehaviour
}
}
currentTeamSettings[currentSelectedTeam].teamIdList = newCurrentTeam;
teamSettingPanelInstance.updateTeamSettingElements();
// attempt to update UI panel safely
var panel = teamSettingPanelInstance ?? teamSettingPanel.Instance;
if (panel != null)
{
panel.updateTeamSettingElements();
}
else
{
Debug.LogWarning("TeamManager.removeTeamCharacter: teamSettingPanel instance missing, UI not updated.");
}
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5f507082dd646a246829ec5fa8d7b338
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3fb4a89eabb098e4587e510803e52884
+140
View File
@@ -0,0 +1,140 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class newTeamSelector : MonoBehaviour
{
[Header("µÈ¼¶Í¼Æ¬CBAS")]
public Sprite levelIcon_sprite_C;
public Sprite levelIcon_sprite_B;
public Sprite levelIcon_sprite_A;
public Sprite levelIcon_sprite_S;
[Tooltip("Prefab for a single hero slot. Must contain slots_heroSlots component.")]
public GameObject slotPrefab;
[Tooltip("Container (GameObject with HorizontalLayoutGroup) where slots will be instantiated")]
public RectTransform container;
[Tooltip("Number of slots to create (default 5)")]
public int slotCount = 5;
[Tooltip("Optional override colors used for header images per slot. If not set, prefab's headerImage_colors will be used.")]
public Color[] overrideHeaderColors;
[Tooltip("If true, create slots automatically on Start")]
public bool instantiateOnStart = true;
private readonly List<slots_heroSlots> createdSlots = new List<slots_heroSlots>();
void Start()
{
if (instantiateOnStart)
CreateSlots();
}
void Update() { }
public void CreateSlots()
{
if (slotPrefab == null || container == null)
{
Debug.LogError("newTeamSelector: slotPrefab or container is not assigned.");
return;
}
// Clear existing
for (int i = container.childCount - 1; i >= 0; i--)
{
var c = container.GetChild(i);
#if UNITY_EDITOR
if (!Application.isPlaying) DestroyImmediate(c.gameObject);
else Destroy(c.gameObject);
#else
Destroy(c.gameObject);
#endif
}
createdSlots.Clear();
for (int i = 0; i < slotCount; i++)
{
var go = Instantiate(slotPrefab, container);
go.transform.SetParent(container, false);
go.name = $"heroSlot_{i}";
var slotComp = go.GetComponent<slots_heroSlots>();
if (slotComp == null)
{
Debug.LogWarning("newTeamSelector: instantiated prefab does not contain slots_heroSlots component.");
continue;
}
slotComp.heroSlot_slotID = i;
// choose color: overrideHeaderColors takes priority, then prefab's headerImage_colors if available
Color chosen = Color.white;
if (overrideHeaderColors != null && i < overrideHeaderColors.Length)
{
chosen = overrideHeaderColors[i];
}
else if (slotComp.headerImage_colors != null && i < slotComp.headerImage_colors.Length)
{
chosen = slotComp.headerImage_colors[i];
}
// Ensure visible alpha
chosen.a = Mathf.Clamp01(chosen.a);
if (chosen.a <= 0f) chosen.a = 1f;
// Apply immediately if possible
if (slotComp.heroSlot_colorImage != null)
{
slotComp.heroSlot_colorImage.color = chosen;
}
createdSlots.Add(slotComp);
}
// Force immediate layout rebuild so HorizontalLayoutGroup arranges children right away
LayoutRebuilder.ForceRebuildLayoutImmediate(container);
// Re-apply colors next frame to override any Start() logic on instantiated prefabs
StartCoroutine(ApplyHeaderColorsNextFrame());
}
private IEnumerator ApplyHeaderColorsNextFrame()
{
yield return null; // wait one frame
for (int i = 0; i < createdSlots.Count; i++)
{
var slot = createdSlots[i];
if (slot == null) continue;
Color chosen = Color.white;
if (overrideHeaderColors != null && i < overrideHeaderColors.Length)
{
chosen = overrideHeaderColors[i];
}
else if (slot.headerImage_colors != null && i < slot.headerImage_colors.Length)
{
chosen = slot.headerImage_colors[i];
}
chosen.a = 1f;
if (slot.heroSlot_colorImage == null)
{
var img = slot.GetComponentInChildren<Image>(true);
if (img != null) slot.heroSlot_colorImage = img;
}
if (slot.heroSlot_colorImage != null)
slot.heroSlot_colorImage.color = chosen;
}
// ensure layout rebuilt after modifications
LayoutRebuilder.ForceRebuildLayoutImmediate(container);
}
public List<slots_heroSlots> GetCreatedSlots() => createdSlots;
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 2ad385fc06957ce4b89dd5f098a3889d
+58 -37
View File
@@ -156,48 +156,69 @@ public class teamSettingPanel : MonoBehaviour
}
public void updateTeamSettingElements()
{
TeamSetting currentSelectedTeam = teamManager.getCurrentSelectedTeam();
// defensive guards
if (teamManager == null) teamManager = TeamManager.Instance;
if (teamManager == null)
{
Debug.LogWarning("teamSettingPanel.updateTeamSettingElements: TeamManager is null. Skipping update.");
clearTeamSettingElements();
return;
}
TeamSetting currentSelectedTeam = null;
try { currentSelectedTeam = teamManager.getCurrentSelectedTeam(); } catch { currentSelectedTeam = null; }
if (currentSelectedTeam == null)
{
clearTeamSettingElements();
return;
}
if (currentSelectedTeam.teamIdList == null)
{
clearTeamSettingElements();
return;
}
if (teamElementsObj == null)
{
Debug.LogWarning("teamSettingPanel.updateTeamSettingElements: teamElementsObj is null");
return;
}
List<CharacterView> currentTeam = currentSelectedTeam.teamIdList;
clearTeamSettingElements();
for (int i = 0; i < teamElementsObj.Length && i < currentTeam.Count; i++)
{
if(teamElementsObj[i]!=null && currentTeam[i]!=null)
if (teamElementsObj[i] == null) continue;
if (currentTeam[i] == null) continue;
teamCharacterView t = teamElementsObj[i].GetComponent<teamCharacterView>();
if (t == null) continue;
t.characterID= currentTeam[i].characterId;
TeamCharacterDataInfo tcdi = getCharacterViewInfo(t.characterID);
if (tcdi != null)
{
//Debug.Log($"当前元素为第{i},当前角色为{currentTeam[i].characterId}");
teamCharacterView t = teamElementsObj[i].GetComponent<teamCharacterView>();
if(t!=null)
{
t.characterID= currentTeam[i].characterId;
TeamCharacterDataInfo tcdi = getCharacterViewInfo(t.characterID);
if (tcdi != null)
{
t.charcterImg.sprite = tcdi.CharacterTeamSprite;
t.charcterImg.color=new Color(t.charcterImg.color.r,t.charcterImg.color.g,t.charcterImg.color.b,255f);
t.levelIcon.sprite = getLevelSprite(currentTeam[i].currentBoundaryLevel);
t.levelIcon.color=new Color(t.levelIcon.color.r,t.levelIcon.color.g,t.levelIcon.color.b,255f);
t.skillName.text = tcdi.CharacterSkillName;
}
else
{
t.charcterImg.sprite = null;
t.charcterImg.color=new Color(t.charcterImg.color.r,t.charcterImg.color.g,t.charcterImg.color.b,0f);
t.levelIcon.sprite = null;
t.levelIcon.color=new Color(t.levelIcon.color.r,t.levelIcon.color.g,t.levelIcon.color.b,0f);
t.skillName.text="";
}
if(currentSelectedTeam.LeaderId==currentTeam[i].characterId)
{
t.isLeader.SetActive(true);
t.notLeader.SetActive(false);
}
else
{
t.isLeader.SetActive(false);
t.notLeader.SetActive(true);
}
}
if (t.charcterImg != null) { t.charcterImg.sprite = tcdi.CharacterTeamSprite; t.charcterImg.color=new Color(t.charcterImg.color.r,t.charcterImg.color.g,t.charcterImg.color.b,1f); }
if (t.levelIcon != null) { t.levelIcon.sprite = getLevelSprite(currentTeam[i].currentBoundaryLevel); t.levelIcon.color=new Color(t.levelIcon.color.r,t.levelIcon.color.g,t.levelIcon.color.b,1f); }
if (t.skillName != null) t.skillName.text = tcdi.CharacterSkillName ?? string.Empty;
}
else
{
if (t.charcterImg != null) { t.charcterImg.sprite = null; t.charcterImg.color=new Color(t.charcterImg.color.r,t.charcterImg.color.g,t.charcterImg.color.b,0f); }
if (t.levelIcon != null) { t.levelIcon.sprite = null; t.levelIcon.color=new Color(t.levelIcon.color.r,t.levelIcon.color.g,t.levelIcon.color.b,0f); }
if (t.skillName != null) t.skillName.text="";
}
if(currentSelectedTeam.LeaderId==currentTeam[i].characterId)
{
if (t.isLeader != null) t.isLeader.SetActive(true);
if (t.notLeader != null) t.notLeader.SetActive(false);
}
else
{
if (t.isLeader != null) t.isLeader.SetActive(false);
if (t.notLeader != null) t.notLeader.SetActive(true);
}
}
}