CubismInspectorAbstruct.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 System;
  9. using UnityEngine;
  10. namespace Live2D.Cubism.Framework
  11. {
  12. public abstract class CubismInspectorAbstract : MonoBehaviour, ICubismUpdatable
  13. {
  14. /// <summary>
  15. /// Called by cubism update controller. Order to invoke OnLateUpdate.
  16. /// </summary>
  17. public abstract int ExecutionOrder { get; }
  18. /// <summary>
  19. /// Called by cubism update controller. Needs to invoke OnLateUpdate on Editing.
  20. /// </summary>
  21. public bool NeedsUpdateOnEditing => false;
  22. /// <summary>
  23. /// Model has cubism update controller component.
  24. /// </summary>
  25. public bool HasUpdateController { get; set; }
  26. /// <summary>
  27. /// Called by cubism update controller. Updates controller.
  28. /// </summary>
  29. public abstract void OnLateUpdate();
  30. #if UNITY_EDITOR
  31. /// <summary>
  32. /// CubismModel cache.
  33. /// </summary>
  34. [NonSerialized, HideInInspector]
  35. public CubismModel Model;
  36. /// <summary>
  37. /// Override values.
  38. /// </summary>
  39. [NonSerialized, HideInInspector]
  40. public float[] OverrideValues;
  41. /// <summary>
  42. /// Flag whether to Ovaerride.
  43. /// </summary>
  44. [NonSerialized, HideInInspector]
  45. public bool[] OverrideFlags;
  46. /// <summary>
  47. /// Editor UI Update delegate.
  48. /// </summary>
  49. /// <param name="sender"></param>
  50. public delegate void ValueChangesHandler(CubismInspectorAbstract sender);
  51. /// <summary>
  52. /// Editor UI Update event.
  53. /// </summary>
  54. public event ValueChangesHandler OnChangedValues;
  55. /// <summary>
  56. /// Dispatch Editor UI Update event.
  57. /// </summary>
  58. protected void DispatchValueChanges()
  59. {
  60. OnChangedValues?.Invoke(this);
  61. }
  62. /// <summary>
  63. /// Called by Unity.
  64. /// </summary>
  65. public void OnEnable()
  66. {
  67. // Get cubism update controller.
  68. HasUpdateController = (GetComponent<CubismUpdateController>() != null);
  69. }
  70. /// <summary>
  71. /// Called by Unity.
  72. /// </summary>
  73. private void LateUpdate()
  74. {
  75. // OnLateUpdate is not called because OriginalWorkflow is assumed.
  76. }
  77. #endif
  78. }
  79. }