UI工具翻新
1. 增加UI工具 2. 增加设置页面 3. GameLoop更新 4. 导入ActionKit工具
This commit is contained in:
@@ -2,12 +2,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class CursorManager : MonoBehaviour
|
||||
public class CursorManager : Singleton<CursorManager>
|
||||
{
|
||||
private const float DelayTime = 0.1f;
|
||||
|
||||
@@ -22,13 +23,14 @@ namespace AibisDream
|
||||
private CursorState _curState = CursorState.Default;
|
||||
private bool _isTalking;
|
||||
[HideInInspector] public bool isInMenu;
|
||||
[HideInInspector] public bool isPaused;
|
||||
|
||||
#endregion
|
||||
|
||||
// 卸载时注销事件
|
||||
private readonly List<IUnRegister> _unRegisters = new();
|
||||
|
||||
public void Awake()
|
||||
public override void OnSingletonInit()
|
||||
{
|
||||
InitRefs();
|
||||
InitCursor();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using TMPro;
|
||||
@@ -198,7 +199,7 @@ namespace AibisDream
|
||||
|
||||
#region 对话回顾
|
||||
|
||||
[Header("对话回顾组件")] [SerializeField] private TMP_Text logText;
|
||||
private StringBuilder DialogRecord => UIManager.Instance.GetPanel<RecordPanel>().recordStr;
|
||||
|
||||
/// <summary>
|
||||
/// 记录对话
|
||||
@@ -206,12 +207,12 @@ namespace AibisDream
|
||||
/// <param name="line">对话</param>
|
||||
private void AddDialogueLine(DialogText line)
|
||||
{
|
||||
logText.text += line.GetDialogText();
|
||||
DialogRecord.Append(line.GetDialogText());
|
||||
}
|
||||
|
||||
private void CleanDialogHistory()
|
||||
{
|
||||
logText.text = null;
|
||||
DialogRecord.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5010337b422cfa74ea2d2939e762693e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
/// <summary>
|
||||
/// 表单项父类
|
||||
/// </summary>
|
||||
public abstract class AbsFormItem : MonoBehaviour
|
||||
{
|
||||
#region 数据部分
|
||||
|
||||
public string prop;
|
||||
public string label;
|
||||
public abstract FieldType FieldType { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region 索引部分
|
||||
|
||||
private TMP_Text _labelRef;
|
||||
public UnityEvent<string, string> OnValueChanged;
|
||||
|
||||
#endregion
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InitItem();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化FormItem
|
||||
/// </summary>
|
||||
private void InitItem()
|
||||
{
|
||||
// label设置
|
||||
_labelRef = transform.Find("Label").GetComponent<TMP_Text>();
|
||||
_labelRef.text = label;
|
||||
// field设置
|
||||
InitField();
|
||||
}
|
||||
|
||||
protected abstract void InitField();
|
||||
public abstract void SetValue(string value);
|
||||
}
|
||||
|
||||
public enum FieldType
|
||||
{
|
||||
Input,
|
||||
Slider,
|
||||
Select,
|
||||
Radio
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 429e0ca7a1096a1478e50195b88539b8
|
||||
guid: dd06484c1f627d249ad5a16558c9cdb9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
/// <summary>
|
||||
/// 表单接口。
|
||||
/// 表单Root主要承担数据逻辑功能
|
||||
/// 1. 修改表单数据时对应改动
|
||||
/// 2. 从配置文件读取表单数据对应改动
|
||||
/// 3. 表单初始化
|
||||
/// </summary>
|
||||
public interface IUIForm
|
||||
{
|
||||
public void OnItemChanged(string propName, string value);
|
||||
public void UpdateForm();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e80043371ab4923944ceda3823424b9
|
||||
timeCreated: 1744619745
|
||||
@@ -0,0 +1,32 @@
|
||||
using TMPro;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class SelectItem : AbsFormItem
|
||||
{
|
||||
public override FieldType FieldType => FieldType.Select;
|
||||
|
||||
private TMP_Dropdown _dropdown;
|
||||
|
||||
protected override void InitField()
|
||||
{
|
||||
// 获取索引
|
||||
_dropdown = GetComponentInChildren<TMP_Dropdown>(true);
|
||||
// 注册事件
|
||||
_dropdown.onValueChanged.AddListener(OnSelectChanged);
|
||||
}
|
||||
|
||||
public override void SetValue(string value)
|
||||
{
|
||||
var target = _dropdown.options.FindIndex(item => item.text == value);
|
||||
_dropdown.value = target;
|
||||
}
|
||||
|
||||
private void OnSelectChanged(int value)
|
||||
{
|
||||
// 序号转字符串
|
||||
var strValue = _dropdown.options[value].text;
|
||||
OnValueChanged?.Invoke(prop, strValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 39f0dc8bcf2641458cf3f8726add30f9
|
||||
timeCreated: 1744702543
|
||||
@@ -0,0 +1,51 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class SettingForm : MonoBehaviour, IUIForm
|
||||
{
|
||||
#region 索引
|
||||
|
||||
private AbsFormItem[] _formItems;
|
||||
|
||||
#endregion
|
||||
|
||||
public void Init()
|
||||
{
|
||||
// 获取索引
|
||||
_formItems = GetComponentsInChildren<AbsFormItem>();
|
||||
UpdateForm();
|
||||
// 绑定变化
|
||||
foreach (var formItem in _formItems)
|
||||
{
|
||||
formItem.OnValueChanged.AddListener(OnItemChanged);
|
||||
}
|
||||
}
|
||||
|
||||
public void UnInit()
|
||||
{
|
||||
// 绑定变化
|
||||
foreach (var formItem in _formItems)
|
||||
{
|
||||
formItem.OnValueChanged.RemoveAllListeners();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnItemChanged(string propName, string value)
|
||||
{
|
||||
SettingLoader.Instance.Write(propName, value);
|
||||
}
|
||||
|
||||
public void UpdateForm()
|
||||
{
|
||||
var settingDict = SettingLoader.Instance.ReadAll();
|
||||
foreach (var formItem in _formItems)
|
||||
{
|
||||
if (settingDict.TryGetValue(formItem.prop, out var value))
|
||||
{
|
||||
formItem.SetValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6564f6671e32475c981a8c3c1ca63ffd
|
||||
timeCreated: 1744622926
|
||||
@@ -0,0 +1,42 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class SliderItem : AbsFormItem
|
||||
{
|
||||
public override FieldType FieldType => FieldType.Slider;
|
||||
|
||||
#region 索引
|
||||
|
||||
private Slider _slider;
|
||||
private TMP_Text _sliderText;
|
||||
|
||||
#endregion
|
||||
|
||||
protected override void InitField()
|
||||
{
|
||||
// 初始化索引
|
||||
_slider = GetComponentInChildren<Slider>();
|
||||
_sliderText = _slider.GetComponentInChildren<TMP_Text>(true);
|
||||
// 绑定事件
|
||||
_slider.onValueChanged.AddListener(OnSliderChanged);
|
||||
}
|
||||
|
||||
private void OnSliderChanged(float value)
|
||||
{
|
||||
// 更新数字显示
|
||||
_sliderText.text = Mathf.RoundToInt(value * 100).ToString();
|
||||
// 触发修改事件
|
||||
OnValueChanged.Invoke(prop, value.ToString("F2"));
|
||||
}
|
||||
|
||||
public override void SetValue(string value)
|
||||
{
|
||||
var floatValue = float.Parse(value);
|
||||
_slider.value = floatValue;
|
||||
_sliderText.text = Mathf.RoundToInt(floatValue * 100).ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cb985d5e95047f88ddec878de7972a2
|
||||
timeCreated: 1744617521
|
||||
@@ -1,200 +0,0 @@
|
||||
using System.Collections;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class MainUIController : Singleton<MainUIController>
|
||||
{
|
||||
private const string TVScene = "TV Scene";
|
||||
private const string BlackImage = "Fade Image";
|
||||
private const string NewsImage = "News";
|
||||
private const string ObjPanel = "Show Obj";
|
||||
|
||||
#region ShowObj参数
|
||||
|
||||
[Header("Obj尺寸参数")] public float objWidth;
|
||||
public float objHeight;
|
||||
|
||||
#endregion
|
||||
|
||||
#region 主场景图片
|
||||
|
||||
[SerializeField] private GameObject mainUIPanel;
|
||||
|
||||
private FadeImage _tvScene;
|
||||
private FadeImage _blackImage;
|
||||
private FadeImage _news;
|
||||
private GameObject _objPanel;
|
||||
private Image _objImage;
|
||||
private Image _fullScreen;
|
||||
|
||||
#endregion
|
||||
|
||||
public override void OnSingletonInit()
|
||||
{
|
||||
InitChildObj();
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
EnumEventSystem.Global.Register(EventEnum.SceneUnload, OnSceneUnload);
|
||||
}
|
||||
|
||||
private void OnSceneUnload()
|
||||
{
|
||||
StartCoroutine(HideFullScreen());
|
||||
StartCoroutine(HideObj());
|
||||
FadeOut(0.1f);
|
||||
}
|
||||
|
||||
#region 基本淡入淡出
|
||||
|
||||
public void FadeIn(float duration)
|
||||
{
|
||||
_blackImage.FadeIn(duration);
|
||||
}
|
||||
|
||||
public IEnumerator FadeInSync(float duration)
|
||||
{
|
||||
return _blackImage.FadeInSync(duration);
|
||||
}
|
||||
|
||||
public void FadeOut(float duration)
|
||||
{
|
||||
_blackImage.FadeOut(duration);
|
||||
}
|
||||
|
||||
public IEnumerator FadeOutSync(float duration)
|
||||
{
|
||||
return _blackImage.FadeOutSync(duration);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region TV场景淡入淡出
|
||||
|
||||
public void TVFadeIn(float duration)
|
||||
{
|
||||
_tvScene.FadeIn(duration);
|
||||
_news.FadeIn(duration);
|
||||
}
|
||||
|
||||
public IEnumerator TVFadeInSync(float duration)
|
||||
{
|
||||
_news.FadeIn(duration);
|
||||
return _tvScene.FadeInSync(duration);
|
||||
}
|
||||
|
||||
public void TVFadeOut(float duration)
|
||||
{
|
||||
_tvScene.FadeOut(duration);
|
||||
_news.FadeOut(duration);
|
||||
}
|
||||
|
||||
public IEnumerator TVFadeOutSync(float duration)
|
||||
{
|
||||
_news.FadeOut(duration);
|
||||
return _tvScene.FadeOutSync(duration);
|
||||
}
|
||||
|
||||
public void SwitchTV(string newsName)
|
||||
{
|
||||
_news.SwitchImage($"Art/Background/{newsName}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏整个UI
|
||||
/// </summary>
|
||||
public void HideMainUI()
|
||||
{
|
||||
mainUIPanel.SetActive(false);
|
||||
}
|
||||
|
||||
public void ShowMainUI()
|
||||
{
|
||||
mainUIPanel.SetActive(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示物体
|
||||
/// </summary>
|
||||
/// <returns>协程</returns>
|
||||
public IEnumerator ShowObj(string picName)
|
||||
{
|
||||
_objPanel.gameObject.SetActive(true);
|
||||
|
||||
// 切换图片
|
||||
var newSprite = Resources.Load<Sprite>($"Art/Obj/{picName}");
|
||||
// 获取图片的长宽比
|
||||
var imageAspect = (float)newSprite.texture.width / newSprite.texture.height;
|
||||
|
||||
// 计算新的尺寸
|
||||
if (imageAspect > 1) // 宽图
|
||||
{
|
||||
var newHeight = objWidth / imageAspect;
|
||||
_objImage.rectTransform.sizeDelta = new Vector2(objWidth, newHeight);
|
||||
}
|
||||
else // 高图
|
||||
{
|
||||
var newWidth = objHeight * imageAspect;
|
||||
_objImage.rectTransform.sizeDelta = new Vector2(newWidth, objHeight);
|
||||
}
|
||||
|
||||
// 淡入
|
||||
_objImage.sprite = newSprite;
|
||||
_objImage.gameObject.SetActive(true);
|
||||
yield return _objImage.DOBlendableColor(Color.white, 1).WaitForCompletion();
|
||||
}
|
||||
|
||||
public IEnumerator ShowFullScreen(string picName)
|
||||
{
|
||||
_fullScreen.sprite = Resources.Load<Sprite>($"Art/Obj/{picName}");
|
||||
|
||||
// 淡入
|
||||
_fullScreen.gameObject.SetActive(true);
|
||||
yield return _objImage.DOBlendableColor(Color.white, 1).WaitForCompletion();
|
||||
}
|
||||
|
||||
public IEnumerator HideFullScreen()
|
||||
{
|
||||
_fullScreen.gameObject.SetActive(true);
|
||||
yield return _objImage.DOBlendableColor(Color.clear, 1).WaitForCompletion();
|
||||
_fullScreen.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏物体
|
||||
/// </summary>
|
||||
/// <returns>协程</returns>
|
||||
public IEnumerator HideObj()
|
||||
{
|
||||
_objImage.gameObject.SetActive(true);
|
||||
yield return _objImage.DOBlendableColor(Color.clear, 1).WaitForCompletion();
|
||||
_objImage.gameObject.SetActive(false);
|
||||
_objPanel.SetActive(false);
|
||||
}
|
||||
|
||||
private void InitChildObj()
|
||||
{
|
||||
var rawTvScene = transform.GetChild(0).Find(TVScene).gameObject.GetComponent<Image>();
|
||||
_tvScene = new FadeImage(rawTvScene);
|
||||
|
||||
var rawBlackImage = transform.GetChild(0).Find(BlackImage).gameObject.GetComponent<Image>();
|
||||
_blackImage = new FadeImage(rawBlackImage);
|
||||
|
||||
var rawNews = transform.GetChild(0).Find(NewsImage).gameObject.GetComponent<Image>();
|
||||
_news = new FadeImage(rawNews);
|
||||
|
||||
_objPanel = transform.GetChild(0).Find(ObjPanel).gameObject;
|
||||
_objImage = _objPanel.transform.GetChild(0).GetComponent<Image>();
|
||||
|
||||
_fullScreen = transform.GetChild(0).Find("Full Screen Image").GetComponent<Image>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3c03e9f6ddaadd408fba26d40f93c26
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
using AibisDream.Utility;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class EndPanel : MonoBehaviour, IUIPanel
|
||||
{
|
||||
public bool IsOpen => gameObject.activeSelf;
|
||||
|
||||
#region 打开和关闭
|
||||
|
||||
public void Show()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
RegisterButton();
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
UnRegisterButton();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void RegisterButton()
|
||||
{
|
||||
var returnBtn = transform.Find("返回").GetComponent<Button>();
|
||||
returnBtn.onClick.AddListener(BackToMain);
|
||||
var backToMain = transform.Find("问卷").GetComponent<Button>();
|
||||
backToMain.onClick.AddListener(OpenFeedbackLink);
|
||||
var quit = transform.Find("Bug反馈").GetComponent<Button>();
|
||||
quit.onClick.AddListener(OpenBugLink);
|
||||
}
|
||||
|
||||
private void UnRegisterButton()
|
||||
{
|
||||
var returnBtn = transform.Find("返回").GetComponent<Button>();
|
||||
returnBtn.onClick.RemoveAllListeners();
|
||||
var backToMain = transform.Find("问卷").GetComponent<Button>();
|
||||
backToMain.onClick.RemoveAllListeners();
|
||||
var quit = transform.Find("Bug反馈").GetComponent<Button>();
|
||||
quit.onClick.RemoveAllListeners();
|
||||
}
|
||||
|
||||
private void BackToMain()
|
||||
{
|
||||
UIManager.Instance.HidePanel<EndPanel>();
|
||||
GameManager.Instance.QuitGame();
|
||||
}
|
||||
|
||||
private void OpenFeedbackLink()
|
||||
{
|
||||
Application.OpenURL(ConstRef.SurveyURL);
|
||||
}
|
||||
|
||||
private void OpenBugLink()
|
||||
{
|
||||
Application.OpenURL(ConstRef.BugSurveyURL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 102c329e03bc4e4882e2beb365e3ae1b
|
||||
timeCreated: 1745221838
|
||||
@@ -0,0 +1,59 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class MainPanel : MonoBehaviour, IUIPanel
|
||||
{
|
||||
public bool IsOpen => gameObject.activeSelf;
|
||||
|
||||
#region 面板控制
|
||||
|
||||
public void Show()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
RegisterButton();
|
||||
}
|
||||
|
||||
private void RegisterButton()
|
||||
{
|
||||
// 为按钮注册事件
|
||||
var topBar = transform.Find("Top Bar");
|
||||
topBar.Find("Setting").GetComponent<Button>().onClick.AddListener(OpenSettingPanel);
|
||||
topBar.Find("Record").GetComponent<Button>().onClick.AddListener(OpenRecordPanel);
|
||||
topBar.Find("Auto Skip").GetComponent<Button>().onClick.AddListener(AutoSkip);
|
||||
topBar.Find("Quick Forward").GetComponent<Button>().onClick.AddListener(QuickForward);
|
||||
}
|
||||
|
||||
private void AutoSkip()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void QuickForward()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OpenSettingPanel()
|
||||
{
|
||||
UIManager.Instance.ShowPanel<SettingPanel>();
|
||||
}
|
||||
|
||||
private void OpenRecordPanel()
|
||||
{
|
||||
UIManager.Instance.ShowPanel<RecordPanel>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4518044cbe67a4647af3110956c37758
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,171 @@
|
||||
using System.Collections;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using DG.Tweening;
|
||||
using RainbowArt.CleanFlatUI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Yarn.Unity;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
/// <summary>
|
||||
/// 主要用来放置淡入淡出,图片展示等演出工具
|
||||
/// </summary>
|
||||
public class PlayToolPanel : MonoBehaviour, IUIPanel
|
||||
{
|
||||
public bool IsOpen => gameObject.activeSelf;
|
||||
|
||||
[Header("Obj尺寸参数")] public float objWidth;
|
||||
public float objHeight;
|
||||
|
||||
#region 索引
|
||||
|
||||
private Image _fadeImage;
|
||||
private GameObject _showObjPanel;
|
||||
private Image _showObjImage;
|
||||
private Image _fullScreenImage;
|
||||
private Image _redFlash;
|
||||
private ModalWindowProgressBar _window;
|
||||
|
||||
#endregion
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InitRefs();
|
||||
}
|
||||
|
||||
private void InitRefs()
|
||||
{
|
||||
_fadeImage = transform.Find("Fade Image").GetComponent<Image>();
|
||||
_showObjPanel = transform.Find("Show Obj").gameObject;
|
||||
_showObjImage = _showObjPanel.transform.Find("Obj").GetComponent<Image>();
|
||||
_fullScreenImage = transform.Find("Full Screen Image").GetComponent<Image>();
|
||||
_window = transform.Find("进度条窗口").GetComponent<ModalWindowProgressBar>();
|
||||
_redFlash = transform.Find("Red Flash").GetComponent<Image>();
|
||||
}
|
||||
|
||||
public IEnumerator FadeInAsync(float duration = 1)
|
||||
{
|
||||
return _fadeImage.FadeInAsync(duration);
|
||||
}
|
||||
|
||||
public IEnumerator FadeOutAsync(float duration = 1)
|
||||
{
|
||||
return _fadeImage.FadeOutAsync(duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示物体
|
||||
/// </summary>
|
||||
/// <returns>协程</returns>
|
||||
public IEnumerator ShowObj(string picName)
|
||||
{
|
||||
_showObjPanel.gameObject.SetActive(true);
|
||||
|
||||
// 切换图片
|
||||
var newSprite = Resources.Load<Sprite>($"Art/Obj/{picName}");
|
||||
// 获取图片的长宽比
|
||||
var imageAspect = (float)newSprite.texture.width / newSprite.texture.height;
|
||||
|
||||
// 计算新的尺寸
|
||||
if (imageAspect > 1) // 宽图
|
||||
{
|
||||
var newHeight = objWidth / imageAspect;
|
||||
_showObjImage.rectTransform.sizeDelta = new Vector2(objWidth, newHeight);
|
||||
}
|
||||
else // 高图
|
||||
{
|
||||
var newWidth = objHeight * imageAspect;
|
||||
_showObjImage.rectTransform.sizeDelta = new Vector2(newWidth, objHeight);
|
||||
}
|
||||
|
||||
// 淡入
|
||||
_showObjImage.sprite = newSprite;
|
||||
yield return _showObjImage.FadeInAsync(1);
|
||||
}
|
||||
|
||||
public IEnumerator HideObj()
|
||||
{
|
||||
yield return _showObjImage.FadeOutAsync(1);
|
||||
_showObjPanel.SetActive(false);
|
||||
}
|
||||
|
||||
public IEnumerator ShowFullScreen(string picName)
|
||||
{
|
||||
_fullScreenImage.sprite = Resources.Load<Sprite>($"Art/Obj/{picName}");
|
||||
|
||||
// 淡入
|
||||
yield return _fullScreenImage.FadeInAsync(1);
|
||||
}
|
||||
|
||||
public IEnumerator HideFullScreen()
|
||||
{
|
||||
return _fullScreenImage.FadeOutAsync(1);
|
||||
}
|
||||
|
||||
public IEnumerator OpenProgressWindow(string title, string description, float duration)
|
||||
{
|
||||
AudioManager.Instance.PlaySfx("event:/Scriptal/Ui");
|
||||
_window.TitleValue = title;
|
||||
_window.DescriptionValue = description;
|
||||
float currentProgress = 0;
|
||||
|
||||
DOTween.To(
|
||||
() => currentProgress,
|
||||
value =>
|
||||
{
|
||||
currentProgress = value;
|
||||
_window.SetProgress(currentProgress); // 更新进度
|
||||
},
|
||||
100,
|
||||
duration
|
||||
);
|
||||
|
||||
_window.ShowModalWindow();
|
||||
|
||||
// 获取 moveText 的 RectTransform
|
||||
RectTransform moveTextRect =
|
||||
_window.transform.Find("View/mask/moveText")?.GetComponent<RectTransform>();
|
||||
if (moveTextRect != null)
|
||||
{
|
||||
moveTextRect.DOAnchorPosY(330f, duration).SetEase(Ease.Linear);
|
||||
}
|
||||
|
||||
// 等待用户确认
|
||||
yield return new WaitUntil(() => currentProgress >= 100);
|
||||
_window.HideModalWindow();
|
||||
moveTextRect.DOAnchorPosY(-611f, 0.1f).SetEase(Ease.Linear);
|
||||
}
|
||||
|
||||
// 红色闪烁效果
|
||||
public IEnumerator FlashRed(float duration)
|
||||
{
|
||||
_redFlash.gameObject.SetActive(true);
|
||||
yield return _redFlash.FadeInAsync(duration / 2);
|
||||
yield return _redFlash.FadeOutAsync(duration / 2);
|
||||
_redFlash.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void HideAll()
|
||||
{
|
||||
_fullScreenImage.FadeOut(0.1f);
|
||||
_showObjImage.FadeOut(0.1f);
|
||||
_showObjPanel.SetActive(false);
|
||||
}
|
||||
|
||||
#region 感觉这个面板应该常驻
|
||||
|
||||
public void Show()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae9caaab66fd459493d673ef3fd524f2
|
||||
timeCreated: 1744779595
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Text;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class RecordPanel : MonoBehaviour, IUIPanel
|
||||
{
|
||||
public bool IsOpen => gameObject.activeSelf;
|
||||
|
||||
public readonly StringBuilder recordStr = new();
|
||||
|
||||
public void Show()
|
||||
{
|
||||
ShowText();
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
// 关闭时停止渲染
|
||||
ClearText();
|
||||
}
|
||||
|
||||
private void ShowText()
|
||||
{
|
||||
var text = transform.Find("Log View").GetComponentInChildren<TMP_Text>();
|
||||
text.text = recordStr.ToString();
|
||||
}
|
||||
|
||||
private void ClearText()
|
||||
{
|
||||
var text = transform.Find("Log View").GetComponentInChildren<TMP_Text>();
|
||||
text.text = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc6a1b2ccb564028b69d821ab33778f5
|
||||
timeCreated: 1744779271
|
||||
@@ -0,0 +1,81 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class SettingPanel : MonoBehaviour, IUIPanel
|
||||
{
|
||||
public bool IsOpen => gameObject.activeSelf;
|
||||
|
||||
#region 打开和关闭
|
||||
|
||||
public void Show()
|
||||
{
|
||||
// 暂停游戏
|
||||
GameManager.Instance.PauseGame();
|
||||
|
||||
gameObject.SetActive(true);
|
||||
// 更新表单内容
|
||||
var form = GetComponentInChildren<SettingForm>();
|
||||
form.Init();
|
||||
// 注册函数
|
||||
RegisterButton();
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
// 更新表单内容
|
||||
var form = GetComponentInChildren<SettingForm>();
|
||||
form.UnInit();
|
||||
UnRegisterButton();
|
||||
|
||||
gameObject.SetActive(false);
|
||||
// 继续游戏
|
||||
GameManager.Instance.ContinueGame();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void RegisterButton()
|
||||
{
|
||||
var buttonGroup = transform.Find("Button Group");
|
||||
var continueBtn = buttonGroup.Find("Continue").GetComponent<Button>();
|
||||
continueBtn.onClick.AddListener(BackToGame);
|
||||
var backToMain = buttonGroup.Find("BackMain").GetComponent<Button>();
|
||||
backToMain.onClick.AddListener(BackToMain);
|
||||
var quit = buttonGroup.Find("Quit").GetComponent<Button>();
|
||||
quit.onClick.AddListener(Quit);
|
||||
}
|
||||
|
||||
private void UnRegisterButton()
|
||||
{
|
||||
var buttonGroup = transform.Find("Button Group");
|
||||
var continueBtn = buttonGroup.Find("Continue").GetComponent<Button>();
|
||||
continueBtn.onClick.RemoveAllListeners();
|
||||
var backToMain = buttonGroup.Find("BackMain").GetComponent<Button>();
|
||||
backToMain.onClick.RemoveAllListeners();
|
||||
var quit = buttonGroup.Find("Quit").GetComponent<Button>();
|
||||
quit.onClick.RemoveAllListeners();
|
||||
}
|
||||
|
||||
private void BackToGame()
|
||||
{
|
||||
// 关闭Setting面板
|
||||
UIManager.Instance.HidePanel<SettingPanel>();
|
||||
// TODO 解除暂停
|
||||
}
|
||||
|
||||
private void BackToMain()
|
||||
{
|
||||
// 关闭Setting面板
|
||||
UIManager.Instance.HidePanel<SettingPanel>();
|
||||
// 重启
|
||||
GameManager.Instance.QuitGame();
|
||||
}
|
||||
|
||||
private void Quit()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff78a14b28070864692582ecc5db824c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,68 @@
|
||||
using AibisDream.Utility;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class StartPanel : MonoBehaviour, IUIPanel
|
||||
{
|
||||
public bool IsOpen => gameObject.activeSelf;
|
||||
|
||||
#region 开启和关闭
|
||||
|
||||
public void Show()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
RegisterButton();
|
||||
}
|
||||
|
||||
private void RegisterButton()
|
||||
{
|
||||
// 开始界面按钮
|
||||
var tabs = transform.Find("Tabs");
|
||||
tabs.Find("Start").GetComponent<Button>().onClick.AddListener(StartNewGame);
|
||||
tabs.Find("Select Level").GetComponent<Button>().onClick.AddListener(OpenLevelPanel);
|
||||
tabs.Find("Load Save File").GetComponent<Button>().onClick.AddListener(OpenSaveFilePanel);
|
||||
tabs.Find("Quit").GetComponent<Button>().onClick.AddListener(QuitApp);
|
||||
// 打开链接
|
||||
transform.Find("问卷").GetComponent<Button>().onClick.AddListener(() => Application.OpenURL(ConstRef.SurveyURL));
|
||||
transform.Find("关注").GetComponent<Button>().onClick.AddListener(() => Application.OpenURL(ConstRef.QQURL));
|
||||
}
|
||||
|
||||
#region 按钮对应的函数
|
||||
|
||||
|
||||
private void StartNewGame()
|
||||
{
|
||||
GameManager.Instance.StartNewGame();
|
||||
}
|
||||
|
||||
private void OpenLevelPanel()
|
||||
{
|
||||
// TODO 打开选关面板
|
||||
}
|
||||
|
||||
private void OpenSaveFilePanel()
|
||||
{
|
||||
// TODO 打开存档面板
|
||||
}
|
||||
|
||||
private void QuitApp()
|
||||
{
|
||||
GameManager.Instance.QuitApp();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ba6256b10e589d478fc8c1910595417
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -49,7 +49,7 @@ namespace AibisDream
|
||||
// 隐藏UI
|
||||
gameObject.SetActive(false);
|
||||
// 开始游戏
|
||||
GameLoopManager.Instance.StartWithSaveFile(saveFileName);
|
||||
// GameLoopManager.Instance.StartWithSaveFile(saveFileName);
|
||||
}
|
||||
|
||||
public void HideSaveFileUI()
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AibisDream.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class UIManager : Kit.Singleton<UIManager>, IUIManager
|
||||
{
|
||||
#region 索引
|
||||
|
||||
private Dictionary<Type, IUIPanel> _panelPool;
|
||||
|
||||
public RectTransform Canvas { get; private set; }
|
||||
public Vector2 Resolution { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
public override void OnSingletonInit()
|
||||
{
|
||||
InitRefs();
|
||||
}
|
||||
|
||||
private void InitRefs()
|
||||
{
|
||||
// 获取Canvas
|
||||
Canvas = transform.Find("UI Canvas").GetComponent<RectTransform>();
|
||||
// 获取Panel
|
||||
var panels = Canvas.GetComponentsInChildren<IUIPanel>(true);
|
||||
_panelPool = new Dictionary<Type, IUIPanel>();
|
||||
foreach (var panel in panels)
|
||||
{
|
||||
_panelPool[panel.GetType()] = panel;
|
||||
}
|
||||
|
||||
EnumEventSystem.Global.Register(GameLoopEnum.AppStart, OnAppStart);
|
||||
EnumEventSystem.Global.Register(GameLoopEnum.GameStart, OnGameStart);
|
||||
EnumEventSystem.Global.Register(GameLoopEnum.GameQuit, OnGameQuit);
|
||||
}
|
||||
|
||||
private void OnAppStart()
|
||||
{
|
||||
// 游戏打开
|
||||
ShowPanel<StartPanel>();
|
||||
ShowPanel<PlayToolPanel>();
|
||||
|
||||
HidePanel<MainPanel>();
|
||||
HidePanel<SettingPanel>();
|
||||
HidePanel<RecordPanel>();
|
||||
HidePanel<EndPanel>();
|
||||
}
|
||||
|
||||
private void OnGameStart()
|
||||
{
|
||||
// 开始游戏
|
||||
HidePanel<StartPanel>();
|
||||
ShowPanel<MainPanel>();
|
||||
}
|
||||
|
||||
private void OnGameQuit()
|
||||
{
|
||||
HidePanel<MainPanel>();
|
||||
ShowPanel<StartPanel>();
|
||||
}
|
||||
|
||||
public void ShowPanel<T>(Action<T> call = null) where T : class, IUIPanel
|
||||
{
|
||||
var type = typeof(T);
|
||||
// 从缓存中检查panel
|
||||
if (_panelPool.TryGetValue(type, out var panel))
|
||||
{
|
||||
if (panel.IsOpen) return;
|
||||
panel.Show();
|
||||
call?.Invoke(panel as T);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"panel {type} 未注册");
|
||||
}
|
||||
}
|
||||
|
||||
public void HidePanel<T>() where T : IUIPanel
|
||||
{
|
||||
var type = typeof(T);
|
||||
// 从缓存中检查panel
|
||||
if (_panelPool.TryGetValue(type, out var panel))
|
||||
{
|
||||
if (!panel.IsOpen) return;
|
||||
panel.Hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"panel {type} 未注册");
|
||||
}
|
||||
}
|
||||
|
||||
public T GetPanel<T>() where T : class, IUIPanel
|
||||
{
|
||||
return _panelPool.TryGetValue(typeof(T), out var ui) ? ui as T : null;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IUIManager
|
||||
{
|
||||
void ShowPanel<T>(Action<T> call = null) where T : class, IUIPanel;
|
||||
void HidePanel<T>() where T : IUIPanel;
|
||||
T GetPanel<T>() where T : class, IUIPanel;
|
||||
RectTransform Canvas { get; }
|
||||
Vector2 Resolution { get; set; }
|
||||
|
||||
// 还没想好要不要用栈
|
||||
// UIPanel Pop();
|
||||
// void Push<T>(T panel) where T : UIPanel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0981e1188cb42a844b3b7b79a186bd39
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public interface IUIPanel
|
||||
{
|
||||
public virtual void Show() { }
|
||||
public virtual void Hide() { }
|
||||
public bool IsOpen { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 714c1d8a65854c1fb1355f6ff2c6f670
|
||||
timeCreated: 1743669973
|
||||
Reference in New Issue
Block a user