Files
Main/Assets/GameAssets/Resources/GameUI/Common/UIShandowPlane/UIShandowPlane.cs
2025-01-25 04:38:09 +08:00

108 lines
3.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using Thousandto.Core.Asset;
using Thousandto.Core.Base;
using Thousandto.GameUI.Form;
using UnityEngine;
public class UIShandowPlane : MonoBehaviour
{
#region//私有变量
private UIRoleSkinCompoent _roleCmp = null;
private List<Renderer> _cacheList = new List<Renderer>();
#endregion
#region //编辑器属性
public Material ShandowCast_NotReciver = null;
#endregion
#region//继承mono
private void Start()
{
}
#endregion
#region//私有函数
private void OnSkinLoadCallBack(FSkinBase skin, int part)
{
if (part != FSkinPartCode.Body)
return;
var body = _roleCmp.Skin.GetSkinPart(FSkinPartCode.Body);
if (body != null)
{
var rdList = body.RenderList;
if (rdList == null)
return;
for (int i = 0; i < rdList.Count; i++)
{
if (rdList[i] is SkinnedMeshRenderer)
{
var rd = rdList[i];
List<Material> matList = new List<Material>();
rd.GetSharedMaterials(matList);
if (!matList.Contains(ShandowCast_NotReciver))
{
//ShandowCast_NotReciver.renderQueue = _roleCmp.Skin.RenderQueue + 1;
matList.Add(ShandowCast_NotReciver);
rd.sharedMaterials = matList.ToArray();
}
if (!_cacheList.Contains(rd))
{
_cacheList.Add(rd);
}
}
}
}
}
#endregion
#region//公共函数
public void SetShandow(UIRoleSkinCompoent roleCmp)
{
if (ShandowCast_NotReciver == null)
{
Shader sh = ShaderEx.Find("Ares/SpecialEffect/StencilShadowCaster_NoReceiver");
ShandowCast_NotReciver = new Material(sh);
ShandowCast_NotReciver.SetVector("_LightDir", new Vector4(-16.07f, -19.78f, -8.62f, 0));
ShandowCast_NotReciver.SetColor("_ShadowColor", new Color(0.133f, 0.133f, 0.133f));
ShandowCast_NotReciver.SetVector("_ReceiverDir", new Vector4(0f, 1.2815f, 0, -2562.944f));
}
if (roleCmp == null)
return;
_roleCmp = roleCmp;
_roleCmp.SetOnSkinPartChangedHandler(OnSkinLoadCallBack);
}
public void DelShandow()
{
for (int i = _cacheList.Count-1; i >= 0; i--)
{
var rd = _cacheList[i];
List<Material> matList = new List<Material>();
if (rd == null)
continue;
rd.GetSharedMaterials(matList);
for (int m = matList.Count - 1; m >= 0; m--)
{
if (matList[m] == null)
matList.RemoveAt(m);
}
if (matList.Contains(ShandowCast_NotReciver))
{
matList.Remove(ShandowCast_NotReciver);
}
rd.sharedMaterials = matList.ToArray();
}
_cacheList.Clear();
}
public void RealseMat()
{
DelShandow();
Destroy(ShandowCast_NotReciver);
ShandowCast_NotReciver = null;
_roleCmp = null;
}
#endregion
}