2025-09-25 19:04:05 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Convention;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Demo.Game
|
|
|
|
|
|
{
|
|
|
|
|
|
public class MaterialUpdatement : Updatement<string>, IAssetBundleLoader
|
|
|
|
|
|
{
|
|
|
|
|
|
public static MaterialUpdatement Make()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new GameObject().AddComponent<MaterialUpdatement>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string MaterialAssetBundlePath;
|
|
|
|
|
|
public AssetBundle MaterialAssetBundle;
|
|
|
|
|
|
|
|
|
|
|
|
protected override string Lerp(string begin, string end, float t)
|
|
|
|
|
|
{
|
|
|
|
|
|
return begin;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Content, SerializeField] private string Cache;
|
|
|
|
|
|
|
|
|
|
|
|
protected override void UpdateData(string data)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(MaterialAssetBundlePath))
|
|
|
|
|
|
return;
|
|
|
|
|
|
if (Cache != data && Parent.TryGetComponent<MeshRenderer>(out var meshRenderer))
|
|
|
|
|
|
{
|
|
|
|
|
|
meshRenderer.material = MaterialAssetBundle.LoadAsset<Material>(data);
|
|
|
|
|
|
Cache = data;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override IEnumerator UnloadScript()
|
|
|
|
|
|
{
|
|
|
|
|
|
Cache = null;
|
|
|
|
|
|
if (string.IsNullOrEmpty(MaterialAssetBundlePath) == false)
|
|
|
|
|
|
yield return this.UnloadAssetBundle(MaterialAssetBundlePath);
|
|
|
|
|
|
MaterialAssetBundlePath = "";
|
|
|
|
|
|
yield return base.UnloadScript();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 对应ab包名称,自动匹配对应平台
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="ab"></param>
|
2025-10-27 20:24:15 +08:00
|
|
|
|
[Convention.RScript.Variable.Attr.Method]
|
2025-10-06 16:09:52 +08:00
|
|
|
|
public IEnumerator Load(string ab)
|
2025-09-25 19:04:05 +08:00
|
|
|
|
{
|
2025-10-06 16:09:52 +08:00
|
|
|
|
yield return this.LoadAssetBundle(ab, x =>
|
2025-09-25 19:04:05 +08:00
|
|
|
|
{
|
|
|
|
|
|
MaterialAssetBundlePath = ab;
|
|
|
|
|
|
MaterialAssetBundle = x;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 在指定时刻切换父物体上的MeshRenderer.material
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="time"></param>
|
|
|
|
|
|
/// <param name="material"></param>
|
2025-10-27 20:24:15 +08:00
|
|
|
|
[Convention.RScript.Variable.Attr.Method]
|
2025-09-25 19:04:05 +08:00
|
|
|
|
public void Add(string time, string material)
|
|
|
|
|
|
{
|
|
|
|
|
|
ManualAddEntry(time, material, default);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|