MaskTexturePreview.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * Copyright(c) Live2D Inc. All rights reserved.
  3. *
  4. * Use of this source code is governed by the Live2D Open Software license
  5. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
  6. */
  7. using Live2D.Cubism.Rendering.Masking;
  8. using UnityEngine;
  9. namespace Live2D.Cubism.Samples.Masking
  10. {
  11. /// <summary>
  12. /// Allows previewing of a <see cref="CubismMaskTexture"/> by assigning it to an attached <see cref="Renderer"/>.
  13. /// </summary>
  14. [ExecuteInEditMode, RequireComponent(typeof(Renderer))]
  15. public class MaskTexturePreview : MonoBehaviour
  16. {
  17. /// <summary>
  18. /// Mask texture to preview.
  19. /// </summary>
  20. public CubismMaskTexture MaskTexture;
  21. #region Unity Event Handling
  22. /// <summary>
  23. /// Called by Unity. Applies <see cref="MaskTexture"/> to attached <see cref="Renderer"/>.
  24. /// </summary>
  25. private void Start()
  26. {
  27. var material = (!Application.isEditor || Application.isPlaying)
  28. ? GetComponent<Renderer>().material
  29. : GetComponent<Renderer>().sharedMaterial;
  30. material.mainTexture = (Texture)MaskTexture;
  31. }
  32. #endregion
  33. }
  34. }