123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- using System;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- using kt.Utility;
- using UnityEngine;
- namespace kt.ik
- {
- public static class IKScriptHelper
- {
- public static IKAttachParam GetIKAttachParam(KagTagSupport tagData, Maid src_chara, Maid target_chara = null)
- {
- IKAttachParam ikattachParam = new IKAttachParam(src_chara, target_chara);
- IKScriptHelper.SetIKAttachParam(ikattachParam, tagData);
- return ikattachParam;
- }
- public static void SetIKAttachParam(IKAttachParam param, KagTagSupport tagData)
- {
- param.offset = Vector3.zero;
- if (tagData.IsValid("offsetx"))
- {
- param.offset.x = tagData.GetTagProperty("offsetx").AsReal();
- }
- if (tagData.IsValid("offsety"))
- {
- param.offset.y = tagData.GetTagProperty("offsety").AsReal();
- }
- if (tagData.IsValid("offsetz"))
- {
- param.offset.z = tagData.GetTagProperty("offsetz").AsReal();
- }
- param.attachType = ((!param.srcChara.body0.IsCrcBody) ? AIKCtrl.IKAttachType.Point : AIKCtrl.IKAttachType.NewPoint);
- if (tagData.IsValid("attach_type"))
- {
- string value = tagData.GetTagProperty("attach_type").AsString();
- param.attachType = (AIKCtrl.IKAttachType)Enum.Parse(typeof(AIKCtrl.IKAttachType), value);
- if (param.srcChara.body0.IsCrcBody && param.attachType == AIKCtrl.IKAttachType.Point)
- {
- param.attachType = AIKCtrl.IKAttachType.NewPoint;
- }
- }
- if (param.attachType == AIKCtrl.IKAttachType.NewPoint)
- {
- param.posOffsetType = AIKCtrl.PosOffsetType.OffsetTarget;
- if (tagData.IsValid("offset_world"))
- {
- param.posOffsetType = AIKCtrl.PosOffsetType.OffsetWorld;
- }
- else if (tagData.IsValid("offset_bone"))
- {
- param.posOffsetType = AIKCtrl.PosOffsetType.OffsetBone;
- }
- }
- if (tagData.IsValid("blend"))
- {
- param.blendTime = MathUtility.MillisecondToSecond(tagData.GetTagProperty("blend").AsInteger());
- }
- else if (tagData.IsValid("blendtime"))
- {
- param.blendTime = MathUtility.MillisecondToSecond(tagData.GetTagProperty("blendtime").AsInteger());
- }
- else
- {
- param.blendTime = param.srcChara.fullBodyIK.blendTime;
- }
- if (tagData.IsValid("disable"))
- {
- string[] array = tagData.GetTagProperty("disable").AsString().Split(new char[]
- {
- ','
- });
- int i = 0;
- while (i < array.Length)
- {
- string text = array[i];
- string text2 = text.ToLower();
- if (text2 != null)
- {
- if (!(text2 == "x"))
- {
- if (!(text2 == "y"))
- {
- if (text2 == "z")
- {
- param.offsetEnable.enableZ = false;
- }
- }
- else
- {
- param.offsetEnable.enableY = false;
- }
- }
- else
- {
- param.offsetEnable.enableX = false;
- }
- }
- IL_288:
- i++;
- continue;
- goto IL_288;
- }
- }
- param.doAnimation = false;
- if (tagData.IsValid("do_animation"))
- {
- param.doAnimation = true;
- }
- param.bodyPull = (param.attachType == AIKCtrl.IKAttachType.NewPoint);
- if (param.attachType == AIKCtrl.IKAttachType.NewPoint)
- {
- param.bodyPull = !tagData.IsValid("pull_off");
- }
- }
- public static InsertIKParam GetInsertIKParam(KagTagSupport tagData, Maid src_chara = null, Maid target_chara = null)
- {
- InsertIKParam insertIKParam = new InsertIKParam(src_chara, target_chara);
- IKScriptHelper.SetInsertIKParam(insertIKParam, tagData);
- return insertIKParam;
- }
- public static void SetInsertIKParam(InsertIKParam param, KagTagSupport tagData)
- {
- IKScriptHelper.SetIKAttachParam(param, tagData);
- param.insertBefore = MathUtility.Vec3Parse(tagData.GetTagProperty("insert_before").AsString(), ',').normalized;
- param.insertAfter = MathUtility.Vec3Parse(tagData.GetTagProperty("insert_after").AsString(), ',').normalized;
- if (param.attachTarget && AutoKupaCtrl.InsertBoneMorphDic.ContainsKey(param.attachTarget.name))
- {
- AutoKupaCtrl.MorphType morph_type = AutoKupaCtrl.InsertBoneMorphDic[param.attachTarget.name];
- param.kupaCtrl = param.targetChara.body0.GetKupaCtrl(morph_type);
- if (param.kupaCtrl != null)
- {
- param.kupaCtrl.SetInsertParamFromScript(tagData);
- }
- }
- }
- public static PenisIKParam GetPenisIKParam(KagTagSupport tagData, Maid src_chara, Maid target_chara)
- {
- PenisIKParam penisIKParam = new PenisIKParam(src_chara, target_chara);
- IKScriptHelper.SetPenisIKPatam(penisIKParam, tagData);
- return penisIKParam;
- }
- public static void SetPenisIKPatam(PenisIKParam param, KagTagSupport tagData)
- {
- IKScriptHelper.SetInsertIKParam(param, tagData);
- param.sensorLength = 0f;
- if (tagData.IsValid("sensorlength"))
- {
- param.sensorLength = tagData.GetTagProperty("sensorlength").AsReal();
- }
- param.isNotEscape = tagData.IsValid("notescape");
- param.isForciblyBend = tagData.IsValid("forcebend");
- param.alwaysLookTarget = tagData.IsValid("alwayslook");
- if (tagData.IsValid("scaling"))
- {
- string[] array = tagData.GetTagProperty("scaling").AsString().Split(new char[]
- {
- ' '
- });
- foreach (string text in array)
- {
- string[] array3 = text.Split(new char[]
- {
- ':'
- });
- string key = array3[0];
- float value = MathUtility.PercentageToRatio(int.Parse(array3[1]), false);
- param.boneNameScaleValPair.Add(new KeyValuePair<string, float>(key, value));
- }
- }
- if (tagData.IsValid("motionctrlbone"))
- {
- param.motionCtrlBoneName = tagData.GetTagProperty("motionctrlbone").AsString();
- if (tagData.IsValid("motionctrlweight"))
- {
- param.motionCtrlWeight = MathUtility.PercentageToRatio(tagData.GetTagProperty("motionctrlweight").AsInteger(), false);
- }
- }
- }
- public static BodyOffsetIKParam GetBodyIKParam(KagTagSupport tagData, Maid src_chara, Maid target_chara = null)
- {
- BodyOffsetIKParam bodyOffsetIKParam = new BodyOffsetIKParam(src_chara, target_chara);
- IKScriptHelper.SetBodyIKPatam(bodyOffsetIKParam, tagData);
- return bodyOffsetIKParam;
- }
- public static void SetBodyIKPatam(BodyOffsetIKParam param, KagTagSupport tagData)
- {
- IKScriptHelper.SetIKAttachParam(param, tagData);
- param.attachType = AIKCtrl.IKAttachType.NewPoint;
- param.posOffsetType = AIKCtrl.PosOffsetType.OffsetTarget;
- if (tagData.IsValid("heighttype"))
- {
- param.heightFitType = (IKBodyOffsetCtrl.HeightFitType)Enum.Parse(typeof(IKBodyOffsetCtrl.HeightFitType), tagData.GetTagProperty("heighttype").AsString());
- }
- param.posBaseBoneName = tagData.GetTagProperty("srcbone").AsString();
- if (tagData.IsValid("addoffset"))
- {
- param.addOffset = MathUtility.Vec3Parse(tagData.GetTagProperty("addoffset").AsString(), ',');
- }
- }
- public static string ConvertColliderNameToIKName(string name)
- {
- string text = Regex.Replace(name, "左|右", string.Empty);
- if (text != null)
- {
- if (!(text == "上腕"))
- {
- if (!(text == "前腕"))
- {
- if (!(text == "腿"))
- {
- if (text == "脛")
- {
- name = name.Replace("脛", "足");
- }
- }
- else
- {
- name = name.Replace("腿", "膝");
- }
- }
- else
- {
- name = name.Replace("前腕", "手");
- }
- }
- else
- {
- name = name.Replace("上腕", "肘");
- }
- }
- return name;
- }
- }
- }
|