mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Init TEngine4.0.0
Init TEngine4.0.0
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3026f5e2510440618f6d4f28b37c5244
|
||||
timeCreated: 1695289286
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6dd993a020654e8bbcc4e70ea0029447
|
||||
timeCreated: 1695289810
|
@@ -0,0 +1,189 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// 红点个体行为
|
||||
/// </summary>
|
||||
public class RedNoteBehaviour : UIWidget
|
||||
{
|
||||
public Action<bool> HaveRedNoteAction;
|
||||
|
||||
//当前红点类型
|
||||
public RedNoteNotify RedNoteNotifyType { get; private set; }
|
||||
|
||||
//启用时当作标记,解决带有ID,创建多个类似条目的情况
|
||||
public readonly List<ulong> IdParamList = new List<ulong>();
|
||||
private readonly List<ulong> _tmpIdParam = new List<ulong>();
|
||||
|
||||
private Image _image;
|
||||
|
||||
private Image Image
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_image == null && gameObject != null)
|
||||
{
|
||||
_image = gameObject.GetComponent<Image>();
|
||||
}
|
||||
return _image;
|
||||
}
|
||||
}
|
||||
|
||||
private Text _text;
|
||||
private Text Text
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_text == null && gameObject != null)
|
||||
{
|
||||
_text = FindChildComponent<Text>(rectTransform, "Text");
|
||||
}
|
||||
return _text;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _state = false;
|
||||
|
||||
/// <summary>
|
||||
/// 当前红点状态。
|
||||
/// </summary>
|
||||
public bool CurState
|
||||
{
|
||||
private set
|
||||
{
|
||||
_state = value;
|
||||
|
||||
if (Image == null)
|
||||
{
|
||||
gameObject.SetActive(_state);
|
||||
return;
|
||||
}
|
||||
|
||||
Color c = Image.color;
|
||||
c.a = _state ? 1f : 0.01f;
|
||||
Image.color = c;
|
||||
|
||||
if (HaveRedNoteAction != null)
|
||||
{
|
||||
HaveRedNoteAction(_state);
|
||||
}
|
||||
}
|
||||
get => _state;
|
||||
}
|
||||
|
||||
|
||||
//设置显示状态
|
||||
public void SetRedNoteState(bool state)
|
||||
{
|
||||
CurState = state;
|
||||
}
|
||||
|
||||
// 设置红点类型
|
||||
public void SetNotifyType(RedNoteNotify notifyType)
|
||||
{
|
||||
_tmpIdParam.Clear();
|
||||
SetNotifyType(notifyType, _tmpIdParam);
|
||||
}
|
||||
|
||||
#region 参数重载
|
||||
public void SetNotifyType(RedNoteNotify notifyType, ulong param1)
|
||||
{
|
||||
_tmpIdParam.Clear();
|
||||
_tmpIdParam.Add(param1);
|
||||
SetNotifyType(notifyType, _tmpIdParam);
|
||||
}
|
||||
|
||||
public void SetNotifyType(RedNoteNotify notifyType, ulong param1, ulong param2)
|
||||
{
|
||||
_tmpIdParam.Clear();
|
||||
_tmpIdParam.Add(param1);
|
||||
_tmpIdParam.Add(param2);
|
||||
SetNotifyType(notifyType, _tmpIdParam);
|
||||
}
|
||||
|
||||
public void SetNotifyType(RedNoteNotify notifyType, ulong param1, ulong param2, ulong param3)
|
||||
{
|
||||
_tmpIdParam.Clear();
|
||||
_tmpIdParam.Add(param1);
|
||||
_tmpIdParam.Add(param2);
|
||||
_tmpIdParam.Add(param3);
|
||||
SetNotifyType(notifyType, _tmpIdParam);
|
||||
}
|
||||
|
||||
public void SetNotifyType(RedNoteNotify notifyType, params ulong[] param)
|
||||
{
|
||||
_tmpIdParam.Clear();
|
||||
for (int i = 0; i < param.Length; i++)
|
||||
{
|
||||
_tmpIdParam.Add(param[i]);
|
||||
}
|
||||
SetNotifyType(notifyType, _tmpIdParam);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void SetNotifyType(RedNoteNotify notifyType, List<ulong> paramList)
|
||||
{
|
||||
RemoveNotifyBind();
|
||||
if (notifyType == RedNoteNotify.None) return;
|
||||
|
||||
IdParamList.Clear();
|
||||
IdParamList.AddRange(paramList);
|
||||
SetRedNoteNotifyProcess(notifyType);
|
||||
}
|
||||
|
||||
private void SetRedNoteNotifyProcess(RedNoteNotify notifyType)
|
||||
{
|
||||
// 移除红点通知的绑定
|
||||
if (Image != null)
|
||||
{
|
||||
Image.rectTransform.SetAsLastSibling();
|
||||
}
|
||||
|
||||
RedNoteNotifyType = notifyType;
|
||||
|
||||
RedNoteMgr.Instance.RegisterNotify(RedNoteNotifyType, this);
|
||||
|
||||
if (!RedNoteMgr.Instance.IsNumType(notifyType, IdParamList))
|
||||
{
|
||||
CurState = RedNoteMgr.Instance.GetNotifyValue(RedNoteNotifyType, IdParamList);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetRedNotePointNum(RedNoteMgr.Instance.GetNotifyPointNum(RedNoteNotifyType, IdParamList));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除红点通知的绑定。
|
||||
/// </summary>
|
||||
public void RemoveNotifyBind()
|
||||
{
|
||||
if (RedNoteNotifyType != RedNoteNotify.None)
|
||||
{
|
||||
RedNoteMgr.Instance.UnRegisterNotify(RedNoteNotifyType, this);
|
||||
}
|
||||
|
||||
CurState = false;
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
RemoveNotifyBind();
|
||||
}
|
||||
|
||||
public void SetRedNotePointNum(int pointNum)
|
||||
{
|
||||
if (Text != null)
|
||||
{
|
||||
Text.text = pointNum > 0 ? pointNum.ToString() : string.Empty;
|
||||
|
||||
CurState = pointNum > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dba30ea267ff4b988310dec14c0df1c3
|
||||
timeCreated: 1687263893
|
@@ -0,0 +1,85 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary> 红点关联 </summary>
|
||||
public class RedNoteCheckMgr
|
||||
{
|
||||
public string m_ownerStr;
|
||||
public List<string> m_childList { get; private set; }
|
||||
|
||||
public RedNoteCheckMgr(RedNoteNotify ower, List<RedNoteNotify> childList)
|
||||
{
|
||||
m_ownerStr = ower.ToString();
|
||||
m_childList = new List<string>();
|
||||
for (int i = 0; i < childList.Count; i++)
|
||||
{
|
||||
var value = childList[i];
|
||||
m_childList.Add(value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public RedNoteCheckMgr(string paramKey)
|
||||
{
|
||||
m_ownerStr = paramKey;
|
||||
}
|
||||
|
||||
public bool AddChild(string childKey)
|
||||
{
|
||||
if (m_childList == null)
|
||||
{
|
||||
m_childList = new List<string>();
|
||||
}
|
||||
if (!m_childList.Contains(childKey))
|
||||
{
|
||||
m_childList.Add(childKey);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void CheckChildRedNote()
|
||||
{
|
||||
var valueItem = RedNoteMgr.Instance.GetNotifyValueItem(m_ownerStr);
|
||||
|
||||
bool childHaveRed = false;
|
||||
int childNotePointNum = 0;
|
||||
|
||||
int count = m_childList.Count;
|
||||
for (var index = 0; index < count; index++)
|
||||
{
|
||||
var child = m_childList[index];
|
||||
var childItem = RedNoteMgr.Instance.GetNotifyValueItem(child);
|
||||
if (childItem.GetRedNoteType() == RedNoteType.Simple)
|
||||
{
|
||||
if (RedNoteMgr.Instance.GetNotifyValue(child))
|
||||
{
|
||||
childHaveRed = true;
|
||||
childNotePointNum++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
childNotePointNum += childItem.GetRedNotePointNum();
|
||||
}
|
||||
}
|
||||
|
||||
if (valueItem.GetRedNoteType() == RedNoteType.Simple)
|
||||
{
|
||||
RedNoteMgr.Instance.SetNotifyKeyValue(m_ownerStr, childHaveRed);
|
||||
}
|
||||
else
|
||||
{
|
||||
RedNoteMgr.Instance.SetNotifyKeyPointNum(m_ownerStr, childNotePointNum);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool CheckChild(string childKey)
|
||||
{
|
||||
bool red = RedNoteMgr.Instance.GetNotifyValue(childKey);
|
||||
return red;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3dd181174bbf408e9932a6f9484e41a5
|
||||
timeCreated: 1687263893
|
@@ -0,0 +1,669 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GameBase;
|
||||
using GameLogic;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
#region 红点添加步骤
|
||||
|
||||
/// 1,增加RedNoteNotify定义,加入新的红点枚举。
|
||||
/// 2,添加红点关联,关联定义在InitRelation,查看当前有的关联关系,确定是增加还是重新创建
|
||||
/// 3,把RedNoteBehaviour挂在红点图片上,红点图片一般放置在需要显示红点的按钮/页签上,设置脚本上的枚举类型
|
||||
/// 4,如果是带参数的红点类型,在红点所在的UI声明红点对象,对参数进行设置,参数统一为uint,一般用一个可以唯一区分的ID。
|
||||
/// 有多个参数时,每后一个参数节点都是前一个参数的子节点。 无参数为该层级的根节点。
|
||||
/// 5,红点激活/隐藏
|
||||
/// 在对应模块数据管理类中,检测达到红点激活条件,或红点消失条件,调用SetNotifyValue激活/隐藏红点
|
||||
#endregion
|
||||
|
||||
public enum RedNoteNotify
|
||||
{
|
||||
None = 0,
|
||||
CharacterMain,
|
||||
ShopMain,
|
||||
BagMain,
|
||||
BagUseType,
|
||||
ExploreMain,
|
||||
HomeUI,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 红点指引
|
||||
/// </summary>
|
||||
public class RedNoteMgr : Singleton<RedNoteMgr>
|
||||
{
|
||||
//红点状态记录
|
||||
private Dictionary<string, RedNoteValueItem> _notifyMap;
|
||||
|
||||
//红点关联
|
||||
private readonly Dictionary<string, RedNoteCheckMgr> _checkDic = new Dictionary<string, RedNoteCheckMgr>();
|
||||
|
||||
/// <summary>
|
||||
/// child to parent list
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, List<string>> _checkOwnDic = new Dictionary<string, List<string>>();
|
||||
|
||||
private readonly Dictionary<string, RedNoteKeyStruct> _keyConvertDic = new Dictionary<string, RedNoteKeyStruct>();
|
||||
private readonly Dictionary<string, RedNoteStructDic> _keyDic = new Dictionary<string, RedNoteStructDic>();
|
||||
|
||||
/// <summary>
|
||||
/// 红点映射
|
||||
/// key => 红点名称
|
||||
/// val => 对应的红点类型
|
||||
/// </summary>
|
||||
private Dictionary<string, RedNoteNotify> _dicRedNoteMap;
|
||||
|
||||
private Dictionary<int, string> _notifyStringMap;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
InitState();
|
||||
InitRedNoteConfig();
|
||||
InitRelation();
|
||||
InitRedNoteTween();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全局缓动缩放
|
||||
/// </summary>
|
||||
public Vector3 GlobalTwScale { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// 初始化红点缓动
|
||||
/// </summary>
|
||||
private void InitRedNoteTween()
|
||||
{
|
||||
// LeanTween.value(LeanTween.tweenEmpty, OnRedNoteTween, 1f, 0.75f, 0.5f).setLoopPingPong();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 缓动
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
private void OnRedNoteTween(float value)
|
||||
{
|
||||
GlobalTwScale = value * Vector3.one;
|
||||
}
|
||||
|
||||
//注册红点通知
|
||||
public void RegisterNotify(RedNoteNotify notify, RedNoteBehaviour redNote)
|
||||
{
|
||||
RedNoteValueItem redNoteValueItem = GetOrNewNotifyValueItem(notify, redNote.IdParamList);
|
||||
redNoteValueItem.AddRedNote(redNote);
|
||||
}
|
||||
|
||||
//销毁红点通知
|
||||
public void UnRegisterNotify(RedNoteNotify notify, RedNoteBehaviour redNote)
|
||||
{
|
||||
RedNoteValueItem redNoteValueItem = GetOrNewNotifyValueItem(notify, redNote.IdParamList);
|
||||
if (redNoteValueItem == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
redNoteValueItem.RemoveRedNote(redNote);
|
||||
}
|
||||
|
||||
private readonly List<ulong> _tmpRedNoteParams = new List<ulong>();
|
||||
|
||||
/// <summary>
|
||||
/// 设置红点状态。
|
||||
/// </summary>
|
||||
/// <param name="notify"></param>
|
||||
/// <param name="value"></param>
|
||||
public void SetNotifyValue(RedNoteNotify notify, bool value)
|
||||
{
|
||||
_tmpRedNoteParams.Clear();
|
||||
SetNotifyValue(notify, value, _tmpRedNoteParams);
|
||||
}
|
||||
|
||||
#region 参数重载 bool
|
||||
|
||||
public void SetNotifyValue(RedNoteNotify notify, bool value, ulong param1)
|
||||
{
|
||||
_tmpRedNoteParams.Clear();
|
||||
_tmpRedNoteParams.Add(param1);
|
||||
SetNotifyValue(notify, value, _tmpRedNoteParams);
|
||||
}
|
||||
|
||||
public void SetNotifyValue(RedNoteNotify notify, bool value, ulong param1, ulong param2)
|
||||
{
|
||||
_tmpRedNoteParams.Clear();
|
||||
_tmpRedNoteParams.Add(param1);
|
||||
_tmpRedNoteParams.Add(param2);
|
||||
SetNotifyValue(notify, value, _tmpRedNoteParams);
|
||||
}
|
||||
|
||||
public void SetNotifyValue(RedNoteNotify notify, bool value, params ulong[] param)
|
||||
{
|
||||
_tmpRedNoteParams.Clear();
|
||||
for (var i = 0; i < param.Length; i++)
|
||||
{
|
||||
_tmpRedNoteParams.Add(param[i]);
|
||||
}
|
||||
|
||||
SetNotifyValue(notify, value, _tmpRedNoteParams);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void SetNotifyValue(RedNoteNotify notify, bool value, List<ulong> redNoteParamList)
|
||||
{
|
||||
var key = BuildKey(notify, redNoteParamList);
|
||||
if (!value && !_notifyMap.TryGetValue(key, out var redNoteValueItem))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GetOrNewNotifyValueItem(notify, redNoteParamList);
|
||||
MarkNotifyKeyValueDirty(key, value);
|
||||
}
|
||||
|
||||
public void MarkNotifyKeyValueDirty(string key, bool value)
|
||||
{
|
||||
if (!_notifyMap.TryGetValue(key, out var redNoteValueItem))
|
||||
{
|
||||
return;
|
||||
}
|
||||
redNoteValueItem.SetStateDirty(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置红点状态。
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
public void SetNotifyKeyValue(string key, bool value)
|
||||
{
|
||||
if (!_notifyMap.TryGetValue(key, out var redNoteValueItem))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//设置红点状态
|
||||
if (redNoteValueItem.SetRedNoteState(value))
|
||||
{
|
||||
//设置红点关联状态
|
||||
CalcRedNoteRelation(key);
|
||||
}
|
||||
}
|
||||
|
||||
//设置红点状态数量
|
||||
public void SetNotifyKeyPointNum(string key, int pointNum)
|
||||
{
|
||||
if (!_notifyMap.TryGetValue(key, out var redNoteValueItem))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (redNoteValueItem.SetRedNotePoint(pointNum))
|
||||
{
|
||||
//设置红点关联状态
|
||||
CalcRedNoteRelation(key);
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetNotifyValue(RedNoteNotify notify, ulong param1)
|
||||
{
|
||||
_tmpRedNoteParams.Clear();
|
||||
_tmpRedNoteParams.Add(param1);
|
||||
return GetNotifyValue(notify, _tmpRedNoteParams);
|
||||
}
|
||||
|
||||
public bool GetNotifyValue(RedNoteNotify notify, ulong param1, ulong param2)
|
||||
{
|
||||
_tmpRedNoteParams.Clear();
|
||||
_tmpRedNoteParams.Add(param1);
|
||||
_tmpRedNoteParams.Add(param2);
|
||||
return GetNotifyValue(notify, _tmpRedNoteParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取红点状态。
|
||||
/// </summary>
|
||||
/// <param name="notify"></param>
|
||||
/// <param name="param"></param>
|
||||
/// <returns></returns>
|
||||
public bool GetNotifyValue(RedNoteNotify notify, List<ulong> param = null)
|
||||
{
|
||||
if (notify == (uint)RedNoteNotify.None)
|
||||
return false;
|
||||
|
||||
RedNoteValueItem item = GetOrNewNotifyValueItem(notify, param);
|
||||
return item.GetRedNoteState();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取红点数量。
|
||||
/// </summary>
|
||||
/// <param name="notify"></param>
|
||||
/// <param name="param"></param>
|
||||
/// <returns></returns>
|
||||
public int GetNotifyPointNum(RedNoteNotify notify, List<ulong> param)
|
||||
{
|
||||
if (notify == (uint)RedNoteNotify.None)
|
||||
return 0;
|
||||
|
||||
RedNoteValueItem item = GetOrNewNotifyValueItem(notify, param);
|
||||
return item.GetRedNotePointNum();
|
||||
}
|
||||
|
||||
public bool GetNotifyValue(string paramKey)
|
||||
{
|
||||
if (_notifyMap.TryGetValue(paramKey, out var redNoteValueItem))
|
||||
{
|
||||
return redNoteValueItem.GetRedNoteState();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理红点状态.
|
||||
/// </summary>
|
||||
/// <param name="notify"></param>
|
||||
public void ClearNotifyValue(RedNoteNotify notify)
|
||||
{
|
||||
var notifyStr = NotifyTypeToString(notify);
|
||||
RecursiveClearNotifyKeyValue(notifyStr);
|
||||
|
||||
RedNoteValueItem redNoteValueItem = GetNotifyValueItem(notifyStr);
|
||||
redNoteValueItem.ClearRedNoteState(false);
|
||||
CalcRedNoteRelation(notifyStr);
|
||||
}
|
||||
|
||||
public void RecursiveClearNotifyKeyValue(string key)
|
||||
{
|
||||
if (!_checkDic.TryGetValue(key, out var checkMgr))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var childList = checkMgr.m_childList;
|
||||
foreach (var childKey in childList)
|
||||
{
|
||||
RedNoteValueItem redNoteValueItem = GetNotifyValueItem(childKey);
|
||||
redNoteValueItem.ClearRedNoteState(false);
|
||||
|
||||
RecursiveClearNotifyKeyValue(childKey);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理数据。
|
||||
/// </summary>
|
||||
public void OnRoleLogout()
|
||||
{
|
||||
var enumerator = _notifyMap.GetEnumerator();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
enumerator.Current.Value.ClearRedNoteState(true);
|
||||
}
|
||||
|
||||
enumerator.Dispose();
|
||||
}
|
||||
|
||||
public string NotifyTypeToString(RedNoteNotify notify)
|
||||
{
|
||||
_notifyStringMap.TryGetValue((int)notify, out var str);
|
||||
return str;
|
||||
}
|
||||
|
||||
public string BuildKey(RedNoteNotify notifyType, List<ulong> paramList)
|
||||
{
|
||||
var notifyStr = NotifyTypeToString(notifyType);
|
||||
if (notifyStr == null)
|
||||
{
|
||||
Log.Error("RedNoteNotifyId :{0} Not Exit! Please Check", notifyType.ToString());
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (!_keyDic.TryGetValue(notifyStr, out var dicData))
|
||||
{
|
||||
dicData = new RedNoteStructDic();
|
||||
_keyDic[notifyStr] = dicData;
|
||||
}
|
||||
|
||||
var key = dicData.TryGetKey(notifyStr, paramList);
|
||||
return key;
|
||||
}
|
||||
|
||||
public static string GetKeyString(string notify, List<ulong> paramList)
|
||||
{
|
||||
if (paramList == null || paramList.Count == 0)
|
||||
{
|
||||
return notify;
|
||||
}
|
||||
|
||||
string key;
|
||||
if (paramList.Count <= 1)
|
||||
{
|
||||
key = $"{notify}-{paramList[0]}";
|
||||
}
|
||||
else if (paramList.Count <= 2)
|
||||
{
|
||||
key = $"{notify}-{paramList[0]}-{paramList[1]}";
|
||||
}
|
||||
else if (paramList.Count <= 3)
|
||||
{
|
||||
key = $"{notify}-{paramList[0]}-{paramList[1]}-{paramList[2]}";
|
||||
}
|
||||
else
|
||||
{
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.Append(notify + "-");
|
||||
for (var i = 0; i < paramList.Count; i++)
|
||||
{
|
||||
s.Append(paramList[i]);
|
||||
if (i != paramList.Count - 1)
|
||||
s.Append("-");
|
||||
}
|
||||
|
||||
key = s.ToString();
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
public void SetKeyConvertDic(string key, RedNoteKeyStruct keyStruct)
|
||||
{
|
||||
_keyConvertDic[key] = keyStruct;
|
||||
}
|
||||
|
||||
private readonly List<ulong> _tmpParamList = new List<ulong>();
|
||||
|
||||
/// <summary>
|
||||
/// 计算红点关联.
|
||||
/// </summary>
|
||||
/// <param name="notifyKey"></param>
|
||||
private void CalcRedNoteRelation(string notifyKey)
|
||||
{
|
||||
var key = notifyKey;
|
||||
if (_checkOwnDic.TryGetValue(key, out var ownerList))
|
||||
{
|
||||
foreach (var owner in ownerList)
|
||||
{
|
||||
if (_checkDic.TryGetValue(owner, out var checker))
|
||||
{
|
||||
checker.CheckChildRedNote();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化红点状态.
|
||||
/// </summary>
|
||||
private void InitState()
|
||||
{
|
||||
var array = (RedNoteNotify[])Enum.GetValues(typeof(RedNoteNotify));
|
||||
|
||||
var redNoteCnt = array.Length;
|
||||
_notifyMap = new Dictionary<string, RedNoteValueItem>();
|
||||
_dicRedNoteMap = new Dictionary<string, RedNoteNotify>(redNoteCnt);
|
||||
_notifyStringMap = new Dictionary<int, string>(redNoteCnt);
|
||||
|
||||
foreach (var redNoteNotify in array)
|
||||
{
|
||||
var redNoteStr = redNoteNotify.ToString();
|
||||
_dicRedNoteMap.Add(redNoteStr, redNoteNotify);
|
||||
_notifyStringMap.Add((int)redNoteNotify, redNoteStr);
|
||||
|
||||
var key = BuildKey(redNoteNotify, _tmpParamList);
|
||||
var redNoteValueItem = new RedNoteValueItem();
|
||||
bool isNumType = IsNumType(redNoteNotify, null);
|
||||
redNoteValueItem.Init(key, isNumType ? RedNoteType.WithNum : RedNoteType.Simple);
|
||||
_notifyMap.Add(key, redNoteValueItem);
|
||||
}
|
||||
}
|
||||
|
||||
public RedNoteValueItem GetNotifyValueItem(string key)
|
||||
{
|
||||
_notifyMap.TryGetValue(key, out var redNoteValueItem);
|
||||
return redNoteValueItem;
|
||||
}
|
||||
|
||||
private RedNoteValueItem GetOrNewNotifyValueItem(RedNoteNotify notify, List<ulong> paramList)
|
||||
{
|
||||
var key = BuildKey(notify, paramList);
|
||||
var redNoteValueItem = GetNotifyValueItem(key);
|
||||
|
||||
if (redNoteValueItem == null)
|
||||
{
|
||||
List<ulong> tmpParamList = new List<ulong>(paramList);
|
||||
|
||||
//从后往前创建item,如(A, 1, 2)会创建A-1-2,A-1,A。
|
||||
string lastChildKey = string.Empty;
|
||||
int paramIndex = paramList.Count;
|
||||
while (paramIndex >= 0)
|
||||
{
|
||||
var keyStr = BuildKey(notify, tmpParamList);
|
||||
|
||||
if (!_notifyMap.ContainsKey(keyStr))
|
||||
{
|
||||
RedNoteValueItem noteValueItem = new RedNoteValueItem();
|
||||
bool isNumType = IsNumType(notify, paramList);
|
||||
noteValueItem.Init(keyStr, isNumType ? RedNoteType.WithNum : RedNoteType.Simple);
|
||||
_notifyMap.Add(keyStr, noteValueItem);
|
||||
}
|
||||
|
||||
//叶子节点跳过(因为他没有子节点)
|
||||
if (tmpParamList.Count < paramList.Count)
|
||||
{
|
||||
bool addedChild;
|
||||
if (!_checkDic.TryGetValue(keyStr, out var checkMgr))
|
||||
{
|
||||
checkMgr = new RedNoteCheckMgr(keyStr);
|
||||
addedChild = checkMgr.AddChild(lastChildKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
addedChild = checkMgr.AddChild(lastChildKey);
|
||||
}
|
||||
|
||||
if (addedChild)
|
||||
{
|
||||
AddDic(checkMgr); //重新生成父子关系
|
||||
}
|
||||
}
|
||||
|
||||
lastChildKey = keyStr;
|
||||
paramIndex--;
|
||||
if (paramIndex < tmpParamList.Count && tmpParamList.Count > 0)
|
||||
{
|
||||
tmpParamList.RemoveAt(paramIndex);
|
||||
}
|
||||
}
|
||||
|
||||
redNoteValueItem = _notifyMap[key];
|
||||
}
|
||||
|
||||
return redNoteValueItem;
|
||||
}
|
||||
|
||||
public void AddDic(RedNoteNotify owner, List<RedNoteNotify> childList)
|
||||
{
|
||||
AddDic(new RedNoteCheckMgr(owner, childList));
|
||||
}
|
||||
|
||||
private void AddDic(RedNoteCheckMgr checker)
|
||||
{
|
||||
var owner = checker.m_ownerStr;
|
||||
_checkDic[owner] = checker;
|
||||
|
||||
var childList = checker.m_childList;
|
||||
int count = childList.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var child = childList[i];
|
||||
if (!_checkOwnDic.TryGetValue(child, out var ownerList))
|
||||
{
|
||||
ownerList = new List<string>();
|
||||
_checkOwnDic[child] = ownerList;
|
||||
}
|
||||
|
||||
if (!ownerList.Contains(owner))
|
||||
{
|
||||
ownerList.Add(owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsNumType(RedNoteNotify noteNotify, List<ulong> paramList)
|
||||
{
|
||||
if (paramList is { Count: > 0 })
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 通过名字获取红点类型
|
||||
public static RedNoteNotify GetRedNoteByName(string redNoteName)
|
||||
{
|
||||
Instance._dicRedNoteMap.TryGetValue(redNoteName, out var redNote);
|
||||
|
||||
return redNote;
|
||||
}
|
||||
|
||||
public void OnUpdate()
|
||||
{
|
||||
foreach (var redNoteValueItem in _notifyMap)
|
||||
{
|
||||
redNoteValueItem.Value.CheckDirty();
|
||||
}
|
||||
}
|
||||
|
||||
#region 初始化红点
|
||||
|
||||
/// <summary>
|
||||
/// 初始化红点配置表
|
||||
/// </summary>
|
||||
private void InitRedNoteConfig()
|
||||
{
|
||||
// ResDictionaryList<uint, RedNoteConfig> cfgs = new ResDictionaryList<uint, RedNoteConfig>();
|
||||
// cfgs.Init(val => val.RedNoteParentID);
|
||||
// List<RedNoteNotify> list = new List<RedNoteNotify>();
|
||||
// foreach (var kv in cfgs.Data)
|
||||
// {
|
||||
// list.Clear();
|
||||
// foreach (var cfg in kv.Value)
|
||||
// {
|
||||
// list.Add((RedNoteNotify)cfg.RedNoteID);
|
||||
// }
|
||||
//
|
||||
// AddDic((RedNoteNotify)kv.Key, list);
|
||||
// }
|
||||
}
|
||||
|
||||
//初始化红点关联
|
||||
private void InitRelation()
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
public class RedNoteStructDic
|
||||
{
|
||||
private readonly List<RedNoteKeyStruct> _keyStructList = new List<RedNoteKeyStruct>();
|
||||
|
||||
public string TryGetKey(string notify, List<ulong> paramList)
|
||||
{
|
||||
string key = string.Empty;
|
||||
List<RedNoteKeyStruct> list = _keyStructList;
|
||||
{
|
||||
int count = list.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var keyStruct = list[i];
|
||||
if (keyStruct.IsSame(notify, paramList))
|
||||
{
|
||||
key = keyStruct.Key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
var keyStruct = new RedNoteKeyStruct(notify, paramList);
|
||||
key = keyStruct.Key;
|
||||
RedNoteMgr.Instance.SetKeyConvertDic(key, keyStruct);
|
||||
list.Add(keyStruct);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
public class RedNoteKeyStruct
|
||||
{
|
||||
public string Notify;
|
||||
public List<ulong> ParamList;
|
||||
|
||||
public RedNoteKeyStruct(string notify, List<ulong> paramList)
|
||||
{
|
||||
Notify = notify;
|
||||
if (paramList != null)
|
||||
{
|
||||
ParamList = new List<ulong>(paramList);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParamList = new List<ulong>();
|
||||
}
|
||||
}
|
||||
|
||||
private string _key;
|
||||
|
||||
public string Key
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_key))
|
||||
{
|
||||
_key = RedNoteMgr.GetKeyString(Notify, ParamList);
|
||||
}
|
||||
return _key;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSame(string notify, List<ulong> paramList)
|
||||
{
|
||||
if (notify != Notify)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var list1 = paramList;
|
||||
var list2 = ParamList;
|
||||
|
||||
int cnt1 = list1?.Count ?? 0;
|
||||
int cnt2 = list2?.Count ?? 0;
|
||||
|
||||
if (cnt1 != cnt2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cnt1 == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < cnt1; i++)
|
||||
{
|
||||
// ReSharper disable PossibleNullReferenceException
|
||||
if (list1[i] != list2[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66ededab0a1e409588f150be58193032
|
||||
timeCreated: 1687263893
|
@@ -0,0 +1,159 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public class RedNoteValueItem
|
||||
{
|
||||
public string m_key;
|
||||
//所有关联的红点UI
|
||||
private HashSet<RedNoteBehaviour> m_redNoteDic = new HashSet<RedNoteBehaviour>();
|
||||
private bool m_state;
|
||||
private int m_pointNum;
|
||||
private RedNoteType m_noteType;
|
||||
|
||||
private bool m_dirty;
|
||||
private bool m_tmpState;
|
||||
|
||||
public void Init(string keyStr, RedNoteType noteType)
|
||||
{
|
||||
m_key = keyStr;
|
||||
m_noteType = noteType;
|
||||
}
|
||||
|
||||
//添加红点对象
|
||||
public void AddRedNote(RedNoteBehaviour redNote)
|
||||
{
|
||||
m_redNoteDic.Add(redNote);
|
||||
}
|
||||
|
||||
//移除对象
|
||||
public void RemoveRedNote(RedNoteBehaviour redNote)
|
||||
{
|
||||
m_redNoteDic.Remove(redNote);
|
||||
}
|
||||
|
||||
//获取具体对象的状态
|
||||
public bool GetRedNoteState()
|
||||
{
|
||||
if (m_dirty)
|
||||
{
|
||||
return m_tmpState;
|
||||
}
|
||||
|
||||
return m_state;
|
||||
}
|
||||
|
||||
//获取具体对象的红点数
|
||||
public int GetRedNotePointNum()
|
||||
{
|
||||
return m_pointNum;
|
||||
}
|
||||
|
||||
public RedNoteType GetRedNoteType()
|
||||
{
|
||||
return m_noteType;
|
||||
}
|
||||
|
||||
public void SetStateDirty(bool state)
|
||||
{
|
||||
m_dirty = m_state != state;
|
||||
m_tmpState = state;
|
||||
}
|
||||
|
||||
//设置对象状态
|
||||
public bool SetRedNoteState(bool state)
|
||||
{
|
||||
bool chg = state != m_state;
|
||||
m_state = state;
|
||||
if (chg)
|
||||
{
|
||||
SetBehaviourState(state);
|
||||
}
|
||||
|
||||
return chg;
|
||||
}
|
||||
|
||||
public bool SetRedNotePoint(int num)
|
||||
{
|
||||
if (m_pointNum != num)
|
||||
{
|
||||
m_pointNum = num;
|
||||
SetBehaviourPoint(num);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void SetBehaviourState(bool state)
|
||||
{
|
||||
//检查是否注册过具体对象
|
||||
foreach (var redNote in m_redNoteDic)
|
||||
{
|
||||
if (redNote == null || redNote.gameObject == null)
|
||||
continue;
|
||||
|
||||
redNote.SetRedNoteState(state);
|
||||
}
|
||||
|
||||
// 移除空的红点
|
||||
ClearTheNullRedNote();
|
||||
}
|
||||
|
||||
private void SetBehaviourPoint(int pointNum)
|
||||
{
|
||||
foreach (var redNote in m_redNoteDic)
|
||||
{
|
||||
if (redNote == null || redNote.gameObject == null)
|
||||
continue;
|
||||
|
||||
redNote.SetRedNotePointNum(pointNum);
|
||||
}
|
||||
|
||||
// 移除空的红点
|
||||
ClearTheNullRedNote();
|
||||
}
|
||||
|
||||
// 移除空的红点
|
||||
private void ClearTheNullRedNote()
|
||||
{
|
||||
m_redNoteDic.RemoveWhere(redNote => redNote == null || redNote.gameObject == null);
|
||||
}
|
||||
|
||||
//清理状态
|
||||
public void ClearRedNoteState(bool clearBehavior)
|
||||
{
|
||||
foreach (var redNote in m_redNoteDic)
|
||||
{
|
||||
if (redNote != null)
|
||||
{
|
||||
redNote.SetRedNoteState(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (clearBehavior)
|
||||
{
|
||||
m_redNoteDic.Clear();
|
||||
}
|
||||
|
||||
m_state = false;
|
||||
m_dirty = false;
|
||||
m_tmpState = false;
|
||||
}
|
||||
|
||||
public void CheckDirty()
|
||||
{
|
||||
if (m_dirty)
|
||||
{
|
||||
m_dirty = false;
|
||||
RedNoteMgr.Instance.SetNotifyKeyValue(m_key, m_tmpState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum RedNoteType
|
||||
{
|
||||
Simple,
|
||||
WithNum,
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c29f4a552c34bd8ab9d2c64b5b2b49d
|
||||
timeCreated: 1687263893
|
@@ -0,0 +1,58 @@
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public class RedNoteWidget : UIWidget
|
||||
{
|
||||
#region 脚本工具生成的代码
|
||||
public override void ScriptGenerator()
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
private Image m_image;
|
||||
public RedNoteBehaviour m_redNote;
|
||||
public override void OnCreate()
|
||||
{
|
||||
m_redNote = CreateWidget<RedNoteBehaviour>(gameObject);
|
||||
m_image = gameObject.GetComponent<Image>();
|
||||
rectTransform.anchoredPosition = Vector2.zero;
|
||||
SetNotifyState(false);
|
||||
}
|
||||
|
||||
public void SetNotifyType(RedNoteNotify notifyType)
|
||||
{
|
||||
m_redNote.SetNotifyType(notifyType);
|
||||
}
|
||||
public void SetNotifyType(RedNoteNotify notifyType, ulong param1)
|
||||
{
|
||||
m_redNote.SetNotifyType(notifyType, param1);
|
||||
}
|
||||
public void SetNotifyType(RedNoteNotify notifyType, ulong param1, ulong param2)
|
||||
{
|
||||
m_redNote.SetNotifyType(notifyType, param1, param2);
|
||||
}
|
||||
|
||||
public void SetNotifyState(bool state)
|
||||
{
|
||||
m_redNote.SetRedNoteState(state);
|
||||
}
|
||||
|
||||
public void SetSprite(string sprite)
|
||||
{
|
||||
m_image.sprite = LoadAsset<Sprite>(sprite);
|
||||
m_image.SetNativeSize();
|
||||
}
|
||||
|
||||
public override void OnUpdate()
|
||||
{
|
||||
/*if (!m_redNote.CurState)
|
||||
{
|
||||
return;
|
||||
}
|
||||
gameObject.transform.localScale = RedNoteMgr.Instance.GlobalTwScale;*/
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2644c5700a07442a995008ee9fa8159d
|
||||
timeCreated: 1695289825
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a214e54975b4d7da2d804f869524801
|
||||
timeCreated: 1695289293
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0615e8b32d534bc48a60e42c973053ad
|
||||
timeCreated: 1695289443
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0e67891bd0f0c7449b345c622ed6b0e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fcee77031f85f84dbc6735c875d64b8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,84 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public class ClickEventListener : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler
|
||||
{
|
||||
public static ClickEventListener Get(GameObject obj)
|
||||
{
|
||||
ClickEventListener listener = obj.GetComponent<ClickEventListener>();
|
||||
if (listener == null)
|
||||
{
|
||||
listener = obj.AddComponent<ClickEventListener>();
|
||||
}
|
||||
|
||||
return listener;
|
||||
}
|
||||
|
||||
private System.Action<GameObject> _clickedHandler = null;
|
||||
private System.Action<GameObject> _doubleClickedHandler = null;
|
||||
private System.Action<GameObject> _onPointerDownHandler = null;
|
||||
private System.Action<GameObject> _onPointerUpHandler = null;
|
||||
bool _isPressed = false;
|
||||
|
||||
public bool IsPressed => _isPressed;
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (eventData.clickCount == 2)
|
||||
{
|
||||
if (_doubleClickedHandler != null)
|
||||
{
|
||||
_doubleClickedHandler(gameObject);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_clickedHandler != null)
|
||||
{
|
||||
_clickedHandler(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetClickEventHandler(System.Action<GameObject> handler)
|
||||
{
|
||||
_clickedHandler = handler;
|
||||
}
|
||||
|
||||
public void SetDoubleClickEventHandler(System.Action<GameObject> handler)
|
||||
{
|
||||
_doubleClickedHandler = handler;
|
||||
}
|
||||
|
||||
public void SetPointerDownHandler(System.Action<GameObject> handler)
|
||||
{
|
||||
_onPointerDownHandler = handler;
|
||||
}
|
||||
|
||||
public void SetPointerUpHandler(System.Action<GameObject> handler)
|
||||
{
|
||||
_onPointerUpHandler = handler;
|
||||
}
|
||||
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
_isPressed = true;
|
||||
if (_onPointerDownHandler != null)
|
||||
{
|
||||
_onPointerDownHandler(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
_isPressed = false;
|
||||
if (_onPointerUpHandler != null)
|
||||
{
|
||||
_onPointerUpHandler(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa13a2165836fda459a6c28562ac101a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
||||
public enum SnapStatus
|
||||
{
|
||||
NoTargetSet = 0,
|
||||
TargetHasSet = 1,
|
||||
SnapMoving = 2,
|
||||
SnapMoveFinish = 3
|
||||
}
|
||||
|
||||
|
||||
public enum ItemCornerEnum
|
||||
{
|
||||
LeftBottom = 0,
|
||||
LeftTop,
|
||||
RightTop,
|
||||
RightBottom,
|
||||
}
|
||||
|
||||
|
||||
public enum ListItemArrangeType
|
||||
{
|
||||
TopToBottom = 0,
|
||||
BottomToTop,
|
||||
LeftToRight,
|
||||
RightToLeft,
|
||||
}
|
||||
|
||||
public enum GridItemArrangeType
|
||||
{
|
||||
TopLeftToBottomRight = 0,
|
||||
BottomLeftToTopRight,
|
||||
TopRightToBottomLeft,
|
||||
BottomRightToTopLeft,
|
||||
}
|
||||
public enum GridFixedType
|
||||
{
|
||||
ColumnCountFixed = 0,
|
||||
RowCountFixed,
|
||||
}
|
||||
|
||||
public struct RowColumnPair
|
||||
{
|
||||
public RowColumnPair(int row1, int column1)
|
||||
{
|
||||
mRow = row1;
|
||||
mColumn = column1;
|
||||
}
|
||||
|
||||
public bool Equals(RowColumnPair other)
|
||||
{
|
||||
return this.mRow == other.mRow && this.mColumn == other.mColumn;
|
||||
}
|
||||
|
||||
public static bool operator ==(RowColumnPair a, RowColumnPair b)
|
||||
{
|
||||
return (a.mRow == b.mRow)&&(a.mColumn == b.mColumn);
|
||||
}
|
||||
public static bool operator !=(RowColumnPair a, RowColumnPair b)
|
||||
{
|
||||
return (a.mRow != b.mRow) || (a.mColumn != b.mColumn); ;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return (obj is RowColumnPair) && Equals((RowColumnPair)obj);
|
||||
}
|
||||
|
||||
|
||||
public int mRow;
|
||||
public int mColumn;
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19e4e487f35877f4b9bb864eb43484d6
|
||||
timeCreated: 1534508353
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,326 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public class ItemSizeGroup
|
||||
{
|
||||
public float[] ItemSizeArray = null;
|
||||
public float[] ItemStartPosArray = null;
|
||||
public int ItemCount = 0;
|
||||
private int _dirtyBeginIndex = ItemPosMgr.ItemMaxCountPerGroup;
|
||||
public float GroupSize = 0;
|
||||
public float GroupStartPos = 0;
|
||||
public float GroupEndPos = 0;
|
||||
public int GroupIndex = 0;
|
||||
public float ItemDefaultSize = 0;
|
||||
|
||||
public ItemSizeGroup(int index, float itemDefaultSize)
|
||||
{
|
||||
GroupIndex = index;
|
||||
ItemDefaultSize = itemDefaultSize;
|
||||
Init();
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
ItemSizeArray = new float[ItemPosMgr.ItemMaxCountPerGroup];
|
||||
if (ItemDefaultSize != 0)
|
||||
{
|
||||
for (int i = 0; i < ItemSizeArray.Length; ++i)
|
||||
{
|
||||
ItemSizeArray[i] = ItemDefaultSize;
|
||||
}
|
||||
}
|
||||
|
||||
ItemStartPosArray = new float[ItemPosMgr.ItemMaxCountPerGroup];
|
||||
ItemStartPosArray[0] = 0;
|
||||
ItemCount = ItemPosMgr.ItemMaxCountPerGroup;
|
||||
GroupSize = ItemDefaultSize * ItemSizeArray.Length;
|
||||
if (ItemDefaultSize != 0)
|
||||
{
|
||||
_dirtyBeginIndex = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_dirtyBeginIndex = ItemPosMgr.ItemMaxCountPerGroup;
|
||||
}
|
||||
}
|
||||
|
||||
public float GetItemStartPos(int index)
|
||||
{
|
||||
return GroupStartPos + ItemStartPosArray[index];
|
||||
}
|
||||
|
||||
public bool IsDirty
|
||||
{
|
||||
get { return (_dirtyBeginIndex < ItemCount); }
|
||||
}
|
||||
|
||||
public float SetItemSize(int index, float size)
|
||||
{
|
||||
float old = ItemSizeArray[index];
|
||||
if (Math.Abs(old - size) < 0.001f)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
ItemSizeArray[index] = size;
|
||||
if (index < _dirtyBeginIndex)
|
||||
{
|
||||
_dirtyBeginIndex = index;
|
||||
}
|
||||
|
||||
float ds = size - old;
|
||||
GroupSize = GroupSize + ds;
|
||||
return ds;
|
||||
}
|
||||
|
||||
public void SetItemCount(int count)
|
||||
{
|
||||
if (ItemCount == count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ItemCount = count;
|
||||
RecalcGroupSize();
|
||||
}
|
||||
|
||||
public void RecalcGroupSize()
|
||||
{
|
||||
GroupSize = 0;
|
||||
for (int i = 0; i < ItemCount; ++i)
|
||||
{
|
||||
GroupSize += ItemSizeArray[i];
|
||||
}
|
||||
}
|
||||
|
||||
public int GetItemIndexByPos(float pos)
|
||||
{
|
||||
if (ItemCount == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int low = 0;
|
||||
int high = ItemCount - 1;
|
||||
while (low <= high)
|
||||
{
|
||||
int mid = (low + high) / 2;
|
||||
float startPos = ItemStartPosArray[mid];
|
||||
float endPos = startPos + ItemSizeArray[mid];
|
||||
if (startPos <= pos && endPos >= pos)
|
||||
{
|
||||
return mid;
|
||||
}
|
||||
else if (pos > endPos)
|
||||
{
|
||||
low = mid + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
high = mid - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void UpdateAllItemStartPos()
|
||||
{
|
||||
if (_dirtyBeginIndex >= ItemCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int startIndex = (_dirtyBeginIndex < 1) ? 1 : _dirtyBeginIndex;
|
||||
for (int i = startIndex; i < ItemCount; ++i)
|
||||
{
|
||||
ItemStartPosArray[i] = ItemStartPosArray[i - 1] + ItemSizeArray[i - 1];
|
||||
}
|
||||
|
||||
_dirtyBeginIndex = ItemCount;
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemPosMgr
|
||||
{
|
||||
public const int ItemMaxCountPerGroup = 100;
|
||||
readonly List<ItemSizeGroup> _itemSizeGroupList = new List<ItemSizeGroup>();
|
||||
public int _dirtyBeginIndex = int.MaxValue;
|
||||
public float TotalSize = 0;
|
||||
public float ItemDefaultSize = 20;
|
||||
|
||||
public ItemPosMgr(float itemDefaultSize)
|
||||
{
|
||||
ItemDefaultSize = itemDefaultSize;
|
||||
}
|
||||
|
||||
public void SetItemMaxCount(int maxCount)
|
||||
{
|
||||
_dirtyBeginIndex = 0;
|
||||
TotalSize = 0;
|
||||
int st = maxCount % ItemMaxCountPerGroup;
|
||||
int lastGroupItemCount = st;
|
||||
int needMaxGroupCount = maxCount / ItemMaxCountPerGroup;
|
||||
if (st > 0)
|
||||
{
|
||||
needMaxGroupCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastGroupItemCount = ItemMaxCountPerGroup;
|
||||
}
|
||||
|
||||
int count = _itemSizeGroupList.Count;
|
||||
if (count > needMaxGroupCount)
|
||||
{
|
||||
int d = count - needMaxGroupCount;
|
||||
_itemSizeGroupList.RemoveRange(needMaxGroupCount, d);
|
||||
}
|
||||
else if (count < needMaxGroupCount)
|
||||
{
|
||||
int d = needMaxGroupCount - count;
|
||||
for (int i = 0; i < d; ++i)
|
||||
{
|
||||
ItemSizeGroup tGroup = new ItemSizeGroup(count + i, ItemDefaultSize);
|
||||
_itemSizeGroupList.Add(tGroup);
|
||||
}
|
||||
}
|
||||
|
||||
count = _itemSizeGroupList.Count;
|
||||
if (count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count - 1; ++i)
|
||||
{
|
||||
_itemSizeGroupList[i].SetItemCount(ItemMaxCountPerGroup);
|
||||
}
|
||||
|
||||
_itemSizeGroupList[count - 1].SetItemCount(lastGroupItemCount);
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
TotalSize = TotalSize + _itemSizeGroupList[i].GroupSize;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetItemSize(int itemIndex, float size)
|
||||
{
|
||||
int groupIndex = itemIndex / ItemMaxCountPerGroup;
|
||||
int indexInGroup = itemIndex % ItemMaxCountPerGroup;
|
||||
ItemSizeGroup tGroup = _itemSizeGroupList[groupIndex];
|
||||
float changedSize = tGroup.SetItemSize(indexInGroup, size);
|
||||
if (changedSize != 0f)
|
||||
{
|
||||
if (groupIndex < _dirtyBeginIndex)
|
||||
{
|
||||
_dirtyBeginIndex = groupIndex;
|
||||
}
|
||||
}
|
||||
|
||||
TotalSize += changedSize;
|
||||
}
|
||||
|
||||
public float GetItemPos(int itemIndex)
|
||||
{
|
||||
Update(true);
|
||||
int groupIndex = itemIndex / ItemMaxCountPerGroup;
|
||||
int indexInGroup = itemIndex % ItemMaxCountPerGroup;
|
||||
return _itemSizeGroupList[groupIndex].GetItemStartPos(indexInGroup);
|
||||
}
|
||||
|
||||
public void GetItemIndexAndPosAtGivenPos(float pos, ref int index, ref float itemPos)
|
||||
{
|
||||
Update(true);
|
||||
index = 0;
|
||||
itemPos = 0f;
|
||||
int count = _itemSizeGroupList.Count;
|
||||
if (count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ItemSizeGroup hitGroup = null;
|
||||
|
||||
int low = 0;
|
||||
int high = count - 1;
|
||||
while (low <= high)
|
||||
{
|
||||
int mid = (low + high) / 2;
|
||||
ItemSizeGroup tGroup = _itemSizeGroupList[mid];
|
||||
if (tGroup.GroupStartPos <= pos && tGroup.GroupEndPos >= pos)
|
||||
{
|
||||
hitGroup = tGroup;
|
||||
break;
|
||||
}
|
||||
else if (pos > tGroup.GroupEndPos)
|
||||
{
|
||||
low = mid + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
high = mid - 1;
|
||||
}
|
||||
}
|
||||
|
||||
int hitIndex = -1;
|
||||
if (hitGroup != null)
|
||||
{
|
||||
hitIndex = hitGroup.GetItemIndexByPos(pos - hitGroup.GroupStartPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (hitIndex < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
index = hitIndex + hitGroup.GroupIndex * ItemMaxCountPerGroup;
|
||||
itemPos = hitGroup.GetItemStartPos(hitIndex);
|
||||
}
|
||||
|
||||
public void Update(bool updateAll)
|
||||
{
|
||||
int count = _itemSizeGroupList.Count;
|
||||
if (count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_dirtyBeginIndex >= count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int loopCount = 0;
|
||||
for (int i = _dirtyBeginIndex; i < count; ++i)
|
||||
{
|
||||
loopCount++;
|
||||
ItemSizeGroup tGroup = _itemSizeGroupList[i];
|
||||
_dirtyBeginIndex++;
|
||||
tGroup.UpdateAllItemStartPos();
|
||||
if (i == 0)
|
||||
{
|
||||
tGroup.GroupStartPos = 0;
|
||||
tGroup.GroupEndPos = tGroup.GroupSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
tGroup.GroupStartPos = _itemSizeGroupList[i - 1].GroupEndPos;
|
||||
tGroup.GroupEndPos = tGroup.GroupStartPos + tGroup.GroupSize;
|
||||
}
|
||||
|
||||
if (!updateAll && loopCount > 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61adb6a884bfbfc4292a5d39261a74f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7f738dc5a266e94d9e9870fc76009c2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,173 @@
|
||||
namespace GameLogic
|
||||
{
|
||||
//if GridFixedType is GridFixedType.ColumnCountFixed, then the GridItemGroup is one row of the gridview
|
||||
//if GridFixedType is GridFixedType.RowCountFixed, then the GridItemGroup is one column of the gridview
|
||||
public class GridItemGroup
|
||||
{
|
||||
private int _count = 0;
|
||||
private int _groupIndex = -1;//the row index or the column index of this group
|
||||
private LoopGridViewItem _first = null;
|
||||
private LoopGridViewItem _last = null;
|
||||
public int Count => _count;
|
||||
|
||||
public LoopGridViewItem First => _first;
|
||||
|
||||
public LoopGridViewItem Last => _last;
|
||||
|
||||
public int GroupIndex
|
||||
{
|
||||
get => _groupIndex;
|
||||
set => _groupIndex = value;
|
||||
}
|
||||
|
||||
|
||||
public LoopGridViewItem GetItemByColumn(int column)
|
||||
{
|
||||
LoopGridViewItem cur = _first;
|
||||
while(cur != null)
|
||||
{
|
||||
if(cur.Column == column)
|
||||
{
|
||||
return cur;
|
||||
}
|
||||
cur = cur.NextItem;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public LoopGridViewItem GetItemByRow(int row)
|
||||
{
|
||||
LoopGridViewItem cur = _first;
|
||||
while (cur != null)
|
||||
{
|
||||
if (cur.Row == row)
|
||||
{
|
||||
return cur;
|
||||
}
|
||||
cur = cur.NextItem;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void ReplaceItem(LoopGridViewItem curItem,LoopGridViewItem newItem)
|
||||
{
|
||||
newItem.PrevItem = curItem.PrevItem;
|
||||
newItem.NextItem = curItem.NextItem;
|
||||
if(newItem.PrevItem != null)
|
||||
{
|
||||
newItem.PrevItem.NextItem = newItem;
|
||||
}
|
||||
if(newItem.NextItem != null)
|
||||
{
|
||||
newItem.NextItem.PrevItem = newItem;
|
||||
}
|
||||
if(_first == curItem)
|
||||
{
|
||||
_first = newItem;
|
||||
}
|
||||
if(_last == curItem)
|
||||
{
|
||||
_last = newItem;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddFirst(LoopGridViewItem newItem)
|
||||
{
|
||||
newItem.PrevItem = null;
|
||||
newItem.NextItem = null;
|
||||
if (_first == null)
|
||||
{
|
||||
_first = newItem;
|
||||
_last = newItem;
|
||||
_first.PrevItem = null;
|
||||
_first.NextItem = null;
|
||||
_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_first.PrevItem = newItem;
|
||||
newItem.PrevItem = null;
|
||||
newItem.NextItem = _first;
|
||||
_first = newItem;
|
||||
_count++;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddLast(LoopGridViewItem newItem)
|
||||
{
|
||||
newItem.PrevItem = null;
|
||||
newItem.NextItem = null;
|
||||
if (_first == null)
|
||||
{
|
||||
_first = newItem;
|
||||
_last = newItem;
|
||||
_first.PrevItem = null;
|
||||
_first.NextItem = null;
|
||||
_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_last.NextItem = newItem;
|
||||
newItem.PrevItem = _last;
|
||||
newItem.NextItem = null;
|
||||
_last = newItem;
|
||||
_count++;
|
||||
}
|
||||
}
|
||||
|
||||
public LoopGridViewItem RemoveFirst()
|
||||
{
|
||||
LoopGridViewItem ret = _first;
|
||||
if (_first == null)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
if(_first == _last)
|
||||
{
|
||||
_first = null;
|
||||
_last = null;
|
||||
--_count;
|
||||
return ret;
|
||||
}
|
||||
_first = _first.NextItem;
|
||||
_first.PrevItem = null;
|
||||
--_count;
|
||||
return ret;
|
||||
}
|
||||
public LoopGridViewItem RemoveLast()
|
||||
{
|
||||
LoopGridViewItem ret = _last;
|
||||
if (_first == null)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
if (_first == _last)
|
||||
{
|
||||
_first = null;
|
||||
_last = null;
|
||||
--_count;
|
||||
return ret;
|
||||
}
|
||||
_last = _last.PrevItem;
|
||||
_last.NextItem = null;
|
||||
--_count;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
LoopGridViewItem current = _first;
|
||||
while (current != null)
|
||||
{
|
||||
current.PrevItem = null;
|
||||
current.NextItem = null;
|
||||
current = current.NextItem;
|
||||
}
|
||||
_first = null;
|
||||
_last = null;
|
||||
_count = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7e7eb25fe1319d4b8773ddfab7a240e
|
||||
timeCreated: 1554538573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public class GridItemPool
|
||||
{
|
||||
private GameObject _prefabObj;
|
||||
private string _prefabName;
|
||||
private int _initCreateCount = 1;
|
||||
private readonly List<LoopGridViewItem> _tmpPooledItemList = new List<LoopGridViewItem>();
|
||||
private readonly List<LoopGridViewItem> _pooledItemList = new List<LoopGridViewItem>();
|
||||
private static int _curItemIdCount = 0;
|
||||
private RectTransform _itemParent = null;
|
||||
public GridItemPool()
|
||||
{
|
||||
|
||||
}
|
||||
public void Init(GameObject prefabObj, int createCount, RectTransform parent)
|
||||
{
|
||||
_prefabObj = prefabObj;
|
||||
_prefabName = _prefabObj.name;
|
||||
_initCreateCount = createCount;
|
||||
_itemParent = parent;
|
||||
_prefabObj.SetActive(false);
|
||||
for (int i = 0; i < _initCreateCount; ++i)
|
||||
{
|
||||
LoopGridViewItem tViewItem = CreateItem();
|
||||
RecycleItemReal(tViewItem);
|
||||
}
|
||||
}
|
||||
public LoopGridViewItem GetItem()
|
||||
{
|
||||
_curItemIdCount++;
|
||||
LoopGridViewItem tItem = null;
|
||||
if (_tmpPooledItemList.Count > 0)
|
||||
{
|
||||
int count = _tmpPooledItemList.Count;
|
||||
tItem = _tmpPooledItemList[count - 1];
|
||||
_tmpPooledItemList.RemoveAt(count - 1);
|
||||
tItem.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
int count = _pooledItemList.Count;
|
||||
if (count == 0)
|
||||
{
|
||||
tItem = CreateItem();
|
||||
}
|
||||
else
|
||||
{
|
||||
tItem = _pooledItemList[count - 1];
|
||||
_pooledItemList.RemoveAt(count - 1);
|
||||
tItem.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
tItem.ItemId = _curItemIdCount;
|
||||
return tItem;
|
||||
|
||||
}
|
||||
|
||||
public void DestroyAllItem()
|
||||
{
|
||||
ClearTmpRecycledItem();
|
||||
int count = _pooledItemList.Count;
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
GameObject.DestroyImmediate(_pooledItemList[i].gameObject);
|
||||
}
|
||||
_pooledItemList.Clear();
|
||||
}
|
||||
public LoopGridViewItem CreateItem()
|
||||
{
|
||||
|
||||
GameObject go = GameObject.Instantiate<GameObject>(_prefabObj, Vector3.zero, Quaternion.identity, _itemParent);
|
||||
go.SetActive(true);
|
||||
RectTransform rf = go.GetComponent<RectTransform>();
|
||||
rf.localScale = Vector3.one;
|
||||
rf.anchoredPosition3D = Vector3.zero;
|
||||
rf.localEulerAngles = Vector3.zero;
|
||||
LoopGridViewItem tViewItem = go.GetComponent<LoopGridViewItem>();
|
||||
tViewItem.ItemPrefabName = _prefabName;
|
||||
tViewItem.GoId = go.GetHashCode();
|
||||
return tViewItem;
|
||||
}
|
||||
void RecycleItemReal(LoopGridViewItem item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
_pooledItemList.Add(item);
|
||||
}
|
||||
public void RecycleItem(LoopGridViewItem item)
|
||||
{
|
||||
item.PrevItem = null;
|
||||
item.NextItem = null;
|
||||
_tmpPooledItemList.Add(item);
|
||||
}
|
||||
public void ClearTmpRecycledItem()
|
||||
{
|
||||
int count = _tmpPooledItemList.Count;
|
||||
if (count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
RecycleItemReal(_tmpPooledItemList[i]);
|
||||
}
|
||||
_tmpPooledItemList.Clear();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1eb92a17e8cee642a2245950dfaabea
|
||||
timeCreated: 1554538573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17e9881a7bce8124a8f855b96a8ca11a
|
||||
timeCreated: 1554538573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,184 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
||||
public class LoopGridViewItem : MonoBehaviour
|
||||
{
|
||||
// indicates the item’s index in the list the mItemIndex can only be from 0 to itemTotalCount -1.
|
||||
int mItemIndex = -1;
|
||||
// the row index, the item is in. starting from 0.
|
||||
int mRow = -1;
|
||||
// the column index, the item is in. starting from 0.
|
||||
int mColumn = -1;
|
||||
//indicates the item’s id.
|
||||
//This property is set when the item is created or fetched from pool,
|
||||
//and will no longer change until the item is recycled back to pool.
|
||||
int mItemId = -1;
|
||||
|
||||
private int _goId = 0;
|
||||
|
||||
public int GoId
|
||||
{
|
||||
set => _goId = value;
|
||||
get => _goId;
|
||||
}
|
||||
|
||||
LoopGridView mParentGridView = null;
|
||||
bool mIsInitHandlerCalled = false;
|
||||
string mItemPrefabName;
|
||||
RectTransform mCachedRectTransform;
|
||||
int mItemCreatedCheckFrameCount = 0;
|
||||
|
||||
object mUserObjectData = null;
|
||||
int mUserIntData1 = 0;
|
||||
int mUserIntData2 = 0;
|
||||
string mUserStringData1 = null;
|
||||
string mUserStringData2 = null;
|
||||
|
||||
LoopGridViewItem mPrevItem;
|
||||
LoopGridViewItem mNextItem;
|
||||
|
||||
public object UserObjectData
|
||||
{
|
||||
get { return mUserObjectData; }
|
||||
set { mUserObjectData = value; }
|
||||
}
|
||||
public int UserIntData1
|
||||
{
|
||||
get { return mUserIntData1; }
|
||||
set { mUserIntData1 = value; }
|
||||
}
|
||||
public int UserIntData2
|
||||
{
|
||||
get { return mUserIntData2; }
|
||||
set { mUserIntData2 = value; }
|
||||
}
|
||||
public string UserStringData1
|
||||
{
|
||||
get { return mUserStringData1; }
|
||||
set { mUserStringData1 = value; }
|
||||
}
|
||||
public string UserStringData2
|
||||
{
|
||||
get { return mUserStringData2; }
|
||||
set { mUserStringData2 = value; }
|
||||
}
|
||||
|
||||
public int ItemCreatedCheckFrameCount
|
||||
{
|
||||
get { return mItemCreatedCheckFrameCount; }
|
||||
set { mItemCreatedCheckFrameCount = value; }
|
||||
}
|
||||
|
||||
|
||||
public RectTransform CachedRectTransform
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mCachedRectTransform == null)
|
||||
{
|
||||
mCachedRectTransform = gameObject.GetComponent<RectTransform>();
|
||||
}
|
||||
return mCachedRectTransform;
|
||||
}
|
||||
}
|
||||
|
||||
public string ItemPrefabName
|
||||
{
|
||||
get
|
||||
{
|
||||
return mItemPrefabName;
|
||||
}
|
||||
set
|
||||
{
|
||||
mItemPrefabName = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int Row
|
||||
{
|
||||
get
|
||||
{
|
||||
return mRow;
|
||||
}
|
||||
set
|
||||
{
|
||||
mRow = value;
|
||||
}
|
||||
}
|
||||
public int Column
|
||||
{
|
||||
get
|
||||
{
|
||||
return mColumn;
|
||||
}
|
||||
set
|
||||
{
|
||||
mColumn = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int ItemIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return mItemIndex;
|
||||
}
|
||||
set
|
||||
{
|
||||
mItemIndex = value;
|
||||
}
|
||||
}
|
||||
public int ItemId
|
||||
{
|
||||
get
|
||||
{
|
||||
return mItemId;
|
||||
}
|
||||
set
|
||||
{
|
||||
mItemId = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool IsInitHandlerCalled
|
||||
{
|
||||
get
|
||||
{
|
||||
return mIsInitHandlerCalled;
|
||||
}
|
||||
set
|
||||
{
|
||||
mIsInitHandlerCalled = value;
|
||||
}
|
||||
}
|
||||
|
||||
public LoopGridView ParentGridView
|
||||
{
|
||||
get
|
||||
{
|
||||
return mParentGridView;
|
||||
}
|
||||
set
|
||||
{
|
||||
mParentGridView = value;
|
||||
}
|
||||
}
|
||||
|
||||
public LoopGridViewItem PrevItem
|
||||
{
|
||||
get { return mPrevItem; }
|
||||
set { mPrevItem = value; }
|
||||
}
|
||||
public LoopGridViewItem NextItem
|
||||
{
|
||||
get { return mNextItem; }
|
||||
set { mNextItem = value; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec0432517adfcb84bb6163d7a44ab8c1
|
||||
timeCreated: 1554538573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9bbd48a4abc45c46a92b92d0df3ae07
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd536d252034dd74b87b436507ec44f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,216 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public class LoopListViewItem : MonoBehaviour
|
||||
{
|
||||
public float Padding;
|
||||
|
||||
private int _itemIndex = -1;
|
||||
private int _itemId = -1;
|
||||
private LoopListView _parentListView = null;
|
||||
private bool _isInitHandlerCalled = false;
|
||||
private string _itemPrefabName;
|
||||
private RectTransform _cachedRectTransform;
|
||||
private float _padding;
|
||||
private float _distanceWithViewPortSnapCenter = 0;
|
||||
private int _itemCreatedCheckFrameCount = 0;
|
||||
private float _startPosOffset = 0;
|
||||
|
||||
private object _userObjectData = null;
|
||||
private int _userIntData1 = 0;
|
||||
private int _userIntData2 = 0;
|
||||
private string _userStringData1 = null;
|
||||
private string _userStringData2 = null;
|
||||
|
||||
private int _goId = 0;
|
||||
|
||||
public int GoId
|
||||
{
|
||||
set => _goId = value;
|
||||
get => _goId;
|
||||
}
|
||||
|
||||
public object UserObjectData
|
||||
{
|
||||
get => _userObjectData;
|
||||
set => _userObjectData = value;
|
||||
}
|
||||
|
||||
public int UserIntData1
|
||||
{
|
||||
get => _userIntData1;
|
||||
set => _userIntData1 = value;
|
||||
}
|
||||
|
||||
public int UserIntData2
|
||||
{
|
||||
get => _userIntData2;
|
||||
set => _userIntData2 = value;
|
||||
}
|
||||
|
||||
public string UserStringData1
|
||||
{
|
||||
get => _userStringData1;
|
||||
set => _userStringData1 = value;
|
||||
}
|
||||
|
||||
public string UserStringData2
|
||||
{
|
||||
get => _userStringData2;
|
||||
set => _userStringData2 = value;
|
||||
}
|
||||
|
||||
public float DistanceWithViewPortSnapCenter
|
||||
{
|
||||
get => _distanceWithViewPortSnapCenter;
|
||||
set => _distanceWithViewPortSnapCenter = value;
|
||||
}
|
||||
|
||||
public float StartPosOffset
|
||||
{
|
||||
get => _startPosOffset;
|
||||
set => _startPosOffset = value;
|
||||
}
|
||||
|
||||
public int ItemCreatedCheckFrameCount
|
||||
{
|
||||
get => _itemCreatedCheckFrameCount;
|
||||
set => _itemCreatedCheckFrameCount = value;
|
||||
}
|
||||
|
||||
public RectTransform CachedRectTransform
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_cachedRectTransform == null)
|
||||
{
|
||||
_cachedRectTransform = gameObject.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
return _cachedRectTransform;
|
||||
}
|
||||
}
|
||||
|
||||
public string ItemPrefabName
|
||||
{
|
||||
get => _itemPrefabName;
|
||||
set => _itemPrefabName = value;
|
||||
}
|
||||
|
||||
public int ItemIndex
|
||||
{
|
||||
get => _itemIndex;
|
||||
set => _itemIndex = value;
|
||||
}
|
||||
|
||||
public int ItemId
|
||||
{
|
||||
get => _itemId;
|
||||
set => _itemId = value;
|
||||
}
|
||||
|
||||
|
||||
public bool IsInitHandlerCalled
|
||||
{
|
||||
get => _isInitHandlerCalled;
|
||||
set => _isInitHandlerCalled = value;
|
||||
}
|
||||
|
||||
public LoopListView ParentListView
|
||||
{
|
||||
get => _parentListView;
|
||||
set => _parentListView = value;
|
||||
}
|
||||
|
||||
public float TopY
|
||||
{
|
||||
get
|
||||
{
|
||||
ListItemArrangeType arrageType = ParentListView.ArrangeType;
|
||||
if (arrageType == ListItemArrangeType.TopToBottom)
|
||||
{
|
||||
return CachedRectTransform.localPosition.y;
|
||||
}
|
||||
else if (arrageType == ListItemArrangeType.BottomToTop)
|
||||
{
|
||||
return CachedRectTransform.localPosition.y + CachedRectTransform.rect.height;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public float BottomY
|
||||
{
|
||||
get
|
||||
{
|
||||
ListItemArrangeType arrageType = ParentListView.ArrangeType;
|
||||
if (arrageType == ListItemArrangeType.TopToBottom)
|
||||
{
|
||||
return CachedRectTransform.localPosition.y - CachedRectTransform.rect.height;
|
||||
}
|
||||
else if (arrageType == ListItemArrangeType.BottomToTop)
|
||||
{
|
||||
return CachedRectTransform.localPosition.y;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public float LeftX
|
||||
{
|
||||
get
|
||||
{
|
||||
ListItemArrangeType arrageType = ParentListView.ArrangeType;
|
||||
if (arrageType == ListItemArrangeType.LeftToRight)
|
||||
{
|
||||
return CachedRectTransform.localPosition.x;
|
||||
}
|
||||
else if (arrageType == ListItemArrangeType.RightToLeft)
|
||||
{
|
||||
return CachedRectTransform.localPosition.x - CachedRectTransform.rect.width;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public float RightX
|
||||
{
|
||||
get
|
||||
{
|
||||
ListItemArrangeType arrageType = ParentListView.ArrangeType;
|
||||
if (arrageType == ListItemArrangeType.LeftToRight)
|
||||
{
|
||||
return CachedRectTransform.localPosition.x + CachedRectTransform.rect.width;
|
||||
}
|
||||
else if (arrageType == ListItemArrangeType.RightToLeft)
|
||||
{
|
||||
return CachedRectTransform.localPosition.x;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public float ItemSize
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ParentListView.IsVertList)
|
||||
{
|
||||
return CachedRectTransform.rect.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
return CachedRectTransform.rect.width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float ItemSizeWithPadding => ItemSize + _padding;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29af6e9bda3402e4eba67bb72531e618
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f3fbd5ce2514056b72986a6dea2aec2
|
||||
timeCreated: 1695289443
|
@@ -0,0 +1,71 @@
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// 子界面之间共享的数据。
|
||||
/// </summary>
|
||||
public class ChildPageSharData
|
||||
{
|
||||
private object[] m_arrParams = new object[3]; // 共享参数列表
|
||||
|
||||
public object Param1 { get { return m_arrParams[0]; } }
|
||||
public object Param2 { get { return m_arrParams[1]; } }
|
||||
public object Param3 { get { return m_arrParams[2]; } }
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定索引的参数。
|
||||
/// </summary>
|
||||
/// <param name="paramIdx"></param>
|
||||
/// <param name="param"></param>
|
||||
public void SetParam(int paramIdx, object param)
|
||||
{
|
||||
if (paramIdx >= m_arrParams.Length)
|
||||
return;
|
||||
|
||||
m_arrParams[paramIdx] = param;
|
||||
}
|
||||
}
|
||||
|
||||
public class ChildPageBase : UIWidget
|
||||
{
|
||||
|
||||
protected ChildPageSharData m_shareObjData; // 共享数据
|
||||
|
||||
// 初始化数据
|
||||
public void InitData(ChildPageSharData shareObjData)
|
||||
{
|
||||
m_shareObjData = shareObjData;
|
||||
}
|
||||
|
||||
public virtual void OnPageShowed(int oldShowType, int newShowType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// 无参数刷新当前子界面
|
||||
// 收到那些数据变动的消息的时候使用
|
||||
public virtual void RefreshPage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public object ShareData1
|
||||
{
|
||||
get => m_shareObjData.Param1;
|
||||
set => m_shareObjData.SetParam(0, value);
|
||||
}
|
||||
|
||||
public object ShareData2
|
||||
{
|
||||
get => m_shareObjData.Param2;
|
||||
set => m_shareObjData.SetParam(1, value);
|
||||
}
|
||||
|
||||
public object ShareData3
|
||||
{
|
||||
get => m_shareObjData.Param3;
|
||||
set => m_shareObjData.SetParam(2, value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4b742d9af72478b9d6f7ebd2fa493a0
|
||||
timeCreated: 1687859782
|
@@ -0,0 +1,457 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public class SwitchPageMgr
|
||||
{
|
||||
private event Action<int, int> SwitchTabAction;
|
||||
|
||||
public delegate bool SwitchTabCondition(int selectId);
|
||||
|
||||
private SwitchTabCondition _switchTabCondition;
|
||||
|
||||
/// <summary>
|
||||
/// 页签Grid。
|
||||
/// </summary>
|
||||
protected Transform m_tabGrid;
|
||||
|
||||
/// <summary>
|
||||
/// 子UI父节点。
|
||||
/// </summary>
|
||||
public Transform ChildPageParent;
|
||||
|
||||
/// <summary>
|
||||
/// 存储子UI。
|
||||
/// </summary>
|
||||
private readonly Dictionary<int, List<string>> _switchPageDic = new Dictionary<int, List<string>>();
|
||||
|
||||
/// <summary>
|
||||
/// 子页签名字。
|
||||
/// </summary>
|
||||
private readonly List<string> _childPageNames = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 子页签字典。
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, ChildPageBase> _childPageDic = new Dictionary<string, ChildPageBase>();
|
||||
|
||||
/// <summary>
|
||||
/// 存储页签。
|
||||
/// </summary>
|
||||
private readonly Dictionary<int, SwitchTabItem> _tabDic = new Dictionary<int, SwitchTabItem>();
|
||||
|
||||
private readonly Dictionary<int, string> _tabName = new Dictionary<int, string>();
|
||||
|
||||
protected readonly List<int> IDList = new List<int>();
|
||||
|
||||
private readonly UIBase _owner;
|
||||
|
||||
protected int CurrentChildID = -100;
|
||||
|
||||
/// <summary>
|
||||
/// 需要设置显示隐藏。
|
||||
/// </summary>
|
||||
private readonly bool _needSetActive;
|
||||
|
||||
/// <summary>
|
||||
/// 子界面的共享数据。
|
||||
/// </summary>
|
||||
private readonly ChildPageSharData _shareData = new ChildPageSharData();
|
||||
|
||||
public object ShareData1 => _shareData.Param1;
|
||||
public object ShareData2 => _shareData.Param2;
|
||||
public object ShareData3 => _shareData.Param3;
|
||||
|
||||
public SwitchPageMgr(Transform grid, Transform childPageParent, UIBase owner, bool needSetActive = true)
|
||||
{
|
||||
m_tabGrid = grid;
|
||||
ChildPageParent = childPageParent;
|
||||
_owner = owner;
|
||||
_needSetActive = needSetActive;
|
||||
}
|
||||
|
||||
public void AddSwitchAction(Action<int, int> action)
|
||||
{
|
||||
SwitchTabAction += action;
|
||||
}
|
||||
|
||||
public void RemoveSwitchAction(Action<int, int> action)
|
||||
{
|
||||
SwitchTabAction -= action;
|
||||
}
|
||||
|
||||
public void AddSwitchCondition(SwitchTabCondition action)
|
||||
{
|
||||
_switchTabCondition = action;
|
||||
}
|
||||
|
||||
public void BindChildPage<T>(int childID) where T : ChildPageBase, new()
|
||||
{
|
||||
BindChildPage<T>(childID, string.Empty);
|
||||
}
|
||||
|
||||
public void BindChildPage<T>(int childID, string tabName) where T : ChildPageBase, new()
|
||||
{
|
||||
var pageName = typeof(T).Name;
|
||||
|
||||
if (IDList.IndexOf(childID) < 0)
|
||||
{
|
||||
IDList.Add(childID);
|
||||
}
|
||||
|
||||
if (!_childPageDic.ContainsKey(pageName))
|
||||
{
|
||||
_childPageDic[pageName] = new T();
|
||||
_childPageNames.Add(pageName);
|
||||
}
|
||||
|
||||
if (!_switchPageDic.ContainsKey(childID))
|
||||
{
|
||||
_switchPageDic[childID] = new List<string>();
|
||||
}
|
||||
|
||||
if (_switchPageDic[childID].IndexOf(pageName) < 0)
|
||||
{
|
||||
_switchPageDic[childID].Add(pageName);
|
||||
}
|
||||
|
||||
_tabName[childID] = tabName;
|
||||
}
|
||||
|
||||
public T CreatTab<T>(int initChildID, GameObject tabTemp = null) where T : SwitchTabItem, new()
|
||||
{
|
||||
T tab = null;
|
||||
for (var index = 0; index < IDList.Count; index++)
|
||||
{
|
||||
var childID = IDList[index];
|
||||
if (!_tabDic.ContainsKey(childID))
|
||||
{
|
||||
if (tabTemp != null)
|
||||
{
|
||||
tab = _owner.CreateWidgetByPrefab<T>(tabTemp, m_tabGrid);
|
||||
}
|
||||
else
|
||||
{
|
||||
tab = _owner.CreateWidgetByType<T>(m_tabGrid);
|
||||
}
|
||||
|
||||
tab.UpdateTabName(_tabName[childID]);
|
||||
tab.BindClickEvent(TabOnClick, childID);
|
||||
_tabDic[childID] = tab;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SwitchPage(initChildID);
|
||||
return tab;
|
||||
}
|
||||
|
||||
public void CreatTabByItem<T>(int initChildID, GameObject go) where T : SwitchTabItem, new()
|
||||
{
|
||||
if (!_tabDic.ContainsKey(initChildID))
|
||||
{
|
||||
T tab = _owner.CreateWidgetByPrefab<T>(go, m_tabGrid);
|
||||
tab.UpdateTabName(_tabName[initChildID]);
|
||||
tab.BindClickEvent(TabOnClick, initChildID);
|
||||
_tabDic[initChildID] = tab;
|
||||
}
|
||||
}
|
||||
|
||||
// 设置页签的自定义点击行为
|
||||
public void SetCustomTabClickAction(int tabIdx, Action<SwitchTabItem> clickAction, object param1 = null,
|
||||
object param2 = null, object param3 = null)
|
||||
{
|
||||
_tabDic[tabIdx].BindClickEvent(clickAction, param1, param2, param3);
|
||||
}
|
||||
|
||||
public int TabCount => _tabDic.Count;
|
||||
|
||||
public void SetTabRedNode(int tabId, bool isShow)
|
||||
{
|
||||
if (_tabDic.TryGetValue(tabId, out var value))
|
||||
{
|
||||
value.SetRedNote(isShow);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTabFontSize(int fontSize)
|
||||
{
|
||||
for (int i = 0; i < IDList.Count; i++)
|
||||
{
|
||||
var tabId = IDList[i];
|
||||
_tabDic[tabId].SetITabTextFontSize(fontSize);
|
||||
}
|
||||
}
|
||||
|
||||
private void TabOnClick(SwitchTabItem tab)
|
||||
{
|
||||
var childID = (int)tab.EventParam1;
|
||||
SwitchPage(childID);
|
||||
}
|
||||
|
||||
public virtual void SwitchPage(int selectID)
|
||||
{
|
||||
if (_switchTabCondition != null && !_switchTabCondition(selectID))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (CurrentChildID != selectID)
|
||||
{
|
||||
if (_switchPageDic.TryGetValue(selectID, out var pageLs))
|
||||
{
|
||||
for (int i = 0; i < pageLs.Count; i++)
|
||||
{
|
||||
var pageName = pageLs[i];
|
||||
ChildPageBase page = GetChildPageByName(pageName);
|
||||
if (page != null && page.gameObject == null)
|
||||
{
|
||||
page.CreateByPath(pageName, _owner, ChildPageParent);
|
||||
page.InitData(_shareData);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < _childPageNames.Count; i++)
|
||||
{
|
||||
string pageName = _childPageNames[i];
|
||||
ChildPageBase page = GetChildPageByName(pageName);
|
||||
bool beShow = pageLs.IndexOf(pageName) >= 0;
|
||||
if (page != null && page.gameObject != null)
|
||||
{
|
||||
if (_needSetActive)
|
||||
{
|
||||
//page.Show(beShow);
|
||||
if (beShow)
|
||||
{
|
||||
page.gameObject.SetActive(true);
|
||||
// page.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
page.gameObject.SetActive(false);
|
||||
// page.Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (page != null && beShow)
|
||||
if (page != null)
|
||||
{
|
||||
page.OnPageShowed(CurrentChildID, selectID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var index = 0; index < IDList.Count; index++)
|
||||
{
|
||||
var childID = IDList[index];
|
||||
SwitchTabItem tab;
|
||||
if (_tabDic.TryGetValue(childID, out tab))
|
||||
{
|
||||
tab.SetState(selectID == childID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var oldID = CurrentChildID;
|
||||
CurrentChildID = selectID;
|
||||
if (SwitchTabAction != null)
|
||||
{
|
||||
SwitchTabAction(oldID, selectID);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ShowPage(int selectID)
|
||||
{
|
||||
if (_switchPageDic.TryGetValue(selectID, out var pageLs))
|
||||
{
|
||||
for (int i = 0; i < pageLs.Count; i++)
|
||||
{
|
||||
var pageName = pageLs[i];
|
||||
ChildPageBase page = GetChildPageByName(pageName);
|
||||
if (page != null && page.gameObject == null)
|
||||
{
|
||||
page.CreateByPath(pageName, _owner, ChildPageParent);
|
||||
page.InitData(_shareData);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < _childPageNames.Count; i++)
|
||||
{
|
||||
string pageName = _childPageNames[i];
|
||||
ChildPageBase page = GetChildPageByName(pageName);
|
||||
bool beShow = pageLs.IndexOf(pageName) >= 0;
|
||||
if (page != null && page.gameObject != null)
|
||||
{
|
||||
if (beShow)
|
||||
{
|
||||
page.gameObject.SetActive(true);
|
||||
// page.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
page.gameObject.SetActive(false);
|
||||
// page.Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var index = 0; index < IDList.Count; index++)
|
||||
{
|
||||
var childID = IDList[index];
|
||||
SwitchTabItem tab;
|
||||
if (_tabDic.TryGetValue(childID, out tab))
|
||||
{
|
||||
tab.SetState(selectID == childID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RefreshCurrentChildPage()
|
||||
{
|
||||
if (_switchPageDic.TryGetValue(CurrentChildID, out var pageNames))
|
||||
{
|
||||
for (int i = 0; i < pageNames.Count; i++)
|
||||
{
|
||||
ChildPageBase page = GetChildPageByName(pageNames[i]);
|
||||
if (page != null && page.gameObject != null)
|
||||
{
|
||||
page.RefreshPage();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RefreshChildPage(int childID)
|
||||
{
|
||||
if (_switchPageDic.TryGetValue(childID, out var pageNames))
|
||||
{
|
||||
for (int i = 0; i < pageNames.Count; i++)
|
||||
{
|
||||
ChildPageBase page = GetChildPageByName(pageNames[i]);
|
||||
if (page != null && page.gameObject != null)
|
||||
{
|
||||
page.RefreshPage();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGetChildPage<T>(out T t) where T : ChildPageBase
|
||||
{
|
||||
t = GetChildPage<T>();
|
||||
return t != null;
|
||||
}
|
||||
|
||||
public int GetCurShowType()
|
||||
{
|
||||
return CurrentChildID;
|
||||
}
|
||||
|
||||
public void ReductionShowType()
|
||||
{
|
||||
CurrentChildID = -100;
|
||||
}
|
||||
|
||||
#region 没有ChildPage,可通过m_switchTabAction来处理切页事件(也可以光展示用)
|
||||
|
||||
public SwitchTabItem GetTabItem(int childId)
|
||||
{
|
||||
_tabDic.TryGetValue(childId, out var item);
|
||||
return item;
|
||||
}
|
||||
|
||||
public void CreateJumpTab<T>(int initChildID, string tabName, GameObject tabTemp = null)
|
||||
where T : SwitchTabItem, new()
|
||||
{
|
||||
if (IDList.IndexOf(initChildID) < 0)
|
||||
{
|
||||
IDList.Add(initChildID);
|
||||
}
|
||||
|
||||
_tabName[initChildID] = tabName;
|
||||
|
||||
for (var index = 0; index < IDList.Count; index++)
|
||||
{
|
||||
var childID = IDList[index];
|
||||
if (!_tabDic.ContainsKey(childID))
|
||||
{
|
||||
T tab;
|
||||
if (tabTemp != null)
|
||||
{
|
||||
tab = _owner.CreateWidgetByPrefab<T>(tabTemp, m_tabGrid);
|
||||
}
|
||||
else
|
||||
{
|
||||
tab = _owner.CreateWidgetByType<T>(m_tabGrid);
|
||||
}
|
||||
|
||||
tab.UpdateTabName(_tabName[childID]);
|
||||
tab.BindClickEvent(TabOnClick, childID);
|
||||
_tabDic[childID] = tab;
|
||||
}
|
||||
}
|
||||
|
||||
SwitchPage(initChildID);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 设置共享参数。
|
||||
/// </summary>
|
||||
/// <param name="paramIdx"></param>
|
||||
/// <param name="param"></param>
|
||||
public void SetShareParam(int paramIdx, object param)
|
||||
{
|
||||
_shareData.SetParam(paramIdx, param);
|
||||
}
|
||||
|
||||
public T GetChildPage<T>() where T : ChildPageBase
|
||||
{
|
||||
var pageName = typeof(T).Name;
|
||||
_childPageDic.TryGetValue(pageName, out var page);
|
||||
return page as T;
|
||||
}
|
||||
|
||||
public ChildPageBase GetChildPageByName(string pageName)
|
||||
{
|
||||
_childPageDic.TryGetValue(pageName, out var page);
|
||||
return page;
|
||||
}
|
||||
|
||||
public void BindChildPage<T, U>(int childID, string tabName)
|
||||
where T : ChildPageBase, new()
|
||||
where U : ChildPageBase, new()
|
||||
{
|
||||
BindChildPage<T>(childID, tabName);
|
||||
BindChildPage<U>(childID, tabName);
|
||||
}
|
||||
|
||||
public void BindChildPage<T, U, V>(int childID, string tabName)
|
||||
where T : ChildPageBase, new()
|
||||
where U : ChildPageBase, new()
|
||||
where V : ChildPageBase, new()
|
||||
{
|
||||
BindChildPage<T>(childID, tabName);
|
||||
BindChildPage<U>(childID, tabName);
|
||||
BindChildPage<V>(childID, tabName);
|
||||
}
|
||||
|
||||
public void BindChildPage<T, U, V, W>(int childID, string tabName)
|
||||
where T : ChildPageBase, new()
|
||||
where U : ChildPageBase, new()
|
||||
where V : ChildPageBase, new()
|
||||
where W : ChildPageBase, new()
|
||||
{
|
||||
BindChildPage<T>(childID, tabName);
|
||||
BindChildPage<U>(childID, tabName);
|
||||
BindChildPage<V>(childID, tabName);
|
||||
BindChildPage<W>(childID, tabName);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e04155ae1ce3448587a5e322477d0076
|
||||
timeCreated: 1687859725
|
@@ -0,0 +1,263 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public class SwitchTabItem : UIEventItem<SwitchTabItem>
|
||||
{
|
||||
//选中时的文本
|
||||
protected TextMeshProUGUI m_selectText;
|
||||
//未选中时的文本
|
||||
protected TextMeshProUGUI m_noSelectText;
|
||||
//选中时的图片
|
||||
protected Image m_selectImage;
|
||||
//未选中时的图片
|
||||
protected Image m_noSelectImage;
|
||||
//选中时的节点
|
||||
protected Transform m_selectNode;
|
||||
//未选中时的节点
|
||||
protected Transform m_noSelectNode;
|
||||
|
||||
//选中时的Icon
|
||||
protected Image m_selectIcon;
|
||||
//未选中时的Icon
|
||||
protected Image m_noSelectIcon;
|
||||
|
||||
protected GameObject m_goRedNote;
|
||||
|
||||
//是否选中
|
||||
public bool IsSelect
|
||||
{
|
||||
get { return m_isSelect; }
|
||||
set { SetState(value); }
|
||||
}
|
||||
|
||||
protected bool m_isSelect = false;
|
||||
|
||||
//private RedNoteBehaviour m_redNote;
|
||||
public RedNoteWidget m_redNote { get; private set; }
|
||||
|
||||
public virtual Vector2 SelectRedPointPos
|
||||
{
|
||||
get
|
||||
{
|
||||
return Vector2.zero;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Vector2 NoSelectRedPointPos
|
||||
{
|
||||
get
|
||||
{
|
||||
return Vector2.zero;
|
||||
}
|
||||
}
|
||||
|
||||
public override void BindMemberProperty()
|
||||
{
|
||||
m_selectNode = FindChild("SelectNode");
|
||||
m_noSelectNode = FindChild("NoSelectNode");
|
||||
if (m_selectNode != null)
|
||||
{
|
||||
m_selectText = FindChildComponent<TextMeshProUGUI>(m_selectNode, "SelectText");
|
||||
m_selectImage = FindChildComponent<Image>(m_selectNode, "SelectImage");
|
||||
m_selectIcon = FindChildComponent<Image>(m_selectNode, "SelectIcon");
|
||||
}
|
||||
if (m_noSelectNode != null)
|
||||
{
|
||||
m_noSelectText = FindChildComponent<TextMeshProUGUI>(m_noSelectNode, "NoSelectText");
|
||||
m_noSelectImage = FindChildComponent<Image>(m_noSelectNode, "NoSelectImage");
|
||||
m_noSelectIcon = FindChildComponent<Image>(m_noSelectNode, "NoSelectIcon");
|
||||
}
|
||||
|
||||
var tf = FindChild("m_goRedNote");
|
||||
if (tf != null)
|
||||
{
|
||||
m_goRedNote = tf.gameObject;
|
||||
m_redNote = CreateWidgetByType<RedNoteWidget>(tf);
|
||||
m_redNote.rectTransform.anchoredPosition = Vector2.zero;
|
||||
SetRedNote(false);
|
||||
//CreateDefaultRedNote();
|
||||
}
|
||||
}
|
||||
|
||||
#region 红点相关
|
||||
public void SetRedNoteType(RedNoteNotify type)
|
||||
{
|
||||
if (m_redNote != null)
|
||||
{
|
||||
m_redNote.m_redNote.SetNotifyType(type);
|
||||
}
|
||||
SetRedNote(true);
|
||||
}
|
||||
|
||||
public void SetRedNoteType(RedNoteNotify type, ulong param1)
|
||||
{
|
||||
if (m_redNote != null)
|
||||
{
|
||||
m_redNote.m_redNote.SetNotifyType(type, param1);
|
||||
}
|
||||
SetRedNote(true);
|
||||
}
|
||||
|
||||
public void SetRedNoteType(RedNoteNotify type, ulong param1, ulong param2)
|
||||
{
|
||||
if (m_redNote != null)
|
||||
{
|
||||
m_redNote.m_redNote.SetNotifyType(type, param1, param2);
|
||||
}
|
||||
SetRedNote(true);
|
||||
}
|
||||
|
||||
public void SetRedNoteType(RedNoteNotify type, ulong param1, ulong param2, ulong param3)
|
||||
{
|
||||
if (m_redNote != null)
|
||||
{
|
||||
m_redNote.m_redNote.SetNotifyType(type, param1, param2, param3);
|
||||
}
|
||||
SetRedNote(true);
|
||||
}
|
||||
|
||||
public void SetRedNoteState(bool state)
|
||||
{
|
||||
if (m_redNote != null)
|
||||
{
|
||||
m_redNote.m_redNote.SetRedNoteState(state);
|
||||
}
|
||||
SetRedNote(state);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void UpdateTabName(string tabName)
|
||||
{
|
||||
if (m_selectText != null)
|
||||
{
|
||||
m_selectText.text = tabName;
|
||||
m_selectText.rectTransform.sizeDelta = new Vector2(m_selectText.preferredWidth, m_selectText.rectTransform.sizeDelta.y);
|
||||
}
|
||||
if (m_noSelectText != null)
|
||||
{
|
||||
m_noSelectText.text = tabName;
|
||||
m_noSelectText.rectTransform.sizeDelta = new Vector2(m_noSelectText.preferredWidth, m_noSelectText
|
||||
.rectTransform.sizeDelta.y);
|
||||
}
|
||||
}
|
||||
|
||||
// public void UpdateTabImage(string selectImageName,string noSelectImageName)
|
||||
// {
|
||||
// if (m_selectImage != null)
|
||||
// {
|
||||
// UISpriteHelper.Instance.SetSprite(m_selectImage, selectImageName);
|
||||
// }
|
||||
// if (m_noSelectImage != null)
|
||||
// {
|
||||
// UISpriteHelper.Instance.SetSprite(m_noSelectImage, noSelectImageName);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void UpdateIcon(string selectIconName, string noSelectIconName)
|
||||
// {
|
||||
// if (m_selectIcon != null)
|
||||
// {
|
||||
// DUISpriteHelper.Instance.SetSprite(m_selectIcon, selectIconName, true);
|
||||
// }
|
||||
// if (m_noSelectIcon != null)
|
||||
// {
|
||||
// DUISpriteHelper.Instance.SetSprite(m_noSelectIcon, noSelectIconName, true);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public virtual void CreateDefaultRedNote()
|
||||
// {
|
||||
// if (m_goRedNote != null)
|
||||
// {
|
||||
// UIEffectHelper.CreateUIEffectGoById((uint)CommonEffectID.EffectRedPoint, m_goRedNote.transform);
|
||||
// }
|
||||
// }
|
||||
|
||||
public void SetRedNote(bool show)
|
||||
{
|
||||
if (m_goRedNote != null)
|
||||
{
|
||||
m_goRedNote.SetActive(show);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SetState(bool select)
|
||||
{
|
||||
m_isSelect = select;
|
||||
if (m_selectNode != null)
|
||||
{
|
||||
m_selectNode.gameObject.SetActive(select);
|
||||
}
|
||||
if (m_noSelectNode != null)
|
||||
{
|
||||
m_noSelectNode.gameObject.SetActive(!select);
|
||||
}
|
||||
|
||||
if (m_goRedNote != null)
|
||||
{
|
||||
if (select)
|
||||
{
|
||||
if (SelectRedPointPos != Vector2.zero)
|
||||
{
|
||||
((RectTransform)m_goRedNote.transform).anchoredPosition = SelectRedPointPos;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (NoSelectRedPointPos != Vector2.zero)
|
||||
{
|
||||
((RectTransform)m_goRedNote.transform).anchoredPosition = NoSelectRedPointPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetITabTextFontSize(int fontSize)
|
||||
{
|
||||
if (m_selectText != null)
|
||||
{
|
||||
m_selectText.fontSize = fontSize;
|
||||
}
|
||||
if (m_noSelectText != null)
|
||||
{
|
||||
m_noSelectText.fontSize = fontSize;
|
||||
}
|
||||
}
|
||||
|
||||
#region UI-ID
|
||||
/// <summary>
|
||||
/// UI-ID
|
||||
/// </summary>
|
||||
public uint uiID;
|
||||
|
||||
/// <summary>
|
||||
/// UI标识
|
||||
/// </summary>
|
||||
protected string m_uiFlag;
|
||||
|
||||
/// <summary>
|
||||
/// 检查方法
|
||||
/// </summary>
|
||||
protected Func<bool> m_funcCheck;
|
||||
|
||||
/// <summary>
|
||||
/// 页签索引
|
||||
/// </summary>
|
||||
public int tabIndex = -1;
|
||||
|
||||
/// <summary>
|
||||
/// UI标识
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual string GetUiFlag()
|
||||
{
|
||||
return string.IsNullOrEmpty(m_uiFlag) ? uiID.ToString() : m_uiFlag;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 498417b8785d47249da952f77d069c33
|
||||
timeCreated: 1687667780
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b50cf85b0f0d4e43b12cb694f6c07979
|
||||
timeCreated: 1695289335
|
@@ -0,0 +1,18 @@
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class EmptyGraph : Graphic
|
||||
{
|
||||
public bool m_debug = false;
|
||||
|
||||
protected override void OnPopulateMesh(VertexHelper vbo)
|
||||
{
|
||||
vbo.Clear();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (m_debug)
|
||||
{
|
||||
base.OnPopulateMesh(vbo);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21df3dfa358b498e8da3d169d736df58
|
||||
timeCreated: 1695289370
|
@@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
[AddComponentMenu("UI/TScrollRect Rect", 37)]
|
||||
[SelectionBase]
|
||||
[ExecuteAlways]
|
||||
[DisallowMultipleComponent]
|
||||
[RequireComponent(typeof (RectTransform))]
|
||||
public class TScrollRect : ScrollRect
|
||||
{
|
||||
private event Action ActionBeginDrag;
|
||||
private event Action ActionOnDrag;
|
||||
private event Action ActionEndDrag;
|
||||
|
||||
public List<ScrollRect> parentScrollRectList;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
if (parentScrollRectList != null && parentScrollRectList.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < parentScrollRectList.Count; i++)
|
||||
{
|
||||
AddParentScrollRect(parentScrollRectList[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<ScrollRect> m_listParentScrollRect;
|
||||
|
||||
public void AddParentScrollRect(ScrollRect parentScrollRect)
|
||||
{
|
||||
if (parentScrollRect == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_listParentScrollRect == null)
|
||||
{
|
||||
m_listParentScrollRect = new List<ScrollRect>();
|
||||
}
|
||||
|
||||
if (!m_listParentScrollRect.Contains(parentScrollRect))
|
||||
{
|
||||
m_listParentScrollRect.Add(parentScrollRect);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddBeginDragListener(Action action)
|
||||
{
|
||||
ActionBeginDrag += action;
|
||||
}
|
||||
|
||||
public void RemoveBeginDragListener(Action action)
|
||||
{
|
||||
ActionBeginDrag -= action;
|
||||
}
|
||||
|
||||
public void AddOnDragListener(Action action)
|
||||
{
|
||||
ActionOnDrag += action;
|
||||
}
|
||||
|
||||
public void RemoveOnDragListener(Action action)
|
||||
{
|
||||
ActionOnDrag -= action;
|
||||
}
|
||||
|
||||
public void AddEndDragListener(Action action)
|
||||
{
|
||||
ActionEndDrag += action;
|
||||
}
|
||||
|
||||
public void RemoveEndDragListener(Action action)
|
||||
{
|
||||
ActionEndDrag -= action;
|
||||
}
|
||||
|
||||
public override void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
base.OnBeginDrag(eventData);
|
||||
if (ActionBeginDrag != null)
|
||||
{
|
||||
ActionBeginDrag();
|
||||
}
|
||||
|
||||
if (m_listParentScrollRect != null)
|
||||
{
|
||||
for (int i = 0; i < m_listParentScrollRect.Count; i++)
|
||||
{
|
||||
var parentScrollRect = m_listParentScrollRect[i];
|
||||
parentScrollRect.OnBeginDrag(eventData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
base.OnDrag(eventData);
|
||||
if (ActionOnDrag != null)
|
||||
{
|
||||
ActionOnDrag();
|
||||
}
|
||||
|
||||
if (m_listParentScrollRect != null)
|
||||
{
|
||||
for (int i = 0; i < m_listParentScrollRect.Count; i++)
|
||||
{
|
||||
var parentScrollRect = m_listParentScrollRect[i];
|
||||
parentScrollRect.OnDrag(eventData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
base.OnEndDrag(eventData);
|
||||
if (ActionEndDrag != null)
|
||||
{
|
||||
ActionEndDrag();
|
||||
}
|
||||
|
||||
if (m_listParentScrollRect != null)
|
||||
{
|
||||
for (int i = 0; i < m_listParentScrollRect.Count; i++)
|
||||
{
|
||||
var parentScrollRect = m_listParentScrollRect[i];
|
||||
parentScrollRect.OnEndDrag(eventData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d322e77e03014f65a9ec277d50bd12f8
|
||||
timeCreated: 1695289370
|
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public class UIButtonSound : MonoBehaviour, IPointerClickHandler
|
||||
{
|
||||
private static Action<int> _playSoundAction = null;
|
||||
|
||||
public int clickSound = 2;
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (_playSoundAction != null)
|
||||
{
|
||||
_playSoundAction(clickSound);
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddPlaySoundAction(Action<int> onClick)
|
||||
{
|
||||
_playSoundAction += onClick;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb272eb1eec94625884e6e83889daa9a
|
||||
timeCreated: 1695289370
|
@@ -0,0 +1,226 @@
|
||||
using System;
|
||||
using TEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public class UIEventItem<T> : UIWidget where T : UIEventItem<T>
|
||||
{
|
||||
private object m_eventParam1;
|
||||
private object m_eventParam2;
|
||||
private object m_eventParam3;
|
||||
public object EventParam1 => m_eventParam1;
|
||||
|
||||
public object EventParam2 => m_eventParam2;
|
||||
|
||||
public object EventParam3 => m_eventParam3;
|
||||
private Action<T> m_clickAction;
|
||||
private Action<T, bool> m_pressAction;
|
||||
private Action<T, PointerEventData> m_beginDragAction;
|
||||
private Action<T, PointerEventData> m_dragAction;
|
||||
private Action<T, PointerEventData> m_endDragAction;
|
||||
|
||||
public void BindClickEvent(Action<T> clickAction, object eParam1 = null, object eParam2 = null, object eParam3 = null,
|
||||
Selectable.Transition transition = Selectable.Transition.ColorTint)
|
||||
{
|
||||
if (m_clickAction != null)
|
||||
{
|
||||
m_clickAction = clickAction;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_clickAction = clickAction;
|
||||
var button = gameObject.GetOrAddComponent<Button>();
|
||||
button.transition = transition;
|
||||
button.onClick.AddListener(() =>
|
||||
{
|
||||
if (m_clickAction != null)
|
||||
{
|
||||
m_clickAction(this as T);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
SetEventParam(eParam1, eParam2, eParam3);
|
||||
}
|
||||
|
||||
public void BindClickEventEx(Action<T> clickAction, object eParam1 = null, object eParam2 = null, object eParam3 = null)
|
||||
{
|
||||
if (m_clickAction != null)
|
||||
{
|
||||
m_clickAction = clickAction;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_clickAction = clickAction;
|
||||
var button = gameObject.GetOrAddComponent<Button>();
|
||||
button.onClick.AddListener(() =>
|
||||
{
|
||||
if (m_clickAction != null)
|
||||
{
|
||||
m_clickAction(this as T);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
SetEventParam(eParam1, eParam2, eParam3);
|
||||
}
|
||||
|
||||
public void BindBeginDragEvent(Action<T, PointerEventData> dragAction, object eParam1 = null, object eParam2 = null, object eParam3 = null)
|
||||
{
|
||||
if (m_beginDragAction != null)
|
||||
{
|
||||
m_beginDragAction = dragAction;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_beginDragAction = dragAction;
|
||||
var trigger = gameObject.GetOrAddComponent<EventTrigger>();
|
||||
EventTrigger.Entry entry = new EventTrigger.Entry();
|
||||
entry.eventID = EventTriggerType.BeginDrag;
|
||||
entry.callback = new EventTrigger.TriggerEvent();
|
||||
entry.callback.AddListener((data) =>
|
||||
{
|
||||
var pointerEventData = (PointerEventData)data;
|
||||
if (m_beginDragAction != null)
|
||||
{
|
||||
m_beginDragAction(this as T, pointerEventData);
|
||||
}
|
||||
});
|
||||
trigger.triggers.Add(entry);
|
||||
}
|
||||
|
||||
SetEventParam(eParam1, eParam2, eParam3);
|
||||
}
|
||||
|
||||
public void BindDragEvent(Action<T, PointerEventData> dragAction, object eParam1 = null, object eParam2 = null, object eParam3 = null)
|
||||
{
|
||||
if (m_dragAction != null)
|
||||
{
|
||||
m_dragAction = dragAction;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dragAction = dragAction;
|
||||
var trigger = gameObject.GetOrAddComponent<EventTrigger>();
|
||||
EventTrigger.Entry entry = new EventTrigger.Entry();
|
||||
entry.eventID = EventTriggerType.Drag;
|
||||
entry.callback = new EventTrigger.TriggerEvent();
|
||||
entry.callback.AddListener((data) =>
|
||||
{
|
||||
var pointerEventData = (PointerEventData)data;
|
||||
if (m_dragAction != null)
|
||||
{
|
||||
m_dragAction(this as T, pointerEventData);
|
||||
}
|
||||
});
|
||||
trigger.triggers.Add(entry);
|
||||
}
|
||||
|
||||
SetEventParam(eParam1, eParam2, eParam3);
|
||||
}
|
||||
|
||||
public void BindEndDragEvent(Action<T, PointerEventData> dragendAction, object eParam1 = null, object eParam2 = null, object eParam3 = null)
|
||||
{
|
||||
if (m_endDragAction != null)
|
||||
{
|
||||
m_endDragAction = dragendAction;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_endDragAction = dragendAction;
|
||||
var trigger = gameObject.GetOrAddComponent<EventTrigger>();
|
||||
EventTrigger.Entry entry = new EventTrigger.Entry();
|
||||
entry.eventID = EventTriggerType.EndDrag;
|
||||
entry.callback = new EventTrigger.TriggerEvent();
|
||||
entry.callback.AddListener((data) =>
|
||||
{
|
||||
if (m_endDragAction != null)
|
||||
{
|
||||
m_endDragAction(this as T, (PointerEventData)data);
|
||||
}
|
||||
});
|
||||
trigger.triggers.Add(entry);
|
||||
}
|
||||
|
||||
SetEventParam(eParam1, eParam2, eParam3);
|
||||
}
|
||||
|
||||
public void BindPressEvent(Action<T, bool> pressAction, object eParam1 = null, object eParam2 = null, object eParam3 = null)
|
||||
{
|
||||
if (m_pressAction != null)
|
||||
{
|
||||
m_pressAction = pressAction;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pressAction = pressAction;
|
||||
var trigger = gameObject.GetOrAddComponent<EventTrigger>();
|
||||
EventTrigger.Entry entry = new EventTrigger.Entry();
|
||||
entry.eventID = EventTriggerType.PointerDown;
|
||||
entry.callback = new EventTrigger.TriggerEvent();
|
||||
entry.callback.AddListener((data) =>
|
||||
{
|
||||
if (m_pressAction != null)
|
||||
{
|
||||
m_pressAction(this as T, true);
|
||||
}
|
||||
});
|
||||
trigger.triggers.Add(entry);
|
||||
entry = new EventTrigger.Entry();
|
||||
entry.eventID = EventTriggerType.PointerUp;
|
||||
entry.callback = new EventTrigger.TriggerEvent();
|
||||
entry.callback.AddListener((data) =>
|
||||
{
|
||||
if (m_pressAction != null)
|
||||
{
|
||||
m_pressAction(this as T, false);
|
||||
}
|
||||
});
|
||||
trigger.triggers.Add(entry);
|
||||
}
|
||||
|
||||
SetEventParam(eParam1, eParam2, eParam3);
|
||||
}
|
||||
|
||||
public void BindPressEventEx(Action<T, bool> pressAction, object eParam1 = null, object eParam2 = null, object eParam3 = null,
|
||||
float durationThreshold = 1)
|
||||
{
|
||||
if (m_pressAction != null)
|
||||
{
|
||||
m_pressAction = pressAction;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pressAction = pressAction;
|
||||
var button = gameObject.GetOrAddComponent<UIButtonSuper>();
|
||||
button.m_LongPressDurationTime = durationThreshold;
|
||||
button.onPress.AddListener(() =>
|
||||
{
|
||||
if (m_pressAction != null)
|
||||
{
|
||||
m_pressAction(this as T, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
SetEventParam(eParam1, eParam2, eParam3);
|
||||
}
|
||||
|
||||
public void SetEventParam(object eParam1, object eParam2 = null, object eParam3 = null)
|
||||
{
|
||||
m_eventParam1 = eParam1;
|
||||
m_eventParam2 = eParam2;
|
||||
m_eventParam3 = eParam3;
|
||||
}
|
||||
|
||||
public void OnTriggerBtnEvent()
|
||||
{
|
||||
if (m_clickAction != null)
|
||||
{
|
||||
m_clickAction(this as T);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9972ff1d1514807bbd21d6bc4c035f4
|
||||
timeCreated: 1695289504
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d3f2e9ab868464da947f3d52aa9c3f6
|
||||
timeCreated: 1695289443
|
@@ -0,0 +1,337 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// UI列表Item
|
||||
/// </summary>
|
||||
/// <typeparam name="DataT"></typeparam>
|
||||
public interface IListDataItem<in DataT>
|
||||
{
|
||||
void SetItemData(DataT d);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UI列表Item
|
||||
/// </summary>
|
||||
public interface IListSelectItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取索引。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
int GetItemIndex();
|
||||
|
||||
/// <summary>
|
||||
/// 设置索引。
|
||||
/// </summary>
|
||||
/// <param name="i"></param>
|
||||
void SetItemIndex(int i);
|
||||
|
||||
/// <summary>
|
||||
/// 是否被选中。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
bool IsSelected();
|
||||
|
||||
/// <summary>
|
||||
/// 设置是否选中。
|
||||
/// </summary>
|
||||
/// <param name="v"></param>
|
||||
void SetSelected(bool v);
|
||||
}
|
||||
|
||||
public class SelectItemBase : UIEventItem<SelectItemBase>, IListSelectItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 索引。
|
||||
/// </summary>
|
||||
protected int m_itemIndex;
|
||||
|
||||
public int GetItemIndex()
|
||||
{
|
||||
return m_itemIndex;
|
||||
}
|
||||
|
||||
public void SetItemIndex(int i)
|
||||
{
|
||||
m_itemIndex = i;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否被选中。
|
||||
/// </summary>
|
||||
protected bool m_isSelected;
|
||||
|
||||
public virtual bool IsSelected()
|
||||
{
|
||||
return m_isSelected;
|
||||
}
|
||||
|
||||
public virtual void SetSelected(bool v)
|
||||
{
|
||||
if (m_isSelected == v) return;
|
||||
m_isSelected = v;
|
||||
UpdateSelect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新选中状态。
|
||||
/// </summary>
|
||||
public virtual void UpdateSelect()
|
||||
{
|
||||
}
|
||||
|
||||
public override void RegisterEvent()
|
||||
{
|
||||
base.RegisterEvent();
|
||||
AddSelectEvt();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 监听选中事件。
|
||||
/// </summary>
|
||||
protected virtual void AddSelectEvt()
|
||||
{
|
||||
if (Parent == null || !(Parent is IUISelectList)) return;
|
||||
var btn = gameObject.GetOrAddComponent<Button>();
|
||||
if (btn != null)
|
||||
{
|
||||
btn.onClick.AddListener(OnSelectClick);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选中点击
|
||||
/// </summary>
|
||||
protected virtual void OnSelectClick()
|
||||
{
|
||||
var p = Parent as IUISelectList;
|
||||
if (p != null)
|
||||
{
|
||||
p.OnItemClick(this, GetItemIndex());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface IUISelectList
|
||||
{
|
||||
void OnItemClick(object item, int i);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UI列表
|
||||
/// </summary>
|
||||
public class UIListBase<ItemT, DataT> : UIWidget, IUISelectList where ItemT : UIWidget, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// item模板
|
||||
/// </summary>
|
||||
public GameObject itemBase;
|
||||
|
||||
/// <summary>
|
||||
/// 数据列表
|
||||
/// </summary>
|
||||
protected List<DataT> m_datas;
|
||||
|
||||
/// <summary>
|
||||
/// 数据列表
|
||||
/// </summary>
|
||||
public List<DataT> datas => m_datas;
|
||||
|
||||
/// <summary>
|
||||
/// 数据数量
|
||||
/// </summary>
|
||||
public int DataNum => m_datas?.Count ?? 0;
|
||||
|
||||
/// <summary>
|
||||
/// 数量
|
||||
/// </summary>
|
||||
protected int m_num;
|
||||
|
||||
/// <summary>
|
||||
/// 数量
|
||||
/// </summary>
|
||||
public int num => m_num;
|
||||
|
||||
/// <summary>
|
||||
/// 设置数据数量
|
||||
/// </summary>
|
||||
/// <param name="n"></param>
|
||||
/// <param name="funcItem"></param>
|
||||
public void SetDataNum(int n, Action<ItemT, int> funcItem = null)
|
||||
{
|
||||
AdjustItemNum(n, null, funcItem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据起始索引
|
||||
/// </summary>
|
||||
public int dataStartOffset = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 设置数据
|
||||
/// </summary>
|
||||
/// <param name="dataList"></param>
|
||||
/// <param name="n"></param>
|
||||
public void SetDatas(List<DataT> dataList, int n = -1)
|
||||
{
|
||||
AdjustItemNum(Mathf.Max(0, n >= 0 ? n : (dataList == null ? 0 : (dataList.Count - dataStartOffset))),
|
||||
dataList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置显示数据
|
||||
/// </summary>
|
||||
/// <param name="n"></param>
|
||||
/// <param name="datas"></param>
|
||||
/// <param name="funcItem"></param>
|
||||
protected virtual void AdjustItemNum(int n, List<DataT> datas = null, Action<ItemT, int> funcItem = null)
|
||||
{
|
||||
m_num = n;
|
||||
m_datas = datas;
|
||||
if (itemBase != null)
|
||||
{
|
||||
itemBase.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新列表ITEM
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="i"></param>
|
||||
/// <param name="func"></param>
|
||||
protected virtual void UpdateListItem(ItemT item, int i, Action<ItemT, int> func)
|
||||
{
|
||||
if (item == null) return;
|
||||
if (func != null)
|
||||
{
|
||||
func.Invoke(item, i);
|
||||
return;
|
||||
}
|
||||
|
||||
var listDataItem = item as IListDataItem<DataT>;
|
||||
if (listDataItem != null)
|
||||
{
|
||||
listDataItem.SetItemData(GetData(i));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选中索引
|
||||
/// </summary>
|
||||
protected int m_selectIndex = -1;
|
||||
|
||||
/// <summary>
|
||||
/// Item点击
|
||||
/// </summary>
|
||||
public Action<int> funcOnItemClick;
|
||||
|
||||
/// <summary>
|
||||
/// 选中变化回调函数
|
||||
/// </summary>
|
||||
public Action funcOnSelectChange;
|
||||
|
||||
/// <summary>
|
||||
/// 点击无选中变化回调
|
||||
/// </summary>
|
||||
public Action funcNoSelectChange;
|
||||
|
||||
/// <summary>
|
||||
/// 选中索引
|
||||
/// </summary>
|
||||
public int selectIndex
|
||||
{
|
||||
get => m_selectIndex;
|
||||
set => SetSelectIndex(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置选中索引
|
||||
/// </summary>
|
||||
/// <param name="i"></param>
|
||||
/// <param name="forceUpdate"></param>
|
||||
/// <param name="triggerEvt"></param>
|
||||
public void SetSelectIndex(int i, bool forceUpdate = false, bool triggerEvt = true)
|
||||
{
|
||||
if (!forceUpdate && m_selectIndex == i)
|
||||
{
|
||||
if (funcNoSelectChange != null)
|
||||
{
|
||||
funcNoSelectChange.Invoke();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var preIndex = selectIndex;
|
||||
m_selectIndex = i;
|
||||
var item = GetItem(preIndex) as IListSelectItem;
|
||||
if (item != null)
|
||||
{
|
||||
item.SetSelected(false);
|
||||
}
|
||||
|
||||
item = GetItem(selectIndex) as IListSelectItem;
|
||||
if (item != null)
|
||||
{
|
||||
item.SetSelected(true);
|
||||
}
|
||||
|
||||
if (triggerEvt && funcOnSelectChange != null)
|
||||
{
|
||||
funcOnSelectChange.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前选中的数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DataT GetSelectData()
|
||||
{
|
||||
return GetData(selectIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据
|
||||
/// </summary>
|
||||
/// <param name="i"></param>
|
||||
/// <returns></returns>
|
||||
public DataT GetData(int i)
|
||||
{
|
||||
i += dataStartOffset;
|
||||
return m_datas == null || i < 0 || i >= m_datas.Count ? default(DataT) : m_datas[i];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取item
|
||||
/// </summary>
|
||||
/// <param name="i"></param>
|
||||
/// <returns></returns>
|
||||
public virtual ItemT GetItem(int i)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// item被点击
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="i"></param>
|
||||
public void OnItemClick(object item, int i)
|
||||
{
|
||||
if (funcOnItemClick != null)
|
||||
{
|
||||
funcOnItemClick.Invoke(i);
|
||||
}
|
||||
|
||||
selectIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d3742a744bb4934a4848b54bb6910a2
|
||||
timeCreated: 1691679426
|
@@ -0,0 +1,14 @@
|
||||
namespace GameLogic
|
||||
{
|
||||
public class UILoopGridItemWidget: SelectItemBase
|
||||
{
|
||||
public LoopGridViewItem LoopItem { set; get; }
|
||||
|
||||
public int Index { private set; get; }
|
||||
|
||||
public virtual void UpdateItem(int index)
|
||||
{
|
||||
Index = index;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47ee457a0d7549b3a3b5d23f4ac048cd
|
||||
timeCreated: 1692346002
|
@@ -0,0 +1,171 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// UI列表。
|
||||
/// </summary>
|
||||
public class UILoopGridWidget<TItem, TData> : UIListBase<TItem, TData> where TItem : UILoopGridItemWidget, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// LoopRectView
|
||||
/// </summary>
|
||||
public LoopGridView LoopRectView { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// Item字典
|
||||
/// </summary>
|
||||
private Dictionary<int, TItem> m_itemCache = new Dictionary<int, TItem>();
|
||||
|
||||
/// <summary>
|
||||
/// 计算偏差后的ItemList
|
||||
/// </summary>
|
||||
private List<TItem> m_items = new List<TItem>();
|
||||
|
||||
/// <summary>
|
||||
/// 计算偏差后的ItemList
|
||||
/// </summary>
|
||||
public List<TItem> items => m_items;
|
||||
|
||||
public override void BindMemberProperty()
|
||||
{
|
||||
base.BindMemberProperty();
|
||||
LoopRectView = rectTransform.GetComponent<LoopGridView>();
|
||||
}
|
||||
|
||||
public override void OnCreate()
|
||||
{
|
||||
base.OnCreate();
|
||||
LoopRectView.InitGridView(0, OnGetItemByIndex);
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
m_itemCache.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Item回调函数
|
||||
/// </summary>
|
||||
protected Action<TItem, int> m_tpFuncItem;
|
||||
|
||||
/// <summary>
|
||||
/// 设置显示数据
|
||||
/// </summary>
|
||||
/// <param name="n"></param>
|
||||
/// <param name="datas"></param>
|
||||
/// <param name="funcItem"></param>
|
||||
protected override void AdjustItemNum(int n, List<TData> datas = null, Action<TItem, int> funcItem = null)
|
||||
{
|
||||
base.AdjustItemNum(n, datas, funcItem);
|
||||
m_tpFuncItem = funcItem;
|
||||
LoopRectView.SetListItemCount(n);
|
||||
LoopRectView.RefreshAllShownItem();
|
||||
m_tpFuncItem = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取Item
|
||||
/// </summary>
|
||||
/// <param name="listView"></param>
|
||||
/// <param name="itemIndex"></param>
|
||||
/// <param name="row"></param>
|
||||
/// <param name="column"></param>
|
||||
/// <returns></returns>
|
||||
protected LoopGridViewItem OnGetItemByIndex(LoopGridView listView, int itemIndex,int row,int column)
|
||||
{
|
||||
if (itemIndex < 0 || itemIndex >= num) return null;
|
||||
var item = itemBase == null ? CreateItem() : CreateItem(itemBase);
|
||||
if (item == null) return null;
|
||||
item.SetItemIndex(itemIndex);
|
||||
UpdateListItem(item, itemIndex, m_tpFuncItem);
|
||||
return item.LoopItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建Item
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public TItem CreateItem()
|
||||
{
|
||||
return CreateItem(typeof(TItem).Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建Item
|
||||
/// </summary>
|
||||
/// <param name="itemName"></param>
|
||||
/// <returns></returns>
|
||||
public TItem CreateItem(string itemName)
|
||||
{
|
||||
TItem widget = null;
|
||||
LoopGridViewItem item = LoopRectView.AllocOrNewListViewItem(itemName);
|
||||
if (item != null)
|
||||
{
|
||||
widget = CreateItem(item);
|
||||
}
|
||||
return widget;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建Item
|
||||
/// </summary>
|
||||
/// <param name="prefab"></param>
|
||||
/// <returns></returns>
|
||||
public TItem CreateItem(GameObject prefab)
|
||||
{
|
||||
TItem widget = null;
|
||||
LoopGridViewItem item = LoopRectView.AllocOrNewListViewItem(prefab);
|
||||
if (item != null)
|
||||
{
|
||||
widget = CreateItem(item);
|
||||
}
|
||||
return widget;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建Item
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
private TItem CreateItem(LoopGridViewItem item)
|
||||
{
|
||||
TItem widget;
|
||||
if (!m_itemCache.TryGetValue(item.GoId, out widget))
|
||||
{
|
||||
widget = CreateWidget<TItem>(item.gameObject);
|
||||
widget.LoopItem = item;
|
||||
m_itemCache.Add(item.GoId, widget);
|
||||
}
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取item
|
||||
/// </summary>
|
||||
/// <param name="i"></param>
|
||||
/// <returns></returns>
|
||||
public override TItem GetItem(int i)
|
||||
{
|
||||
return i >= 0 && i < m_items.Count ? m_items[i] : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取itemList
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<TItem> GetItemList()
|
||||
{
|
||||
m_items.Clear();
|
||||
for (int i = 0; i < m_itemCache.Count; i++)
|
||||
{
|
||||
m_items.Add(m_itemCache[i]);
|
||||
}
|
||||
return m_items;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0930448d067145dfb0428b248f1086ae
|
||||
timeCreated: 1692346037
|
@@ -0,0 +1,14 @@
|
||||
namespace GameLogic
|
||||
{
|
||||
public class UILoopItemWidget : SelectItemBase
|
||||
{
|
||||
public LoopListViewItem LoopItem { set; get; }
|
||||
|
||||
public int Index { private set; get; }
|
||||
|
||||
public virtual void UpdateItem(int index)
|
||||
{
|
||||
Index = index;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b39b2f052eec4a4a97256e5aeee9e7dc
|
||||
timeCreated: 1691679577
|
@@ -0,0 +1,95 @@
|
||||
using System.Collections.Generic;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public class UILoopListViewWidget<T> : UIWidget where T : UILoopItemWidget, new()
|
||||
{
|
||||
public LoopListView LoopRectView { private set; get; }
|
||||
|
||||
private Dictionary<int, T> m_itemCache = new Dictionary<int, T>();
|
||||
|
||||
public override void BindMemberProperty()
|
||||
{
|
||||
base.BindMemberProperty();
|
||||
LoopRectView = this.rectTransform.GetComponent<LoopListView>();
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
m_itemCache.Clear();
|
||||
}
|
||||
|
||||
public T CreateItem()
|
||||
{
|
||||
string typeName = typeof(T).Name;
|
||||
return CreateItem(typeName);
|
||||
;
|
||||
}
|
||||
|
||||
public T CreateItem(string itemName)
|
||||
{
|
||||
T widget = null;
|
||||
var item = LoopRectView.AllocOrNewListViewItem(itemName);
|
||||
if (item != null)
|
||||
{
|
||||
widget = CreateItem(item);
|
||||
}
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
public T CreateItem(GameObject prefab)
|
||||
{
|
||||
T widget = null;
|
||||
var item = LoopRectView.AllocOrNewListViewItem(prefab);
|
||||
if (item != null)
|
||||
{
|
||||
widget = CreateItem(item);
|
||||
}
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
private T CreateItem(LoopListViewItem item)
|
||||
{
|
||||
T widget;
|
||||
if (!m_itemCache.TryGetValue(item.GoId, out widget))
|
||||
{
|
||||
widget = CreateWidget<T>(item.gameObject);
|
||||
widget.LoopItem = item;
|
||||
m_itemCache.Add(item.GoId, widget);
|
||||
}
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
public List<T> GetItemList()
|
||||
{
|
||||
List<T> list = new List<T>();
|
||||
for (int i = 0; i < m_itemCache.Count; i++)
|
||||
{
|
||||
list.Add(m_itemCache[i]);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public int GetItemCount()
|
||||
{
|
||||
return m_itemCache.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取Item。
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
public T GetItemByIndex(int index)
|
||||
{
|
||||
return m_itemCache[index];
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b87126ba47740708bc82eb0bb9e414e
|
||||
timeCreated: 1691679617
|
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// UI列表。
|
||||
/// </summary>
|
||||
public class UILoopListWidget<TItem, TData> : UIListBase<TItem, TData> where TItem : UILoopItemWidget, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// LoopRectView
|
||||
/// </summary>
|
||||
public LoopListView LoopRectView { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// Item字典
|
||||
/// </summary>
|
||||
private Dictionary<int, TItem> m_itemCache = new Dictionary<int, TItem>();
|
||||
|
||||
/// <summary>
|
||||
/// 计算偏差后的ItemList
|
||||
/// </summary>
|
||||
private List<TItem> m_items = new List<TItem>();
|
||||
|
||||
/// <summary>
|
||||
/// 计算偏差后的ItemList
|
||||
/// </summary>
|
||||
public List<TItem> items => m_items;
|
||||
|
||||
public override void BindMemberProperty()
|
||||
{
|
||||
base.BindMemberProperty();
|
||||
LoopRectView = rectTransform.GetComponent<LoopListView>();
|
||||
}
|
||||
|
||||
public override void OnCreate()
|
||||
{
|
||||
base.OnCreate();
|
||||
LoopRectView.InitListView(0, OnGetItemByIndex);
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
m_itemCache.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Item回调函数
|
||||
/// </summary>
|
||||
protected Action<TItem, int> m_tpFuncItem;
|
||||
|
||||
/// <summary>
|
||||
/// 设置显示数据
|
||||
/// </summary>
|
||||
/// <param name="n"></param>
|
||||
/// <param name="datas"></param>
|
||||
/// <param name="funcItem"></param>
|
||||
protected override void AdjustItemNum(int n, List<TData> datas = null, Action<TItem, int> funcItem = null)
|
||||
{
|
||||
base.AdjustItemNum(n, datas, funcItem);
|
||||
m_tpFuncItem = funcItem;
|
||||
LoopRectView.SetListItemCount(n);
|
||||
LoopRectView.RefreshAllShownItem();
|
||||
m_tpFuncItem = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取Item
|
||||
/// </summary>
|
||||
/// <param name="listView"></param>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
protected LoopListViewItem OnGetItemByIndex(LoopListView listView, int index)
|
||||
{
|
||||
if (index < 0 || index >= num) return null;
|
||||
var item = itemBase == null ? CreateItem() : CreateItem(itemBase);
|
||||
if (item == null) return null;
|
||||
item.SetItemIndex(index);
|
||||
UpdateListItem(item, index, m_tpFuncItem);
|
||||
return item.LoopItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建Item
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public TItem CreateItem()
|
||||
{
|
||||
return CreateItem(typeof(TItem).Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建Item
|
||||
/// </summary>
|
||||
/// <param name="itemName"></param>
|
||||
/// <returns></returns>
|
||||
public TItem CreateItem(string itemName)
|
||||
{
|
||||
TItem widget = null;
|
||||
LoopListViewItem item = LoopRectView.AllocOrNewListViewItem(itemName);
|
||||
if (item != null)
|
||||
{
|
||||
widget = CreateItem(item);
|
||||
}
|
||||
return widget;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建Item
|
||||
/// </summary>
|
||||
/// <param name="prefab"></param>
|
||||
/// <returns></returns>
|
||||
public TItem CreateItem(GameObject prefab)
|
||||
{
|
||||
TItem widget = null;
|
||||
LoopListViewItem item = LoopRectView.AllocOrNewListViewItem(prefab);
|
||||
if (item != null)
|
||||
{
|
||||
widget = CreateItem(item);
|
||||
}
|
||||
return widget;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建Item
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
private TItem CreateItem(LoopListViewItem item)
|
||||
{
|
||||
TItem widget;
|
||||
if (!m_itemCache.TryGetValue(item.GoId, out widget))
|
||||
{
|
||||
widget = CreateWidget<TItem>(item.gameObject);
|
||||
widget.LoopItem = item;
|
||||
m_itemCache.Add(item.GoId, widget);
|
||||
}
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取item
|
||||
/// </summary>
|
||||
/// <param name="i"></param>
|
||||
/// <returns></returns>
|
||||
public override TItem GetItem(int i)
|
||||
{
|
||||
return i >= 0 && i < m_items.Count ? m_items[i] : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取itemList
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<TItem> GetItemList()
|
||||
{
|
||||
m_items.Clear();
|
||||
for (int i = 0; i < m_itemCache.Count; i++)
|
||||
{
|
||||
m_items.Add(m_itemCache[i]);
|
||||
}
|
||||
return m_items;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前起始索引
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetItemStartIndex()
|
||||
{
|
||||
return LoopRectView.GetItemStartIndex();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72b7444fb04642039aacc2db27dd002a
|
||||
timeCreated: 1691679907
|
152
UnityProject/Assets/GameScripts/HotFix/GameLogic/GameApp.cs
Normal file
152
UnityProject/Assets/GameScripts/HotFix/GameLogic/GameApp.cs
Normal file
@@ -0,0 +1,152 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using GameBase;
|
||||
using TEngine;
|
||||
|
||||
public partial class GameApp:Singleton<GameApp>
|
||||
{
|
||||
private static List<Assembly> _hotfixAssembly;
|
||||
|
||||
/// <summary>
|
||||
/// 热更域App主入口。
|
||||
/// </summary>
|
||||
/// <param name="objects"></param>
|
||||
public static void Entrance(object[] objects)
|
||||
{
|
||||
_hotfixAssembly = (List<Assembly>)objects[0];
|
||||
Log.Warning("======= 看到此条日志代表你成功运行了热更新代码 =======");
|
||||
Log.Warning("======= Entrance GameApp =======");
|
||||
Instance.Init();
|
||||
Instance.Start();
|
||||
Utility.Unity.AddUpdateListener(Instance.Update);
|
||||
Utility.Unity.AddFixedUpdateListener(Instance.FixedUpdate);
|
||||
Utility.Unity.AddLateUpdateListener(Instance.LateUpdate);
|
||||
Utility.Unity.AddDestroyListener(Instance.OnDestroy);
|
||||
Utility.Unity.AddOnDrawGizmosListener(Instance.OnDrawGizmos);
|
||||
Utility.Unity.AddOnApplicationPauseListener(Instance.OnApplicationPause);
|
||||
Instance.StartGameLogic();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始游戏业务层逻辑。
|
||||
/// <remarks>显示UI、加载场景等。</remarks>
|
||||
/// </summary>
|
||||
private void StartGameLogic()
|
||||
{
|
||||
GameModule.UI.ShowUI<GameLogic.GameMainUI>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭游戏。
|
||||
/// </summary>
|
||||
/// <param name="shutdownType">关闭游戏框架类型。</param>
|
||||
public static void Shutdown(ShutdownType shutdownType)
|
||||
{
|
||||
if (shutdownType == ShutdownType.None)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (shutdownType == ShutdownType.Restart)
|
||||
{
|
||||
Utility.Unity.RemoveUpdateListener(Instance.Update);
|
||||
Utility.Unity.RemoveFixedUpdateListener(Instance.FixedUpdate);
|
||||
Utility.Unity.RemoveLateUpdateListener(Instance.LateUpdate);
|
||||
Utility.Unity.RemoveDestroyListener(Instance.OnDestroy);
|
||||
Utility.Unity.RemoveOnDrawGizmosListener(Instance.OnDrawGizmos);
|
||||
Utility.Unity.RemoveOnApplicationPauseListener(Instance.OnApplicationPause);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
var listLogic = _listLogicMgr;
|
||||
var logicCnt = listLogic.Count;
|
||||
for (int i = 0; i < logicCnt; i++)
|
||||
{
|
||||
var logic = listLogic[i];
|
||||
logic.OnStart();
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
TProfiler.BeginFirstSample("Update");
|
||||
var listLogic = _listLogicMgr;
|
||||
var logicCnt = listLogic.Count;
|
||||
for (int i = 0; i < logicCnt; i++)
|
||||
{
|
||||
var logic = listLogic[i];
|
||||
TProfiler.BeginSample(logic.GetType().FullName);
|
||||
logic.OnUpdate();
|
||||
TProfiler.EndSample();
|
||||
}
|
||||
TProfiler.EndFirstSample();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
TProfiler.BeginFirstSample("FixedUpdate");
|
||||
var listLogic = _listLogicMgr;
|
||||
var logicCnt = listLogic.Count;
|
||||
for (int i = 0; i < logicCnt; i++)
|
||||
{
|
||||
var logic = listLogic[i];
|
||||
TProfiler.BeginSample(logic.GetType().FullName);
|
||||
logic.OnFixedUpdate();
|
||||
TProfiler.EndSample();
|
||||
}
|
||||
TProfiler.EndFirstSample();
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
TProfiler.BeginFirstSample("LateUpdate");
|
||||
var listLogic = _listLogicMgr;
|
||||
var logicCnt = listLogic.Count;
|
||||
for (int i = 0; i < logicCnt; i++)
|
||||
{
|
||||
var logic = listLogic[i];
|
||||
TProfiler.BeginSample(logic.GetType().FullName);
|
||||
logic.OnLateUpdate();
|
||||
TProfiler.EndSample();
|
||||
}
|
||||
TProfiler.EndFirstSample();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
var listLogic = _listLogicMgr;
|
||||
var logicCnt = listLogic.Count;
|
||||
for (int i = 0; i < logicCnt; i++)
|
||||
{
|
||||
var logic = listLogic[i];
|
||||
logic.OnDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var listLogic = _listLogicMgr;
|
||||
var logicCnt = listLogic.Count;
|
||||
for (int i = 0; i < logicCnt; i++)
|
||||
{
|
||||
var logic = listLogic[i];
|
||||
logic.OnDrawGizmos();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private void OnApplicationPause(bool isPause)
|
||||
{
|
||||
var listLogic = _listLogicMgr;
|
||||
var logicCnt = listLogic.Count;
|
||||
for (int i = 0; i < logicCnt; i++)
|
||||
{
|
||||
var logic = listLogic[i];
|
||||
logic.OnApplicationPause(isPause);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87dc927a71fa444468edfce6da4e54ca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,57 @@
|
||||
using System.Collections.Generic;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
|
||||
public partial class GameApp
|
||||
{
|
||||
private List<ILogicSys> _listLogicMgr;
|
||||
|
||||
private void Init()
|
||||
{
|
||||
_listLogicMgr = new List<ILogicSys>();
|
||||
RegisterAllSystem();
|
||||
InitSystemSetting();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置一些通用的系统属性。
|
||||
/// </summary>
|
||||
private void InitSystemSetting()
|
||||
{
|
||||
Application.targetFrameRate = 120;
|
||||
Log.Warning("Set UnityEngine.Application.targetFrameRate = 120");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册所有逻辑系统
|
||||
/// </summary>
|
||||
private void RegisterAllSystem()
|
||||
{
|
||||
//带生命周期的单例系统。
|
||||
AddLogicSys(BehaviourSingleSystem.Instance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册逻辑系统。
|
||||
/// </summary>
|
||||
/// <param name="logicSys">ILogicSys</param>
|
||||
/// <returns></returns>
|
||||
protected bool AddLogicSys(ILogicSys logicSys)
|
||||
{
|
||||
if (_listLogicMgr.Contains(logicSys))
|
||||
{
|
||||
Log.Fatal("Repeat add logic system: {0}", logicSys.GetType().Name);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!logicSys.OnInit())
|
||||
{
|
||||
Log.Fatal("{0} Init failed", logicSys.GetType().Name);
|
||||
return false;
|
||||
}
|
||||
|
||||
_listLogicMgr.Add(logicSys);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44cc95ba54fa4fd49012f55199ddd907
|
||||
timeCreated: 1695288685
|
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "GameLogic",
|
||||
"rootNamespace": "GameLogic",
|
||||
"references": [
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
||||
"GUID:15fc0a57446b3144c949da3e2b9737a9",
|
||||
"GUID:cbb0d51b565003841ae81cdbaf747114",
|
||||
"GUID:8f58f15387c7a6f4fad9857024eb47f7",
|
||||
"GUID:24c092aee38482f4e80715eaa8148782",
|
||||
"GUID:e34a5702dd353724aa315fb8011f08c3",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.unity.render-pipelines.universal",
|
||||
"expression": "",
|
||||
"define": "ENABLE_URP"
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e76b07590314a543b982daed6af2509
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8914094b46cb447398954c1f4e459d3b
|
||||
timeCreated: 1695716057
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 750c210d8c3f4a3aa99db8a58aafff46
|
||||
timeCreated: 1695716057
|
@@ -0,0 +1,104 @@
|
||||
//namespace DentedPixel{
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
||||
public class LTDescrOptional
|
||||
{
|
||||
|
||||
public Transform toTrans { get; set; }
|
||||
public Vector3 point { get; set; }
|
||||
public Vector3 axis { get; set; }
|
||||
public float lastVal { get; set; }
|
||||
public Quaternion origRotation { get; set; }
|
||||
public LTBezierPath path { get; set; }
|
||||
public LTSpline spline { get; set; }
|
||||
public AnimationCurve animationCurve;
|
||||
public int initFrameCount;
|
||||
|
||||
public LTRect ltRect { get; set; } // maybe get rid of this eventually
|
||||
|
||||
public Action<float> onUpdateFloat { get; set; }
|
||||
public Action<float, float> onUpdateFloatRatio { get; set; }
|
||||
public Action<float, object> onUpdateFloatObject { get; set; }
|
||||
public Action<Vector2> onUpdateVector2 { get; set; }
|
||||
public Action<Vector3> onUpdateVector3 { get; set; }
|
||||
public Action<Vector3, object> onUpdateVector3Object { get; set; }
|
||||
public Action<Color> onUpdateColor { get; set; }
|
||||
public Action<Color, object> onUpdateColorObject { get; set; }
|
||||
public Action onComplete { get; set; }
|
||||
public Action<object> onCompleteObject { get; set; }
|
||||
public object onCompleteParam { get; set; }
|
||||
public object onUpdateParam { get; set; }
|
||||
public Action onStart { get; set; }
|
||||
|
||||
|
||||
// #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
|
||||
// public SpriteRenderer spriteRen { get; set; }
|
||||
// #endif
|
||||
//
|
||||
// #if LEANTWEEN_1
|
||||
// public Hashtable optional;
|
||||
// #endif
|
||||
// #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
|
||||
// public RectTransform rectTransform;
|
||||
// public UnityEngine.UI.Text uiText;
|
||||
// public UnityEngine.UI.Image uiImage;
|
||||
// public UnityEngine.Sprite[] sprites;
|
||||
// #endif
|
||||
|
||||
|
||||
public void reset()
|
||||
{
|
||||
animationCurve = null;
|
||||
|
||||
this.onUpdateFloat = null;
|
||||
this.onUpdateFloatRatio = null;
|
||||
this.onUpdateVector2 = null;
|
||||
this.onUpdateVector3 = null;
|
||||
this.onUpdateFloatObject = null;
|
||||
this.onUpdateVector3Object = null;
|
||||
this.onUpdateColor = null;
|
||||
this.onComplete = null;
|
||||
this.onCompleteObject = null;
|
||||
this.onCompleteParam = null;
|
||||
this.onStart = null;
|
||||
|
||||
this.point = Vector3.zero;
|
||||
this.initFrameCount = 0;
|
||||
}
|
||||
|
||||
public void callOnUpdate(float val, float ratioPassed)
|
||||
{
|
||||
if (this.onUpdateFloat != null)
|
||||
this.onUpdateFloat(val);
|
||||
|
||||
if (this.onUpdateFloatRatio != null)
|
||||
{
|
||||
this.onUpdateFloatRatio(val, ratioPassed);
|
||||
}
|
||||
else if (this.onUpdateFloatObject != null)
|
||||
{
|
||||
this.onUpdateFloatObject(val, this.onUpdateParam);
|
||||
}
|
||||
else if (this.onUpdateVector3Object != null)
|
||||
{
|
||||
this.onUpdateVector3Object(LTDescr.newVect, this.onUpdateParam);
|
||||
}
|
||||
else if (this.onUpdateVector3 != null)
|
||||
{
|
||||
this.onUpdateVector3(LTDescr.newVect);
|
||||
}
|
||||
else if (this.onUpdateVector2 != null)
|
||||
{
|
||||
this.onUpdateVector2(new Vector2(LTDescr.newVect.x, LTDescr.newVect.y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a9da37b87014b0eada8eccc57bf0279
|
||||
timeCreated: 1695716057
|
@@ -0,0 +1,256 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Internal Representation of a Sequence<br>
|
||||
* <br>
|
||||
* <h4>Example:</h4>
|
||||
* var seq = LeanTween.sequence();<br>
|
||||
* seq.append(1f); <span style="color:gray">// delay everything one second</span><br>
|
||||
* seq.append( () => { <span style="color:gray">// fire an event before start</span><br>
|
||||
* Debug.Log("I have started");<br>
|
||||
* });<br>
|
||||
* seq.append( LeanTween.move(cube1, Vector3.one * 10f, 1f) ); <span style="color:gray">// do a tween</span><br>
|
||||
* seq.append( (object obj) => { <span style="color:gray">// fire event after tween</span><br>
|
||||
* var dict = obj as Dictionary<string,string>;<br>
|
||||
* Debug.Log("We are done now obj value:"+dict["hi"]);<br>
|
||||
* }, new Dictionary<string,string>(){ {"hi","sup"} } );<br>
|
||||
* @class LTSeq
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
public class LTSeq
|
||||
{
|
||||
|
||||
public LTSeq previous;
|
||||
|
||||
public LTSeq current;
|
||||
|
||||
public LTDescr tween;
|
||||
|
||||
public float totalDelay;
|
||||
|
||||
public float timeScale;
|
||||
|
||||
private int debugIter;
|
||||
|
||||
public uint counter;
|
||||
|
||||
public bool toggle = false;
|
||||
|
||||
private uint _id;
|
||||
|
||||
public int id
|
||||
{
|
||||
get
|
||||
{
|
||||
uint toId = _id | counter << 16;
|
||||
|
||||
/*uint backId = toId & 0xFFFF;
|
||||
uint backCounter = toId >> 16;
|
||||
if(_id!=backId || backCounter!=counter){
|
||||
Debug.LogError("BAD CONVERSION toId:"+_id);
|
||||
}*/
|
||||
|
||||
return (int) toId;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
previous = null;
|
||||
tween = null;
|
||||
totalDelay = 0f;
|
||||
}
|
||||
|
||||
public void init(uint id, uint global_counter)
|
||||
{
|
||||
reset();
|
||||
_id = id;
|
||||
|
||||
counter = global_counter;
|
||||
|
||||
this.current = this;
|
||||
}
|
||||
|
||||
private LTSeq addOn()
|
||||
{
|
||||
this.current.toggle = true;
|
||||
LTSeq lastCurrent = this.current;
|
||||
this.current = LeanTween.sequence(true);
|
||||
// Debug.Log("this.current:" + this.current.id + " lastCurrent:" + lastCurrent.id);
|
||||
this.current.previous = lastCurrent;
|
||||
lastCurrent.toggle = false;
|
||||
this.current.totalDelay = lastCurrent.totalDelay;
|
||||
this.current.debugIter = lastCurrent.debugIter + 1;
|
||||
return current;
|
||||
}
|
||||
|
||||
private float addPreviousDelays()
|
||||
{
|
||||
// Debug.Log("delay:"+delay+" count:"+this.current.count+" this.current.totalDelay:"+this.current.totalDelay);
|
||||
|
||||
LTSeq prev = this.current.previous;
|
||||
|
||||
if (prev != null && prev.tween != null)
|
||||
{
|
||||
return this.current.totalDelay + prev.tween.time;
|
||||
}
|
||||
return this.current.totalDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a time delay to the sequence
|
||||
* @method append (delay)
|
||||
* @param {float} delay:float amount of time to add to the sequence
|
||||
* @return {LTSeq} LTDescr an object that distinguishes the tween
|
||||
* var seq = LeanTween.sequence();<br>
|
||||
* seq.append(1f); // delay everything one second<br>
|
||||
* seq.append( LeanTween.move(cube1, Vector3.one * 10f, 1f) ); // do a tween<br>
|
||||
*/
|
||||
|
||||
public LTSeq append(float delay)
|
||||
{
|
||||
this.current.totalDelay += delay;
|
||||
|
||||
return this.current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a time delay to the sequence
|
||||
* @method append (method)
|
||||
* @param {System.Action} callback:System.Action method you want to be called
|
||||
* @return {LTSeq} LTSeq an object that you can add tweens, methods and time on to
|
||||
* @example
|
||||
* var seq = LeanTween.sequence();<br>
|
||||
* seq.append( () => { // fire an event before start<br>
|
||||
* Debug.Log("I have started");<br>
|
||||
* });<br>
|
||||
* seq.append( LeanTween.move(cube1, Vector3.one * 10f, 1f) ); // do a tween<br>
|
||||
* seq.append( () => { // fire event after tween<br>
|
||||
* Debug.Log("We are done now");<br>
|
||||
* });;<br>
|
||||
*/
|
||||
|
||||
public LTSeq append(System.Action callback)
|
||||
{
|
||||
LTDescr newTween = LeanTween.delayedCall(0f, callback);
|
||||
// Debug.Log("newTween:" + newTween);
|
||||
return append(newTween);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a time delay to the sequence
|
||||
* @method add (method(object))
|
||||
* @param {System.Action} callback:System.Action method you want to be called
|
||||
* @return {LTSeq} LTSeq an object that you can add tweens, methods and time on to
|
||||
* @example
|
||||
* var seq = LeanTween.sequence();<br>
|
||||
* seq.append( () => { // fire an event before start<br>
|
||||
* Debug.Log("I have started");<br>
|
||||
* });<br>
|
||||
* seq.append( LeanTween.move(cube1, Vector3.one * 10f, 1f) ); // do a tween<br>
|
||||
* seq.append((object obj) => { // fire event after tween
|
||||
* var dict = obj as Dictionary<string,string>;
|
||||
* Debug.Log("We are done now obj value:"+dict["hi"]);
|
||||
* }, new Dictionary<string,string>(){ {"hi","sup"} } );
|
||||
*/
|
||||
|
||||
public LTSeq append(System.Action<object> callback, object obj)
|
||||
{
|
||||
append(LeanTween.delayedCall(0f, callback).setOnCompleteParam(obj));
|
||||
|
||||
return addOn();
|
||||
}
|
||||
|
||||
public LTSeq append(GameObject gameObject, System.Action callback)
|
||||
{
|
||||
append(LeanTween.delayedCall(gameObject, 0f, callback));
|
||||
|
||||
return addOn();
|
||||
}
|
||||
|
||||
public LTSeq append(GameObject gameObject, System.Action<object> callback, object obj)
|
||||
{
|
||||
append(LeanTween.delayedCall(gameObject, 0f, callback).setOnCompleteParam(obj));
|
||||
|
||||
return addOn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a sequencer object where you can easily chain together tweens and methods one after another
|
||||
*
|
||||
* @method add (tween)
|
||||
* @return {LTSeq} LTSeq an object that you can add tweens, methods and time on to
|
||||
* @example
|
||||
* var seq = LeanTween.sequence();<br>
|
||||
* seq.append( LeanTween.move(cube1, Vector3.one * 10f, 1f) ); // do a move tween<br>
|
||||
* seq.append( LeanTween.rotateAround( avatar1, Vector3.forward, 360f, 1f ) ); // then do a rotate tween<br>
|
||||
*/
|
||||
|
||||
public LTSeq append(LTDescr tween)
|
||||
{
|
||||
this.current.tween = tween;
|
||||
|
||||
// Debug.Log("tween:" + tween + " delay:" + this.current.totalDelay);
|
||||
|
||||
this.current.totalDelay = addPreviousDelays();
|
||||
|
||||
tween.setDelay(this.current.totalDelay);
|
||||
|
||||
return addOn();
|
||||
}
|
||||
|
||||
public LTSeq insert(LTDescr tween)
|
||||
{
|
||||
this.current.tween = tween;
|
||||
|
||||
tween.setDelay(addPreviousDelays());
|
||||
|
||||
return addOn();
|
||||
}
|
||||
|
||||
|
||||
public LTSeq setScale(float timeScale)
|
||||
{
|
||||
// Debug.Log("this.current:" + this.current.previous.debugIter+" tween:"+this.current.previous.tween);
|
||||
setScaleRecursive(this.current, timeScale, 500);
|
||||
|
||||
return addOn();
|
||||
}
|
||||
|
||||
private void setScaleRecursive(LTSeq seq, float timeScale, int count)
|
||||
{
|
||||
if (count > 0)
|
||||
{
|
||||
this.timeScale = timeScale;
|
||||
|
||||
// Debug.Log("seq.count:" + count + " seq.tween:" + seq.tween);
|
||||
seq.totalDelay *= timeScale;
|
||||
if (seq.tween != null)
|
||||
{
|
||||
// Debug.Log("seq.tween.time * timeScale:" + seq.tween.time * timeScale + " seq.totalDelay:"+seq.totalDelay +" time:"+seq.tween.time+" seq.tween.delay:"+seq.tween.delay);
|
||||
if (seq.tween.time != 0f)
|
||||
seq.tween.setTime(seq.tween.time*timeScale);
|
||||
seq.tween.setDelay(seq.tween.delay*timeScale);
|
||||
}
|
||||
|
||||
if (seq.previous != null)
|
||||
setScaleRecursive(seq.previous, timeScale, count - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public LTSeq reverse()
|
||||
{
|
||||
|
||||
return addOn();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7355a7aac6e49b3975763bf3eef477b
|
||||
timeCreated: 1695716057
|
@@ -0,0 +1,418 @@
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class LeanAudioStream {
|
||||
|
||||
public int position = 0;
|
||||
|
||||
public AudioClip audioClip;
|
||||
public float[] audioArr;
|
||||
|
||||
public LeanAudioStream( float[] audioArr ){
|
||||
this.audioArr = audioArr;
|
||||
}
|
||||
|
||||
public void OnAudioRead(float[] data) {
|
||||
int count = 0;
|
||||
while (count < data.Length) {
|
||||
data[count] = audioArr[this.position];
|
||||
position++;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAudioSetPosition(int newPosition) {
|
||||
this.position = newPosition;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Audio dynamically and easily playback
|
||||
*
|
||||
* @class LeanAudio
|
||||
* @constructor
|
||||
*/
|
||||
public class LeanAudio : object {
|
||||
|
||||
public static float MIN_FREQEUNCY_PERIOD = 0.000115f;
|
||||
public static int PROCESSING_ITERATIONS_MAX = 50000;
|
||||
public static float[] generatedWaveDistances;
|
||||
public static int generatedWaveDistancesCount = 0;
|
||||
|
||||
private static float[] longList;
|
||||
|
||||
public static LeanAudioOptions options(){
|
||||
if(generatedWaveDistances==null){
|
||||
generatedWaveDistances = new float[ PROCESSING_ITERATIONS_MAX ];
|
||||
longList = new float[ PROCESSING_ITERATIONS_MAX ];
|
||||
}
|
||||
return new LeanAudioOptions();
|
||||
}
|
||||
|
||||
public static LeanAudioStream createAudioStream( AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options = null ){
|
||||
if(options==null)
|
||||
options = new LeanAudioOptions();
|
||||
|
||||
options.useSetData = false;
|
||||
|
||||
int generatedWavePtsLength = createAudioWave( volume, frequency, options);
|
||||
createAudioFromWave( generatedWavePtsLength, options );
|
||||
|
||||
return options.stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create dynamic audio from a set of Animation Curves and other options.
|
||||
*
|
||||
* @method createAudio
|
||||
* @param {AnimationCurve} volumeCurve:AnimationCurve describing the shape of the audios volume (from 0-1). The length of the audio is dicated by the end value here.
|
||||
* @param {AnimationCurve} frequencyCurve:AnimationCurve describing the width of the oscillations between the sound waves in seconds. Large numbers mean a lower note, while higher numbers mean a tighter frequency and therefor a higher note. Values are usually between 0.01 and 0.000001 (or smaller)
|
||||
* @param {LeanAudioOptions} options:LeanAudioOptions You can pass any other values in here like vibrato or the frequency you would like the sound to be encoded at. See <a href="LeanAudioOptions.html">LeanAudioOptions</a> for more details.
|
||||
* @return {AudioClip} AudioClip of the procedurally generated audio
|
||||
* @example
|
||||
* AnimationCurve volumeCurve = new AnimationCurve( new Keyframe(0f, 1f, 0f, -1f), new Keyframe(1f, 0f, -1f, 0f));<br>
|
||||
* AnimationCurve frequencyCurve = new AnimationCurve( new Keyframe(0f, 0.003f, 0f, 0f), new Keyframe(1f, 0.003f, 0f, 0f));<br>
|
||||
* AudioClip audioClip = LeanAudio.createAudio(volumeCurve, frequencyCurve, LeanAudio.options().setVibrato( new Vector3[]{ new Vector3(0.32f,0f,0f)} ));<br>
|
||||
*/
|
||||
public static AudioClip createAudio( AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options = null ){
|
||||
if(options==null)
|
||||
options = new LeanAudioOptions();
|
||||
|
||||
int generatedWavePtsLength = createAudioWave( volume, frequency, options);
|
||||
// Debug.Log("generatedWavePtsLength:"+generatedWavePtsLength);
|
||||
return createAudioFromWave( generatedWavePtsLength, options );
|
||||
}
|
||||
|
||||
private static int createAudioWave( AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options ){
|
||||
float time = volume[ volume.length - 1 ].time;
|
||||
int listLength = 0;
|
||||
// List<float> list = new List<float>();
|
||||
|
||||
// generatedWaveDistances = new List<float>();
|
||||
// float[] vibratoValues = new float[ vibrato.Length ];
|
||||
float passed = 0f;
|
||||
for(int i = 0; i < PROCESSING_ITERATIONS_MAX; i++){
|
||||
float f = frequency.Evaluate(passed);
|
||||
if(f<MIN_FREQEUNCY_PERIOD)
|
||||
f = MIN_FREQEUNCY_PERIOD;
|
||||
float height = volume.Evaluate(passed + 0.5f*f);
|
||||
if(options.vibrato!=null){
|
||||
for(int j=0; j<options.vibrato.Length; j++){
|
||||
float peakMulti = Mathf.Abs( Mathf.Sin( 1.5708f + passed * (1f/options.vibrato[j][0]) * Mathf.PI ) );
|
||||
float diff = (1f-options.vibrato[j][1]);
|
||||
peakMulti = options.vibrato[j][1] + diff*peakMulti;
|
||||
height *= peakMulti;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Debug.Log("i:"+i+" f:"+f+" passed:"+passed+" height:"+height+" time:"+time);
|
||||
if(passed + 0.5f*f>=time)
|
||||
break;
|
||||
if(listLength >= PROCESSING_ITERATIONS_MAX-1){
|
||||
Debug.LogError("LeanAudio has reached it's processing cap. To avoid this error increase the number of iterations ex: LeanAudio.PROCESSING_ITERATIONS_MAX = "+(PROCESSING_ITERATIONS_MAX*2));
|
||||
break;
|
||||
}else{
|
||||
int distPoint = listLength / 2;
|
||||
|
||||
//generatedWaveDistances.Add( f );
|
||||
passed += f;
|
||||
|
||||
generatedWaveDistances[ distPoint ] = passed;
|
||||
//Debug.Log("distPoint:"+distPoint+" passed:"+passed);
|
||||
|
||||
//list.Add( passed );
|
||||
//list.Add( i%2==0 ? -height : height );
|
||||
|
||||
longList[ listLength ] = passed;
|
||||
longList[ listLength + 1 ] = i%2==0 ? -height : height;
|
||||
}
|
||||
|
||||
|
||||
|
||||
listLength += 2;
|
||||
|
||||
}
|
||||
|
||||
listLength += -2;
|
||||
generatedWaveDistancesCount = listLength / 2;
|
||||
|
||||
/*float[] wave = new float[ listLength ];
|
||||
for(int i = 0; i < wave.Length; i++){
|
||||
wave[i] = longList[i];
|
||||
}*/
|
||||
return listLength;
|
||||
}
|
||||
|
||||
private static AudioClip createAudioFromWave( int waveLength, LeanAudioOptions options ){
|
||||
float time = longList[ waveLength - 2 ];
|
||||
float[] audioArr = new float[ (int)(options.frequencyRate*time) ];
|
||||
|
||||
int waveIter = 0;
|
||||
float subWaveDiff = longList[waveIter];
|
||||
float subWaveTimeLast = 0f;
|
||||
float subWaveTime = longList[waveIter];
|
||||
float waveHeight = longList[waveIter+1];
|
||||
for(int i = 0; i < audioArr.Length; i++){
|
||||
float passedTime = (float)i / (float)options.frequencyRate;
|
||||
if(passedTime > longList[waveIter] ){
|
||||
subWaveTimeLast = longList[waveIter];
|
||||
waveIter += 2;
|
||||
subWaveDiff = longList[waveIter] - longList[waveIter-2];
|
||||
waveHeight = longList[waveIter+1];
|
||||
// Debug.Log("passed wave i:"+i);
|
||||
}
|
||||
subWaveTime = passedTime - subWaveTimeLast;
|
||||
float ratioElapsed = subWaveTime / subWaveDiff;
|
||||
|
||||
float value = Mathf.Sin( ratioElapsed * Mathf.PI );
|
||||
|
||||
if(options.waveStyle==LeanAudioOptions.LeanAudioWaveStyle.Square){
|
||||
if(value>0f)
|
||||
value = 1f;
|
||||
if(value<0f)
|
||||
value = -1f;
|
||||
}else if(options.waveStyle==LeanAudioOptions.LeanAudioWaveStyle.Sawtooth){
|
||||
float sign = value > 0f ? 1f : -1f;
|
||||
if(ratioElapsed<0.5f){
|
||||
value = (ratioElapsed*2f)*sign;
|
||||
}else{ // 0.5f - 1f
|
||||
value = (1f - ratioElapsed)*2f*sign;
|
||||
}
|
||||
}else if(options.waveStyle==LeanAudioOptions.LeanAudioWaveStyle.Noise){
|
||||
float peakMulti = (1f-options.waveNoiseInfluence) + Mathf.PerlinNoise(0f, passedTime * options.waveNoiseScale ) * options.waveNoiseInfluence;
|
||||
|
||||
/*if(i<25){
|
||||
Debug.Log("passedTime:"+passedTime+" peakMulti:"+peakMulti+" infl:"+options.waveNoiseInfluence);
|
||||
}*/
|
||||
|
||||
value *= peakMulti;
|
||||
}
|
||||
|
||||
//if(i<25)
|
||||
// Debug.Log("passedTime:"+passedTime+" value:"+value+" ratioElapsed:"+ratioElapsed+" subWaveTime:"+subWaveTime+" subWaveDiff:"+subWaveDiff);
|
||||
|
||||
value *= waveHeight;
|
||||
|
||||
|
||||
if(options.modulation!=null){
|
||||
for(int k=0; k<options.modulation.Length; k++){
|
||||
float peakMulti = Mathf.Abs( Mathf.Sin( 1.5708f + passedTime * (1f/options.modulation[k][0]) * Mathf.PI ) );
|
||||
float diff = (1f-options.modulation[k][1]);
|
||||
peakMulti = options.modulation[k][1] + diff*peakMulti;
|
||||
// if(k<10){
|
||||
// Debug.Log("k:"+k+" peakMulti:"+peakMulti+" value:"+value+" after:"+(value*peakMulti));
|
||||
// }
|
||||
value *= peakMulti;
|
||||
}
|
||||
}
|
||||
|
||||
audioArr[i] = value;
|
||||
// Debug.Log("pt:"+pt+" i:"+i+" val:"+audioArr[i]+" len:"+audioArr.Length);
|
||||
}
|
||||
|
||||
|
||||
int lengthSamples = audioArr.Length;
|
||||
|
||||
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
|
||||
bool is3dSound = false;
|
||||
AudioClip audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, is3dSound, false);
|
||||
#else
|
||||
AudioClip audioClip = null;
|
||||
if(options.useSetData){
|
||||
audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, false, null, OnAudioSetPosition);
|
||||
audioClip.SetData(audioArr, 0);
|
||||
}else{
|
||||
options.stream = new LeanAudioStream(audioArr);
|
||||
// Debug.Log("len:"+audioArr.Length+" lengthSamples:"+lengthSamples+" freqRate:"+options.frequencyRate);
|
||||
audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, false, options.stream.OnAudioRead, options.stream.OnAudioSetPosition);
|
||||
options.stream.audioClip = audioClip;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return audioClip;
|
||||
}
|
||||
|
||||
private static void OnAudioSetPosition(int newPosition) {
|
||||
|
||||
}
|
||||
|
||||
public static AudioClip generateAudioFromCurve( AnimationCurve curve, int frequencyRate = 44100 ){
|
||||
float curveTime = curve[ curve.length - 1 ].time;
|
||||
float time = curveTime;
|
||||
float[] audioArr = new float[ (int)(frequencyRate*time) ];
|
||||
|
||||
// Debug.Log("curveTime:"+curveTime+" AudioSettings.outputSampleRate:"+AudioSettings.outputSampleRate);
|
||||
for(int i = 0; i < audioArr.Length; i++){
|
||||
float pt = (float)i / (float)frequencyRate;
|
||||
audioArr[i] = curve.Evaluate( pt );
|
||||
// Debug.Log("pt:"+pt+" i:"+i+" val:"+audioArr[i]+" len:"+audioArr.Length);
|
||||
}
|
||||
|
||||
int lengthSamples = audioArr.Length;//(int)( (float)frequencyRate * curveTime );
|
||||
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
|
||||
bool is3dSound = false;
|
||||
AudioClip audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, frequencyRate, is3dSound, false);
|
||||
#else
|
||||
AudioClip audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, frequencyRate, false);
|
||||
#endif
|
||||
audioClip.SetData(audioArr, 0);
|
||||
|
||||
return audioClip;
|
||||
}
|
||||
|
||||
public static AudioSource play( AudioClip audio, float volume ){
|
||||
AudioSource audioSource = playClipAt(audio, Vector3.zero);
|
||||
audioSource.volume = volume;
|
||||
return audioSource;
|
||||
}
|
||||
|
||||
public static AudioSource play( AudioClip audio ){
|
||||
return playClipAt( audio, Vector3.zero );
|
||||
}
|
||||
|
||||
public static AudioSource play( AudioClip audio, Vector3 pos ){
|
||||
return playClipAt( audio, pos );
|
||||
}
|
||||
|
||||
public static AudioSource play( AudioClip audio, Vector3 pos, float volume ){
|
||||
// Debug.Log("audio length:"+audio.length);
|
||||
AudioSource audioSource = playClipAt(audio, pos);
|
||||
audioSource.minDistance = 1f;
|
||||
//audioSource.pitch = pitch;
|
||||
audioSource.volume = volume;
|
||||
|
||||
return audioSource;
|
||||
}
|
||||
|
||||
public static AudioSource playClipAt( AudioClip clip, Vector3 pos ) {
|
||||
GameObject tempGO = new GameObject(); // create the temp object
|
||||
tempGO.transform.position = pos; // set its position
|
||||
AudioSource aSource = tempGO.AddComponent<AudioSource>(); // add an audio source
|
||||
aSource.clip = clip; // define the clip
|
||||
aSource.Play(); // start the sound
|
||||
GameObject.Destroy(tempGO, clip.length); // destroy object after clip duration
|
||||
return aSource; // return the AudioSource reference
|
||||
}
|
||||
|
||||
public static void printOutAudioClip( AudioClip audioClip, ref AnimationCurve curve, float scaleX = 1f ){
|
||||
// Debug.Log("Audio channels:"+audioClip.channels+" frequency:"+audioClip.frequency+" length:"+audioClip.length+" samples:"+audioClip.samples);
|
||||
float[] samples = new float[audioClip.samples * audioClip.channels];
|
||||
audioClip.GetData(samples, 0);
|
||||
int i = 0;
|
||||
|
||||
Keyframe[] frames = new Keyframe[samples.Length];
|
||||
while (i < samples.Length) {
|
||||
frames[i] = new Keyframe( (float)i * scaleX, samples[i] );
|
||||
++i;
|
||||
}
|
||||
curve = new AnimationCurve( frames );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pass in options to LeanAudio
|
||||
*
|
||||
* @class LeanAudioOptions
|
||||
* @constructor
|
||||
*/
|
||||
public class LeanAudioOptions : object {
|
||||
|
||||
public enum LeanAudioWaveStyle{
|
||||
Sine,
|
||||
Square,
|
||||
Sawtooth,
|
||||
Noise
|
||||
}
|
||||
|
||||
public LeanAudioWaveStyle waveStyle = LeanAudioWaveStyle.Sine;
|
||||
public Vector3[] vibrato;
|
||||
public Vector3[] modulation;
|
||||
public int frequencyRate = 44100;
|
||||
public float waveNoiseScale = 1000;
|
||||
public float waveNoiseInfluence = 1f;
|
||||
|
||||
public bool useSetData = true;
|
||||
public LeanAudioStream stream;
|
||||
|
||||
public LeanAudioOptions(){}
|
||||
|
||||
/**
|
||||
* Set the frequency for the audio is encoded. 44100 is CD quality, but you can usually get away with much lower (or use a lower amount to get a more 8-bit sound).
|
||||
*
|
||||
* @method setFrequency
|
||||
* @param {int} frequencyRate:int of the frequency you wish to encode the AudioClip at
|
||||
* @return {LeanAudioOptions} LeanAudioOptions describing optional values
|
||||
* @example
|
||||
* AnimationCurve volumeCurve = new AnimationCurve( new Keyframe(0f, 1f, 0f, -1f), new Keyframe(1f, 0f, -1f, 0f));<br>
|
||||
* AnimationCurve frequencyCurve = new AnimationCurve( new Keyframe(0f, 0.003f, 0f, 0f), new Keyframe(1f, 0.003f, 0f, 0f));<br>
|
||||
* AudioClip audioClip = LeanAudio.createAudio(volumeCurve, frequencyCurve, LeanAudio.options().setVibrato( new Vector3[]{ new Vector3(0.32f,0f,0f)} ).setFrequency(12100) );<br>
|
||||
*/
|
||||
public LeanAudioOptions setFrequency( int frequencyRate ){
|
||||
this.frequencyRate = frequencyRate;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set details about the shape of the curve by adding vibrato modulations through it (alters the peak values giving it a wah-wah effect). You can add as many as you want to sculpt out more detail in the sound wave.
|
||||
*
|
||||
* @method setVibrato
|
||||
* @param {Vector3[]} vibratoArray:Vector3[] The first value is the period in seconds that you wish to have the vibrato wave fluctuate at. The second value is the minimum height you wish the vibrato wave to dip down to (default is zero). The third is reserved for future effects.
|
||||
* @return {LeanAudioOptions} LeanAudioOptions describing optional values
|
||||
* @example
|
||||
* AnimationCurve volumeCurve = new AnimationCurve( new Keyframe(0f, 1f, 0f, -1f), new Keyframe(1f, 0f, -1f, 0f));<br>
|
||||
* AnimationCurve frequencyCurve = new AnimationCurve( new Keyframe(0f, 0.003f, 0f, 0f), new Keyframe(1f, 0.003f, 0f, 0f));<br>
|
||||
* AudioClip audioClip = LeanAudio.createAudio(volumeCurve, frequencyCurve, LeanAudio.options().setVibrato( new Vector3[]{ new Vector3(0.32f,0.3f,0f)} ).setFrequency(12100) );<br>
|
||||
*/
|
||||
public LeanAudioOptions setVibrato( Vector3[] vibrato ){
|
||||
this.vibrato = vibrato;
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
public LeanAudioOptions setModulation( Vector3[] modulation ){
|
||||
this.modulation = modulation;
|
||||
return this;
|
||||
}*/
|
||||
|
||||
public LeanAudioOptions setWaveSine(){
|
||||
this.waveStyle = LeanAudioWaveStyle.Sine;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeanAudioOptions setWaveSquare(){
|
||||
this.waveStyle = LeanAudioWaveStyle.Square;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeanAudioOptions setWaveSawtooth(){
|
||||
this.waveStyle = LeanAudioWaveStyle.Sawtooth;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeanAudioOptions setWaveNoise(){
|
||||
this.waveStyle = LeanAudioWaveStyle.Noise;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeanAudioOptions setWaveStyle( LeanAudioWaveStyle style ){
|
||||
this.waveStyle = style;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public LeanAudioOptions setWaveNoiseScale( float waveScale ){
|
||||
this.waveNoiseScale = waveScale;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LeanAudioOptions setWaveNoiseInfluence( float influence ){
|
||||
this.waveNoiseInfluence = influence;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5bb7206372dd4cc89563d963c6cafb0a
|
||||
timeCreated: 1695716057
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ac444c8e7c3469991e5da64eb2e8dc8
|
||||
timeCreated: 1695716057
|
@@ -0,0 +1,545 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
||||
|
||||
public static class LeanTweenExt
|
||||
{
|
||||
//LeanTween.addListener
|
||||
//LeanTween.alpha
|
||||
public static LTDescr LeanAlpha(this GameObject gameObject, float to, float time)
|
||||
{
|
||||
return LeanTween.alpha(gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.alphaCanvas
|
||||
public static LTDescr LeanAlphaVertex(this GameObject gameObject, float to, float time)
|
||||
{
|
||||
return LeanTween.alphaVertex(gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.alpha (RectTransform)
|
||||
public static LTDescr LeanAlpha(this RectTransform rectTransform, float to, float time)
|
||||
{
|
||||
return LeanTween.alpha(rectTransform, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.alphaCanvas
|
||||
public static LTDescr LeanAlpha(this CanvasGroup canvas, float to, float time)
|
||||
{
|
||||
return LeanTween.alphaCanvas(canvas, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.alphaText
|
||||
public static LTDescr LeanAlphaText(this RectTransform rectTransform, float to, float time)
|
||||
{
|
||||
return LeanTween.alphaText(rectTransform, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.cancel
|
||||
public static void LeanCancel(this GameObject gameObject)
|
||||
{
|
||||
LeanTween.cancel(gameObject);
|
||||
}
|
||||
|
||||
public static void LeanCancel(this GameObject gameObject, bool callOnComplete)
|
||||
{
|
||||
LeanTween.cancel(gameObject, callOnComplete);
|
||||
}
|
||||
|
||||
public static void LeanCancel(this GameObject gameObject, int uniqueId, bool callOnComplete = false)
|
||||
{
|
||||
LeanTween.cancel(gameObject, uniqueId, callOnComplete);
|
||||
}
|
||||
|
||||
//LeanTween.cancel
|
||||
public static void LeanCancel(this RectTransform rectTransform)
|
||||
{
|
||||
LeanTween.cancel(rectTransform);
|
||||
}
|
||||
|
||||
//LeanTween.cancelAll
|
||||
//LeanTween.color
|
||||
public static LTDescr LeanColor(this GameObject gameObject, Color to, float time)
|
||||
{
|
||||
return LeanTween.color(gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.colorText
|
||||
public static LTDescr LeanColorText(this RectTransform rectTransform, Color to, float time)
|
||||
{
|
||||
return LeanTween.colorText(rectTransform, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.delayedCall
|
||||
public static LTDescr LeanDelayedCall(this GameObject gameObject, float delayTime, System.Action callback)
|
||||
{
|
||||
return LeanTween.delayedCall(gameObject, delayTime, callback);
|
||||
}
|
||||
|
||||
public static LTDescr LeanDelayedCall(this GameObject gameObject, float delayTime,
|
||||
System.Action<object> callback)
|
||||
{
|
||||
return LeanTween.delayedCall(gameObject, delayTime, callback);
|
||||
}
|
||||
|
||||
//LeanTween.isPaused
|
||||
public static bool LeanIsPaused(this GameObject gameObject)
|
||||
{
|
||||
return LeanTween.isPaused(gameObject);
|
||||
}
|
||||
|
||||
public static bool LeanIsPaused(this RectTransform rectTransform)
|
||||
{
|
||||
return LeanTween.isPaused(rectTransform);
|
||||
}
|
||||
|
||||
//LeanTween.isTweening
|
||||
public static bool LeanIsTweening(this GameObject gameObject)
|
||||
{
|
||||
return LeanTween.isTweening(gameObject);
|
||||
}
|
||||
|
||||
//LeanTween.isTweening
|
||||
//LeanTween.move
|
||||
public static LTDescr LeanMove(this GameObject gameObject, Vector3 to, float time)
|
||||
{
|
||||
return LeanTween.move(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMove(this Transform transform, Vector3 to, float time)
|
||||
{
|
||||
return LeanTween.move(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMove(this RectTransform rectTransform, Vector3 to, float time)
|
||||
{
|
||||
return LeanTween.move(rectTransform, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.move
|
||||
public static LTDescr LeanMove(this GameObject gameObject, Vector2 to, float time)
|
||||
{
|
||||
return LeanTween.move(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMove(this Transform transform, Vector2 to, float time)
|
||||
{
|
||||
return LeanTween.move(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.move
|
||||
public static LTDescr LeanMove(this GameObject gameObject, Vector3[] to, float time)
|
||||
{
|
||||
return LeanTween.move(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMove(this GameObject gameObject, LTBezierPath to, float time)
|
||||
{
|
||||
return LeanTween.move(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMove(this GameObject gameObject, LTSpline to, float time)
|
||||
{
|
||||
return LeanTween.move(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMove(this Transform transform, Vector3[] to, float time)
|
||||
{
|
||||
return LeanTween.move(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMove(this Transform transform, LTBezierPath to, float time)
|
||||
{
|
||||
return LeanTween.move(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMove(this Transform transform, LTSpline to, float time)
|
||||
{
|
||||
return LeanTween.move(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.moveLocal
|
||||
public static LTDescr LeanMoveLocal(this GameObject gameObject, Vector3 to, float time)
|
||||
{
|
||||
return LeanTween.moveLocal(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMoveLocal(this GameObject gameObject, LTBezierPath to, float time)
|
||||
{
|
||||
return LeanTween.moveLocal(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMoveLocal(this GameObject gameObject, LTSpline to, float time)
|
||||
{
|
||||
return LeanTween.moveLocal(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMoveLocal(this Transform transform, Vector3 to, float time)
|
||||
{
|
||||
return LeanTween.moveLocal(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMoveLocal(this Transform transform, LTBezierPath to, float time)
|
||||
{
|
||||
return LeanTween.moveLocal(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMoveLocal(this Transform transform, LTSpline to, float time)
|
||||
{
|
||||
return LeanTween.moveLocal(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.moveLocal
|
||||
public static LTDescr LeanMoveLocalX(this GameObject gameObject, float to, float time)
|
||||
{
|
||||
return LeanTween.moveLocalX(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMoveLocalY(this GameObject gameObject, float to, float time)
|
||||
{
|
||||
return LeanTween.moveLocalY(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMoveLocalZ(this GameObject gameObject, float to, float time)
|
||||
{
|
||||
return LeanTween.moveLocalZ(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMoveLocalX(this Transform transform, float to, float time)
|
||||
{
|
||||
return LeanTween.moveLocalX(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMoveLocalY(this Transform transform, float to, float time)
|
||||
{
|
||||
return LeanTween.moveLocalY(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMoveLocalZ(this Transform transform, float to, float time)
|
||||
{
|
||||
return LeanTween.moveLocalZ(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.moveSpline
|
||||
public static LTDescr LeanMoveSpline(this GameObject gameObject, Vector3[] to, float time)
|
||||
{
|
||||
return LeanTween.moveSpline(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMoveSpline(this GameObject gameObject, LTSpline to, float time)
|
||||
{
|
||||
return LeanTween.moveSpline(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMoveSpline(this Transform transform, Vector3[] to, float time)
|
||||
{
|
||||
return LeanTween.moveSpline(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMoveSpline(this Transform transform, LTSpline to, float time)
|
||||
{
|
||||
return LeanTween.moveSpline(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.moveSplineLocal
|
||||
public static LTDescr LeanMoveSplineLocal(this GameObject gameObject, Vector3[] to, float time)
|
||||
{
|
||||
return LeanTween.moveSplineLocal(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMoveSplineLocal(this Transform transform, Vector3[] to, float time)
|
||||
{
|
||||
return LeanTween.moveSplineLocal(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.moveX
|
||||
public static LTDescr LeanMoveX(this GameObject gameObject, float to, float time)
|
||||
{
|
||||
return LeanTween.moveX(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMoveX(this Transform transform, float to, float time)
|
||||
{
|
||||
return LeanTween.moveX(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.moveX (RectTransform)
|
||||
public static LTDescr LeanMoveX(this RectTransform rectTransform, float to, float time)
|
||||
{
|
||||
return LeanTween.moveX(rectTransform, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.moveY
|
||||
public static LTDescr LeanMoveY(this GameObject gameObject, float to, float time)
|
||||
{
|
||||
return LeanTween.moveY(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMoveY(this Transform transform, float to, float time)
|
||||
{
|
||||
return LeanTween.moveY(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.moveY (RectTransform)
|
||||
public static LTDescr LeanMoveY(this RectTransform rectTransform, float to, float time)
|
||||
{
|
||||
return LeanTween.moveY(rectTransform, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.moveZ
|
||||
public static LTDescr LeanMoveZ(this GameObject gameObject, float to, float time)
|
||||
{
|
||||
return LeanTween.moveZ(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanMoveZ(this Transform transform, float to, float time)
|
||||
{
|
||||
return LeanTween.moveZ(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.moveZ (RectTransform)
|
||||
public static LTDescr LeanMoveZ(this RectTransform rectTransform, float to, float time)
|
||||
{
|
||||
return LeanTween.moveZ(rectTransform, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.pause
|
||||
public static void LeanPause(this GameObject gameObject)
|
||||
{
|
||||
LeanTween.pause(gameObject);
|
||||
}
|
||||
|
||||
//LeanTween.play
|
||||
public static LTDescr LeanPlay(this RectTransform rectTransform, UnityEngine.Sprite[] sprites)
|
||||
{
|
||||
return LeanTween.play(rectTransform, sprites);
|
||||
}
|
||||
|
||||
//LeanTween.removeListener
|
||||
//LeanTween.resume
|
||||
public static void LeanResume(this GameObject gameObject)
|
||||
{
|
||||
LeanTween.resume(gameObject);
|
||||
}
|
||||
|
||||
//LeanTween.resumeAll
|
||||
//LeanTween.rotate
|
||||
public static LTDescr LeanRotate(this GameObject gameObject, Vector3 to, float time)
|
||||
{
|
||||
return LeanTween.rotate(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanRotate(this Transform transform, Vector3 to, float time)
|
||||
{
|
||||
return LeanTween.rotate(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.rotate
|
||||
//LeanTween.rotate (RectTransform)
|
||||
public static LTDescr LeanRotate(this RectTransform rectTransform, Vector3 to, float time)
|
||||
{
|
||||
return LeanTween.rotate(rectTransform, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.rotateAround
|
||||
public static LTDescr LeanRotateAround(this GameObject gameObject, Vector3 axis, float add, float time)
|
||||
{
|
||||
return LeanTween.rotateAround(gameObject, axis, add, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanRotateAround(this Transform transform, Vector3 axis, float add, float time)
|
||||
{
|
||||
return LeanTween.rotateAround(transform.gameObject, axis, add, time);
|
||||
}
|
||||
|
||||
//LeanTween.rotateAround (RectTransform)
|
||||
public static LTDescr LeanRotateAround(this RectTransform rectTransform, Vector3 axis, float add, float time)
|
||||
{
|
||||
return LeanTween.rotateAround(rectTransform, axis, add, time);
|
||||
}
|
||||
|
||||
//LeanTween.rotateAroundLocal
|
||||
public static LTDescr LeanRotateAroundLocal(this GameObject gameObject, Vector3 axis, float add, float time)
|
||||
{
|
||||
return LeanTween.rotateAroundLocal(gameObject, axis, add, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanRotateAroundLocal(this Transform transform, Vector3 axis, float add, float time)
|
||||
{
|
||||
return LeanTween.rotateAroundLocal(transform.gameObject, axis, add, time);
|
||||
}
|
||||
|
||||
//LeanTween.rotateAround (RectTransform)
|
||||
public static LTDescr LeanRotateAroundLocal(this RectTransform rectTransform, Vector3 axis, float add,
|
||||
float time)
|
||||
{
|
||||
return LeanTween.rotateAroundLocal(rectTransform, axis, add, time);
|
||||
}
|
||||
|
||||
//LeanTween.rotateLocal
|
||||
//LeanTween.rotateX
|
||||
public static LTDescr LeanRotateX(this GameObject gameObject, float to, float time)
|
||||
{
|
||||
return LeanTween.rotateX(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanRotateX(this Transform transform, float to, float time)
|
||||
{
|
||||
return LeanTween.rotateX(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.rotateY
|
||||
public static LTDescr LeanRotateY(this GameObject gameObject, float to, float time)
|
||||
{
|
||||
return LeanTween.rotateY(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanRotateY(this Transform transform, float to, float time)
|
||||
{
|
||||
return LeanTween.rotateY(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.rotateZ
|
||||
public static LTDescr LeanRotateZ(this GameObject gameObject, float to, float time)
|
||||
{
|
||||
return LeanTween.rotateZ(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanRotateZ(this Transform transform, float to, float time)
|
||||
{
|
||||
return LeanTween.rotateZ(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.scale
|
||||
public static LTDescr LeanScale(this GameObject gameObject, Vector3 to, float time)
|
||||
{
|
||||
return LeanTween.scale(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanScale(this Transform transform, Vector3 to, float time)
|
||||
{
|
||||
return LeanTween.scale(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.scale (GUI)
|
||||
//LeanTween.scale (RectTransform)
|
||||
public static LTDescr LeanScale(this RectTransform rectTransform, Vector3 to, float time)
|
||||
{
|
||||
return LeanTween.scale(rectTransform, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.scaleX
|
||||
public static LTDescr LeanScaleX(this GameObject gameObject, float to, float time)
|
||||
{
|
||||
return LeanTween.scaleX(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanScaleX(this Transform transform, float to, float time)
|
||||
{
|
||||
return LeanTween.scaleX(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.scaleY
|
||||
public static LTDescr LeanScaleY(this GameObject gameObject, float to, float time)
|
||||
{
|
||||
return LeanTween.scaleY(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanScaleY(this Transform transform, float to, float time)
|
||||
{
|
||||
return LeanTween.scaleY(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.scaleZ
|
||||
public static LTDescr LeanScaleZ(this GameObject gameObject, float to, float time)
|
||||
{
|
||||
return LeanTween.scaleZ(gameObject, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanScaleZ(this Transform transform, float to, float time)
|
||||
{
|
||||
return LeanTween.scaleZ(transform.gameObject, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.sequence
|
||||
//LeanTween.size (RectTransform)
|
||||
public static LTDescr LeanSize(this RectTransform rectTransform, Vector2 to, float time)
|
||||
{
|
||||
return LeanTween.size(rectTransform, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.tweensRunning
|
||||
//LeanTween.value (Color)
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Color from, Color to, float time)
|
||||
{
|
||||
return LeanTween.value(gameObject, from, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.value (Color)
|
||||
//LeanTween.value (float)
|
||||
public static LTDescr LeanValue(this GameObject gameObject, float from, float to, float time)
|
||||
{
|
||||
return LeanTween.value(gameObject, from, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Vector2 from, Vector2 to, float time)
|
||||
{
|
||||
return LeanTween.value(gameObject, from, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Vector3 from, Vector3 to, float time)
|
||||
{
|
||||
return LeanTween.value(gameObject, from, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.value (float)
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Action<float> callOnUpdate, float from, float to,
|
||||
float time)
|
||||
{
|
||||
return LeanTween.value(gameObject, callOnUpdate, from, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Action<float, float> callOnUpdate, float from,
|
||||
float to, float time)
|
||||
{
|
||||
return LeanTween.value(gameObject, callOnUpdate, from, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Action<float, object> callOnUpdate, float from,
|
||||
float to, float time)
|
||||
{
|
||||
return LeanTween.value(gameObject, callOnUpdate, from, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Action<Color> callOnUpdate, Color from, Color to,
|
||||
float time)
|
||||
{
|
||||
return LeanTween.value(gameObject, callOnUpdate, from, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Action<Vector2> callOnUpdate, Vector2 from,
|
||||
Vector2 to, float time)
|
||||
{
|
||||
return LeanTween.value(gameObject, callOnUpdate, from, to, time);
|
||||
}
|
||||
|
||||
public static LTDescr LeanValue(this GameObject gameObject, Action<Vector3> callOnUpdate, Vector3 from,
|
||||
Vector3 to, float time)
|
||||
{
|
||||
return LeanTween.value(gameObject, callOnUpdate, from, to, time);
|
||||
}
|
||||
|
||||
//LeanTween.value (float)
|
||||
//LeanTween.value (float, object)
|
||||
//LeanTween.value (Vector2)
|
||||
//LeanTween.value (Vector2)
|
||||
//LeanTween.value (Vector3)
|
||||
//LeanTween.value (Vector3)
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: daeb8c5e355b4ff7b8d888e532b9f6a5
|
||||
timeCreated: 1695716057
|
3
UnityProject/Assets/GameScripts/HotFix/GameLogic/UI.meta
Normal file
3
UnityProject/Assets/GameScripts/HotFix/GameLogic/UI.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58574759ecba406ebb5275c9dfc0522b
|
||||
timeCreated: 1695711305
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 850ce87449ea43ef8d72abe3d386e4db
|
||||
timeCreated: 1695711314
|
@@ -0,0 +1,703 @@
|
||||
using System.Collections.Generic;
|
||||
using TEngine;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
//定义的顺序跟游戏中实际的顺序是一致的(从左到右依次是商店、英雄、战斗、天赋、活动(玩法)...等)
|
||||
public enum GameMainButton
|
||||
{
|
||||
//商店
|
||||
BtnShop = 0,
|
||||
|
||||
//英雄
|
||||
BtnHero,
|
||||
|
||||
//主界面
|
||||
BtnFight,
|
||||
|
||||
////天赋
|
||||
//BtnTalent,
|
||||
//主角
|
||||
BtnZhuJue,
|
||||
|
||||
//活动(玩法)
|
||||
BtnActivity,
|
||||
|
||||
BtnMax,
|
||||
}
|
||||
|
||||
[Window(UILayer.UI, fullScreen: true)]
|
||||
public class GameMainUI : UIWindow
|
||||
{
|
||||
#region 声明
|
||||
|
||||
private int m_curIndex; //当前选择的按钮索引
|
||||
private int m_lastIndex; //上一次选择的按钮索引
|
||||
private const float m_aniTime = 0.2f; //按钮上下移动时间
|
||||
private const int m_checkThesHold = 100; //拖拽阈值
|
||||
private UICenterOnChild m_centerOnChild = new UICenterOnChild();
|
||||
private Dictionary<GameMainButton, GameObject> m_btnDic = new Dictionary<GameMainButton, GameObject>();
|
||||
private Dictionary<GameMainButton, Image> m_btnImgDic = new Dictionary<GameMainButton, Image>();
|
||||
private Dictionary<GameMainButton, TextMeshProUGUI> m_btnTextDic = new Dictionary<GameMainButton, TextMeshProUGUI>();
|
||||
private Dictionary<GameMainButton, TextMeshProUGUI> m_btnActiveTextDic = new Dictionary<GameMainButton, TextMeshProUGUI>();
|
||||
private Dictionary<GameMainButton, Image> m_btnLockDic = new Dictionary<GameMainButton, Image>();
|
||||
private Dictionary<GameMainButton, Transform> m_btnRedPointDict = new Dictionary<GameMainButton, Transform>();
|
||||
|
||||
private Vector2 m_tempV2 = new Vector2();
|
||||
private float m_curScaleRatio = 0.9f;
|
||||
private float m_lastScaleRatio = 0.8f;
|
||||
//private HomeChatInfoBlock m_homeChat;
|
||||
|
||||
private float m_cellSize;
|
||||
|
||||
#endregion
|
||||
|
||||
private Dictionary<GameMainButton, HomeChildPage> m_dictHomeChilds = new Dictionary<GameMainButton, HomeChildPage>();
|
||||
private List<HomeChildPage> m_listHomeChilds = new List<HomeChildPage>();
|
||||
private GridLayoutGroup m_gridContent;
|
||||
private Image m_imgActivityTips;
|
||||
private Text m_textActivityTips;
|
||||
|
||||
#region 脚本工具生成的代码
|
||||
|
||||
private RectTransform m_rectInfo;
|
||||
private ScrollRect m_scrollView;
|
||||
private RectTransform m_rectContent;
|
||||
private Image m_imgCheck;
|
||||
private GridLayoutGroup m_rectbtns;
|
||||
private Button m_btnShop;
|
||||
private Transform m_tfShopRed;
|
||||
private Button m_btnHero;
|
||||
private Transform m_tfHeroRed;
|
||||
private Button m_btnFight;
|
||||
private Button m_btnZhuJue;
|
||||
private Transform m_tfZhuJueRed;
|
||||
private Button m_btnActivity;
|
||||
private Transform m_tfActivityRed;
|
||||
private GameObject m_goMask;
|
||||
private Button m_btnGm;
|
||||
private Button m_btnhomeChatMsg;
|
||||
private GameObject m_goChat;
|
||||
private Image m_dimgType;
|
||||
private Text m_textChannlType;
|
||||
private Image m_dimgSex;
|
||||
private GameObject m_goEmpty;
|
||||
private Image m_imgbkg;
|
||||
|
||||
public override void ScriptGenerator()
|
||||
{
|
||||
m_imgbkg = FindChildComponent<Image>("m_imgbkg");
|
||||
m_rectInfo = FindChildComponent<RectTransform>("TopLayout/m_rectInfo");
|
||||
m_scrollView = FindChildComponent<ScrollRect>("TopLayout/m_rectInfo/m_scrollView");
|
||||
m_rectContent = FindChildComponent<RectTransform>("TopLayout/m_rectInfo/m_scrollView/Viewport/m_rectContent");
|
||||
m_imgCheck = FindChildComponent<Image>("TopLayout/m_rectInfo/bottom/m_rectbtns/m_imgCheck");
|
||||
m_rectbtns = FindChildComponent<GridLayoutGroup>("TopLayout/m_rectInfo/bottom/m_rectbtns");
|
||||
m_btnShop = FindChildComponent<Button>("TopLayout/m_rectInfo/bottom/m_rectbtns/m_btnShop");
|
||||
|
||||
m_tfShopRed = FindChild("TopLayout/m_rectInfo/bottom/m_rectbtns/m_btnShop/m_tfShopRed");
|
||||
m_btnHero = FindChildComponent<Button>("TopLayout/m_rectInfo/bottom/m_rectbtns/m_btnHero");
|
||||
m_tfHeroRed = FindChild("TopLayout/m_rectInfo/bottom/m_rectbtns/m_btnHero/m_tfHeroRed");
|
||||
m_btnFight = FindChildComponent<Button>("TopLayout/m_rectInfo/bottom/m_rectbtns/m_btnFight");
|
||||
m_btnActivity = FindChildComponent<Button>("TopLayout/m_rectInfo/bottom/m_rectbtns/m_btnActivity");
|
||||
m_tfActivityRed = FindChild("TopLayout/m_rectInfo/bottom/m_rectbtns/m_btnActivity/m_tfActivityRed");
|
||||
m_btnZhuJue = FindChildComponent<Button>("TopLayout/m_rectInfo/bottom/m_rectbtns/m_btnZhuJue");
|
||||
m_tfZhuJueRed = FindChild("TopLayout/m_rectInfo/bottom/m_rectbtns/m_btnZhuJue/m_tfZhuJueRed");
|
||||
m_goMask = FindChild("TopLayout/m_rectInfo/m_goMask").gameObject;
|
||||
m_btnGm = FindChildComponent<Button>("TopLayout/m_rectInfo/m_btnGm");
|
||||
m_btnShop.onClick.AddListener(OnClickShopBtn);
|
||||
m_btnHero.onClick.AddListener(OnClickHeroBtn);
|
||||
m_btnFight.onClick.AddListener(OnClickFightBtn);
|
||||
m_btnZhuJue.onClick.AddListener(OnClickZhuJueBtn);
|
||||
m_btnActivity.onClick.AddListener(OnClickActivityBtn);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override void BindMemberProperty()
|
||||
{
|
||||
m_gridContent = m_rectContent.GetComponent<GridLayoutGroup>();
|
||||
|
||||
//商店
|
||||
m_btnDic.Add(GameMainButton.BtnShop, m_btnShop.gameObject);
|
||||
m_btnImgDic.Add(GameMainButton.BtnShop, FindChildComponent<Image>(m_btnShop.transform, "m_imgIcon"));
|
||||
m_btnTextDic.Add(GameMainButton.BtnShop, FindChildComponent<TextMeshProUGUI>(m_btnShop.transform, "m_textName"));
|
||||
m_btnLockDic.Add(GameMainButton.BtnShop, FindChildComponent<Image>(m_btnShop.transform, "m_imgLock"));
|
||||
m_btnRedPointDict.Add(GameMainButton.BtnShop, m_tfShopRed);
|
||||
m_btnActiveTextDic.Add(GameMainButton.BtnShop, FindChildComponent<TextMeshProUGUI>(m_btnShop.transform, "m_textActiveName"));
|
||||
// m_shopRedEffGo = CreateUIEffect((uint)CommonEffectID.EffectRedPoint, m_tfShopRed);
|
||||
|
||||
//英雄
|
||||
m_btnDic.Add(GameMainButton.BtnHero, m_btnHero.gameObject);
|
||||
m_btnImgDic.Add(GameMainButton.BtnHero, FindChildComponent<Image>(m_btnHero.transform, "m_imgIcon"));
|
||||
m_btnTextDic.Add(GameMainButton.BtnHero, FindChildComponent<TextMeshProUGUI>(m_btnHero.transform, "m_textName"));
|
||||
m_btnLockDic.Add(GameMainButton.BtnHero, FindChildComponent<Image>(m_btnHero.transform, "m_imgLock"));
|
||||
m_btnActiveTextDic.Add(GameMainButton.BtnHero, FindChildComponent<TextMeshProUGUI>(m_btnHero.transform, "m_textActiveName"));
|
||||
m_btnRedPointDict.Add(GameMainButton.BtnHero, m_tfHeroRed);
|
||||
// m_heroRedEffGo = CreateUIEffect((uint)CommonEffectID.EffectRedPoint, m_tfHeroRed);
|
||||
|
||||
//战斗
|
||||
m_btnDic.Add(GameMainButton.BtnFight, m_btnFight.gameObject);
|
||||
m_btnImgDic.Add(GameMainButton.BtnFight, FindChildComponent<Image>(m_btnFight.transform, "m_imgIcon"));
|
||||
m_btnTextDic.Add(GameMainButton.BtnFight, FindChildComponent<TextMeshProUGUI>(m_btnFight.transform, "m_textName"));
|
||||
m_btnLockDic.Add(GameMainButton.BtnFight, FindChildComponent<Image>(m_btnFight.transform, "m_imgLock"));
|
||||
m_btnActiveTextDic.Add(GameMainButton.BtnFight, FindChildComponent<TextMeshProUGUI>(m_btnFight.transform, "m_textActiveName"));
|
||||
|
||||
////天赋
|
||||
//m_btnDic.Add(GameMainButton.BtnTalent, m_btnTalent.gameObject);
|
||||
//m_btnImgDic.Add(GameMainButton.BtnTalent, FindChildComponent<Image>(m_btnTalent.transform, "m_imgIcon"));
|
||||
//m_btnTextDic.Add(GameMainButton.BtnTalent, FindChildComponent<TextMeshProUGUI>(m_btnTalent.transform, "m_textName"));
|
||||
//m_btnLockDic.Add(GameMainButton.BtnTalent, FindChildComponent<Image>(m_btnTalent.transform, "m_imgLock"));
|
||||
//m_btnRedPointDict.Add(GameMainButton.BtnTalent, m_tfTalentRed);
|
||||
//m_talentRedEffGo = CreateUIEffect((uint)CommonEffectID.EffectRedPoint, m_tfTalentRed);
|
||||
|
||||
//主角
|
||||
m_btnDic.Add(GameMainButton.BtnZhuJue, m_btnZhuJue.gameObject);
|
||||
m_btnImgDic.Add(GameMainButton.BtnZhuJue, FindChildComponent<Image>(m_btnZhuJue.transform, "m_imgIcon"));
|
||||
m_btnTextDic.Add(GameMainButton.BtnZhuJue, FindChildComponent<TextMeshProUGUI>(m_btnZhuJue.transform, "m_textName"));
|
||||
m_btnLockDic.Add(GameMainButton.BtnZhuJue, FindChildComponent<Image>(m_btnZhuJue.transform, "m_imgLock"));
|
||||
m_btnActiveTextDic.Add(GameMainButton.BtnZhuJue, FindChildComponent<TextMeshProUGUI>(m_btnZhuJue.transform, "m_textActiveName"));
|
||||
m_btnRedPointDict.Add(GameMainButton.BtnZhuJue, m_tfZhuJueRed);
|
||||
// m_zhujueRedEffGo = CreateUIEffect((uint)CommonEffectID.EffectRedPoint, m_tfZhuJueRed);
|
||||
|
||||
//活动
|
||||
m_btnDic.Add(GameMainButton.BtnActivity, m_btnActivity.gameObject);
|
||||
m_btnImgDic.Add(GameMainButton.BtnActivity, FindChildComponent<Image>(m_btnActivity.transform, "m_imgIcon"));
|
||||
m_btnTextDic.Add(GameMainButton.BtnActivity, FindChildComponent<TextMeshProUGUI>(m_btnActivity.transform, "m_textName"));
|
||||
m_btnLockDic.Add(GameMainButton.BtnActivity, FindChildComponent<Image>(m_btnActivity.transform, "m_imgLock"));
|
||||
m_btnActiveTextDic.Add(GameMainButton.BtnActivity, FindChildComponent<TextMeshProUGUI>(m_btnActivity.transform, "m_textActiveName"));
|
||||
m_btnRedPointDict.Add(GameMainButton.BtnActivity, m_tfActivityRed);
|
||||
// m_activeRedEffGo = CreateUIEffect((uint)CommonEffectID.EffectRedPoint, m_tfActivityRed);
|
||||
|
||||
// //头顶的信息栏位
|
||||
// CreateWidgetByType<CurrencyDisplayBlock>(transform, "TopLayout/m_rectInfo");
|
||||
|
||||
m_imgActivityTips = FindChildComponent<Image>(m_btnActivity.transform, "m_imgActivityTips");
|
||||
if (m_imgActivityTips != null)
|
||||
{
|
||||
m_textActivityTips = FindChildComponent<Text>(m_imgActivityTips.transform, "m_textActivityTips");
|
||||
if (m_textActivityTips != null)
|
||||
{
|
||||
// m_textActivityTips.text = TextConfigMgr.Instance.GetText(TextDefine.ID_LABEL_WORLD_BOOS_ACTIVITY_OPEN_TIPS);
|
||||
}
|
||||
|
||||
m_imgActivityTips.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
ChangeBtnStyle();
|
||||
}
|
||||
|
||||
public override void OnCreate()
|
||||
{
|
||||
//适配
|
||||
InitGridContent();
|
||||
|
||||
m_centerOnChild.Init(m_scrollView, m_checkThesHold);
|
||||
m_centerOnChild.SetElasticity(0.1f);
|
||||
|
||||
//设置拖拽回调函数
|
||||
m_centerOnChild.SetOnDragCallBack(OnDrag);
|
||||
m_centerOnChild.SetCallback(OnEndDrag);
|
||||
m_centerOnChild.SetEndCallBack(OnEndMovingDrag);
|
||||
CheckHomeOpen();
|
||||
|
||||
//设置按钮的状态
|
||||
// ShowBtnState();
|
||||
|
||||
//设置按钮图标的初始状态
|
||||
// SetBtnImgScale();
|
||||
|
||||
bool showGm = false;
|
||||
// #if UNITY_EDITOR
|
||||
// showGm = true;
|
||||
// #endif
|
||||
|
||||
m_btnGm.gameObject.SetActive(showGm);
|
||||
}
|
||||
|
||||
private void CheckHomeOpen()
|
||||
{
|
||||
GameMainButton curSelectType = GameMainButton.BtnFight;
|
||||
if (m_curIndex >= 0 && m_curIndex < m_listHomeChilds.Count)
|
||||
{
|
||||
curSelectType = m_listHomeChilds[m_curIndex].type;
|
||||
}
|
||||
|
||||
bool chg = false;
|
||||
|
||||
//商城
|
||||
if (!m_dictHomeChilds.ContainsKey(GameMainButton.BtnShop))
|
||||
{
|
||||
var child = CreateWidgetByType<ShopPage>(m_rectContent);
|
||||
child.type = GameMainButton.BtnShop;
|
||||
m_dictHomeChilds.Add(GameMainButton.BtnShop, child);
|
||||
m_listHomeChilds.Add(child);
|
||||
chg = true;
|
||||
}
|
||||
|
||||
//英雄
|
||||
if (!m_dictHomeChilds.ContainsKey(GameMainButton.BtnHero))
|
||||
{
|
||||
var child = CreateWidgetByType<HeroPage>(m_rectContent);
|
||||
child.type = GameMainButton.BtnHero;
|
||||
m_dictHomeChilds.Add(GameMainButton.BtnHero, child);
|
||||
m_listHomeChilds.Add(child);
|
||||
chg = true;
|
||||
}
|
||||
|
||||
//战斗
|
||||
if (!m_dictHomeChilds.ContainsKey(GameMainButton.BtnFight))
|
||||
{
|
||||
var child = CreateWidgetByType<MainLevelPage>(m_rectContent);
|
||||
child.type = GameMainButton.BtnFight;
|
||||
m_dictHomeChilds.Add(GameMainButton.BtnFight, child);
|
||||
m_listHomeChilds.Add(child);
|
||||
chg = true;
|
||||
}
|
||||
|
||||
//主角
|
||||
if (!m_dictHomeChilds.ContainsKey(GameMainButton.BtnZhuJue))
|
||||
{
|
||||
var child = CreateWidgetByType<ZhuJuePage>(m_rectContent);
|
||||
child.type = GameMainButton.BtnZhuJue;
|
||||
m_dictHomeChilds.Add(GameMainButton.BtnZhuJue, child);
|
||||
m_listHomeChilds.Add(child);
|
||||
chg = true;
|
||||
}
|
||||
|
||||
//活动(玩法)
|
||||
if (!m_dictHomeChilds.ContainsKey(GameMainButton.BtnActivity))
|
||||
{
|
||||
var child = CreateWidgetByType<ChallengePage>(m_rectContent);
|
||||
child.type = GameMainButton.BtnActivity;
|
||||
m_dictHomeChilds.Add(GameMainButton.BtnActivity, child);
|
||||
m_listHomeChilds.Add(child);
|
||||
chg = true;
|
||||
}
|
||||
|
||||
|
||||
if (chg)
|
||||
{
|
||||
m_listHomeChilds.Sort(delegate(HomeChildPage lhs, HomeChildPage rhs) { return lhs.type - rhs.type; });
|
||||
for (int i = 0; i < m_listHomeChilds.Count; i++)
|
||||
{
|
||||
m_listHomeChilds[i].Index = i;
|
||||
m_listHomeChilds[i].rectTransform.SetSiblingIndex(i);
|
||||
m_listHomeChilds[i].OnActivePage(m_listHomeChilds[i].type == curSelectType);
|
||||
}
|
||||
|
||||
int idx = GetGameMainIdx(curSelectType);
|
||||
m_curIndex = idx;
|
||||
m_lastIndex = idx;
|
||||
|
||||
//默认显示进入游戏界面
|
||||
m_centerOnChild.CenterOnChild(m_curIndex, true);
|
||||
}
|
||||
}
|
||||
|
||||
void InitGridContent()
|
||||
{
|
||||
var thisRect = this.rectTransform;
|
||||
m_tempV2.x = m_rectInfo.rect.width;
|
||||
m_tempV2.y = m_rectInfo.rect.height;
|
||||
m_gridContent.cellSize = m_tempV2;
|
||||
m_gridContent.SetLayoutHorizontal();
|
||||
m_gridContent.SetLayoutVertical();
|
||||
|
||||
var rectbtns = m_rectbtns.transform as RectTransform;
|
||||
m_cellSize = rectbtns.rect.width / (int)GameMainButton.BtnMax;
|
||||
m_rectbtns.constraint = GridLayoutGroup.Constraint.FixedColumnCount;
|
||||
m_rectbtns.constraintCount = (int)GameMainButton.BtnMax;
|
||||
m_rectbtns.cellSize = new Vector2(m_cellSize, m_rectbtns.cellSize.y);
|
||||
m_rectbtns.SetLayoutHorizontal();
|
||||
m_rectbtns.SetLayoutVertical();
|
||||
var Checkrect = m_imgCheck.transform as RectTransform;
|
||||
Checkrect.sizeDelta = new Vector2(m_cellSize + 30f, Checkrect.rect.height);
|
||||
}
|
||||
|
||||
|
||||
private void ChangeBtnStyle()
|
||||
{
|
||||
// int[] systemIds = new[]
|
||||
// {
|
||||
// (int)FuncType.FUNC_TYPE_MAIN_SHOP,
|
||||
// (int)FuncType.FUNC_TYPE_HERO,
|
||||
// (int)FuncType.FUNC_TYPE_FIGHT,
|
||||
// (int)FuncType.FUNC_TYPE_ZHUJUE,
|
||||
// (int)FuncType.FUNC_TYPE_MAIN_ACTIVITY,
|
||||
// };
|
||||
|
||||
GameMainButton[] types = new[]
|
||||
{
|
||||
//商店
|
||||
GameMainButton.BtnShop,
|
||||
//卡牌
|
||||
GameMainButton.BtnHero,
|
||||
//主界面
|
||||
GameMainButton.BtnFight,
|
||||
//主角
|
||||
GameMainButton.BtnZhuJue,
|
||||
//挑战(玩法)
|
||||
GameMainButton.BtnActivity,
|
||||
};
|
||||
// FuncOpenConfig cfg;
|
||||
// Image img;
|
||||
// TextMeshProUGUI txt;
|
||||
// GameMainButton key;
|
||||
// int id;
|
||||
// var actTxt = GetActiveTextNameByType(key);
|
||||
// for (int i = 0; i < types.Length; i++)
|
||||
// {
|
||||
// id = systemIds[i];
|
||||
// key = types[i];
|
||||
// cfg = FuncOpenCfgMgr.Instance.GetFuncOpenCfg((uint)id);
|
||||
// if (cfg == null)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
// img = GetIconImageByType(key);
|
||||
// if (img != null)
|
||||
// {
|
||||
// img.SetSprite( cfg.FuncIcon);
|
||||
// }
|
||||
//
|
||||
// txt = GetTextNameByType(key);
|
||||
// if (txt != null)
|
||||
// {
|
||||
// txt.text = cfg.FuncName;
|
||||
// }
|
||||
//
|
||||
// if (actTxt != null)
|
||||
// {
|
||||
// actTxt.text = cfg.FuncName;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
#region 通用获取界面接口
|
||||
|
||||
//根据按钮类型获取对应按钮的gameObject
|
||||
private GameObject GetBtnGoByType(GameMainButton buttonType)
|
||||
{
|
||||
return m_btnDic.TryGetValue(buttonType, out var targetGo) ? targetGo : null;
|
||||
}
|
||||
|
||||
//根据按钮类型获取对应Icon
|
||||
private Image GetIconImageByType(GameMainButton buttonType)
|
||||
{
|
||||
return m_btnImgDic.TryGetValue(buttonType, out var targetImage) ? targetImage : null;
|
||||
}
|
||||
|
||||
//根据按钮类型获取对应text
|
||||
private TextMeshProUGUI GetTextNameByType(GameMainButton buttonType)
|
||||
{
|
||||
return m_btnTextDic.TryGetValue(buttonType, out var targetText) ? targetText : null;
|
||||
}
|
||||
|
||||
//根据按钮类型获取对应text
|
||||
private TextMeshProUGUI GetActiveTextNameByType(GameMainButton buttonType)
|
||||
{
|
||||
return m_btnActiveTextDic.TryGetValue(buttonType, out var targetText) ? targetText : null;
|
||||
}
|
||||
|
||||
//获取按钮解锁状态
|
||||
private bool GetBtnLockStateByType(GameMainButton buttonType)
|
||||
{
|
||||
// switch (buttonType)
|
||||
// {
|
||||
// case GameMainButton.BtnHero:
|
||||
// return FuncOpenMgr.Instance.CheckFuncOpen(FuncType.FUNC_TYPE_HERO);
|
||||
// case GameMainButton.BtnShop:
|
||||
// return FuncOpenMgr.Instance.CheckFuncOpen(FuncType.FUNC_TYPE_MAIN_SHOP);
|
||||
// case GameMainButton.BtnFight:
|
||||
// return FuncOpenMgr.Instance.CheckFuncOpen(FuncType.FUNC_TYPE_FIGHT);
|
||||
// case GameMainButton.BtnActivity:
|
||||
// return FuncOpenMgr.Instance.CheckFuncOpen(FuncType.FUNC_TYPE_MAIN_ACTIVITY);
|
||||
// case GameMainButton.BtnZhuJue:
|
||||
// return FuncOpenMgr.Instance.CheckFuncOpen(FuncType.FUNC_TYPE_ZHUJUE);
|
||||
// }
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public HomeChildPage GetChildPage(GameMainButton btnType)
|
||||
{
|
||||
if (m_dictHomeChilds.TryGetValue(btnType, out var ret))
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private int GetGameMainIdx(GameMainButton btnType)
|
||||
{
|
||||
var child = GetChildPage(btnType);
|
||||
if (child != null)
|
||||
{
|
||||
return child.Index;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public bool IsOnMainLevelPage()
|
||||
{
|
||||
bool isBtnFight = m_curIndex != GetGameMainIdx(GameMainButton.BtnFight);
|
||||
OnClickFightBtn();
|
||||
return isBtnFight;
|
||||
}
|
||||
|
||||
public override void OnUpdate()
|
||||
{
|
||||
m_centerOnChild.Update();
|
||||
}
|
||||
|
||||
//商店
|
||||
private void OnClickShopBtn()
|
||||
{
|
||||
int idx = GetGameMainIdx(GameMainButton.BtnShop);
|
||||
if (m_curIndex != idx)
|
||||
{
|
||||
m_centerOnChild.CenterOnChild(idx, false);
|
||||
}
|
||||
}
|
||||
|
||||
//英雄
|
||||
private void OnClickHeroBtn()
|
||||
{
|
||||
int idx = GetGameMainIdx(GameMainButton.BtnHero);
|
||||
if (m_curIndex != idx)
|
||||
{
|
||||
m_centerOnChild.CenterOnChild(idx, false);
|
||||
}
|
||||
|
||||
// 调到英雄界面的时候,重新刷一遍出战英雄特效
|
||||
// GameEvent.Get<IHeroUI>().OnFightHeroEffectRefresh();
|
||||
}
|
||||
|
||||
//战斗(主界面)
|
||||
private void OnClickFightBtn()
|
||||
{
|
||||
int idx = GetGameMainIdx(GameMainButton.BtnFight);
|
||||
if (m_curIndex != idx)
|
||||
{
|
||||
m_centerOnChild.CenterOnChild(idx, false);
|
||||
}
|
||||
}
|
||||
|
||||
//活动(玩法)
|
||||
private void OnClickActivityBtn()
|
||||
{
|
||||
if (m_imgActivityTips != null)
|
||||
{
|
||||
m_imgActivityTips.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
int idx = GetGameMainIdx(GameMainButton.BtnActivity);
|
||||
if (m_curIndex != idx)
|
||||
{
|
||||
m_centerOnChild.CenterOnChild(idx, false);
|
||||
}
|
||||
}
|
||||
|
||||
//点击天赋
|
||||
private void OnClickZhuJueBtn()
|
||||
{
|
||||
int idx = GetGameMainIdx(GameMainButton.BtnZhuJue);
|
||||
if (m_curIndex != idx)
|
||||
{
|
||||
m_centerOnChild.CenterOnChild(idx, false);
|
||||
}
|
||||
}
|
||||
|
||||
#region 拖拽事件
|
||||
|
||||
private float _lastX = 0f;
|
||||
|
||||
private const float DynamicsX = 0.3f;
|
||||
|
||||
//拖拽中
|
||||
private void OnDrag(int curDragIndex)
|
||||
{
|
||||
if (curDragIndex >= m_listHomeChilds.Count)
|
||||
{
|
||||
Log.Error("DragIndex Error : OnDrag exceed Count / curDragIndex:{0} ,m_listHomeChilds.Count{1}", curDragIndex, m_listHomeChilds.Count);
|
||||
return;
|
||||
}
|
||||
|
||||
var btnType = m_listHomeChilds[curDragIndex].type;
|
||||
float offset = m_rectContent.anchoredPosition.x + curDragIndex * m_tempV2.x;
|
||||
float x = m_cellSize * (int)btnType - (offset / m_cellSize) * m_cellSize;
|
||||
|
||||
if (_lastX != 0)
|
||||
{
|
||||
//var Gap = (x - m_LastX)* (m_dynamicsX - (int)GameMainButton.BtnMax / 10);
|
||||
var Gap = (x - _lastX) * DynamicsX;
|
||||
var index = curDragIndex;
|
||||
if (Gap > 0)
|
||||
{
|
||||
index = Mathf.Min(++curDragIndex, (int)GameMainButton.BtnZhuJue);
|
||||
}
|
||||
else
|
||||
{
|
||||
index = Mathf.Max(--curDragIndex, (int)GameMainButton.BtnShop);
|
||||
}
|
||||
|
||||
if (m_listHomeChilds.Count <= index)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_listHomeChilds[index].OnActivePage(true);
|
||||
m_imgCheck.transform.localPosition = new Vector2(m_imgCheck.transform.localPosition.x + Gap, m_imgCheck.transform.localPosition.y);
|
||||
}
|
||||
|
||||
_lastX = x;
|
||||
}
|
||||
|
||||
private void OnEndMovingDrag(int curDragIndex)
|
||||
{
|
||||
var btnType = m_listHomeChilds[curDragIndex].type;
|
||||
GameObject btnGo = GetBtnGoByType(btnType);
|
||||
LeanTweenType tweenType = LeanTweenType.easeOutBack;
|
||||
if (curDragIndex == m_lastIndex)
|
||||
{
|
||||
tweenType = LeanTweenType.notUsed;
|
||||
}
|
||||
|
||||
if (_lastX != 0 || curDragIndex != m_lastIndex)
|
||||
{
|
||||
LeanTween.moveX(m_imgCheck.gameObject, btnGo.transform.position.x, m_aniTime + 0.1f).setEase(tweenType).setOnComplete(
|
||||
() =>
|
||||
{
|
||||
for (int i = 0; i < m_listHomeChilds.Count; i++)
|
||||
{
|
||||
m_listHomeChilds[i].OnActivePage(i == curDragIndex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_lastX = 0f;
|
||||
|
||||
// if (curDragIndex == (int)GameMainButton.BtnZhuJue)
|
||||
// {
|
||||
// GameEvent.Get<ICommUI>().SetMainPageDisplayBlock(
|
||||
// TopDisplayItemType.TOP_DIS_ITEM_TYPE_TALENT,
|
||||
// TopDisplayItemType.TOP_DIS_ITEM_TYPE_GOLD,
|
||||
// TopDisplayItemType.TOP_DIS_ITEM_TYPE_DIAMOND);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// GameEvent.Get<ICommUI>().SetMainPageDisplayBlock(
|
||||
// TopDisplayItemType.TOP_DIS_ITEM_TYPE_POWER,
|
||||
// TopDisplayItemType.TOP_DIS_ITEM_TYPE_GOLD,
|
||||
// TopDisplayItemType.TOP_DIS_ITEM_TYPE_DIAMOND);
|
||||
// }
|
||||
|
||||
// //播放下音效
|
||||
// if (!m_isInitEnter)
|
||||
// {
|
||||
// AudioSys.GameMgr.PlayUISoundEffect(SysEffectSoundID.SysSoundHuaDongYinXiao);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// m_isInitEnter = false;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
//拖拽结束,计算各个按钮的位置
|
||||
private void OnEndDrag(int curDragIndex)
|
||||
{
|
||||
if (curDragIndex >= m_listHomeChilds.Count)
|
||||
{
|
||||
Log.Error("DragIndex Error : OnEndDrag exceed Count / curDragIndex:{0} ,m_listHomeChilds.Count{1}", curDragIndex, m_listHomeChilds.Count);
|
||||
return;
|
||||
}
|
||||
|
||||
m_lastIndex = m_curIndex;
|
||||
m_curIndex = curDragIndex;
|
||||
|
||||
#region 回调下page界面
|
||||
|
||||
for (int i = 0; i < m_listHomeChilds.Count; i++)
|
||||
{
|
||||
m_listHomeChilds[i].OnCenterOn(i == m_curIndex);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
bool isLeftToRight = m_curIndex >= m_lastIndex;
|
||||
var btnType = m_listHomeChilds[m_curIndex].type;
|
||||
var oldBtnType = m_listHomeChilds[m_lastIndex].type;
|
||||
m_listHomeChilds[m_curIndex].OnActivePage(true);
|
||||
// m_homeChat.gameObject.SetActive(btnType == GameMainButton.BtnFight);
|
||||
|
||||
Image curImg = GetIconImageByType(btnType);
|
||||
GameObject imgGo = curImg.gameObject;
|
||||
|
||||
if (isLeftToRight)
|
||||
{
|
||||
for (var i = oldBtnType; i < btnType; i++)
|
||||
{
|
||||
Image lastImg = GetIconImageByType(i);
|
||||
GameObject lastImgGo = lastImg.gameObject;
|
||||
|
||||
//LeanTween.moveLocal(lastImgGo, new Vector2(imgGo.transform.localPosition.x, 0), m_aniTime);
|
||||
if (GetBtnLockStateByType(i))
|
||||
{
|
||||
LeanTween.scale(lastImgGo, new Vector3(m_lastScaleRatio, m_lastScaleRatio, m_lastScaleRatio), m_aniTime);
|
||||
GetTextNameByType(i).gameObject.SetActive(true);
|
||||
GetActiveTextNameByType(i).gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
lastImg.color = new Color(255, 255, 255, 204);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var i = oldBtnType; i > btnType; i--)
|
||||
{
|
||||
Image lastImg = GetIconImageByType(i);
|
||||
GameObject lastImgGo = lastImg.gameObject;
|
||||
|
||||
//LeanTween.moveLocal(lastImgGo, new Vector2(imgGo.transform.localPosition.x, 0), m_aniTime);
|
||||
if (GetBtnLockStateByType(i))
|
||||
{
|
||||
LeanTween.scale(lastImgGo, new Vector3(m_lastScaleRatio, m_lastScaleRatio, m_lastScaleRatio), m_aniTime);
|
||||
|
||||
GetTextNameByType(i).gameObject.SetActive(true);
|
||||
GetActiveTextNameByType(i).gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
lastImg.color = new Color(255, 255, 255, 204);
|
||||
}
|
||||
}
|
||||
|
||||
//LeanTween.moveLocal(imgGo, new Vector2(imgGo.transform.localPosition.x, 30f), m_aniTime);
|
||||
LeanTween.scale(imgGo, new Vector3(m_curScaleRatio, m_curScaleRatio, m_curScaleRatio), m_aniTime).setOnComplete(
|
||||
() =>
|
||||
{
|
||||
#region 回调下page界面
|
||||
|
||||
for (int i = 0; i < m_listHomeChilds.Count; i++)
|
||||
{
|
||||
m_listHomeChilds[i].OnCenterOnEnd(i == m_curIndex);
|
||||
}
|
||||
|
||||
#endregion
|
||||
});
|
||||
curImg.color = new Color(255, 255, 255, 255);
|
||||
GetTextNameByType(btnType).gameObject.SetActive(false);
|
||||
GetActiveTextNameByType(btnType).gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fcc7533a040c48ecbc082567c2cef691
|
||||
timeCreated: 1695711322
|
@@ -0,0 +1,61 @@
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// 首页子界面。
|
||||
/// </summary>
|
||||
public class HomeChildPage : UIWidget
|
||||
{
|
||||
public GameMainButton type;
|
||||
|
||||
public int Index;
|
||||
|
||||
private CanvasGroup _canvasGroup;
|
||||
|
||||
/// <summary>
|
||||
/// 检查红点。
|
||||
/// </summary>
|
||||
/// <returns>红点状态。</returns>
|
||||
public virtual bool CheckRedNote()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 拖拽完成开始。
|
||||
/// </summary>
|
||||
/// <param name="isSelf"></param>
|
||||
public virtual void OnCenterOn(bool isSelf) { }
|
||||
|
||||
/// <summary>
|
||||
/// 拖拽完成回调。
|
||||
/// </summary>
|
||||
/// <param name="isSelf"></param>
|
||||
public virtual void OnCenterOnEnd(bool isSelf) { }
|
||||
|
||||
/// <summary>
|
||||
/// 激活界面回调。
|
||||
/// </summary>
|
||||
/// <param name="isActive">是否激活。</param>
|
||||
public virtual void OnActivePage(bool isActive)
|
||||
{
|
||||
SetAlpha(isActive ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过设置Alpha隐藏,减少SetActive的消耗。
|
||||
/// </summary>
|
||||
/// <param name="alpha">Alpha值。</param>
|
||||
protected void SetAlpha(float alpha)
|
||||
{
|
||||
if (_canvasGroup == null)
|
||||
{
|
||||
_canvasGroup = gameObject.GetOrAddComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
_canvasGroup.alpha = alpha;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0488dff8374745c5b8250103e7136849
|
||||
timeCreated: 1695714988
|
@@ -0,0 +1,27 @@
|
||||
namespace GameLogic
|
||||
{
|
||||
public class ShopPage:HomeChildPage
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class MainLevelPage:HomeChildPage
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class ZhuJuePage:HomeChildPage
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class HeroPage:HomeChildPage
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class ChallengePage:HomeChildPage
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4aabbaba0f0a4f4c96f5b50e38cd7690
|
||||
timeCreated: 1695716304
|
@@ -0,0 +1,316 @@
|
||||
using System;
|
||||
#if ENABLE_CANTMOVE
|
||||
using System.Collections.Generic;
|
||||
#endif
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public class UICenterOnChild
|
||||
{
|
||||
private float _elasticity = 0.1f;
|
||||
private ScrollRect _scrollRect;
|
||||
private RectTransform _content;
|
||||
private EventTrigger _eventTrigger;
|
||||
private Action<int> _callback;
|
||||
private Action<int> _onEndCallback;
|
||||
private Action<int> _onDragCallback;
|
||||
private Action<int> _onEndMovingCallback;
|
||||
|
||||
private int _targetIdx;
|
||||
private bool _isMoving = false;
|
||||
private Vector2 _velocity = Vector2.zero;
|
||||
private readonly Vector3[] _cornersArray = new Vector3[4];
|
||||
|
||||
//用阈值处理翻页,调整背包拖动问题
|
||||
private float _checkThresholdX = 0f;
|
||||
private float _startX;
|
||||
|
||||
#if ENABLE_CANTMOVE
|
||||
//不能作为目标id的id列表
|
||||
private List<int> _canNotMoveIdxs = new List<int>();
|
||||
#endif
|
||||
|
||||
public void Init(ScrollRect scrollRect, float checkThreshold = 0f)
|
||||
{
|
||||
_scrollRect = scrollRect;
|
||||
_scrollRect.movementType = ScrollRect.MovementType.Unrestricted;
|
||||
_scrollRect.inertia = false;
|
||||
_content = _scrollRect.content;
|
||||
_checkThresholdX = checkThreshold;
|
||||
|
||||
_eventTrigger = _scrollRect.GetComponent<EventTrigger>();
|
||||
if (_eventTrigger == null)
|
||||
{
|
||||
_eventTrigger = _scrollRect.gameObject.AddComponent<EventTrigger>();
|
||||
}
|
||||
|
||||
EventTrigger.Entry dragEntry = new EventTrigger.Entry();
|
||||
dragEntry.eventID = EventTriggerType.Drag;
|
||||
dragEntry.callback.AddListener(OnDrag);
|
||||
_eventTrigger.triggers.Add(dragEntry);
|
||||
EventTrigger.Entry endDragEntry = new EventTrigger.Entry();
|
||||
endDragEntry.eventID = EventTriggerType.EndDrag;
|
||||
endDragEntry.callback.AddListener(OnEndDrag);
|
||||
_eventTrigger.triggers.Add(endDragEntry);
|
||||
EventTrigger.Entry startDragEntry = new EventTrigger.Entry();
|
||||
startDragEntry.eventID = EventTriggerType.BeginDrag;
|
||||
startDragEntry.callback.AddListener(OnStartDrag);
|
||||
_eventTrigger.triggers.Add(startDragEntry);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (_isMoving)
|
||||
{
|
||||
if (0 <= _targetIdx && _targetIdx < _content.childCount)
|
||||
{
|
||||
Vector2 center = GetCenter(_scrollRect.viewport);
|
||||
Vector2 pos = GetCenter(_content.GetChild(_targetIdx) as RectTransform);
|
||||
Vector2 offset = pos - center;
|
||||
_content.anchoredPosition = Vector2.SmoothDamp(
|
||||
_content.anchoredPosition,
|
||||
_content.anchoredPosition - offset,
|
||||
ref _velocity,
|
||||
_elasticity,
|
||||
float.MaxValue,
|
||||
GameTime.deltaTime);
|
||||
if (_velocity.magnitude < 1)
|
||||
{
|
||||
if (_onEndMovingCallback != null)
|
||||
{
|
||||
_onEndMovingCallback(_targetIdx);
|
||||
}
|
||||
_isMoving = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_onEndMovingCallback != null)
|
||||
{
|
||||
_onEndMovingCallback(_targetIdx);
|
||||
}
|
||||
|
||||
_isMoving = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetOnDragCallBack(Action<int> callback)
|
||||
{
|
||||
_onDragCallback = callback;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置回调,返回当前居中的 childIndex
|
||||
/// </summary>
|
||||
public void SetCallback(Action<int> callback)
|
||||
{
|
||||
_callback = callback;
|
||||
}
|
||||
|
||||
public void SetEndCallBack(Action<int> endCallback)
|
||||
{
|
||||
_onEndCallback = endCallback;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置停止移动时回调
|
||||
/// </summary>
|
||||
/// <param name="callBack"></param>
|
||||
public void SetOnEndMovingCallback(Action<int> callBack)
|
||||
{
|
||||
_onEndMovingCallback = callBack;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置弹力,默认为0.1
|
||||
/// </summary>
|
||||
public void SetElasticity(float elasticity)
|
||||
{
|
||||
_elasticity = elasticity;
|
||||
}
|
||||
|
||||
//设置不能移动的索引
|
||||
public void SetCanNotMoveId(int id)
|
||||
{
|
||||
#if ENABLE_CANTMOVE
|
||||
if (!_canNotMoveIdxs.Contains(id))
|
||||
{
|
||||
_canNotMoveIdxs.Add(id);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//移除不能移动的索引
|
||||
public void RemoveCanNotMoveId(int id)
|
||||
{
|
||||
#if ENABLE_CANTMOVE
|
||||
if (_canNotMoveIdxs.Contains(id))
|
||||
{
|
||||
_canNotMoveIdxs.Remove(id);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 居中到 childIndex
|
||||
/// </summary>
|
||||
public void CenterOnChild(int childIndex, bool isImmediately = true)
|
||||
{
|
||||
if (0 <= childIndex && childIndex < _content.childCount)
|
||||
{
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(_content);
|
||||
_targetIdx = childIndex;
|
||||
if (isImmediately)
|
||||
{
|
||||
Vector2 center = GetCenter(_scrollRect.viewport);
|
||||
Vector2 pos = GetCenter(_content.GetChild(_targetIdx) as RectTransform);
|
||||
Vector2 offset = pos - center;
|
||||
_content.anchoredPosition = _content.anchoredPosition - offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
_isMoving = true;
|
||||
}
|
||||
|
||||
if (_callback != null)
|
||||
{
|
||||
_callback(_targetIdx);
|
||||
}
|
||||
|
||||
if (_onEndCallback != null)
|
||||
{
|
||||
_onEndCallback(_targetIdx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStartDrag(BaseEventData param)
|
||||
{
|
||||
_startX = _content.anchoredPosition.x;
|
||||
}
|
||||
|
||||
private void OnDrag(BaseEventData param)
|
||||
{
|
||||
_isMoving = false;
|
||||
if (_onDragCallback != null)
|
||||
{
|
||||
_onDragCallback(_targetIdx);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEndDrag(BaseEventData param)
|
||||
{
|
||||
if (_checkThresholdX == 0f)
|
||||
{
|
||||
FindClosest();
|
||||
}
|
||||
else
|
||||
{
|
||||
var moved = _content.anchoredPosition.x - _startX;
|
||||
|
||||
int newIdx = _targetIdx;
|
||||
if (moved > _checkThresholdX)
|
||||
{
|
||||
#if ENABLE_CANTMOVE
|
||||
newIdx = Math.Max(0, m_targetIdx - 1);
|
||||
#endif
|
||||
for (int i = 0; i < _targetIdx; i++)
|
||||
{
|
||||
#if ENABLE_CANTMOVE
|
||||
//新id不能是m_canNotBeTargetIdx
|
||||
if (_canNotMoveIdxs.Contains(i))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
newIdx = i;
|
||||
}
|
||||
}
|
||||
else if (moved < -_checkThresholdX)
|
||||
{
|
||||
#if ENABLE_CANTMOVE
|
||||
//newIdx = Math.Min(m_content.childCount - 1, m_targetIdx + 1);
|
||||
#endif
|
||||
for (int i = _content.childCount - 1; i >= _targetIdx + 1; i--)
|
||||
{
|
||||
#if ENABLE_CANTMOVE
|
||||
if (_canNotMoveIdxs.Contains(i))
|
||||
{
|
||||
continue;
|
||||
|
||||
}
|
||||
#endif
|
||||
newIdx = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (_targetIdx != newIdx)
|
||||
{
|
||||
_targetIdx = newIdx;
|
||||
if (_callback != null)
|
||||
{
|
||||
_callback(_targetIdx);
|
||||
}
|
||||
}
|
||||
|
||||
if (_onEndCallback != null)
|
||||
{
|
||||
_onEndCallback(_targetIdx);
|
||||
}
|
||||
|
||||
_isMoving = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void FindClosest()
|
||||
{
|
||||
if (_content.childCount > 0)
|
||||
{
|
||||
Vector2 center = GetCenter(_scrollRect.viewport);
|
||||
float minDist = float.MaxValue;
|
||||
for (int i = 0; i < _content.childCount; i++)
|
||||
{
|
||||
#if ENABLE_CANTMOVE
|
||||
if (_canNotMoveIdxs.Contains(i))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
Vector2 pos = GetCenter(_content.GetChild(i) as RectTransform);
|
||||
Vector2 offset = pos - center;
|
||||
float sqrDist = Vector2.SqrMagnitude(offset);
|
||||
if (sqrDist < minDist)
|
||||
{
|
||||
minDist = sqrDist;
|
||||
_targetIdx = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (_callback != null)
|
||||
{
|
||||
_callback(_targetIdx);
|
||||
}
|
||||
|
||||
_isMoving = true;
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2 GetCenter(RectTransform rectTransform)
|
||||
{
|
||||
Vector3 offset = _scrollRect.viewport.InverseTransformPoint(rectTransform.position);
|
||||
rectTransform.GetLocalCorners(_cornersArray);
|
||||
offset = offset + (_cornersArray[0] + _cornersArray[2]) * 0.5f;
|
||||
return offset;
|
||||
}
|
||||
|
||||
public bool GetIsMoving()
|
||||
{
|
||||
return _isMoving;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57ed983ab97840a3958e3b375acdaf98
|
||||
timeCreated: 1695714913
|
Reference in New Issue
Block a user