c1_unity/Assets/Scripts/Component/Helper/DreamlandInstancingHelper.cs
2025-11-03 10:59:33 +08:00

82 lines
2.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace BF
{
public class DreamlandInstancingHelper : MonoBehaviour
{
Action luaUpdateAction;
MaterialPropertyBlock block;
MeshFilter meshFilter;
List<Matrix4x4> materixList = new List<Matrix4x4>();
List<Vector4> lightmapOffsetList = new List<Vector4>();
void Awake()
{
block = new MaterialPropertyBlock();
}
public void SetLuaUpdateAction(Action updateAction)
{
luaUpdateAction = updateAction;
}
public void ClearLuaUpdateAction()
{
luaUpdateAction = null;
}
public MaterialPropertyBlock GetMaterialPorpertyBlock()
{
return block;
}
public MeshFilter GetMeshFilter()
{
meshFilter = GetComponentInChildren<MeshFilter>();
return meshFilter;
}
public Vector4[] CollectLightmapOffsetArray()
{
lightmapOffsetList.Clear();
var meshRenderers = GetComponentsInChildren<MeshRenderer>();
foreach (var mr in meshRenderers)
{
lightmapOffsetList.Add(mr.lightmapScaleOffset);
}
return lightmapOffsetList.ToArray();
}
public List<Matrix4x4> CollectMaterixList()
{
materixList.Clear();
var meshRenderers = GetComponentsInChildren<MeshRenderer>();
foreach (var mr in meshRenderers)
{
materixList.Add(mr.localToWorldMatrix);
}
return materixList;
}
public void HideChild()
{
for (var i = 0; i < transform.childCount; i++)
{
transform.GetChild(i).gameObject.SetActive(false);
}
}
void Update()
{
luaUpdateAction?.Invoke();
}
public static bool GetSupportInstancing()
{
return SystemInfo.supportsInstancing;
}
}
}