internal void OnAssetUpdate()

in MREUnityRuntimeLib/Assets/AssetLoader.cs [374:430]


		internal void OnAssetUpdate(AssetUpdate payload, Action onCompleteCallback)
		{
			var def = payload.Asset;
			_app.AssetManager.OnSet(def.Id, asset =>
			{
				if (!_owner) return;

				if (def.Material != null && asset.Asset != null && asset.Asset is UnityEngine.Material mat)
				{
					// make sure material reference is write-safe
					// Note: It's safe to assume existence because we're inside the OnSet callback
					mat = _app.AssetManager.GetById(def.Id, writeSafe: true).Value.Asset as UnityEngine.Material;

					MREAPI.AppsAPI.MaterialPatcher.ApplyMaterialPatch(_app, mat, def.Material.Value);
				}
				else if (def.Texture != null && asset.Asset != null && asset.Asset is UnityEngine.Texture tex)
				{
					var texdef = def.Texture.Value;

					// make sure texture reference actually needs to be updated
					if (texdef.WrapModeU.HasValue && texdef.WrapModeU.Value != tex.wrapModeU ||
						texdef.WrapModeV.HasValue && texdef.WrapModeV.Value != tex.wrapModeV)
					{
						// make texture write-safe
						// Note: It's safe to assume existence because we're inside the OnSet callback
						tex = _app.AssetManager.GetById(def.Id, writeSafe: true).Value.Asset as UnityEngine.Texture;

						if (texdef.WrapModeU.HasValue)
							tex.wrapModeU = texdef.WrapModeU.Value;
						if (texdef.WrapModeV.HasValue)
							tex.wrapModeV = texdef.WrapModeV.Value;
					}
					// otherwise, the shared texture is in exactly the state we want, so use it
				}
				else if (def.Sound != null)
				{
					// do nothing; sound asset properties are immutable
				}
				else if (def.VideoStream != null)
				{
					// do nothing; sound asset properties are immutable
				}
				else if (def.Mesh != null)
				{
					// do nothing; mesh properties are immutable
				}
				else if (def.AnimationData != null)
				{
					// do nothing; animation data are immutable
				}
				else
				{
					_app.Logger.LogError($"Asset {def.Id} is not patchable, or not of the right type!");
				}
				onCompleteCallback?.Invoke();
			});
		}