1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using UnityEngine;
- namespace COM3D2.MeidoPhotoStudio.Plugin
- {
- internal class DragPointTorso : DragPointMeido
- {
- private static readonly float[] blah = new[] { 0.03f, 0.1f, 0.09f, 0.07f };
- private static readonly float[] something = new[] { 0.08f, 0.15f };
- private Transform[] spine = new Transform[4];
- private Quaternion[] spineRotation = new Quaternion[4];
- public override void Set(Transform spine1a)
- {
- base.Set(spine1a);
- Transform spine = spine1a;
- for (int i = 0; i < this.spine.Length; i++)
- {
- this.spine[i] = spine;
- spine = spine.parent;
- }
- }
- protected override void ApplyDragType()
- {
- if (CurrentDragType == DragType.Ignore) ApplyProperties();
- else if (IsBone) ApplyProperties(false, false, false);
- else ApplyProperties(CurrentDragType != DragType.None, false, false);
- }
- protected override void UpdateDragType()
- {
- if (Input.GetKey(KeyCode.Space) || OtherDragType())
- {
- CurrentDragType = DragType.Ignore;
- }
- else if (Utility.GetModKey(Utility.ModKey.Alt) && !Utility.GetModKey(Utility.ModKey.Control))
- {
- bool shift = Utility.GetModKey(Utility.ModKey.Shift);
- CurrentDragType = shift ? DragType.RotLocalY : DragType.RotLocalXZ;
- }
- else
- {
- CurrentDragType = DragType.None;
- }
- }
- protected override void OnMouseDown()
- {
- base.OnMouseDown();
- for (int i = 0; i < spine.Length; i++)
- {
- spineRotation[i] = spine[i].localRotation;
- }
- }
- protected override void Drag()
- {
- if (CurrentDragType == DragType.None) return;
- if (isPlaying) meido.Stop = true;
- Vector3 mouseDelta = MouseDelta();
- if (CurrentDragType == DragType.RotLocalXZ)
- {
- for (int i = 0; i < spine.Length; i++)
- {
- spine[i].localRotation = spineRotation[i];
- spine[i].Rotate(
- camera.transform.forward, -mouseDelta.x / 1.5f * blah[i], Space.World
- );
- spine[i].Rotate(camera.transform.right, mouseDelta.y * blah[i], Space.World);
- }
- }
- if (CurrentDragType == DragType.RotLocalY)
- {
- for (int i = 0; i < spine.Length; i++)
- {
- spine[i].localRotation = spineRotation[i];
- spine[i].Rotate(Vector3.right * (mouseDelta.x / 1.5f * something[i / 2]));
- }
- }
- }
- }
- }
|