2024-07-16 18:53:34 +08:00
|
|
|
|
using TMPro;
|
2024-07-15 20:00:39 +08:00
|
|
|
|
using System;
|
2024-07-19 17:59:28 +08:00
|
|
|
|
using PhxhSDK;
|
2024-07-16 18:53:34 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
2024-07-16 15:04:13 +08:00
|
|
|
|
using Gameplay.Level;
|
2024-07-19 17:59:28 +08:00
|
|
|
|
using Framework.Event;
|
2024-07-12 17:10:33 +08:00
|
|
|
|
using Gameplay.Manager;
|
2024-07-16 18:53:34 +08:00
|
|
|
|
using Framework.Manager;
|
2024-07-11 20:03:13 +08:00
|
|
|
|
using Sirenix.OdinInspector;
|
2024-07-16 18:53:34 +08:00
|
|
|
|
using System.Collections.Generic;
|
2024-07-11 20:03:13 +08:00
|
|
|
|
|
|
|
|
|
public class BuildBoot : MonoBehaviour
|
|
|
|
|
{
|
2024-07-15 20:00:39 +08:00
|
|
|
|
[LabelText("当前条件")] public int CurCondition;
|
2024-07-11 20:03:13 +08:00
|
|
|
|
|
2024-07-12 17:10:33 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 节点类
|
|
|
|
|
/// </summary>
|
2024-07-16 16:00:20 +08:00
|
|
|
|
private class Node
|
2024-07-12 17:10:33 +08:00
|
|
|
|
{
|
2024-07-15 20:00:39 +08:00
|
|
|
|
public string Name;
|
|
|
|
|
|
2024-07-12 17:10:33 +08:00
|
|
|
|
public GameObject NodeObj;
|
|
|
|
|
|
|
|
|
|
public GameObject BubbleObj;
|
|
|
|
|
|
2024-07-16 18:53:34 +08:00
|
|
|
|
public Dictionary<string, Option> Options;
|
2024-07-12 17:10:33 +08:00
|
|
|
|
|
|
|
|
|
public Node(GameObject root)
|
|
|
|
|
{
|
2024-07-15 20:00:39 +08:00
|
|
|
|
Name = root.name;
|
2024-07-16 18:53:34 +08:00
|
|
|
|
Options = new Dictionary<string, Option>();
|
2024-07-12 17:10:33 +08:00
|
|
|
|
foreach (Transform child in root.transform)
|
|
|
|
|
{
|
|
|
|
|
if (!child.gameObject.name.Equals("Btn"))
|
|
|
|
|
{
|
|
|
|
|
var option = new Option(child.gameObject);
|
2024-07-16 18:53:34 +08:00
|
|
|
|
Options.Add(child.gameObject.name, option);
|
2024-07-12 17:10:33 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
BubbleObj = child.gameObject;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-16 18:53:34 +08:00
|
|
|
|
|
|
|
|
|
public Option GetOption(string optionName)
|
|
|
|
|
{
|
|
|
|
|
return Options.GetValueOrDefault(optionName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭其他选项表现
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void OptionDisplay(Option option)
|
|
|
|
|
{
|
2024-07-29 16:01:29 +08:00
|
|
|
|
if (option == null)
|
|
|
|
|
{
|
|
|
|
|
CloseAllOptionButBubble(true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 18:53:34 +08:00
|
|
|
|
foreach (var optionInfo in Options.Values)
|
|
|
|
|
{
|
|
|
|
|
optionInfo.SetOptionActive(option);
|
|
|
|
|
}
|
2024-07-17 17:56:02 +08:00
|
|
|
|
|
|
|
|
|
BubbleObj.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CloseAllOptionButBubble(bool butBubble)
|
|
|
|
|
{
|
|
|
|
|
foreach (var optionInfo in Options.Values)
|
|
|
|
|
{
|
|
|
|
|
optionInfo.SetOptionActive(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BubbleObj.SetActive(butBubble);
|
2024-07-16 18:53:34 +08:00
|
|
|
|
}
|
2024-07-12 17:10:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 选项类
|
|
|
|
|
/// </summary>
|
2024-07-16 16:00:20 +08:00
|
|
|
|
private class Option
|
2024-07-12 17:10:33 +08:00
|
|
|
|
{
|
2024-07-16 18:53:34 +08:00
|
|
|
|
public string Name;
|
2024-07-16 15:04:13 +08:00
|
|
|
|
public GameObject NodeObj;
|
|
|
|
|
public GameObject OptionObj;
|
2024-07-12 17:10:33 +08:00
|
|
|
|
public GameObject NormalObj;
|
|
|
|
|
|
|
|
|
|
public Option(GameObject root)
|
|
|
|
|
{
|
2024-07-16 18:53:34 +08:00
|
|
|
|
Name = root.name;
|
2024-07-16 15:04:13 +08:00
|
|
|
|
NodeObj = root.transform.parent.gameObject;
|
|
|
|
|
OptionObj = root;
|
2024-07-12 17:10:33 +08:00
|
|
|
|
NormalObj = root.transform.Find("Normal").gameObject;
|
|
|
|
|
}
|
2024-07-16 18:53:34 +08:00
|
|
|
|
|
|
|
|
|
public void SetOptionActive(Option option)
|
|
|
|
|
{
|
2024-07-29 16:01:29 +08:00
|
|
|
|
if (option == null)
|
|
|
|
|
{
|
|
|
|
|
OptionObj.SetActive(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 18:53:34 +08:00
|
|
|
|
OptionObj.SetActive(Name.Equals(option.Name));
|
|
|
|
|
}
|
2024-07-17 17:56:02 +08:00
|
|
|
|
|
|
|
|
|
public void SetOptionActive(bool active)
|
|
|
|
|
{
|
|
|
|
|
OptionObj.SetActive(active);
|
|
|
|
|
}
|
2024-07-12 17:10:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 16:00:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 物品栏类
|
|
|
|
|
/// </summary>
|
2024-07-15 20:00:39 +08:00
|
|
|
|
private class BuildBar
|
|
|
|
|
{
|
|
|
|
|
private GameObject _bar;
|
2024-07-16 18:53:34 +08:00
|
|
|
|
private Dictionary<string, BuildItem> _buildItem;
|
|
|
|
|
private Dictionary<string, Transform> _itemTrans;
|
2024-07-15 20:00:39 +08:00
|
|
|
|
private TMP_Text _condition;
|
|
|
|
|
private const string ContentPath = "Bar_Tip/Scroll View/Viewport/Content";
|
2024-07-16 15:04:13 +08:00
|
|
|
|
private const string IconItemTemplate = "Bar_Tip/Scroll View/Viewport/Content/Item";
|
2024-07-15 20:00:39 +08:00
|
|
|
|
private const string TipPath = "Bar_Tip";
|
2024-07-16 15:04:13 +08:00
|
|
|
|
private const string ConditionText = "Level\n{0}/{1}";
|
|
|
|
|
private const string ItemName = "Item{0}";
|
2024-07-25 19:27:22 +08:00
|
|
|
|
|
|
|
|
|
private readonly Color _lockColor = new Color(152f / 255f, 0f, 0f);
|
|
|
|
|
private readonly Color _unlockColor = new Color(255f, 255f, 255f);
|
2024-07-16 18:53:34 +08:00
|
|
|
|
private Action<Option> _optionCallBack;
|
2024-07-15 20:00:39 +08:00
|
|
|
|
|
|
|
|
|
public BuildBar(GameObject root)
|
|
|
|
|
{
|
|
|
|
|
_bar = root;
|
|
|
|
|
_condition = root.transform.Find(TipPath).GetComponent<TMP_Text>();
|
2024-07-16 18:53:34 +08:00
|
|
|
|
_buildItem = new Dictionary<string, BuildItem>();
|
|
|
|
|
_itemTrans = new Dictionary<string, Transform>();
|
2024-07-15 20:00:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 18:53:34 +08:00
|
|
|
|
public void Open(Node node, Action<Option> callBack, Action lockCallBack, int reachCondition, int condition)
|
2024-07-15 20:00:39 +08:00
|
|
|
|
{
|
2024-07-16 18:53:34 +08:00
|
|
|
|
_optionCallBack = callBack;
|
2024-07-15 20:00:39 +08:00
|
|
|
|
_bar.SetActive(true);
|
|
|
|
|
_condition.text = string.Format(ConditionText, reachCondition, condition);
|
2024-07-25 19:27:22 +08:00
|
|
|
|
_condition.color = reachCondition < condition ? _lockColor : _unlockColor;
|
|
|
|
|
|
2024-07-16 15:04:13 +08:00
|
|
|
|
var content = _bar.transform.Find(ContentPath);
|
|
|
|
|
var iconTemplate = _bar.transform.Find(IconItemTemplate);
|
|
|
|
|
|
2024-07-16 18:53:34 +08:00
|
|
|
|
_buildItem.Clear();
|
|
|
|
|
var index = 1;
|
|
|
|
|
foreach (var option in node.Options)
|
2024-07-15 20:00:39 +08:00
|
|
|
|
{
|
2024-07-16 18:53:34 +08:00
|
|
|
|
var optionName = option.Value.OptionObj.name;
|
|
|
|
|
var iconName = string.Format(ItemName, index);
|
|
|
|
|
if (!_itemTrans.TryGetValue(iconName, out var iconItem))
|
2024-07-15 20:00:39 +08:00
|
|
|
|
{
|
2024-07-16 15:04:13 +08:00
|
|
|
|
iconItem = Instantiate(iconTemplate, content);
|
|
|
|
|
iconItem.name = iconName;
|
2024-07-16 18:53:34 +08:00
|
|
|
|
_itemTrans.Add(iconName, iconItem);
|
2024-07-15 20:00:39 +08:00
|
|
|
|
}
|
2024-07-16 15:04:13 +08:00
|
|
|
|
|
|
|
|
|
iconItem.gameObject.SetActive(true);
|
|
|
|
|
var sprite = BuildManager.Instance.GetOptionIcon(node.Name, optionName);
|
2024-07-16 18:53:34 +08:00
|
|
|
|
var unlock = reachCondition >= condition;
|
|
|
|
|
var item = new BuildItem(iconItem.gameObject, option.Value);
|
|
|
|
|
_buildItem.Add(optionName, item);
|
|
|
|
|
item.SetInfo(sprite, unlock, ItemCallBack, lockCallBack);
|
|
|
|
|
index++;
|
2024-07-16 15:04:13 +08:00
|
|
|
|
//DebugUtil.Log("Bar添加物品Icon:{0}", iconItem.name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 18:53:34 +08:00
|
|
|
|
private void ItemCallBack(Option option)
|
|
|
|
|
{
|
|
|
|
|
_optionCallBack?.Invoke(option);
|
|
|
|
|
PickItemDisplay(option.OptionObj.name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PickItemDisplay(string optionName)
|
2024-07-16 15:04:13 +08:00
|
|
|
|
{
|
2024-07-16 18:53:34 +08:00
|
|
|
|
foreach (var item in _buildItem)
|
2024-07-16 15:04:13 +08:00
|
|
|
|
{
|
|
|
|
|
item.Value.SetPickActive(item.Key.Equals(optionName));
|
2024-07-15 20:00:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
|
{
|
|
|
|
|
_bar.SetActive(false);
|
2024-07-16 18:53:34 +08:00
|
|
|
|
foreach (var item in _buildItem)
|
2024-07-16 15:04:13 +08:00
|
|
|
|
{
|
|
|
|
|
item.Value.SetPickActive(false);
|
|
|
|
|
}
|
2024-07-15 20:00:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 16:00:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 物品栏Icon类
|
|
|
|
|
/// </summary>
|
2024-07-15 20:00:39 +08:00
|
|
|
|
private class BuildItem
|
|
|
|
|
{
|
2024-07-16 18:53:34 +08:00
|
|
|
|
public Option Option;
|
2024-07-15 20:00:39 +08:00
|
|
|
|
private Button _btn;
|
2024-07-16 15:04:13 +08:00
|
|
|
|
private Button _lockBtn;
|
2024-07-15 20:00:39 +08:00
|
|
|
|
private Image _imgIcon;
|
|
|
|
|
private GameObject _lock;
|
|
|
|
|
private GameObject _imgPick;
|
|
|
|
|
|
2024-07-16 18:53:34 +08:00
|
|
|
|
public BuildItem(GameObject root, Option option)
|
2024-07-15 20:00:39 +08:00
|
|
|
|
{
|
2024-07-16 18:53:34 +08:00
|
|
|
|
this.Option = option;
|
2024-07-15 20:00:39 +08:00
|
|
|
|
_btn = root.transform.Find("Img_Item").GetComponent<Button>();
|
|
|
|
|
_imgIcon = root.transform.Find("Img_Item").GetComponent<Image>();
|
|
|
|
|
_lock = root.transform.Find("Img_Lock").gameObject;
|
2024-07-16 15:04:13 +08:00
|
|
|
|
_lockBtn = _lock.GetComponent<Button>();
|
2024-07-15 20:00:39 +08:00
|
|
|
|
_imgPick = root.transform.Find("Bg_Pick").gameObject;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 18:53:34 +08:00
|
|
|
|
public void SetInfo(Sprite sprite, bool unlock, Action<Option> callBack, Action lockCallBack)
|
2024-07-15 20:00:39 +08:00
|
|
|
|
{
|
2024-07-16 18:53:34 +08:00
|
|
|
|
_lock.SetActive(!unlock);
|
2024-07-15 20:00:39 +08:00
|
|
|
|
_btn.onClick.RemoveAllListeners();
|
2024-07-16 18:53:34 +08:00
|
|
|
|
_btn.onClick.AddListener(() => { callBack?.Invoke(Option); });
|
2024-07-16 15:04:13 +08:00
|
|
|
|
_lockBtn.onClick.RemoveAllListeners();
|
|
|
|
|
_lockBtn.onClick.AddListener(() => { lockCallBack?.Invoke(); });
|
2024-07-15 20:00:39 +08:00
|
|
|
|
_imgIcon.sprite = sprite;
|
|
|
|
|
}
|
2024-07-16 15:04:13 +08:00
|
|
|
|
|
2024-07-16 18:53:34 +08:00
|
|
|
|
|
2024-07-16 15:04:13 +08:00
|
|
|
|
public void SetPickActive(bool pick)
|
|
|
|
|
{
|
|
|
|
|
_imgPick.SetActive(pick);
|
|
|
|
|
}
|
2024-07-15 20:00:39 +08:00
|
|
|
|
}
|
2024-07-12 17:10:33 +08:00
|
|
|
|
|
2024-07-18 13:03:55 +08:00
|
|
|
|
//适配安全区
|
|
|
|
|
private GameObject _topLiuHai;
|
|
|
|
|
private GameObject _bottomLiuHai;
|
|
|
|
|
private Vector2 _offsets;
|
|
|
|
|
|
2024-07-16 15:04:13 +08:00
|
|
|
|
//物品栏
|
|
|
|
|
private BuildBar _buildBar;
|
2024-07-12 17:10:33 +08:00
|
|
|
|
private Button _btnBarClose;
|
|
|
|
|
private Button _btnBarYes;
|
|
|
|
|
|
2024-07-16 15:04:13 +08:00
|
|
|
|
//当前点击的泡泡按钮
|
2024-07-15 20:00:39 +08:00
|
|
|
|
private GameObject _curBubble;
|
|
|
|
|
|
2024-07-16 18:53:34 +08:00
|
|
|
|
//当前选择的选项
|
2024-07-18 20:01:43 +08:00
|
|
|
|
private Option _newOption;
|
2024-07-16 18:53:34 +08:00
|
|
|
|
private Option _curOption;
|
|
|
|
|
private Node _curNode;
|
|
|
|
|
|
2024-07-16 15:04:13 +08:00
|
|
|
|
//当前节点字典
|
|
|
|
|
private Dictionary<string, Node> _nodes;
|
|
|
|
|
|
|
|
|
|
//提示弹窗
|
|
|
|
|
private GameObject _tipObj;
|
|
|
|
|
private Button _btnTipGoGame;
|
|
|
|
|
private Button _btnTipClose;
|
2024-07-12 17:10:33 +08:00
|
|
|
|
|
2024-07-16 18:53:34 +08:00
|
|
|
|
//遮罩
|
|
|
|
|
private GameObject _mask;
|
|
|
|
|
private bool _isChanging;
|
|
|
|
|
|
2024-07-17 17:56:02 +08:00
|
|
|
|
private GameObject _pickItem;
|
|
|
|
|
private SpriteRenderer _pickSpriteRenderer;
|
|
|
|
|
|
2024-07-18 20:01:43 +08:00
|
|
|
|
//UI界面
|
|
|
|
|
private GameObject _uiMainBuild;
|
|
|
|
|
|
2024-07-11 20:03:13 +08:00
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
2024-07-18 20:01:43 +08:00
|
|
|
|
RegisterEvent();
|
2024-07-12 17:10:33 +08:00
|
|
|
|
InitUI();
|
|
|
|
|
InitBuildData();
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-15 20:00:39 +08:00
|
|
|
|
private void Start()
|
|
|
|
|
{
|
2024-07-18 20:01:43 +08:00
|
|
|
|
InitCamera();
|
2024-07-18 13:03:55 +08:00
|
|
|
|
InitScreenAdaption();
|
|
|
|
|
UpdateScreenAdaption();
|
2024-07-16 16:00:20 +08:00
|
|
|
|
UpdateBuildDisplay();
|
2024-07-15 20:00:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-12 17:10:33 +08:00
|
|
|
|
private void OnDisable()
|
|
|
|
|
{
|
|
|
|
|
UnregisterClickEvent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Build相关
|
|
|
|
|
|
2024-07-16 16:00:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化建造物数据
|
|
|
|
|
/// </summary>
|
2024-07-12 17:10:33 +08:00
|
|
|
|
private void InitBuildData()
|
|
|
|
|
{
|
2024-07-16 15:04:13 +08:00
|
|
|
|
_nodes = new Dictionary<string, Node>();
|
2024-07-17 17:56:02 +08:00
|
|
|
|
var nodeRoot = GameObject.Find("BuildRoot");
|
2024-07-12 17:10:33 +08:00
|
|
|
|
foreach (Transform child in nodeRoot.transform)
|
|
|
|
|
{
|
|
|
|
|
var node = new Node(child.gameObject);
|
2024-07-16 15:04:13 +08:00
|
|
|
|
_nodes.Add(child.name, node);
|
2024-07-12 17:10:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-16 18:53:34 +08:00
|
|
|
|
|
2024-07-16 16:00:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 刷新建造物表现
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void UpdateBuildDisplay()
|
|
|
|
|
{
|
2024-08-15 17:56:54 +08:00
|
|
|
|
DebugUtil.LogError("刷新表现");
|
|
|
|
|
var chooseNodeInfo = BuildManager.Instance.UserBuildInfo.ChooseNodeInfo;
|
2024-07-17 17:56:02 +08:00
|
|
|
|
if (chooseNodeInfo == null || chooseNodeInfo.Count <= 0)
|
|
|
|
|
{
|
|
|
|
|
DebugUtil.LogError("Build Boot: 玩家在该场景的建造信息获取错误");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-19 17:59:28 +08:00
|
|
|
|
CurCondition = BuildManager.Instance.ReachCondition < 0
|
|
|
|
|
? CurCondition
|
|
|
|
|
: BuildManager.Instance.ReachCondition;
|
2024-07-29 16:01:29 +08:00
|
|
|
|
|
2024-07-30 12:29:27 +08:00
|
|
|
|
var nextLockNode = BuildManager.Instance.GetNextLockNode();
|
2024-07-19 17:59:28 +08:00
|
|
|
|
if (string.IsNullOrEmpty(nextLockNode))
|
2024-07-16 16:00:20 +08:00
|
|
|
|
{
|
2024-07-19 17:59:28 +08:00
|
|
|
|
foreach (var chooseNode in chooseNodeInfo)
|
2024-07-16 16:00:20 +08:00
|
|
|
|
{
|
2024-07-19 17:59:28 +08:00
|
|
|
|
if (_nodes.TryGetValue(chooseNode.Key, out var node))
|
2024-07-16 16:00:20 +08:00
|
|
|
|
{
|
2024-07-19 17:59:28 +08:00
|
|
|
|
var option = node.GetOption(chooseNode.Value);
|
2024-07-17 17:56:02 +08:00
|
|
|
|
node.OptionDisplay(option);
|
2024-07-16 16:00:20 +08:00
|
|
|
|
}
|
2024-07-19 17:59:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-07-29 16:01:29 +08:00
|
|
|
|
foreach (var node in _nodes)
|
2024-07-19 17:59:28 +08:00
|
|
|
|
{
|
2024-07-29 16:01:29 +08:00
|
|
|
|
if (!chooseNodeInfo.TryGetValue(node.Key, out var unlockNode)) return;
|
|
|
|
|
//已选择节点
|
|
|
|
|
if (!string.IsNullOrEmpty(unlockNode))
|
2024-07-16 16:00:20 +08:00
|
|
|
|
{
|
2024-07-29 16:01:29 +08:00
|
|
|
|
var option = node.Value.GetOption(unlockNode);
|
|
|
|
|
node.Value.OptionDisplay(option);
|
|
|
|
|
}
|
|
|
|
|
//需解锁节点
|
|
|
|
|
else if (node.Key.Equals(nextLockNode) && string.IsNullOrEmpty(unlockNode))
|
|
|
|
|
{
|
|
|
|
|
_curBubble = node.Value.BubbleObj;
|
|
|
|
|
node.Value.CloseAllOptionButBubble(true);
|
|
|
|
|
}
|
|
|
|
|
//未解锁
|
|
|
|
|
else if (!node.Key.Equals(nextLockNode) && string.IsNullOrEmpty(unlockNode))
|
|
|
|
|
{
|
|
|
|
|
node.Value.CloseAllOptionButBubble(false);
|
2024-07-16 16:00:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-12 17:10:33 +08:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region UI相关
|
|
|
|
|
|
2024-07-18 20:01:43 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化相机 区别游戏内外
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void InitCamera()
|
|
|
|
|
{
|
|
|
|
|
if (BuildManager.Instance.CurBuildCamera == null) return;
|
|
|
|
|
GameObject.Find("BuildCamera").Destroy();
|
|
|
|
|
var canvas = transform.Find("BuildUIRoot").GetComponent<Canvas>();
|
|
|
|
|
canvas.worldCamera = BuildManager.Instance.CurBuildCamera;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-18 13:03:55 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化屏幕适配
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void InitScreenAdaption()
|
|
|
|
|
{
|
|
|
|
|
var offset = DeviceHelper.GetHeightOffset();
|
|
|
|
|
|
|
|
|
|
_bottomLiuHai = transform.Find("BuildUIRoot/UIMainBuild/UI_LiuHaiBottom").gameObject;
|
|
|
|
|
_topLiuHai = transform.Find("BuildUIRoot/UIMainBuild/UI_LiuHaiTop").gameObject;
|
|
|
|
|
if (_topLiuHai)
|
|
|
|
|
{
|
|
|
|
|
var rectTrans = _topLiuHai.GetComponent<RectTransform>();
|
|
|
|
|
var originPos = rectTrans.anchoredPosition;
|
|
|
|
|
_offsets = new Vector2(originPos.y - offset.x, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_bottomLiuHai)
|
|
|
|
|
{
|
|
|
|
|
var rectTrans = _bottomLiuHai.GetComponent<RectTransform>();
|
|
|
|
|
var originPos = rectTrans.anchoredPosition;
|
|
|
|
|
_offsets = new Vector2(_offsets.x, originPos.y + offset.y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新屏幕适配
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void UpdateScreenAdaption()
|
|
|
|
|
{
|
|
|
|
|
if (_topLiuHai)
|
|
|
|
|
{
|
|
|
|
|
var rectTrans = _topLiuHai.GetComponent<RectTransform>();
|
|
|
|
|
var originPos = rectTrans.anchoredPosition;
|
|
|
|
|
rectTrans.anchoredPosition = new Vector2(originPos.x, _offsets.x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_bottomLiuHai)
|
|
|
|
|
{
|
|
|
|
|
var rectTrans = _bottomLiuHai.GetComponent<RectTransform>();
|
|
|
|
|
var originPos = rectTrans.anchoredPosition;
|
|
|
|
|
rectTrans.anchoredPosition = new Vector2(originPos.x, _offsets.y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 16:00:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化UI
|
|
|
|
|
/// </summary>
|
2024-07-12 17:10:33 +08:00
|
|
|
|
private void InitUI()
|
|
|
|
|
{
|
2024-07-26 19:17:22 +08:00
|
|
|
|
var otherRoot = GameObject.Find("OtherRoot").gameObject;
|
2024-07-29 16:01:29 +08:00
|
|
|
|
_mask = otherRoot.transform.Find("Mask").gameObject;
|
2024-07-26 19:17:22 +08:00
|
|
|
|
_pickItem = GameObject.Find("OtherRoot/PickItem").gameObject;
|
2024-07-17 17:56:02 +08:00
|
|
|
|
_pickSpriteRenderer = _pickItem.GetComponent<SpriteRenderer>();
|
2024-07-16 18:53:34 +08:00
|
|
|
|
|
2024-07-18 20:01:43 +08:00
|
|
|
|
_uiMainBuild = transform.Find("BuildUIRoot/UIMainBuild").gameObject;
|
|
|
|
|
|
2024-07-16 15:04:13 +08:00
|
|
|
|
InitTipPanel();
|
2024-07-12 17:10:33 +08:00
|
|
|
|
InitBuildBar();
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 16:00:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化上锁提示界面
|
|
|
|
|
/// </summary>
|
2024-07-16 15:04:13 +08:00
|
|
|
|
private void InitTipPanel()
|
|
|
|
|
{
|
2024-07-17 17:56:02 +08:00
|
|
|
|
_tipObj = transform.Find("BuildUIRoot/UIMainBuild/Build_Tip").gameObject;
|
2024-07-16 15:04:13 +08:00
|
|
|
|
_btnTipClose = _tipObj.transform.Find("Btn_Close").GetComponent<Button>();
|
|
|
|
|
_btnTipGoGame = _tipObj.transform.Find("Btn_Game").GetComponent<Button>();
|
|
|
|
|
_btnTipClose.onClick.AddListener(CloseTipPanel);
|
|
|
|
|
_btnTipGoGame.onClick.AddListener(TipGoGame);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 16:00:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化物品栏
|
|
|
|
|
/// </summary>
|
2024-07-12 17:10:33 +08:00
|
|
|
|
private void InitBuildBar()
|
|
|
|
|
{
|
2024-07-17 17:56:02 +08:00
|
|
|
|
var bar = transform.Find("BuildUIRoot/UIMainBuild/UI_LiuHaiBottom/Build_Bar").gameObject;
|
2024-07-16 16:00:20 +08:00
|
|
|
|
_btnBarClose = bar.transform.Find("Btn_Close").GetComponent<Button>();
|
2024-07-12 17:10:33 +08:00
|
|
|
|
_btnBarClose.onClick.AddListener(CloseBar);
|
2024-07-16 16:00:20 +08:00
|
|
|
|
_btnBarYes = bar.transform.Find("Btn_Yes").GetComponent<Button>();
|
2024-07-12 17:10:33 +08:00
|
|
|
|
_btnBarYes.onClick.AddListener(YesBar);
|
2024-07-16 16:00:20 +08:00
|
|
|
|
_buildBar = new BuildBar(bar);
|
2024-07-12 17:10:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 16:00:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭提示界面
|
|
|
|
|
/// </summary>
|
2024-07-16 15:04:13 +08:00
|
|
|
|
private void CloseTipPanel()
|
|
|
|
|
{
|
|
|
|
|
_tipObj.SetActive(false);
|
2024-07-30 12:29:27 +08:00
|
|
|
|
BuildManager.Instance.PlaySound();
|
2024-07-16 15:04:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 16:00:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 开始游戏
|
|
|
|
|
/// </summary>
|
2024-07-16 15:04:13 +08:00
|
|
|
|
private void TipGoGame()
|
|
|
|
|
{
|
|
|
|
|
var levelID = $"level{LevelSelectManager.Instance.CurPassLevelIndex + 1}";
|
|
|
|
|
if (LevelManager.Instance.IsLevelExist(levelID))
|
|
|
|
|
{
|
|
|
|
|
GameStateManager.Instance.ChangeState(new LevelState(levelID));
|
2024-07-25 15:29:18 +08:00
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.EnterGame);
|
2024-07-16 15:04:13 +08:00
|
|
|
|
}
|
2024-08-15 16:03:41 +08:00
|
|
|
|
|
2024-07-30 12:29:27 +08:00
|
|
|
|
BuildManager.Instance.PlaySound();
|
2024-07-16 15:04:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 16:00:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭物品栏
|
|
|
|
|
/// </summary>
|
2024-07-12 17:10:33 +08:00
|
|
|
|
private void CloseBar()
|
|
|
|
|
{
|
2024-07-30 12:29:27 +08:00
|
|
|
|
BuildManager.Instance.PlaySound();
|
2024-07-16 18:53:34 +08:00
|
|
|
|
_isChanging = false;
|
2024-07-15 20:00:39 +08:00
|
|
|
|
_buildBar.Close();
|
2024-07-16 18:53:34 +08:00
|
|
|
|
_mask.SetActive(false);
|
2024-07-17 17:56:02 +08:00
|
|
|
|
_pickItem.SetActive(false);
|
2024-07-16 18:53:34 +08:00
|
|
|
|
if (_curBubble != null)
|
|
|
|
|
_curBubble.SetActive(true);
|
2024-07-18 20:01:43 +08:00
|
|
|
|
|
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.ShowMainUI);
|
2024-07-16 18:53:34 +08:00
|
|
|
|
//放弃修改
|
2024-07-29 16:01:29 +08:00
|
|
|
|
if (_curNode == null) return;
|
2024-07-16 18:53:34 +08:00
|
|
|
|
_curNode.OptionDisplay(_curOption);
|
|
|
|
|
_curNode = null;
|
|
|
|
|
_curOption = null;
|
2024-07-18 20:01:43 +08:00
|
|
|
|
_newOption = null;
|
2024-07-12 17:10:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 16:00:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存更改
|
|
|
|
|
/// </summary>
|
2024-07-12 17:10:33 +08:00
|
|
|
|
private void YesBar()
|
|
|
|
|
{
|
2024-07-30 12:29:27 +08:00
|
|
|
|
BuildManager.Instance.PlaySound();
|
2024-07-16 18:53:34 +08:00
|
|
|
|
_isChanging = false;
|
|
|
|
|
_mask.SetActive(false);
|
2024-07-17 17:56:02 +08:00
|
|
|
|
_pickItem.SetActive(false);
|
2024-07-15 20:00:39 +08:00
|
|
|
|
_buildBar.Close();
|
2024-07-29 16:01:29 +08:00
|
|
|
|
|
2024-07-25 15:29:18 +08:00
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.CloseUI);
|
2024-07-27 01:36:50 +08:00
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.ShowMainUI);
|
2024-07-17 17:56:02 +08:00
|
|
|
|
|
2024-07-18 20:01:43 +08:00
|
|
|
|
if (_curNode == null || _newOption == null)
|
2024-07-18 13:03:55 +08:00
|
|
|
|
{
|
|
|
|
|
_curBubble.SetActive(true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-07-29 16:01:29 +08:00
|
|
|
|
|
|
|
|
|
//DebugUtil.LogError("保存更改,当前节点:{0},当前选项:{1}", _curNode.Name, _newOption.Name);
|
2024-07-18 20:01:43 +08:00
|
|
|
|
BuildManager.Instance.SaveNodeInfo(_curNode.Name, _newOption.Name);
|
|
|
|
|
_curNode = null;
|
|
|
|
|
_curOption = null;
|
|
|
|
|
_newOption = null;
|
2024-07-29 16:42:11 +08:00
|
|
|
|
_curBubble = null;
|
2024-07-29 16:01:29 +08:00
|
|
|
|
UpdateBuildDisplay();
|
2024-07-18 20:01:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowUI()
|
|
|
|
|
{
|
|
|
|
|
_uiMainBuild.SetActive(true);
|
2024-07-19 17:59:28 +08:00
|
|
|
|
if (_curBubble != null)
|
2024-07-25 19:27:22 +08:00
|
|
|
|
_curBubble.SetActive(true);
|
2024-07-18 20:01:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HideUI()
|
|
|
|
|
{
|
|
|
|
|
_uiMainBuild.SetActive(false);
|
2024-07-19 17:59:28 +08:00
|
|
|
|
if (_curBubble != null)
|
|
|
|
|
_curBubble.SetActive(false);
|
2024-07-12 17:10:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-15 20:00:39 +08:00
|
|
|
|
#endregion
|
2024-07-12 17:10:33 +08:00
|
|
|
|
|
2024-07-16 16:00:20 +08:00
|
|
|
|
#region 点击事件
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 建造物节点点击
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void OnBuildItemClick(GameObject obj)
|
2024-07-12 17:10:33 +08:00
|
|
|
|
{
|
2024-07-16 18:53:34 +08:00
|
|
|
|
if (_isChanging) return;
|
|
|
|
|
_isChanging = true;
|
|
|
|
|
_mask.SetActive(true);
|
2024-07-18 20:01:43 +08:00
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.HideMainUI);
|
2024-07-16 18:53:34 +08:00
|
|
|
|
var optionObj = obj.transform.parent.gameObject;
|
|
|
|
|
var nodeName = optionObj.transform.parent.name;
|
|
|
|
|
var optionName = optionObj.name;
|
2024-07-30 12:29:27 +08:00
|
|
|
|
BuildManager.Instance.PlaySound();
|
2024-07-16 18:53:34 +08:00
|
|
|
|
if (_nodes.TryGetValue(nodeName, out var node))
|
|
|
|
|
{
|
|
|
|
|
_curNode = node;
|
|
|
|
|
_curOption = node.GetOption(optionName);
|
|
|
|
|
var condition = BuildManager.Instance.GetCondition(nodeName);
|
|
|
|
|
_buildBar.Open(node, BuildIconClick, BuildLockIconClick, CurCondition, condition);
|
|
|
|
|
_buildBar.PickItemDisplay(optionName);
|
2024-07-29 16:42:11 +08:00
|
|
|
|
if (_curOption != null)
|
|
|
|
|
OutlinePickItem(_curOption);
|
2024-07-25 15:29:18 +08:00
|
|
|
|
|
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.OpenUI);
|
2024-07-16 18:53:34 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DebugUtil.LogError("节点获取信息错误: {0}", nodeName);
|
|
|
|
|
}
|
2024-07-12 17:10:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 16:00:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 泡泡点击
|
|
|
|
|
/// </summary>
|
2024-07-12 17:10:33 +08:00
|
|
|
|
private void OnBuildBubbleClick(GameObject obj)
|
|
|
|
|
{
|
2024-07-16 18:53:34 +08:00
|
|
|
|
if (_isChanging) return;
|
|
|
|
|
_isChanging = true;
|
|
|
|
|
_mask.SetActive(true);
|
2024-07-15 20:00:39 +08:00
|
|
|
|
_curBubble = obj;
|
|
|
|
|
obj.SetActive(false);
|
2024-07-16 15:04:13 +08:00
|
|
|
|
var nodeName = obj.transform.parent.name;
|
2024-07-18 20:01:43 +08:00
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.HideMainUI);
|
2024-07-30 12:29:27 +08:00
|
|
|
|
BuildManager.Instance.PlaySound();
|
2024-07-16 15:04:13 +08:00
|
|
|
|
if (_nodes.TryGetValue(nodeName, out var node))
|
|
|
|
|
{
|
|
|
|
|
var condition = BuildManager.Instance.GetCondition(nodeName);
|
2024-07-29 16:01:29 +08:00
|
|
|
|
_curNode = node;
|
2024-07-16 15:04:13 +08:00
|
|
|
|
_buildBar.Open(node, BuildIconClick, BuildLockIconClick, CurCondition, condition);
|
2024-07-25 15:29:18 +08:00
|
|
|
|
|
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.OpenUI);
|
2024-07-16 15:04:13 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DebugUtil.LogError("节点获取信息错误: {0}", nodeName);
|
|
|
|
|
}
|
2024-07-15 20:00:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 16:00:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 解锁图标点击
|
|
|
|
|
/// </summary>
|
2024-07-16 18:53:34 +08:00
|
|
|
|
private void BuildIconClick(Option option)
|
2024-07-15 20:00:39 +08:00
|
|
|
|
{
|
2024-07-25 15:29:18 +08:00
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.ChangeBuild);
|
|
|
|
|
if (option == _newOption)
|
|
|
|
|
return;
|
2024-07-16 18:53:34 +08:00
|
|
|
|
var nodeName = option.NodeObj.name;
|
|
|
|
|
//切换UI表现
|
|
|
|
|
if (_nodes.TryGetValue(nodeName, out var node))
|
|
|
|
|
{
|
|
|
|
|
foreach (var optionInfo in node.Options.Values)
|
|
|
|
|
{
|
|
|
|
|
optionInfo.OptionObj.SetActive(option.Name.Equals(optionInfo.Name));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-18 20:01:43 +08:00
|
|
|
|
_newOption = option;
|
2024-07-30 12:29:27 +08:00
|
|
|
|
BuildManager.Instance.PlaySound();
|
2024-07-25 15:29:18 +08:00
|
|
|
|
OutlinePickItem(option);
|
2024-07-17 17:56:02 +08:00
|
|
|
|
|
2024-07-16 18:53:34 +08:00
|
|
|
|
//DebugUtil.LogError("点击了{0}节点的{1}选项", nodeName, option.OptionObj.name);
|
2024-07-12 17:10:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 16:00:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 未解锁图标点击
|
|
|
|
|
/// </summary>
|
2024-07-16 15:04:13 +08:00
|
|
|
|
private void BuildLockIconClick()
|
|
|
|
|
{
|
2024-07-16 18:53:34 +08:00
|
|
|
|
_mask.SetActive(true);
|
2024-07-16 15:04:13 +08:00
|
|
|
|
_tipObj.SetActive(true);
|
2024-07-30 12:29:27 +08:00
|
|
|
|
BuildManager.Instance.PlaySound();
|
2024-07-25 15:29:18 +08:00
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.OpenUI);
|
2024-07-16 15:04:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-30 12:29:27 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 描边展示
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void OutlinePickItem(Option option)
|
|
|
|
|
{
|
|
|
|
|
_pickItem.SetActive(true);
|
|
|
|
|
_pickItem.transform.position = option.OptionObj.transform.position;
|
|
|
|
|
_pickSpriteRenderer.sprite =
|
|
|
|
|
option.NormalObj.GetComponent<SpriteRenderer>().sprite;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateReachCondition()
|
|
|
|
|
{
|
|
|
|
|
//TODO 不同类型的条件
|
|
|
|
|
CurCondition = LevelSelectManager.Instance.CurPassLevelIndex;
|
|
|
|
|
|
|
|
|
|
BuildManager.Instance.UpdateReachCondition(CurCondition);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-18 20:01:43 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private void RegisterEvent()
|
2024-07-12 17:10:33 +08:00
|
|
|
|
{
|
2024-07-16 16:00:20 +08:00
|
|
|
|
InputManager.Instance.OnBuildItemClick += OnBuildItemClick;
|
2024-07-12 17:10:33 +08:00
|
|
|
|
InputManager.Instance.OnBuildBubbleClick += OnBuildBubbleClick;
|
2024-07-18 20:01:43 +08:00
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.HideBuildUI, HideUI);
|
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.ShowBuildUI, ShowUI);
|
2024-08-15 17:56:54 +08:00
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.ChangeBuildScene, UpdateBuildDisplay);
|
2024-07-30 12:29:27 +08:00
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.RefreshGameData, UpdateReachCondition);
|
2024-07-12 17:10:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UnregisterClickEvent()
|
|
|
|
|
{
|
2024-07-29 16:42:11 +08:00
|
|
|
|
if (InputManager.Instance)
|
|
|
|
|
{
|
|
|
|
|
InputManager.Instance.OnBuildItemClick -= OnBuildItemClick;
|
|
|
|
|
InputManager.Instance.OnBuildBubbleClick -= OnBuildBubbleClick;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-18 20:01:43 +08:00
|
|
|
|
EventManager.Instance.Unregister(EventManager.EventName.HideBuildUI, HideUI);
|
|
|
|
|
EventManager.Instance.Unregister(EventManager.EventName.ShowBuildUI, ShowUI);
|
2024-08-15 17:56:54 +08:00
|
|
|
|
EventManager.Instance.Unregister(EventManager.EventName.ChangeBuildScene, UpdateBuildDisplay);
|
2024-07-30 12:29:27 +08:00
|
|
|
|
EventManager.Instance.Unregister(EventManager.EventName.RefreshGameData, UpdateReachCondition);
|
2024-07-11 20:03:13 +08:00
|
|
|
|
}
|
2024-07-12 17:10:33 +08:00
|
|
|
|
}
|