ImportCustomization.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.Core;
  8. using Live2D.Cubism.Rendering;
  9. using Live2D.Cubism.Editor.Importers;
  10. using System.Linq;
  11. using UnityEngine;
  12. using UnityEditor;
  13. namespace Live2D.Cubism.Samples.Editor
  14. {
  15. /// <summary>
  16. /// Shows how Cubism model importing can be customized.
  17. /// </summary>
  18. internal static class ImportCustomization
  19. {
  20. #region Unity Event Handling
  21. /// <summary>
  22. /// Registers processor.
  23. /// </summary>
  24. /// <remarks>
  25. /// BE CAREFUL! Uncomment the following line to enable the sample.
  26. // DON'T DO THIS IN REAL PROJECTS!
  27. /// </remarks>
  28. // [InitializeOnLoadMethod]
  29. private static void RegisterModelImporter()
  30. {
  31. CubismImporter.OnDidImportModel += OnModelImport;
  32. }
  33. #endregion
  34. #region Cubism Import Event Handling
  35. /// <summary>
  36. /// Customizes model importing.
  37. /// </summary>
  38. /// <param name="sender">Event source.</param>
  39. /// <param name="model">Imported model.</param>
  40. private static void OnModelImport(CubismModel3JsonImporter sender, CubismModel model)
  41. {
  42. // Lets pretend we want to change the vertex colors of all drawables to green...
  43. foreach (var renderer in model.Drawables.Select(d => d.GetComponent<CubismRenderer>()))
  44. {
  45. renderer.Color = Color.green;
  46. }
  47. }
  48. #endregion
  49. }
  50. }