合并类似功能的类,添加相关UI方法,优化代码

main
yurui 2024-03-12 15:34:23 +08:00
parent 265bb90739
commit b28bba93bd
11 changed files with 66 additions and 362 deletions

View File

@ -81,7 +81,8 @@ namespace Framework.Wrapper
{
isDisposed = true;
OnDispose();
_goWrapper?.SetActive(false);
if (_goWrapper != null)
_goWrapper.IsActive = false;
// if (_goWrapper != null) GameplayInfoManager.Instance.UnRegister(_goWrapper.GetInstanceID());
//Utils.Destroy(_goWrapper?.GameObject);
if (_goWrapper != null && _goWrapper.GameObject != null)

View File

@ -67,7 +67,7 @@ namespace Gameplay.Level
{
if (_targetGFX != null)
{
_targetGFX.SetActive(false);
_targetGFX.IsActive = false;
}
_targetInfo = null;
@ -108,11 +108,11 @@ namespace Gameplay.Level
_targetGFX.transform.position = _targetInfo.pos;
_targetGFX.transform.localRotation = Quaternion.identity;
_targetGFX.transform.localScale = Vector3.one;
_targetGFX.SetActive(true);
_targetGFX.IsActive = true;
}
else
{
_targetGFX.SetActive(false);
_targetGFX.IsActive = false;
}
}

View File

