Created
September 26, 2022 03:33
-
-
Save badforlabor/2f2b363105b2b9c5b33b283f2fccd911 to your computer and use it in GitHub Desktop.
MaterialPropertyBlock会打断合并批次
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| using UnityEngine.Rendering; | |
| [RequireComponent(typeof(SkinnedMeshRenderer))] | |
| public class MonoTestMaterialPropertyBlock : MonoBehaviour | |
| { | |
| public bool UseMPB; | |
| public bool bEnable; | |
| public float _DissolveFactor = 0; | |
| public bool _DissolveEnable = false; | |
| private SkinnedMeshRenderer r; | |
| private MaterialPropertyBlock mpb; | |
| private void Awake() | |
| { | |
| mpb = new MaterialPropertyBlock(); | |
| } | |
| private void Update() | |
| { | |
| if (!bEnable) | |
| { | |
| return; | |
| } | |
| if (r == null) | |
| { | |
| r = this.gameObject.GetComponent<SkinnedMeshRenderer>(); | |
| } | |
| if (r == null) | |
| { | |
| return; | |
| } | |
| if (UseMPB) | |
| { | |
| r.GetPropertyBlock(mpb); | |
| } | |
| foreach (var it in r.sharedMaterials) | |
| { | |
| if (_DissolveEnable) | |
| { | |
| it.EnableKeyword("_DISSOLVE_EFFECT"); | |
| } | |
| else | |
| { | |
| it.DisableKeyword("_DISSOLVE_EFFECT"); | |
| } | |
| if (UseMPB) | |
| { | |
| mpb.SetFloat("_DissolveAmount", _DissolveFactor); | |
| } | |
| else | |
| { | |
| it.SetFloat("_DissolveAmount", _DissolveFactor); | |
| } | |
| } | |
| if (UseMPB) | |
| { | |
| r.SetPropertyBlock(mpb); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment