【建造】选择切换表现
parent
0451039a5f
commit
54247e110c
|
@ -760,7 +760,7 @@ PrefabInstance:
|
|||
- target: {fileID: 7644366489302203207, guid: e9c96c211fb08417084dbd9a3f85ab3c,
|
||||
type: 3}
|
||||
propertyPath: m_text
|
||||
value: Build_Game
|
||||
value: Start Game
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8263868880915436829, guid: e9c96c211fb08417084dbd9a3f85ab3c,
|
||||
type: 3}
|
||||
|
@ -770,7 +770,9 @@ PrefabInstance:
|
|||
- target: {fileID: 8779257074991400646, guid: e9c96c211fb08417084dbd9a3f85ab3c,
|
||||
type: 3}
|
||||
propertyPath: m_text
|
||||
value: Build_Tip
|
||||
value: 'Not yet unlocked
|
||||
|
||||
Go explore more levels!'
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_RemovedGameObjects: []
|
||||
|
@ -1541,7 +1543,7 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 9b618b5bdf3884745b8cccd94ea6fcf1, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
CurCondition: 50
|
||||
CurCondition: 0
|
||||
--- !u!1 &655320739
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -4099,7 +4101,7 @@ Transform:
|
|||
m_GameObject: {fileID: 1919860221}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalPosition: {x: -0.4, y: 0.41, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
|
@ -4730,7 +4732,7 @@ Transform:
|
|||
m_GameObject: {fileID: 2135953382}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalPosition: {x: -0.09, y: -0.26, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
using TMPro;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Framework.Constants;
|
||||
using Framework.Manager;
|
||||
using UnityEngine;
|
||||
using Gameplay.Game;
|
||||
using UnityEngine.UI;
|
||||
using Gameplay.Level;
|
||||
using Gameplay.Manager;
|
||||
using Framework.Manager;
|
||||
using Framework.Constants;
|
||||
using Sirenix.OdinInspector;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
using LC.Google.Protobuf.WellKnownTypes;
|
||||
|
||||
public class BuildBoot : MonoBehaviour
|
||||
{
|
||||
|
@ -25,19 +26,18 @@ public class BuildBoot : MonoBehaviour
|
|||
|
||||
public GameObject BubbleObj;
|
||||
|
||||
public List<Option> Options;
|
||||
public Dictionary<string, Option> Options;
|
||||
|
||||
public Node(GameObject root)
|
||||
{
|
||||
Name = root.name;
|
||||
Options = new List<Option>();
|
||||
Options = new Dictionary<string, Option>();
|
||||
foreach (Transform child in root.transform)
|
||||
{
|
||||
if (!child.gameObject.name.Equals("Btn"))
|
||||
{
|
||||
//DebugUtil.LogError("当前节点{0}有选项{1}", root.gameObject.name, child.gameObject.name);
|
||||
var option = new Option(child.gameObject);
|
||||
Options.Add(option);
|
||||
Options.Add(child.gameObject.name, option);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -45,6 +45,22 @@ public class BuildBoot : MonoBehaviour
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Option GetOption(string optionName)
|
||||
{
|
||||
return Options.GetValueOrDefault(optionName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭其他选项表现
|
||||
/// </summary>
|
||||
public void OptionDisplay(Option option)
|
||||
{
|
||||
foreach (var optionInfo in Options.Values)
|
||||
{
|
||||
optionInfo.SetOptionActive(option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -52,16 +68,23 @@ public class BuildBoot : MonoBehaviour
|
|||
/// </summary>
|
||||
private class Option
|
||||
{
|
||||
public string Name;
|
||||
public GameObject NodeObj;
|
||||
public GameObject OptionObj;
|
||||
public GameObject NormalObj;
|
||||
|
||||
public Option(GameObject root)
|
||||
{
|
||||
Name = root.name;
|
||||
NodeObj = root.transform.parent.gameObject;
|
||||
OptionObj = root;
|
||||
NormalObj = root.transform.Find("Normal").gameObject;
|
||||
}
|
||||
|
||||
public void SetOptionActive(Option option)
|
||||
{
|
||||
OptionObj.SetActive(Name.Equals(option.Name));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -70,59 +93,65 @@ public class BuildBoot : MonoBehaviour
|
|||
private class BuildBar
|
||||
{
|
||||
private GameObject _bar;
|
||||
public Dictionary<string, BuildItem> buildItem;
|
||||
private Dictionary<string, Transform> itemTrans;
|
||||
private Dictionary<string, BuildItem> _buildItem;
|
||||
private Dictionary<string, Transform> _itemTrans;
|
||||
private TMP_Text _condition;
|
||||
private const string ContentPath = "Bar_Tip/Scroll View/Viewport/Content";
|
||||
private const string IconItemTemplate = "Bar_Tip/Scroll View/Viewport/Content/Item";
|
||||
private const string TipPath = "Bar_Tip";
|
||||
private const string ConditionText = "Level\n{0}/{1}";
|
||||
private const string ItemName = "Item{0}";
|
||||
private Action<Option> _optionCallBack;
|
||||
|
||||
public BuildBar(GameObject root)
|
||||
{
|
||||
_bar = root;
|
||||
_condition = root.transform.Find(TipPath).GetComponent<TMP_Text>();
|
||||
buildItem = new Dictionary<string, BuildItem>();
|
||||
itemTrans = new Dictionary<string, Transform>();
|
||||
_buildItem = new Dictionary<string, BuildItem>();
|
||||
_itemTrans = new Dictionary<string, Transform>();
|
||||
}
|
||||
|
||||
public void Open(Node node, Action callBack, Action lockCallBack, int reachCondition, int condition)
|
||||
public void Open(Node node, Action<Option> callBack, Action lockCallBack, int reachCondition, int condition)
|
||||
{
|
||||
_optionCallBack = callBack;
|
||||
_bar.SetActive(true);
|
||||
_condition.text = string.Format(ConditionText, reachCondition, condition);
|
||||
var content = _bar.transform.Find(ContentPath);
|
||||
var iconTemplate = _bar.transform.Find(IconItemTemplate);
|
||||
|
||||
buildItem.Clear();
|
||||
|
||||
for (var i = 0; i < node.Options.Count; i++)
|
||||
_buildItem.Clear();
|
||||
var index = 1;
|
||||
foreach (var option in node.Options)
|
||||
{
|
||||
var optionName = node.Options[i].OptionObj.name;
|
||||
var iconName = string.Format(ItemName, i + 1);
|
||||
if (!itemTrans.TryGetValue(iconName, out var iconItem))
|
||||
var optionName = option.Value.OptionObj.name;
|
||||
var iconName = string.Format(ItemName, index);
|
||||
if (!_itemTrans.TryGetValue(iconName, out var iconItem))
|
||||
{
|
||||
iconItem = Instantiate(iconTemplate, content);
|
||||
iconItem.name = iconName;
|
||||
itemTrans.Add(iconName, iconItem);
|
||||
_itemTrans.Add(iconName, iconItem);
|
||||
}
|
||||
|
||||
iconItem.gameObject.SetActive(true);
|
||||
var sprite = BuildManager.Instance.GetOptionIcon(node.Name, optionName);
|
||||
var item = new BuildItem(iconItem.gameObject);
|
||||
buildItem.Add(optionName, item);
|
||||
item.SetInfo(sprite, () =>
|
||||
{
|
||||
callBack?.Invoke();
|
||||
PickItemDisplay(optionName);
|
||||
}, lockCallBack);
|
||||
var unlock = reachCondition >= condition;
|
||||
var item = new BuildItem(iconItem.gameObject, option.Value);
|
||||
_buildItem.Add(optionName, item);
|
||||
item.SetInfo(sprite, unlock, ItemCallBack, lockCallBack);
|
||||
index++;
|
||||
//DebugUtil.Log("Bar添加物品Icon:{0}", iconItem.name);
|
||||
}
|
||||
}
|
||||
|
||||
private void PickItemDisplay(string optionName)
|
||||
private void ItemCallBack(Option option)
|
||||
{
|
||||
foreach (var item in buildItem)
|
||||
_optionCallBack?.Invoke(option);
|
||||
PickItemDisplay(option.OptionObj.name);
|
||||
}
|
||||
|
||||
public void PickItemDisplay(string optionName)
|
||||
{
|
||||
foreach (var item in _buildItem)
|
||||
{
|
||||
item.Value.SetPickActive(item.Key.Equals(optionName));
|
||||
}
|
||||
|
@ -131,7 +160,7 @@ public class BuildBoot : MonoBehaviour
|
|||
public void Close()
|
||||
{
|
||||
_bar.SetActive(false);
|
||||
foreach (var item in buildItem)
|
||||
foreach (var item in _buildItem)
|
||||
{
|
||||
item.Value.SetPickActive(false);
|
||||
}
|
||||
|
@ -143,14 +172,16 @@ public class BuildBoot : MonoBehaviour
|
|||
/// </summary>
|
||||
private class BuildItem
|
||||
{
|
||||
public Option Option;
|
||||
private Button _btn;
|
||||
private Button _lockBtn;
|
||||
private Image _imgIcon;
|
||||
private GameObject _lock;
|
||||
private GameObject _imgPick;
|
||||
|
||||
public BuildItem(GameObject root)
|
||||
public BuildItem(GameObject root, Option option)
|
||||
{
|
||||
this.Option = option;
|
||||
_btn = root.transform.Find("Img_Item").GetComponent<Button>();
|
||||
_imgIcon = root.transform.Find("Img_Item").GetComponent<Image>();
|
||||
_lock = root.transform.Find("Img_Lock").gameObject;
|
||||
|
@ -158,15 +189,17 @@ public class BuildBoot : MonoBehaviour
|
|||
_imgPick = root.transform.Find("Bg_Pick").gameObject;
|
||||
}
|
||||
|
||||
public void SetInfo(Sprite sprite, Action callBack, Action lockCallBack)
|
||||
public void SetInfo(Sprite sprite, bool unlock, Action<Option> callBack, Action lockCallBack)
|
||||
{
|
||||
_lock.SetActive(!unlock);
|
||||
_btn.onClick.RemoveAllListeners();
|
||||
_btn.onClick.AddListener(() => { callBack?.Invoke(); });
|
||||
_btn.onClick.AddListener(() => { callBack?.Invoke(Option); });
|
||||
_lockBtn.onClick.RemoveAllListeners();
|
||||
_lockBtn.onClick.AddListener(() => { lockCallBack?.Invoke(); });
|
||||
_imgIcon.sprite = sprite;
|
||||
}
|
||||
|
||||
|
||||
public void SetPickActive(bool pick)
|
||||
{
|
||||
_imgPick.SetActive(pick);
|
||||
|
@ -184,6 +217,10 @@ public class BuildBoot : MonoBehaviour
|
|||
//当前点击的泡泡按钮
|
||||
private GameObject _curBubble;
|
||||
|
||||
//当前选择的选项
|
||||
private Option _curOption;
|
||||
private Node _curNode;
|
||||
|
||||
//当前节点字典
|
||||
private Dictionary<string, Node> _nodes;
|
||||
|
||||
|
@ -192,6 +229,10 @@ public class BuildBoot : MonoBehaviour
|
|||
private Button _btnTipGoGame;
|
||||
private Button _btnTipClose;
|
||||
|
||||
//遮罩
|
||||
private GameObject _mask;
|
||||
private bool _isChanging;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
RegisterClickEvent();
|
||||
|
@ -224,12 +265,13 @@ public class BuildBoot : MonoBehaviour
|
|||
_nodes.Add(child.name, node);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 刷新建造物表现
|
||||
/// </summary>
|
||||
private void UpdateBuildDisplay()
|
||||
{
|
||||
//TODO 加载玩家选择节点
|
||||
foreach (var node in _nodes)
|
||||
{
|
||||
if (BuildManager.Instance.NodeInfos.TryGetValue(node.Key, out var nodeInfo))
|
||||
|
@ -242,7 +284,7 @@ public class BuildBoot : MonoBehaviour
|
|||
{
|
||||
foreach (var option in node.Value.Options)
|
||||
{
|
||||
option.NormalObj.SetActive(false);
|
||||
option.Value.NormalObj.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -263,6 +305,8 @@ public class BuildBoot : MonoBehaviour
|
|||
_btnClose = transform.Find("UIRoot/UIMainBuild/UI_LiuHaiTop/BG_Top/Btn_Close").GetComponent<Button>();
|
||||
_btnClose.onClick.AddListener(CloseBuildPanel);
|
||||
|
||||
_mask = transform.Find("UIRoot/UIMainBuild/Mask").gameObject;
|
||||
|
||||
InitTipPanel();
|
||||
InitBuildBar();
|
||||
}
|
||||
|
@ -325,8 +369,16 @@ public class BuildBoot : MonoBehaviour
|
|||
/// </summary>
|
||||
private void CloseBar()
|
||||
{
|
||||
_isChanging = false;
|
||||
_buildBar.Close();
|
||||
_curBubble.SetActive(true);
|
||||
_mask.SetActive(false);
|
||||
if (_curBubble != null)
|
||||
_curBubble.SetActive(true);
|
||||
//放弃修改
|
||||
if (_curNode == null || _curOption == null) return;
|
||||
_curNode.OptionDisplay(_curOption);
|
||||
_curNode = null;
|
||||
_curOption = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -334,8 +386,12 @@ public class BuildBoot : MonoBehaviour
|
|||
/// </summary>
|
||||
private void YesBar()
|
||||
{
|
||||
DebugUtil.LogError("保存更改");
|
||||
_isChanging = false;
|
||||
_mask.SetActive(false);
|
||||
_buildBar.Close();
|
||||
|
||||
if (_curNode == null || _curOption == null) return;
|
||||
//TODO 保存至本地
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -347,7 +403,26 @@ public class BuildBoot : MonoBehaviour
|
|||
/// </summary>
|
||||
private void OnBuildItemClick(GameObject obj)
|
||||
{
|
||||
DebugUtil.LogError("obj");
|
||||
if (_isChanging) return;
|
||||
_isChanging = true;
|
||||
_mask.SetActive(true);
|
||||
|
||||
var optionObj = obj.transform.parent.gameObject;
|
||||
var nodeName = optionObj.transform.parent.name;
|
||||
var optionName = optionObj.name;
|
||||
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugUtil.LogError("节点获取信息错误: {0}", nodeName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -355,6 +430,9 @@ public class BuildBoot : MonoBehaviour
|
|||
/// </summary>
|
||||
private void OnBuildBubbleClick(GameObject obj)
|
||||
{
|
||||
if (_isChanging) return;
|
||||
_isChanging = true;
|
||||
_mask.SetActive(true);
|
||||
_curBubble = obj;
|
||||
obj.SetActive(false);
|
||||
var nodeName = obj.transform.parent.name;
|
||||
|
@ -372,9 +450,19 @@ public class BuildBoot : MonoBehaviour
|
|||
/// <summary>
|
||||
/// 解锁图标点击
|
||||
/// </summary>
|
||||
private void BuildIconClick()
|
||||
private void BuildIconClick(Option option)
|
||||
{
|
||||
DebugUtil.LogError("点击了图标");
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
//DebugUtil.LogError("点击了{0}节点的{1}选项", nodeName, option.OptionObj.name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -382,6 +470,7 @@ public class BuildBoot : MonoBehaviour
|
|||
/// </summary>
|
||||
private void BuildLockIconClick()
|
||||
{
|
||||
_mask.SetActive(true);
|
||||
DebugUtil.LogError("点击了上锁图标");
|
||||
_tipObj.SetActive(true);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Framework.GameBuild;
|
||||
using PhxhSDK;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using Framework.GameBuild;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
namespace Framework.Manager
|
||||
{
|
||||
|
@ -86,7 +86,7 @@ namespace Framework.Manager
|
|||
public int ID;
|
||||
public string Name;
|
||||
|
||||
public string IconPath;
|
||||
public string IconName;
|
||||
|
||||
//按主题解锁条件
|
||||
public int Condition;
|
||||
|
@ -94,7 +94,11 @@ namespace Framework.Manager
|
|||
|
||||
public class BuildManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 当前选择
|
||||
/// </summary>
|
||||
private const string NodeName = "Node{0}";
|
||||
|
||||
private const string OptionName = "Option{0}";
|
||||
|
||||
private static BuildManager _instance;
|
||||
|
@ -115,6 +119,9 @@ namespace Framework.Manager
|
|||
|
||||
public Dictionary<string, NodeInfo> NodeInfos;
|
||||
|
||||
//动态加载的图标
|
||||
private Dictionary<string, Sprite> _iconSprites;
|
||||
|
||||
private BuildData _curBuildData;
|
||||
private bool _isInit;
|
||||
private bool _isInGame;
|
||||
|
@ -122,7 +129,9 @@ namespace Framework.Manager
|
|||
public void Init(BuildData buildData, bool inGame = true)
|
||||
{
|
||||
if (_isInit) return;
|
||||
|
||||
NodeInfos = new Dictionary<string, NodeInfo>();
|
||||
_iconSprites = new Dictionary<string, Sprite>();
|
||||
_curBuildData = buildData;
|
||||
foreach (var node in buildData.nodeInfos)
|
||||
{
|
||||
|
@ -141,7 +150,7 @@ namespace Framework.Manager
|
|||
ID = index,
|
||||
Name = option
|
||||
};
|
||||
optionInfo.IconPath = InitOptionIconPath(node.IconPath, index);
|
||||
|
||||
nodeInfo.Options.Add(option, optionInfo);
|
||||
}
|
||||
|
||||
|
@ -149,9 +158,23 @@ namespace Framework.Manager
|
|||
}
|
||||
|
||||
InitCondition();
|
||||
InitIcon();
|
||||
_isInit = true;
|
||||
}
|
||||
|
||||
private async void InitIcon()
|
||||
{
|
||||
foreach (var nodeInfo in NodeInfos.Values)
|
||||
{
|
||||
foreach (var optionInfo in nodeInfo.Options.Values)
|
||||
{
|
||||
var index = GameBuildUtils.ExtractNumber(optionInfo.Name);
|
||||
|
||||
optionInfo.IconName = await InitOptionIcon(nodeInfo.IconPath, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化条件
|
||||
/// </summary>
|
||||
|
@ -167,7 +190,7 @@ namespace Framework.Manager
|
|||
if (NodeInfos.TryGetValue(nodeName, out var nodeInfo))
|
||||
{
|
||||
nodeInfo.Condition = unlockInfo.condition;
|
||||
DebugUtil.LogError("挂点解锁:节点{0}的解锁条件是:{1}", nodeInfo.Name, unlockInfo.condition);
|
||||
//DebugUtil.LogError("挂点解锁:节点{0}的解锁条件是:{1}", nodeInfo.Name, unlockInfo.condition);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -199,7 +222,7 @@ namespace Framework.Manager
|
|||
/// <summary>
|
||||
/// 获得选项对应的Icon路径
|
||||
/// </summary>
|
||||
private string InitOptionIconPath(string iconsPath, int index)
|
||||
private async UniTask<string> InitOptionIcon(string iconsPath, int index)
|
||||
{
|
||||
var fileEntries = Directory.GetFiles(iconsPath, "*.png");
|
||||
foreach (var filePath in fileEntries)
|
||||
|
@ -209,7 +232,9 @@ namespace Framework.Manager
|
|||
if (GameBuildUtils.ExtractNumber(name) == index)
|
||||
{
|
||||
var assetPath = filePath.Replace(Application.dataPath, "").Replace('\\', '/');
|
||||
return assetPath;
|
||||
var sprite = await AssetManager.Instance.LoadAssetAsync<Sprite>(assetPath);
|
||||
_iconSprites.TryAdd(name, sprite);
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -225,8 +250,7 @@ namespace Framework.Manager
|
|||
{
|
||||
if (nodeInfo.Options.TryGetValue(optionName, out var optionInfo))
|
||||
{
|
||||
var sprite = AssetManager.Instance.LoadAsset<Sprite>(optionInfo.IconPath);
|
||||
if (sprite != null)
|
||||
if (_iconSprites.TryGetValue(optionInfo.IconName, out var sprite))
|
||||
return sprite;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue