修了很多bug和增加功能,优化不少问题
This commit is contained in:
@@ -2,10 +2,11 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.EventSystems;
|
||||
using System.Collections.Generic;
|
||||
using Bansonic;
|
||||
|
||||
public class btmandtopController : MonoBehaviour
|
||||
public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
{
|
||||
[Header("player unique so")]
|
||||
public Player_SO player_SO;
|
||||
@@ -23,13 +24,17 @@ public class btmandtopController : MonoBehaviour
|
||||
[Header("User Guide")]
|
||||
[SerializeField] private Button userGuideButton;
|
||||
[SerializeField] private Image guideDisplayImage;
|
||||
[SerializeField] private Button preIMGb;
|
||||
[SerializeField] private Button aftIMGb;
|
||||
[SerializeField] private Button closeGuideButton;
|
||||
[SerializeField] private Text guideIndexLegacyText;
|
||||
[SerializeField] private List<GuideMapping> guideMappings;
|
||||
|
||||
[System.Serializable]
|
||||
public struct GuideMapping
|
||||
{
|
||||
public string sceneName;
|
||||
public Sprite guideSprite;
|
||||
public List<Sprite> guideSprites;
|
||||
}
|
||||
|
||||
public Button button_Music;
|
||||
@@ -89,6 +94,8 @@ public class btmandtopController : MonoBehaviour
|
||||
private Coroutine musicPicFade;
|
||||
private bool musicPicVisible = true;
|
||||
private bool navSceneLoading = false;
|
||||
private readonly Dictionary<string, int> guideIndexByScene = new Dictionary<string, int>();
|
||||
private string currentGuideScene = string.Empty;
|
||||
|
||||
private static readonly List<string> sceneHistory = new List<string>();
|
||||
private static bool sceneHistoryHooked = false;
|
||||
@@ -141,6 +148,12 @@ public class btmandtopController : MonoBehaviour
|
||||
market_launch.onClick.AddListener(instantiateMarket);
|
||||
if (userGuideButton != null)
|
||||
userGuideButton.onClick.AddListener(navGuideAction);
|
||||
if (preIMGb != null)
|
||||
preIMGb.onClick.AddListener(ShowPreviousGuideImage);
|
||||
if (aftIMGb != null)
|
||||
aftIMGb.onClick.AddListener(ShowNextGuideImage);
|
||||
if (closeGuideButton != null)
|
||||
closeGuideButton.onClick.AddListener(CloseGuideDisplay);
|
||||
|
||||
BindNewBackButtons();
|
||||
|
||||
@@ -371,6 +384,12 @@ public class btmandtopController : MonoBehaviour
|
||||
market_launch.onClick.RemoveListener(instantiateMarket);
|
||||
if (userGuideButton != null)
|
||||
userGuideButton.onClick.RemoveListener(navGuideAction);
|
||||
if (preIMGb != null)
|
||||
preIMGb.onClick.RemoveListener(ShowPreviousGuideImage);
|
||||
if (aftIMGb != null)
|
||||
aftIMGb.onClick.RemoveListener(ShowNextGuideImage);
|
||||
if (closeGuideButton != null)
|
||||
closeGuideButton.onClick.RemoveListener(CloseGuideDisplay);
|
||||
|
||||
if (button_Music != null)
|
||||
button_Music.onClick.RemoveListener(ToggleMusicPicLocal);
|
||||
@@ -392,35 +411,132 @@ public class btmandtopController : MonoBehaviour
|
||||
|
||||
if (guideDisplayImage.gameObject.activeSelf)
|
||||
{
|
||||
guideDisplayImage.gameObject.SetActive(false);
|
||||
CloseGuideDisplay();
|
||||
}
|
||||
else
|
||||
{
|
||||
string currentScene = SceneManager.GetActiveScene().name;
|
||||
Sprite targetSprite = null;
|
||||
ShowGuideForScene(currentScene, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (guideMappings != null)
|
||||
{
|
||||
foreach (var mapping in guideMappings)
|
||||
{
|
||||
if (mapping.sceneName == currentScene)
|
||||
{
|
||||
targetSprite = mapping.guideSprite;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private void CloseGuideDisplay()
|
||||
{
|
||||
if (guideDisplayImage == null) return;
|
||||
guideDisplayImage.gameObject.SetActive(false);
|
||||
UpdateGuideIndexText(-1, 0);
|
||||
SetGuideButtonsInteractable(false);
|
||||
}
|
||||
|
||||
if (targetSprite != null)
|
||||
public void OnCancel(BaseEventData eventData)
|
||||
{
|
||||
if (guideDisplayImage != null && guideDisplayImage.gameObject.activeSelf)
|
||||
CloseGuideDisplay();
|
||||
}
|
||||
|
||||
private void ShowGuideForScene(string sceneName, bool allowStoredIndex)
|
||||
{
|
||||
if (!TryGetGuideMapping(sceneName, out var mapping))
|
||||
{
|
||||
gNotice.warning.display("未找到指引信息");
|
||||
return;
|
||||
}
|
||||
|
||||
int count = GetGuideSpriteCount(mapping);
|
||||
if (count <= 0)
|
||||
{
|
||||
gNotice.warning.display("未找到指引信息");
|
||||
return;
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
if (allowStoredIndex && guideIndexByScene.TryGetValue(sceneName, out var storedIndex))
|
||||
index = storedIndex;
|
||||
index = Mathf.Clamp(index, 0, count - 1);
|
||||
ApplyGuideSprite(sceneName, mapping, index, count);
|
||||
}
|
||||
|
||||
private void ShowPreviousGuideImage()
|
||||
{
|
||||
if (guideDisplayImage == null || !guideDisplayImage.gameObject.activeSelf) return;
|
||||
if (string.IsNullOrEmpty(currentGuideScene))
|
||||
currentGuideScene = SceneManager.GetActiveScene().name;
|
||||
if (!TryGetGuideMapping(currentGuideScene, out var mapping)) return;
|
||||
int count = GetGuideSpriteCount(mapping);
|
||||
if (count <= 0) return;
|
||||
int index = 0;
|
||||
guideIndexByScene.TryGetValue(currentGuideScene, out index);
|
||||
index = Mathf.Clamp(index - 1, 0, count - 1);
|
||||
ApplyGuideSprite(currentGuideScene, mapping, index, count);
|
||||
}
|
||||
|
||||
private void ShowNextGuideImage()
|
||||
{
|
||||
if (guideDisplayImage == null || !guideDisplayImage.gameObject.activeSelf) return;
|
||||
if (string.IsNullOrEmpty(currentGuideScene))
|
||||
currentGuideScene = SceneManager.GetActiveScene().name;
|
||||
if (!TryGetGuideMapping(currentGuideScene, out var mapping)) return;
|
||||
int count = GetGuideSpriteCount(mapping);
|
||||
if (count <= 0) return;
|
||||
int index = 0;
|
||||
guideIndexByScene.TryGetValue(currentGuideScene, out index);
|
||||
index = Mathf.Clamp(index + 1, 0, count - 1);
|
||||
ApplyGuideSprite(currentGuideScene, mapping, index, count);
|
||||
}
|
||||
|
||||
private void ApplyGuideSprite(string sceneName, GuideMapping mapping, int index, int count)
|
||||
{
|
||||
Sprite targetSprite = GetGuideSpriteAt(mapping, index);
|
||||
if (targetSprite == null)
|
||||
{
|
||||
gNotice.warning.display("未找到指引信息");
|
||||
return;
|
||||
}
|
||||
guideDisplayImage.sprite = targetSprite;
|
||||
guideDisplayImage.gameObject.SetActive(true);
|
||||
currentGuideScene = sceneName;
|
||||
guideIndexByScene[sceneName] = index;
|
||||
UpdateGuideIndexText(index, count);
|
||||
SetGuideButtonsInteractable(count > 1);
|
||||
}
|
||||
|
||||
private void UpdateGuideIndexText(int index, int count)
|
||||
{
|
||||
string text = count > 0 && index >= 0 ? $"{index + 1}/{count}" : string.Empty;
|
||||
if (guideIndexLegacyText != null) guideIndexLegacyText.text = text;
|
||||
}
|
||||
|
||||
private void SetGuideButtonsInteractable(bool enabled)
|
||||
{
|
||||
if (preIMGb != null) preIMGb.interactable = enabled;
|
||||
if (aftIMGb != null) aftIMGb.interactable = enabled;
|
||||
}
|
||||
|
||||
private bool TryGetGuideMapping(string sceneName, out GuideMapping mapping)
|
||||
{
|
||||
mapping = default;
|
||||
if (guideMappings == null) return false;
|
||||
for (int i = 0; i < guideMappings.Count; i++)
|
||||
{
|
||||
if (guideMappings[i].sceneName == sceneName)
|
||||
{
|
||||
guideDisplayImage.sprite = targetSprite;
|
||||
guideDisplayImage.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
gNotice.warning.display("未找到指引信息");
|
||||
mapping = guideMappings[i];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int GetGuideSpriteCount(GuideMapping mapping)
|
||||
{
|
||||
if (mapping.guideSprites != null) return mapping.guideSprites.Count;
|
||||
return 0;
|
||||
}
|
||||
|
||||
private Sprite GetGuideSpriteAt(GuideMapping mapping, int index)
|
||||
{
|
||||
if (mapping.guideSprites == null || mapping.guideSprites.Count == 0) return null;
|
||||
return mapping.guideSprites[Mathf.Clamp(index, 0, mapping.guideSprites.Count - 1)];
|
||||
}
|
||||
|
||||
private void ToggleSettingsPrefab()
|
||||
|
||||
Reference in New Issue
Block a user