You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

103 lines
3.2 KiB

using System.Collections.Generic;
using UnityEngine;
using xFrame;
namespace CoreGame.Render
{
[Combat]
public class BindPointProxy : ProxyBase
{
private Dictionary<int, Transform> m_BindPointMap;
private Dictionary<int, Transform> m_FallbackBindPointMap;
protected override void Initialize(GameObject go, CombatEntity ent)
{
m_BindPointMap = DictionaryPool<int, Transform>.Pop(17);
var bindPoint = go.GetComponentsInChildren<BindPointRender>();
foreach (var bp in bindPoint)
{
// 本地玩家不需要 拆分了
if (ent.isLocalPlayer == false && BattleModule.Instance.IsBattle())
bp.Init();
foreach (var b in bp.bindPoints)
{
if(m_BindPointMap.TryAdd((int)b.type, b.transform) == false)
{
XLog.LogWarning($"BindPointProxy Initialize failed, key: {b.type}");
}
}
}
}
public void AttachFallbackBindPoint(Dictionary<int, Transform> fallbackBindPointMap)
{
if (m_FallbackBindPointMap == null)
{
m_FallbackBindPointMap = DictionaryPool<int, Transform>.Pop(17);
}
foreach (var kv in fallbackBindPointMap)
{
m_FallbackBindPointMap[kv.Key] = kv.Value;
}
}
public void DetachFallbackBindPoint(Dictionary<int, Transform> fallbackBindPointMap)
{
if (m_FallbackBindPointMap == null)
{
return;
}
foreach (var kv in fallbackBindPointMap)
{
if (m_FallbackBindPointMap.Remove(kv.Key, out var _) == false)
{
XLog.LogWarning($"DetachFallbackBindPoint failed, key: {kv.Key}");
}
}
}
public Dictionary<int, Transform> GetBindPointMap()
{
return m_BindPointMap;
}
protected override void OnReset()
{
DictionaryPool<int, Transform>.Push(ref m_BindPointMap);
DictionaryPool<int, Transform>.Push(ref m_FallbackBindPointMap);
}
public Transform GetBindPoint(BindPointType type)
{
var bp = m_BindPointMap.GetValueOrDefault((int)type);
if (bp == null && m_FallbackBindPointMap != null)
{
bp = m_FallbackBindPointMap.GetValueOrDefault((int)type);
}
return bp;
}
public bool TryGetBindPointOrDefault(BindPointType type, out Transform bp)
{
bool ret = m_BindPointMap.TryGetValue((int)type, out bp);
if (ret == false && m_FallbackBindPointMap != null)
{
ret = m_FallbackBindPointMap.TryGetValue((int)type, out bp);
}
if (bp == null && go != null)
{
bp = go.transform;
}
return ret;
}
}
}