using System.Collections.Generic; using UnityEngine; using xFrame; namespace CoreGame.Render { [Combat] public class BindPointProxy : ProxyBase { private Dictionary m_BindPointMap; private Dictionary m_FallbackBindPointMap; protected override void Initialize(GameObject go, CombatEntity ent) { m_BindPointMap = DictionaryPool.Pop(17); var bindPoint = go.GetComponentsInChildren(); 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 fallbackBindPointMap) { if (m_FallbackBindPointMap == null) { m_FallbackBindPointMap = DictionaryPool.Pop(17); } foreach (var kv in fallbackBindPointMap) { m_FallbackBindPointMap[kv.Key] = kv.Value; } } public void DetachFallbackBindPoint(Dictionary 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 GetBindPointMap() { return m_BindPointMap; } protected override void OnReset() { DictionaryPool.Push(ref m_BindPointMap); DictionaryPool.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; } } }