123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using System;
- 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.IsStop = 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]));
- }
- }
- }
- }
- }
|