98 lines
2.8 KiB
C#
98 lines
2.8 KiB
C#
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<string, Kong> _affectedAffectedHoles;
|
|
|
|
public Dictionary<string, GameObject> HolesOfPlank { get; set; }
|
|
public Dictionary<string, Kong> CurAffectedHoles => _affectedAffectedHoles;
|
|
public GameObject Obj { get; set; }
|
|
|
|
public bool StopDetect = false;
|
|
|
|
public Plank()
|
|
{
|
|
_affectedAffectedHoles = new Dictionary<string, Kong>();
|
|
HolesOfPlank = new Dictionary<string, GameObject>();
|
|
}
|
|
|
|
private HashSet<string> _hits = new HashSet<string>();
|
|
//private HashSet<string> _holesToRemove = new HashSet<string>();
|
|
|
|
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()
|
|
{
|
|
}
|
|
}
|
|
} |