ScriptPlayableTrackMatSetParam.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Playables;
  5. // A behaviour that is attached to a playable
  6. public class ScriptPlayableTrackMatSetParam : PlayableBehaviour
  7. {
  8. public Material mat;
  9. public int paramNameId;
  10. public float tarParamNum;
  11. public float oriParamNum;
  12. public void Init(string name)
  13. {
  14. paramNameId = Shader.PropertyToID(name);
  15. oriParamNum = mat.GetFloat(paramNameId);
  16. }
  17. // Called when the owning graph starts playing
  18. public override void OnGraphStart(Playable playable)
  19. {
  20. }
  21. // Called when the owning graph stops playing
  22. public override void OnGraphStop(Playable playable)
  23. {
  24. }
  25. // Called when the state of the playable is set to Play
  26. public override void OnBehaviourPlay(Playable playable, FrameData info)
  27. {
  28. mat.SetFloat(paramNameId, tarParamNum);
  29. }
  30. // Called when the state of the playable is set to Paused
  31. public override void OnBehaviourPause(Playable playable, FrameData info)
  32. {
  33. mat.SetFloat(paramNameId, oriParamNum);
  34. }
  35. // Called each frame while the state is set to Play
  36. public override void PrepareFrame(Playable playable, FrameData info)
  37. {
  38. }
  39. }