feat(battle-engine): M1 auto-copy closure (782 battle-logic files)
Compile-driven bulk-copy loop (tools/engine-port/m1_copy_loop.py) pulled the precise reference closure of the battle-core roots, stopping at the classify god-object/View-VFX-UI boundary. 782 files; no re-explosion (M0 had estimated ~order 1000). Residual frontier = 52 shim-classified + 80 external (Unity/BCL) types to author next.
This commit is contained in:
72
SVSim.BattleEngine/Engine/Wizard/UIShaderSprite.cs
Normal file
72
SVSim.BattleEngine/Engine/Wizard/UIShaderSprite.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Wizard;
|
||||
|
||||
public class UIShaderSprite : UISprite
|
||||
{
|
||||
[SerializeField]
|
||||
private Shader _shader;
|
||||
|
||||
private Material _material;
|
||||
|
||||
private bool _isSharedMaterial = true;
|
||||
|
||||
private static Dictionary<int, Dictionary<int, Material>> _materialDic = new Dictionary<int, Dictionary<int, Material>>();
|
||||
|
||||
public override Material material
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shader != null && base.atlas != null)
|
||||
{
|
||||
if (_material == null || mChanged)
|
||||
{
|
||||
if (!_materialDic.TryGetValue(base.atlas.GetInstanceID(), out var value))
|
||||
{
|
||||
value = (_materialDic[base.atlas.GetInstanceID()] = new Dictionary<int, Material>());
|
||||
}
|
||||
int key = (_isSharedMaterial ? _shader.GetInstanceID() : GetInstanceID());
|
||||
if ((!value.TryGetValue(key, out _material) || _material == null) && base.atlas != null)
|
||||
{
|
||||
Dictionary<int, Material> dictionary2 = value;
|
||||
Material obj = new Material(base.atlas.spriteMaterial)
|
||||
{
|
||||
shader = _shader
|
||||
};
|
||||
Material value2 = obj;
|
||||
_material = obj;
|
||||
dictionary2[key] = value2;
|
||||
}
|
||||
}
|
||||
return _material;
|
||||
}
|
||||
return base.atlas?.spriteMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetShader(Shader shader, bool isSharedMaterial = true)
|
||||
{
|
||||
_shader = shader;
|
||||
_isSharedMaterial = isSharedMaterial;
|
||||
mChanged = true;
|
||||
if (drawCall != null)
|
||||
{
|
||||
drawCall.shader = shader;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (!_isSharedMaterial && _shader != null && base.atlas != null && _materialDic.TryGetValue(base.atlas.GetInstanceID(), out var value))
|
||||
{
|
||||
Material value2 = null;
|
||||
int instanceID = GetInstanceID();
|
||||
if (value.TryGetValue(instanceID, out value2))
|
||||
{
|
||||
Object.Destroy(value2);
|
||||
value.Remove(instanceID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user