@ -297,7 +297,7 @@ namespace Gameplay.Level
renders[i].enabled = true;
OutlineManager.instance.AddRenderer(renders[i], false);
}
selectedCharacter.Node.SetActive(true);
selectedCharacter.Node.IsActive = true;
}
private static async void _SetAnother(GameUnit characterHere,

View File

@ -2,28 +2,29 @@ using System.Collections.Generic;
public class CommandSkillManager
{
/// <summary>
/// 指挥官可以携带的技能数量
/// </summary>
public static readonly int COMMAND_SKILL_COUNT = 3;
/// <summary>
/// 指挥官技能无效id
/// </summary>
public static readonly int NONE_ID = 0;
private readonly List<int> _commandSkillIDs = new List<int> { NONE_ID, NONE_ID, NONE_ID };
private readonly List<int> _commandSkillIDs = new() { NONE_ID, NONE_ID, NONE_ID };
public List<int> CommandSkillIDs => _commandSkillIDs;
public CommandSkillManager(int id0 = 0, int id1 = 0, int id2 = 0)
{
if (id0 > NONE_ID)
{
if(IsIdValid(id0))
_commandSkillIDs[0] = id0;
}
if (id1 > NONE_ID)
{
if (IsIdValid(id0))
_commandSkillIDs[1] = id1;
}
if (id2 > NONE_ID)
{
if (IsIdValid(id0))
_commandSkillIDs[2] = id2;
}
}
public int GetCommandSkillID(int idx)
@ -35,4 +36,13 @@ public class CommandSkillManager
{
_commandSkillIDs[idx] = id;
}
/// <summary>
/// 指挥官技能id是否有效
/// </summary>
/// <returns></returns>
public static bool IsIdValid(int skillId)
{
return skillId > NONE_ID;
}
}

View File

@ -86,8 +86,7 @@ public class TeamEditManager : Singlenton<TeamEditManager>, IInitable
{
var headEmptyImgStr =
"Assets/Art/UI/Texture/UI_Pic_Main/UI_Pic_CultivateAll/UI_Pic_Cultivate/UI_Cultivate_RankPlus.png";
AssetManager.Instance.PostPreload<Sprite>(headEmptyImgStr);
await AssetManager.Instance.PostPreload<Sprite>(headEmptyImgStr);
}
//在管理器内部创建一个成员Team
@ -263,7 +262,7 @@ public class TeamEditManager : Singlenton<TeamEditManager>, IInitable
for (int i = 0; i < charList.Count; i++)
{
var path = CommonUtils.GetDefaultHeadPathByUid(charList[i].Uid);
AssetManager.Instance.PostPreload<Sprite>(path);
await AssetManager.Instance.PostPreload<Sprite>(path);
}
await AssetManager.Instance.WaitAllPreloads();

View File

@ -1,5 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
@ -17,7 +16,6 @@ using Gameplay;
using Constants = Framework.Constants;
using Gameplay.Net;
using cfg.ActorCfg;
using System.Linq;
/// <summary>
/// 队伍和技能选择界面
@ -36,7 +34,7 @@ public class UI_TeamAndSkillSelectController : UIWindow
/// <summary>
/// 队伍
/// </summary>
private class TeamItem : UIBaseItem
private class TeamItem : UIGameObjectWrapper
{
#region UI
/// <summary>
@ -157,7 +155,7 @@ public class UI_TeamAndSkillSelectController : UIWindow
/// <summary>
/// 选中的指挥官技能
/// </summary>
private class UseSkillItem : UIBaseItem
private class UseSkillItem : UIGameObjectWrapper
{
/// <summary>
/// 打开技能选择按钮
@ -218,12 +216,12 @@ public class UI_TeamAndSkillSelectController : UIWindow
/// <summary>
/// 技能选择面板
/// </summary>
private class SelectSkillPanel : UIBaseItem
private class SelectSkillPanel : UIGameObjectWrapper
{
/// <summary>
/// 页签
/// </summary>
private class TabItem : UIBaseItem
private class TabItem : UIGameObjectWrapper
{
#region UI
/// <summary>
@ -304,7 +302,7 @@ public class UI_TeamAndSkillSelectController : UIWindow
/// <summary>
/// 技能
/// </summary>
private class SkillItem : UIBaseItem
private class SkillItem : UIGameObjectWrapper
{
/// <summary>
/// 选中状态
@ -490,20 +488,23 @@ public class UI_TeamAndSkillSelectController : UIWindow
uint[] skillIds = team.GetPlayerSkillIDs();
curSelectSkillID = (int)skillIds[skillIndex];
if (curSelectSkillID == Team.NONE_ID)
if (CommandSkillManager.IsIdValid(curSelectSkillID))
{
List<DataPlayerSkillUpgrade> listCurSkillData = GetCurTapSkillDatas();
if (listCurSkillData == null || listCurSkillData.Count < 1)
return;
curSelectSkillID = listCurSkillData[0].ID;
OnSelectTab(PlayerSkillType.Conduct); // 默认选中指挥系
DataPlayerSkillUpgrade skillUpgradeData = TableManager.Instance.Tables.PlayerSkillUpgrade.Get(curSelectSkillID, 0);
OnSelectTab(skillUpgradeData.SkillType);
}
else
{
DataPlayerSkillUpgrade skillUpgradeData = TableManager.Instance.Tables.PlayerSkillUpgrade.Get(curSelectSkillID, 0);
OnSelectTab(skillUpgradeData.SkillType);
}
List<DataPlayerSkillUpgrade> listCurSkillData = GetSkillDatasByTab(PlayerSkillType.Conduct);
if (listCurSkillData == null || listCurSkillData.Count < 1)
{
DebugUtil.LogError("指挥官技能数据错误");
return;
}
curSelectSkillID = listCurSkillData[0].ID;
OnSelectTab(PlayerSkillType.Conduct); // 默认选中指挥系
}
IsScaleShow = true;
}
@ -521,7 +522,7 @@ public class UI_TeamAndSkillSelectController : UIWindow
dicSkillItem[cell.GetInstanceID()] = skillItem;
}
List<DataPlayerSkillUpgrade> listPlayerSkillData = GetCurTapSkillDatas();
List<DataPlayerSkillUpgrade> listPlayerSkillData = GetSkillDatasByTab(curSelectTab);
if (listPlayerSkillData == null)
return;
@ -539,12 +540,12 @@ public class UI_TeamAndSkillSelectController : UIWindow
}
/// <summary>
/// 获取当前页签对应所有技能数据
/// 获取页签对应所有技能数据
/// </summary>
/// <returns></returns>
private List<DataPlayerSkillUpgrade> GetCurTapSkillDatas()
private List<DataPlayerSkillUpgrade> GetSkillDatasByTab(PlayerSkillType playerSkillType)
{
dicSkillUpgradeData.TryGetValue(curSelectTab, out List<DataPlayerSkillUpgrade> listData);
dicSkillUpgradeData.TryGetValue(playerSkillType, out List<DataPlayerSkillUpgrade> listData);
return listData;
}
@ -555,7 +556,7 @@ public class UI_TeamAndSkillSelectController : UIWindow
/// <returns></returns>
private int GetRecycleListShowCount()
{
List<DataPlayerSkillUpgrade> listSkillData = GetCurTapSkillDatas();
List<DataPlayerSkillUpgrade> listSkillData = GetSkillDatasByTab(curSelectTab);
if (listSkillData == null)
return 0;
@ -661,10 +662,10 @@ public class UI_TeamAndSkillSelectController : UIWindow
/// </summary>
private int curLevelId;
/// <summary>
/// 初始化
/// </summary>
public override void OnInit()
/// <summary>
/// 初始化
/// </summary>
public override void OnInit()
{
TeamAndSkillSelectBinder.GetComponents(this);
@ -755,7 +756,7 @@ public class UI_TeamAndSkillSelectController : UIWindow
if (skills.Length > i)
listSkill[i].SetInfo((int)skills[i]);
else
listSkill[i].SetInfo((int)Team.NONE_ID);
listSkill[i].SetInfo(CommandSkillManager.NONE_ID);
}
}

View File

@ -31,7 +31,7 @@ public class UIDebugShowIDController : UIWindow
public TextMeshProUGUI Text_State;
public UIInfos(GameObject go) : base(go)
public UIInfos(GameObject go) : base(go, true)
{
@ -165,7 +165,7 @@ public class UIDebugShowIDController : UIWindow
{
info.SetActive(false);
info.IsActive = false;
}
@ -187,7 +187,7 @@ public class UIDebugShowIDController : UIWindow
}
infos.SetActive(true);
infos.IsActive = true;
infos.Text_ID.text = $"ID:{id:000000}";

View File

@ -2,18 +2,12 @@
using cfg.PlayerSkillCfg;
using Cysharp.Threading.Tasks;
using Framework;
using Framework.Condition;
using Gameplay;
using Gameplay.Net;
using NLDPB;
using PhxhSDK;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using TGS;
using TMPro;
using UnityEngine;
@ -43,7 +37,7 @@ public class UI_CommandSkillCultivateController : UIWindow
/// <summary>
/// 技能树
/// </summary>
private class SkillTree : UIBaseItem
private class SkillTree : UIGameObjectWrapper
{
/// <summary>
/// 技能树层数修改该值时同时修改prefab
@ -53,7 +47,7 @@ public class UI_CommandSkillCultivateController : UIWindow
/// <summary>
/// 技能树的一层
/// </summary>
private class SkillFloor : UIBaseItem
private class SkillFloor : UIGameObjectWrapper
{
/// <summary>
/// 锁定状态
@ -220,7 +214,7 @@ public class UI_CommandSkillCultivateController : UIWindow
/// <summary>
/// 单个技能
/// </summary>
private class SkillItem : UIBaseItem
private class SkillItem : UIGameObjectWrapper
{
/// <summary>
/// 等级文本解锁显示颜色

View File

@ -1,290 +0,0 @@
using System;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// UI内部类基类
/// </summary>
public abstract class UIBaseItem
{
/// <summary>
/// 根节点
/// </summary>
protected GameObject GoRoot;
/// <summary>
/// 以缩放判定是否显示(缩放比SetActive性能好,优先用这个)
/// </summary>
public bool IsScaleShow
{
get
{
if (GoRoot.transform.localScale.x == 0f)
return false;
if (GoRoot.transform.localScale.y == 0f)
return false;
return true;
}
set
{
GoRoot.IsScaleShow(value);
}
}
/// <summary>
/// 以SetActivex显示隐藏
/// </summary>
public bool IsActive
{
get { return GoRoot.activeSelf; }
set { GoRoot.SetActive(value); }
}
/// <summary>
/// 根据现有实例构造
/// </summary>
/// <param name="root"></param>
/// <param name="isScaleShow"></param>
public UIBaseItem(GameObject root, bool isScaleShow = false)
{
GoRoot = root;
IsScaleShow = isScaleShow;
}
/// <summary>
/// 根据现有实例克隆新的实例并构造
/// </summary>
/// <param name="root"></param>
/// <param name="i"></param>
/// <param name="isScaleShow"></param>
public UIBaseItem(GameObject root, int i, bool isScaleShow = false)
{
GoRoot = UnityEngine.Object.Instantiate(root, root.transform.parent);
GoRoot.name = i.ToString();
IsScaleShow = isScaleShow;
}
#region 绑定方法
public GameObject BindButton(string target, Action action, bool playAudio = true)
{
GameObject obj = GoRoot.transform.Find(target)?.gameObject;
if (obj != null)
{
if (obj.TryGetComponent(out Button button))
{
button.onClick.AddListener(
delegate ()
{
if (playAudio)
{
//AudioManager.Instance.PlaySound(SfxNameConst.button_s);
}
action?.Invoke();
});
}
}
else
DebugUtil.LogError("未找到 {0}/{1}", GoRoot.name, target);
return obj;
}
/// <summary>
/// 增加一个可绑定对应变量的点击事件
/// 传入GameObject
/// </summary>
/// <param name="obj"></param>
/// <param name="action"></param>
/// <param name="playAudio"></param>
/// <returns></returns>
public GameObject BindButton(GameObject obj, Action action, bool playAudio = true)
{
if (obj != null)
{
if (obj.TryGetComponent(out Button button))
{
button.onClick.AddListener(
delegate ()
{
if (playAudio)
{
//AudioManager.Instance.PlaySound(SfxNameConst.button_s);
}
action?.Invoke();
});
}
}
else
DebugUtil.LogError("未找到 {0}/{1}", GoRoot.name, obj.name);
return obj;
}
/// <summary>
/// 传入参数
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <param name="action"></param>
/// <param name="parameter"></param>
/// <param name="playAudio"></param>
/// <returns></returns>
public GameObject BindButton<T>(GameObject obj, Action<T> action, T parameter, bool playAudio = true)
{
if (obj != null)
{
if (obj.TryGetComponent(out Button button))
{
button.onClick.AddListener(
delegate ()
{
if (playAudio)
{
//AudioManager.Instance.PlaySound(SfxNameConst.button_s);
}
action?.Invoke(parameter);
});
}
}
else
DebugUtil.LogError("未找到 {0}/{1}", GoRoot.name, obj.name);
return obj;
}
/// <summary>
/// 直接绑按钮
/// </summary>
/// <param name="button"></param>
/// <param name="action"></param>
/// <param name="playAudio"></param>
/// <returns></returns>
public GameObject BindButton(Button button, Action action, bool playAudio = true)
{
if (button != null)
{
//Button button = button.GetComponent<Button>();
if (button != null)
{
button.onClick.AddListener
(
delegate ()
{
if (playAudio)
{
//AudioManager.Instance.PlaySound(SfxNameConst.button_s);
}
action?.Invoke();
}
);
}
}
else
{
DebugUtil.LogError("传入按钮为空,请检查按钮绑定参数!!!");
//DebugUtil.LogError($"未找到 {gameObject.name}/{button.name}");
return null;
}
return button.gameObject;
}
/// <summary>
/// 可传入参数
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="button"></param>
/// <param name="action"></param>
/// <param name="parameter"></param>
/// <param name="playAudio"></param>
/// <returns></returns>
public GameObject BindButton<T>(Button button, Action<T> action, T parameter, bool playAudio = true)
{
if (button != null)
{
//Button button = obj.GetComponent<Button>();
if (button != null)
{
button.onClick.AddListener
(
delegate ()
{
if (playAudio)
{
//AudioManager.Instance.PlaySound(SfxNameConst.button_s);
}
if (parameter == null)
{
DebugUtil.LogError("=== 传入参数为空! ===");
}
action?.Invoke(parameter);
}
);
}
}
else
{
DebugUtil.LogError("传入按钮为空,请检查按钮绑定参数!!!");
return null;
}
return button.gameObject;
}
public void ClearBind(Button button)
{
if (button != null)
{
button.onClick.RemoveAllListeners();
}
}
public void ClearBind(GameObject go)
{
if (go.TryGetComponent(out Button button))
button.onClick.RemoveAllListeners();
}
public GameObject FindObj(string path)
{
GameObject obj = GoRoot.transform.Find(path)?.gameObject;
if (obj == null)
{
DebugUtil.LogError("未找到 {0}/{1}", GoRoot.name, path);
}
return obj;
}
public T GetComponent<T>(string path = "") where T : Behaviour
{
T component = GoRoot.transform.Find(path)?.GetComponent<T>();
if (component == null)
{
DebugUtil.LogError("未找到组件{0} {1}", typeof(T).Name, path);
}
return component;
}
#endregion
}
public static class GameObjectExtension
{
/// <summary>
/// 修改缩放的方式显示隐藏
/// </summary>
/// <param name="go"></param>
/// <param name="isShow"></param>
public static void IsScaleShow(this GameObject go, bool isShow)
{
if (isShow)
go.transform.localScale = Vector3.one;
else
go.transform.localScale = Vector3.zero;
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f360947ab08f1904da7a5708e8d811a1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -1 +1 @@
Subproject commit a9168438683ab7a1a3d154df80bf48fc5c0d4690
Subproject commit 86d277977c6a3095e6bfd0bc69635a7303fcc12b