using System.Collections.Generic; using UnityEngine; using System.Linq; using PhxhSDK; namespace Gameplay.Level { public class Plank : IUpdatable, IInitable { private const string HoleLayer = "Hole"; private Dictionary _affectedAffectedHoles; public Dictionary HolesOfPlank { get; set; } public Dictionary CurAffectedHoles => _affectedAffectedHoles; public GameObject Obj { get; set; } public bool StopDetect = false; public Plank() { _affectedAffectedHoles = new Dictionary(); HolesOfPlank = new Dictionary(); } private HashSet _hits = new HashSet(); //private HashSet _holesToRemove = new HashSet(); public void Update(float deltaTime) { if (!Obj.activeSelf) return; if(StopDetect) return; _affectedAffectedHoles.Clear(); var hitColliders = LevelUtils.GetTriggerColliders(Obj, HoleLayer); foreach (var hit in hitColliders) { if (!_affectedAffectedHoles.Keys.Contains(hit.name)) { _affectedAffectedHoles.Add(hit.name, KongManager.Instance.HoleDic[hit.name]); } //_hits.Add(hit.name); } /*if (!Obj) { _affectedAffectedHoles.Clear(); return; } /检测添加 foreach (var hit in hitColliders) { if (!_affectedAffectedHoles.Keys.Contains(hit.name)) { _affectedAffectedHoles.Add(hit.name, HoleManager.Instance.HoleDic[hit.name]); } _hits.Add(hit.name); } //检测移除 foreach (var hole in _affectedAffectedHoles.Keys) { if (!_hits.Contains(hole)) { _holesToRemove.Add(hole); } } foreach (var removeHole in _holesToRemove) { _affectedAffectedHoles.Remove(removeHole); } _hits.Clear(); _holesToRemove.Clear();*/ } public void Init() { if (!Obj) return; var hitColliders = LevelUtils.GetTriggerColliders(Obj, HoleLayer); foreach (var hit in hitColliders) { var name = hit.name; if (!_affectedAffectedHoles.Keys.Contains(name)) { _affectedAffectedHoles.Add(name, KongManager.Instance.HoleDic[name]); } } } public void Release() { } } }