ModelController.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Magica Cloth.
  2. // Copyright (c) MagicaSoft, 2020-2022.
  3. // https://magicasoft.jp
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. namespace MagicaCloth
  7. {
  8. public class ModelController : MonoBehaviour
  9. {
  10. [SerializeField]
  11. private List<GameObject> characterList = new List<GameObject>();
  12. [SerializeField]
  13. private float slowTime = 0.1f;
  14. private bool slow;
  15. void Start()
  16. {
  17. }
  18. void Update()
  19. {
  20. }
  21. private void AnimatorAction(System.Action<Animator> act)
  22. {
  23. foreach (var chara in characterList)
  24. {
  25. if (chara && chara.activeInHierarchy)
  26. {
  27. var animator = chara.GetComponent<Animator>();
  28. if (animator)
  29. {
  30. act(animator);
  31. }
  32. }
  33. }
  34. }
  35. private void ClothAction(System.Action<BaseCloth> act)
  36. {
  37. foreach (var chara in characterList)
  38. {
  39. if (chara && chara.activeInHierarchy)
  40. {
  41. var clothList = chara.GetComponentsInChildren<BaseCloth>(true);
  42. if (clothList != null)
  43. {
  44. foreach (var cloth in clothList)
  45. {
  46. act(cloth);
  47. }
  48. }
  49. }
  50. }
  51. }
  52. public void OnNextButton()
  53. {
  54. AnimatorAction((ani) => ani.SetTrigger("Next"));
  55. }
  56. public void OnBackButton()
  57. {
  58. AnimatorAction((ani) => ani.SetTrigger("Back"));
  59. }
  60. public void OnSlowButton()
  61. {
  62. slow = !slow;
  63. float timeScale = slow ? slowTime : 1.0f;
  64. AnimatorAction((ani) => ani.speed = timeScale);
  65. ClothAction((cloth) => cloth.SetTimeScale(timeScale));
  66. }
  67. public void OnActiveButton()
  68. {
  69. ClothAction((cloth) => cloth.gameObject.SetActive(!cloth.gameObject.activeSelf));
  70. }
  71. }
  72. }