主界面添加,许多bug修复。祝贺黑盒1如期开始

This commit is contained in:
FloatGaming
2026-03-02 04:34:13 +08:00
parent e11cc1da7a
commit 3c1d263ef1
308 changed files with 59216 additions and 32756 deletions
+151 -28
View File
@@ -9,8 +9,11 @@ using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using DG.Tweening;
using JetBrains.Annotations;
using UnityEngine;
using UnityEngine.UI;
using Bansonic;
class UI_Panel_Character : MonoBehaviour
{
[SerializeField] float anim_Time = 0.5f;
@@ -22,6 +25,11 @@ class UI_Panel_Character : MonoBehaviour
[SerializeField] Image Image_Character_Illustration;
[SerializeField] Image Image_Character_Illustration_BG;
[Header("buttons")]
public Button change_thisHero_skin;
public Button thisHero_detail;
public Button confirm_thisHero;
[Header("Data Paths")]
[Tooltip("Path relative to Resources folder for Editor mode")]
public string editorResourcePath = "so/ally";
@@ -37,36 +45,98 @@ class UI_Panel_Character : MonoBehaviour
gameObject.SetActive(false);
}
}
private Vector2 originalIllustrationPos;
private Vector2 originalIllustrationBGPos;
private bool hasCachedPositions = false;
private const string SAVED_HERO_ID_KEY = "SelectedMainHeroID";
void Start()
{
if (Image_Character_Illustration.transform.parent.TryGetComponent(out CanvasGroup canvasGroup))
UnityEngine.Debug.Log($"[UI_Panel_Character] Start called. Illustration: {Image_Character_Illustration}");
// 初始化按钮监听
if (change_thisHero_skin != null)
change_thisHero_skin.onClick.AddListener(() => gNotice.warning.display("此版本未开放皮肤切换功能"));
if (thisHero_detail != null)
thisHero_detail.onClick.AddListener(() => gNotice.warning.display("此版本未开放详情查看功能"));
if (confirm_thisHero != null)
confirm_thisHero.onClick.AddListener(OnConfirmHeroClicked);
if (Image_Character_Illustration != null)
{
canvasGroup.alpha = 0;
}
else if(canvasGroup == null)
{
// Documentation text normalized.
return;
// 设置为图示的数值:Pos X: 376, Pos Y: -306
Image_Character_Illustration.rectTransform.anchoredPosition = new Vector2(376, -306);
originalIllustrationPos = Image_Character_Illustration.rectTransform.anchoredPosition;
if (Image_Character_Illustration.transform.parent.TryGetComponent(out CanvasGroup canvasGroup))
{
canvasGroup.alpha = 0;
}
}
if (Image_Character_Illustration_BG != null)
{
// 设置运行时 X 值为 376
Vector2 pos = Image_Character_Illustration_BG.rectTransform.anchoredPosition;
pos.x = 376;
Image_Character_Illustration_BG.rectTransform.anchoredPosition = pos;
originalIllustrationBGPos = Image_Character_Illustration_BG.rectTransform.anchoredPosition;
}
hasCachedPositions = true;
foreach (var item in ui_Anim)
{
item.speed = Anim_Speed;
if (item != null) item.speed = Anim_Speed;
}
content_Character_Slot.Get_Childrens_Component<UI_Button_Character_Head_Slot>(true, true);
if (content_Character_Slot != null)
content_Character_Slot.Get_Childrens_Component<UI_Button_Character_Head_Slot>(true, true);
// Load AllyHero_SO data
string path = Application.isEditor ? editorResourcePath : runtimeResourcePath;
var loadedData = Resources.LoadAll<AllyHero_SO>(path);
allyHeroList = new List<AllyHero_SO>(loadedData);
UnityEngine.Debug.Log($"[UI_Panel_Character] Loaded {allyHeroList.Count} heroes from {path}");
// Ensure consistent order with UI_Panel_Main
allyHeroList.Sort((a, b) => a.ally_heroID.CompareTo(b.ally_heroID));
// 读取保存的角色 ID
int savedHeroID = PlayerPrefs.GetInt(SAVED_HERO_ID_KEY, -1);
int initialIndex = 0;
for (int i = 0; i < allyHeroList.Count; i++)
{
var obj = Instantiate(button_Character_Slot_Prefab, content_Character_Slot);
// Register UI sounds for the newly instantiated button
UISystemBootstrap.RegisterHierarchy(obj.gameObject);
var data = allyHeroList[i];
obj.image.sprite = data.ally_hero_squareProfile;
// 如果 ID 匹配,设置初始索引
if (savedHeroID != -1 && data.ally_heroID == savedHeroID)
{
initialIndex = i;
}
if (obj.image != null)
{
obj.image.sprite = data.ally_heroSelectIcon;
obj.image.preserveAspect = true; // 保持比例,防止拉伸变形
obj.image.type = Image.Type.Simple; // 确保是普通显示模式
// 确保 RectTransform 撑满父物体并居中
obj.image.rectTransform.anchorMin = Vector2.zero;
obj.image.rectTransform.anchorMax = Vector2.one;
obj.image.rectTransform.sizeDelta = Vector2.zero;
obj.image.rectTransform.anchoredPosition = Vector2.zero;
}
if (obj.TryGetComponent(out UI_Button_Character_Head_Slot head_Slot))
{
head_Slot.index = i;
@@ -74,12 +144,52 @@ class UI_Panel_Character : MonoBehaviour
obj.onClick.AddListener(() => Set_Character_Index(capturedIndex));
}
}
// 应用初始索引(来自保存的 ID 或默认 0)
UI_Panel_Main.Singleton.Character_Index = initialIndex;
// Initial character display
Set_Character();
}
public void Set_Character_Index(int index)
{
if (UI_Panel_Main.Singleton.Character_Index == index) return;
UI_Panel_Main.Singleton.Character_Index = index;
Set_Character();
// 人性化逻辑:点击头像即自动设为看板并保存,并显示提示内容
SaveCurrentCharacter(true);
}
private void OnConfirmHeroClicked()
{
if (SaveCurrentCharacter(true))
{
// 确认按钮逻辑:保存后禁用自身物体(隐藏面板)
gameObject.SetActive(false);
}
}
private bool SaveCurrentCharacter(bool showNotice)
{
int currentIndex = UI_Panel_Main.Singleton.Character_Index;
if (allyHeroList != null && currentIndex >= 0 && currentIndex < allyHeroList.Count)
{
int heroID = allyHeroList[currentIndex].ally_heroID;
PlayerPrefs.SetInt(SAVED_HERO_ID_KEY, heroID);
PlayerPrefs.Save();
if (showNotice)
{
gNotice.alarm.display($"已将 {allyHeroList[currentIndex].ally_heroName} 设置为记录对象。");
}
// 同步更新主面板的看板图
UI_Panel_Main.Singleton.Character_Index = currentIndex;
return true;
}
return false;
}
private void OnEnable()
{
@@ -102,27 +212,40 @@ class UI_Panel_Character : MonoBehaviour
int index = UI_Panel_Main.Singleton.Character_Index;
if (allyHeroList == null || index < 0 || index >= allyHeroList.Count) return;
var data = allyHeroList[index];
var pos1 = Image_Character_Illustration.rectTransform.anchoredPosition;
Image_Character_Illustration.sprite = data.ally_hero_HD_image;
DOTween.To(value =>
{ Image_Character_Illustration.rectTransform.anchoredPosition = new Vector2(value, pos1.y); },
startValue: Image_Character_Illustration.rectTransform.anchoredPosition.x - 200,
pos1.x, anim_Time);
// Image_Character_Illustration.SetNativeSize(); // 注释掉以保持自适应而不改变大小
var pos = Image_Character_Illustration_BG.rectTransform.anchoredPosition;
Image_Character_Illustration_BG.sprite = data.ally_hero_HD_image;
DOTween.To(value =>
{ Image_Character_Illustration_BG.rectTransform.anchoredPosition = new Vector2(value, pos.y); },
startValue: Image_Character_Illustration_BG.rectTransform.anchoredPosition.x - 200,
pos.x, anim_Time);
// Image_Character_Illustration_BG.SetNativeSize(); // 注释掉以保持自适应而不改变大小
Image_Character_Illustration_BG.transform.localScale = new(2.7f, 2.7f, 2.7f);
// 停止之前的 Tween 以防冲突
Image_Character_Illustration.rectTransform.DOKill();
Image_Character_Illustration_BG.rectTransform.DOKill();
text_Character_Name.DOKill();
var data = allyHeroList[index];
// 使用初始缓存的坐标,防止频繁点击导致的偏移累积
Vector2 targetPos1 = hasCachedPositions ? originalIllustrationPos : Image_Character_Illustration.rectTransform.anchoredPosition;
Image_Character_Illustration.sprite = data.ally_hero_HD_image;
// 动画:从左侧 200 像素滑入到目标位置
float startX1 = targetPos1.x - 200;
Image_Character_Illustration.rectTransform.anchoredPosition = new Vector2(startX1, targetPos1.y);
Image_Character_Illustration.rectTransform.DOAnchorPos(targetPos1, anim_Time)
.SetEase(Ease.OutCubic)
.SetLink(Image_Character_Illustration.gameObject);
Vector2 targetPosBG = hasCachedPositions ? originalIllustrationBGPos : Image_Character_Illustration_BG.rectTransform.anchoredPosition;
Image_Character_Illustration_BG.sprite = data.ally_hero_HD_image;
float startXBG = targetPosBG.x - 200;
Image_Character_Illustration_BG.rectTransform.anchoredPosition = new Vector2(startXBG, targetPosBG.y);
Image_Character_Illustration_BG.rectTransform.DOAnchorPos(targetPosBG, anim_Time)
.SetEase(Ease.OutCubic)
.SetLink(Image_Character_Illustration_BG.gameObject);
Image_Character_Illustration_BG.transform.localScale = Vector3.one;
string text = data.ally_heroName;
var t = DOTween.To(() => string.Empty, value => text_Character_Name.text = value, text, anim_Time).SetEase(Ease.Linear);
t.SetOptions(true);
text_Character_Name.text = string.Empty;
text_Character_Name.DOText(text, anim_Time)
.SetEase(Ease.Linear)
.SetLink(text_Character_Name.gameObject);
}
IEnumerator C_Character_Illustration_Anim(CanvasGroup canvasGroup, Action onHide)
{
+11
View File
@@ -270,6 +270,17 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
yield return null;
// 读取保存的角色 ID 并初始化索引
int savedHeroID = PlayerPrefs.GetInt("SelectedMainHeroID", -1);
if (savedHeroID != -1)
{
int foundIndex = data_List.FindIndex(h => h.ally_heroID == savedHeroID);
if (foundIndex != -1)
{
character_Index = foundIndex;
}
}
Character_Index = character_Index;
if(Character_Index >= 0 && Character_Index < data_List.Count)
Set_Character_Illustration(Get_Character_Image_Data(Character_Index).ally_hero_HD_image);
@@ -258,7 +258,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 0
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 0
m_OnCullStateChanged:
@@ -4732,6 +4732,7 @@ GameObject:
- component: {fileID: 8671031786275937763}
- component: {fileID: 5224241407313794548}
- component: {fileID: 61231020966361337}
- component: {fileID: 3093056817030257919}
- component: {fileID: 2510911207525280717}
m_Layer: 5
m_Name: btm and top
@@ -4854,6 +4855,7 @@ MonoBehaviour:
guideSprites: []
button_Music: {fileID: 5472029888669800656}
musicPicRoot: {fileID: 0}
bgmMixerGroup: {fileID: -1352833484795664833, guid: 1ec6b149cf654494d8d97065d8f2ccac, type: 2}
showMusicPicInUI: 1
uiSceneName: UI_UI
musicPicFadeTime: 0.25
@@ -4884,6 +4886,18 @@ MonoBehaviour:
- sceneName:
backTargetScene:
depth: 4
--- !u!114 &3093056817030257919
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5054239668136224504}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 76ce63b908338a84c8a3aa071b90c46b, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &2510911207525280717
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -4,6 +4,7 @@ using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.EventSystems;
using System.Collections.Generic;
using UnityEngine.Audio;
using Bansonic;
public class btmandtopController : MonoBehaviour, ICancelHandler
@@ -40,6 +41,7 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
public Button button_Music;
[Header("MusicPic")]
public RectTransform musicPicRoot;
public AudioMixerGroup bgmMixerGroup;
public bool showMusicPicInUI = false;
public string uiSceneName = "UI_UI";
public float musicPicFadeTime = 0.25f;
+75 -1
View File
@@ -1,9 +1,59 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Music_Mgr : Singleton_Mono<Music_Mgr>
{
private void OnEnable()
{
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnDisable()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
// 现在这两个场景是不合规的,需要停止播放
bool isDisallowedScene = scene.name == "Main_main" || scene.name == "gamePlay_gamePlay";
if (isDisallowedScene)
{
// 如果是不合规场景且正在播放,则停止
if (AudioSource != null && AudioSource.isPlaying)
{
AudioSource.Stop();
}
}
else
{
// 如果是合规场景(其他所有场景)且当前没在播放,则尝试播放
if (AudioSource != null && !AudioSource.isPlaying)
{
if (Music_Cur != null)
{
AudioSource.Play();
}
else if (Music_Data_List != null && Music_Data_List.Count > 0)
{
Play(Music_Data_List[0]);
}
}
}
// 切换场景后,如果存在播放器UI,确保其显示正确的数据
if (Music_Cur != null)
{
var players = Object.FindObjectsByType<MusicPlayer>(FindObjectsInactive.Include, FindObjectsSortMode.None);
foreach (var player in players)
{
player.Refresh(Music_Cur);
}
}
}
public static string Get_Time_Max(AudioClip clip)
{
@@ -68,9 +118,33 @@ public class Music_Mgr : Singleton_Mono<Music_Mgr>
}
public void Play(Music_Data data)
{
if (data == null) return;
Music_Cur = data;
AudioSource.clip = data.Clip;
AudioSource.Play();
// 刷新所有正在显示的 MusicPlayer UI
var players = Object.FindObjectsByType<MusicPlayer>(FindObjectsInactive.Include, FindObjectsSortMode.None);
foreach (var player in players)
{
player.Refresh(data);
}
}
public void Next()
{
if (Music_Data_List == null || Music_Data_List.Count == 0) return;
int index = Music_Data_List.IndexOf(Music_Cur);
index = (index + 1) % Music_Data_List.Count;
Play(Music_Data_List[index]);
}
public void Last()
{
if (Music_Data_List == null || Music_Data_List.Count == 0) return;
int index = Music_Data_List.IndexOf(Music_Cur);
index = (index - 1 + Music_Data_List.Count) % Music_Data_List.Count;
Play(Music_Data_List[index]);
}
protected override bool Is_Singleton_Auto()
{
@@ -60,6 +60,7 @@ public class UI_Panel_Music : MonoBehaviour
foreach (var item in music_Data_List)
{
var slot = Instantiate(prefab_Music_Slot, group_Music.transform);
UISystemBootstrap.RegisterHierarchy(slot.gameObject);
slot.Refresh(item);
music_Slot_List.Add(slot);
}