using System.Collections.Generic;
using UnityEngine;
///
/// 热力图管理
///
public class HeatMapPoints : MonoBehaviour
{
static HeatMapPoints _inst;
public static HeatMapPoints Inst
{
get
{
if (_inst == null)
{
_inst = FindObjectOfType();
if (_inst == null)
{
GameObject singletonObject = new GameObject();
_inst = singletonObject.AddComponent();
singletonObject.name = typeof(HeatMapPoints).ToString() + " (热力图管理)";
}
}
return _inst;
}
}
///
/// 热力图点位
///
public Transform myTransform;
/////
///// 点位列表
/////
//public List points = new List();
///
/// 热力图脚本
///
public HeatMapComponent heatMapComponent;
///
/// 点位预制体
///
public Transform prefab;
private void Awake()
{
if (_inst != null && _inst != this)
{
Destroy(this.gameObject);
}
else
{
_inst = this;
DontDestroyOnLoad(this.gameObject);
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
[ContextMenu("生成热力图组件")]
public void F1()
{
if (myTransform == null)
return;
if (!prefab || TransparentGlowManage.Inst.points.Count == 0 || heatMapComponent == null || heatMapComponent.impactFactors.Count != 0)
return;
for (int i = 0; i < TransparentGlowManage.Inst.points.Count - 1; i++)
{
Transform t = GameObject.Instantiate(prefab);
t.SetParent(myTransform);
}
for (int i = 0; i < myTransform.childCount; i++)
{
myTransform.GetChild(i).position = TransparentGlowManage.Inst.points[i].position;
myTransform.GetChild(i).localEulerAngles = TransparentGlowManage.Inst.points[i].localEulerAngles;
}
if (heatMapComponent == null)
return;
for (int i = 0; i < myTransform.childCount; i++)
{
HeatMapFactor heatMapFactor = myTransform.GetChild(i).GetComponent();
heatMapComponent.impactFactors.Add(heatMapFactor);
}
}
[ContextMenu("清除")]
void Delate()
{
if (myTransform == null || myTransform.childCount == 1)
return;
for (int i = 1; i < myTransform.childCount; i++)
{
GameObject.DestroyImmediate(myTransform.GetChild(i).gameObject);
}
heatMapComponent.impactFactors.Clear();
Delate();
}
}