using System; using System.Collections.Generic; using UnityEngine; public class ShoulderTwist : ATwistCtrl { public ShoulderTwist(bool is_left, TBody body) : base((!is_left) ? Maid.AutoTwist.ShoulderR : Maid.AutoTwist.ShoulderL, body) { string str; if (body.IsCrcBody) { str = "Bip01"; } else { str = (body.boMAN ? "ManBip" : "Bip01"); } string str2 = (!is_left) ? " R UpperArm" : " L UpperArm"; base.bone = body.GetBone(str + str2); base.mrBone = base.GetMRBone(str + str2); if (body.IsCrcBody) { for (int i = 0; i < 5; i++) { string name = (!is_left) ? string.Format("UpperTwist{0}_R", i + 1) : string.Format("UpperTwist{0}_L", i + 1); Transform transform = base.bone.Find(name); if (transform) { Transform transform2 = base.mrBone.Find(name); if (transform2) { base.twistBones.Add(new KeyValuePair(transform2, transform)); } } } string text = (!is_left) ? "Kata_R" : "Kata_L"; Transform bone = body.GetBone(text); Transform mrbone = base.GetMRBone(text); if (bone && mrbone) { this.KataPair = new KeyValuePair(mrbone, bone); } } } public void SetCalcMode(ShoulderTwist.CalcType calc_mode) { this.TwistCalcType = calc_mode; } public override void ApplyTwist() { Quaternion quaternion = base.bone.parent.rotation; quaternion = Quaternion.FromToRotation(quaternion * Vector3.right, base.bone.rotation * Vector3.right) * quaternion; for (int i = 0; i < base.twistBones.Count; i++) { KeyValuePair keyValuePair = base.twistBones[i]; float t = (float)(i + 1) / (float)base.twistBones.Count; keyValuePair.Value.rotation = Quaternion.Lerp(quaternion, base.bone.rotation, t); } if (base.twistBones.Count > 0 && this.KataPair.Key && this.KataPair.Value) { if (this.TwistCalcType == ShoulderTwist.CalcType.Normal) { this.KataPair.Value.localRotation = this.KataPair.Key.localRotation; this.KataPair.Value.rotation = Quaternion.Lerp(this.KataPair.Value.rotation, base.twistBones[0].Value.rotation, 0.5f); } else { this.KataPair.Value.rotation = Quaternion.Lerp(quaternion, base.twistBones[0].Value.rotation, 0.5f); } } } private KeyValuePair KataPair; private const float KATA_BLEND_VAL = 0.5f; private ShoulderTwist.CalcType TwistCalcType; public enum CalcType { Normal, Behind } }