2023-10-19 15:00:19 +08:00
|
|
|
|
using cfg.RedPoint;
|
|
|
|
|
|
using Framework;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using PhxhSDK;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using Debug = DebugUtil;
|
|
|
|
|
|
|
|
|
|
|
|
public partial class RedPointManager : Singlenton<RedPointManager>, IInitable
|
|
|
|
|
|
{
|
|
|
|
|
|
const string RED_POINT_NODE_TYPE_PREFIX = "RedPointNode";
|
|
|
|
|
|
public const int RED_POINT_NODE_ROOT_FLAG = 0;
|
|
|
|
|
|
|
|
|
|
|
|
private List<RedPointNode> _treeRoots = new();
|
|
|
|
|
|
private Dictionary<int, RedPointNode> _nodeDic = new();
|
2023-11-02 20:02:10 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
public void Init()
|
|
|
|
|
|
{
|
|
|
|
|
|
RegisterEvent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Release()
|
|
|
|
|
|
{
|
|
|
|
|
|
UnRegisterEvent();
|
|
|
|
|
|
DisposeAllNodes();
|
|
|
|
|
|
_treeRoots = null;
|
|
|
|
|
|
_nodeDic = null;
|
|
|
|
|
|
}
|
2023-11-02 20:02:10 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
private void RegisterEvent()
|
|
|
|
|
|
{
|
|
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.AllConfigLoad, OnConfigLoad);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void UnRegisterEvent()
|
|
|
|
|
|
{
|
|
|
|
|
|
EventManager.Instance.Unregister(EventManager.EventName.AllConfigLoad, OnConfigLoad);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnConfigLoad()
|
|
|
|
|
|
{
|
|
|
|
|
|
ConstructTreeFromConfig();
|
|
|
|
|
|
InitAllNodes();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ConstructTreeFromConfig()
|
|
|
|
|
|
{
|
|
|
|
|
|
ConstructAllNode();
|
|
|
|
|
|
ConstructNodeRelationship();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ConstructAllNode()
|
|
|
|
|
|
{
|
|
|
|
|
|
var config = TableManager.Instance.Tables.RedPointConfig.DataMap;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var data in config.Values)
|
|
|
|
|
|
{
|
|
|
|
|
|
var id = data.Id;
|
|
|
|
|
|
var node = GetANode(id, data.Type);
|
|
|
|
|
|
if (node != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_nodeDic.Add(id, node);
|
|
|
|
|
|
if (data.ParentID == RED_POINT_NODE_ROOT_FLAG)
|
|
|
|
|
|
{
|
|
|
|
|
|
_treeRoots.Add(node);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"转换Node失败,nodeID:{data.Id}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ConstructNodeRelationship()
|
|
|
|
|
|
{
|
|
|
|
|
|
var config = TableManager.Instance.Tables.RedPointConfig.DataMap;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var data in config.Values)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (data.ParentID != RED_POINT_NODE_ROOT_FLAG)
|
|
|
|
|
|
{
|
|
|
|
|
|
var node = GetNodeByID(data.Id);
|
|
|
|
|
|
if (node != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var parentNode = GetNodeByID(data.ParentID);
|
|
|
|
|
|
if (parentNode != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
parentNode.AddChild(node);
|
|
|
|
|
|
node.parent = parentNode;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void InitAllNodes()
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var node in _nodeDic.Values)
|
|
|
|
|
|
{
|
|
|
|
|
|
node.Init();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void DisposeAllNodes()
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var node in _nodeDic.Values)
|
|
|
|
|
|
{
|
|
|
|
|
|
node.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-02 20:02:10 +08:00
|
|
|
|
private RedPointNode GetANode(int id, NodeType nodeType, object param = null)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (nodeType == NodeType.InValid)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"RedPoint Type非法,请修改配置!id:{id}");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2023-11-02 20:02:10 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
RedPointNode result = null;
|
|
|
|
|
|
var nodeTypeStr = RED_POINT_NODE_TYPE_PREFIX + nodeType.ToString();
|
2023-11-02 20:02:10 +08:00
|
|
|
|
Type type = CommonUtilsFramework.GamePlayAssembly.GetType(nodeTypeStr);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
if (type != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
result = Activator.CreateInstance(type, id) as RedPointNode;
|
2023-11-02 20:02:10 +08:00
|
|
|
|
if (result != null)
|
|
|
|
|
|
result.param = param;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"枚举NodeType转Type失败!请检查是否有对应类型!nodeType:{nodeType.ToString()}");
|
|
|
|
|
|
}
|
2023-11-02 20:02:10 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region API
|
2023-11-02 20:02:10 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
public RedPointNode GetNodeByID(int nodeID)
|
|
|
|
|
|
{
|
|
|
|
|
|
return _nodeDic.GetValueOrDefault(nodeID, null);
|
|
|
|
|
|
}
|
2023-11-02 20:02:10 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
#endregion
|
2023-11-02 20:02:10 +08:00
|
|
|
|
}
|