113 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			113 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			C#
		
	
	
	
using System.Collections.Generic;
 | 
						|
using UnityEngine;
 | 
						|
 | 
						|
 | 
						|
/// <summary>
 | 
						|
/// 热力图管理
 | 
						|
/// </summary>
 | 
						|
public class HeatMapPoints : MonoBehaviour
 | 
						|
{
 | 
						|
    static HeatMapPoints _inst;
 | 
						|
    public static HeatMapPoints Inst
 | 
						|
    {
 | 
						|
        get
 | 
						|
        {
 | 
						|
            if (_inst == null)
 | 
						|
            {
 | 
						|
                _inst = FindObjectOfType<HeatMapPoints>();
 | 
						|
                if (_inst == null)
 | 
						|
                {
 | 
						|
                    GameObject singletonObject = new GameObject();
 | 
						|
                    _inst = singletonObject.AddComponent<HeatMapPoints>();
 | 
						|
                    singletonObject.name = typeof(HeatMapPoints).ToString() + " (热力图管理)";
 | 
						|
                }
 | 
						|
            }
 | 
						|
            return _inst;
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// 热力图点位
 | 
						|
    /// </summary>
 | 
						|
    public Transform myTransform;
 | 
						|
    ///// <summary>
 | 
						|
    ///// 点位列表
 | 
						|
    ///// </summary>
 | 
						|
    //public List<Transform> points = new List<Transform>();
 | 
						|
    /// <summary>
 | 
						|
    /// 热力图脚本
 | 
						|
    /// </summary>
 | 
						|
    public HeatMapComponent heatMapComponent;
 | 
						|
    /// <summary>
 | 
						|
    /// 点位预制体
 | 
						|
    /// </summary>
 | 
						|
    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<HeatMapFactor>();
 | 
						|
            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();
 | 
						|
    }
 | 
						|
 | 
						|
}
 |