BITFALL/Assets/Artists/Scripts/HotFix/FixShaderRuntime.cs

41 lines
945 B
C#
Raw Normal View History

2024-05-03 18:29:09 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using BITKit;
2024-05-03 23:42:30 +08:00
using BITKit.IO;
using BITKit.Mod;
using Cysharp.Threading.Tasks;
2024-05-03 18:29:09 +08:00
using UnityEngine;
using UnityEngine.SceneManagement;
2024-05-03 23:42:30 +08:00
using YooAsset;
2024-05-03 18:29:09 +08:00
namespace BITFALL.HotFix
{
public class FixShaderRuntime : MonoBehaviour
{
private void OnEnable()
{
2024-05-03 23:42:30 +08:00
YooAssetUtils.OnPackageRegistered += Execute;
2024-05-03 18:29:09 +08:00
}
2024-05-03 23:42:30 +08:00
2024-05-03 18:29:09 +08:00
private void OnDisable()
{
2024-05-03 23:42:30 +08:00
YooAssetUtils.OnPackageRegistered -= Execute;
2024-05-03 18:29:09 +08:00
}
2024-05-03 23:42:30 +08:00
private async void Execute(string obj)
2024-05-03 18:29:09 +08:00
{
2024-05-03 23:42:30 +08:00
var package = YooAssets.GetPackage(obj);
foreach (var asset in package.GetAssetInfos("material"))
2024-05-03 18:29:09 +08:00
{
2024-05-03 23:42:30 +08:00
var assetHandle = package.LoadAssetAsync<Material>(asset.AssetPath);
await assetHandle;
if (destroyCancellationToken.IsCancellationRequested) return;
if (assetHandle.AssetObject is not Material material) continue;
material.shader = Shader.Find(material.shader.name);
2024-05-03 18:29:09 +08:00
}
}
}
}