DragPointGravity.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. using static TBody;
  5. public class DragPointGravity : DragPointGeneral
  6. {
  7. private static readonly SlotID[] skirtSlots = { SlotID.skirt, SlotID.onepiece, SlotID.mizugi, SlotID.panz };
  8. private static readonly SlotID[] hairSlots = { SlotID.hairF, SlotID.hairR, SlotID.hairS, SlotID.hairT };
  9. public GravityTransformControl Control { get; private set; }
  10. public bool Valid => Control.isValid;
  11. public bool Active => Valid && gameObject.activeSelf;
  12. public static GravityTransformControl MakeGravityControl(Maid maid, bool skirt = false)
  13. {
  14. string category = skirt ? "skirt" : "hair";
  15. Transform bone = maid.body0.GetBone("Bip01");
  16. string gravityGoName = $"GravityDatas_{maid.status.guid}_{category}";
  17. Transform gravityTransform = maid.gameObject.transform.Find(gravityGoName);
  18. if (gravityTransform == null)
  19. {
  20. GameObject go = new GameObject(gravityGoName);
  21. go.transform.SetParent(bone, false);
  22. go.transform.SetParent(maid.transform, true);
  23. go.transform.localScale = Vector3.one;
  24. go.transform.rotation = Quaternion.identity;
  25. GameObject go2 = new GameObject(gravityGoName);
  26. go2.transform.SetParent(go.transform, false);
  27. gravityTransform = go2.transform;
  28. }
  29. else
  30. {
  31. gravityTransform = gravityTransform.GetChild(0);
  32. GravityTransformControl control = gravityTransform.GetComponent<GravityTransformControl>();
  33. if (control != null) GameObject.Destroy(control);
  34. }
  35. GravityTransformControl gravityControl = gravityTransform.gameObject.AddComponent<GravityTransformControl>();
  36. SlotID[] slots = skirt ? skirtSlots : hairSlots;
  37. gravityControl.SetTargetSlods(slots);
  38. gravityControl.forceRate = 0.1f;
  39. return gravityControl;
  40. }
  41. public override void Set(Transform myObject)
  42. {
  43. base.Set(myObject);
  44. Control = myObject.GetComponent<GravityTransformControl>();
  45. gameObject.SetActive(false);
  46. }
  47. protected override void ResetPosition() => Control.transform.localPosition = DefaultPosition;
  48. protected override void ApplyDragType()
  49. {
  50. ApplyProperties(Moving, Moving, false);
  51. ApplyColours();
  52. }
  53. protected override void OnDestroy()
  54. {
  55. if (Control.isValid)
  56. {
  57. Control.transform.localPosition = Vector3.zero;
  58. Control.Update();
  59. }
  60. GameObject.Destroy(Control.transform.parent.gameObject);
  61. base.OnDestroy();
  62. }
  63. private void OnDisable() => Control.isEnabled = false;
  64. private void OnEnable()
  65. {
  66. if (Control)
  67. {
  68. Control.isEnabled = true;
  69. if (!Control.isEnabled) gameObject.SetActive(false);
  70. }
  71. }
  72. }
  73. }