private void BaseReturnSet(SmoothJoint sjc, int i, int ai) { //初期値に戻す if (this.baseRot != null && this.baseRot.Length > i) { if (this.baseRot[i].Length > ai) { //ベース回転に戻す sjc.FixedTarget[ai].transform.rotation = this.baseRot[i][ai]; } } if (this.basePos != null && this.basePos.Length > i) { if (this.basePos[i].Length > ai) { if (this.WorldPos == false) { //子を解除 sjc.FixedTarget[ai].transform.parent = null; sjc.FixedTarget[ai].transform.position = this.basePos[i][ai]; } else { sjc.FixedTarget[ai].transform.position = this.basePos[i][ai]; } } } if (this.baseScale != null && this.baseScale.Length > i) { if (this.baseScale[i].Length > ai) { //ベーススケールに戻す sjc.FixedTarget[ai].transform.localScale = this.baseScale[i][ai]; } } if (this.oldPos != null && this.oldPos.Length > i) { if (this.oldPos[i].Length > ai) { this.oldPos[i][ai] = Vector3.zero; } } if (this.AddRandom == true && this.rndF != null && this.rndF.Length > i && this.rndF[i] != null && this.rndF[i].Length > ai) { if (this.rndF[i][ai] == true) { this.rndF[i][ai] = false; } } }
private void BaseReturnSet(SmoothJoint sjc, int i, int ai) { //Return to the initial value if (this.baseRot != null && this.baseRot.Length > i) { if (this.baseRot[i].Length > ai) { //Back to the base rotation sjc.FixedTarget[ai].transform.rotation = this.baseRot[i][ai]; } } if (this.basePos != null && this.basePos.Length > i) { if (this.basePos[i].Length > ai) { if (this.WorldPos == false) { //Release the child sjc.FixedTarget[ai].transform.parent = null; sjc.FixedTarget[ai].transform.position = this.basePos[i][ai]; } else { sjc.FixedTarget[ai].transform.position = this.basePos[i][ai]; } } } if (this.baseScale != null && this.baseScale.Length > i) { if (this.baseScale[i].Length > ai) { //Back to the base scale sjc.FixedTarget[ai].transform.localScale = this.baseScale[i][ai]; } } if (this.oldPos != null && this.oldPos.Length > i) { if (this.oldPos[i].Length > ai) { this.oldPos[i][ai] = Vector3.zero; } } if (this.AddRandom == true && this.rndF != null && this.rndF.Length > i && this.rndF[i] != null && this.rndF[i].Length > ai) { if (this.rndF[i][ai] == true) { this.rndF[i][ai] = false; } } }
public void CatchAllClear() { //全てのCatchフラグの初期化 if (this.SJList != null && this.SJList.Count > 0) { for (int i = 0; i < this.SJList.Count; i++) { SmoothJoint sjc = this.SJList[i]; //IKあるか確認 if (sjc != null && this.Catch != null && this.Catch[i] != null) { for (int ai = 0; ai < this.Catch[i].Length; ai++) { this.Catch[i][ai] = false; } } } } }
public void CatchAllClear() { //Initialization of all of Catch flag if (this.SJList != null && this.SJList.Count > 0) { for (int i = 0; i < this.SJList.Count; i++) { SmoothJoint sjc = this.SJList[i]; //IK sure there if (sjc != null && this.Catch != null && this.Catch[i] != null) { for (int ai = 0; ai < this.Catch[i].Length; ai++) { this.Catch[i][ai] = false; } } } } }
private void confirmation() { //確認 if (this.SJList != null && this.SJList.Count > 0 && this.Catch != null) { for (int i = 0; i < this.SJList.Count; i++) { SmoothJoint sjc = this.SJList[i]; //IKあるか確認 if (sjc != null && sjc.FixedJointNo != null && sjc.FixedTarget != null && this.Catch[i] != null) { for (int ai = 0; ai < sjc.FixedJointNo.Length; ai++) { int jn = sjc.FixedJointNo[ai] - 1; //IK起動中確認 bool ikrf = false; if (sjc.RangeHitIK != null && sjc.RangeHitIK.Length > ai) { ikrf = sjc.RangeHitIK[ai]; } if (this.RangeOutOn == true && ikrf == false) //IK範囲外 { this.Catch[i][ai] = false; } //衝突確認 if (sjc.FixedTarget.Length > ai && sjc.HitPosition != null && sjc.HitPosition.Length > jn) { Vector3 hitpos = sjc.HitPosition[jn]; if (this.basePos != null && this.basePos.Length > i) { bool hpf = false; if (this.RangeOutOn == true && hitpos != Vector3.zero) { hpf = true; } if (this.RangeOutOn == false && hitpos != Vector3.zero && this.Catch[i][ai] == false) { hpf = true; } //衝突中 if (hpf == true) { this.Catch[i][ai] = true; sjc.IKRangeOn[ai] = false; //範囲IK一時停止 if (this.hitF != null && this.hitF.Length > i && this.hitF[i] != null && this.hitF[i].Length > ai) { this.hitF[i][ai] = true; } GameObject hitobj = null; if (sjc.HitSCC != null && sjc.HitSCC.SJCCTransform.parent.gameObject != null) { hitobj = sjc.HitSCC.SJCCTransform.parent.gameObject; } //乱数 Vector3 rndd0 = Vector3.zero; if (this.AddRandom == true && sjc.HitSCC != null && this.rndF != null && this.rndF.Length > i && this.rndF[i] != null && this.rndF[i].Length > ai) { if (this.rndF[i][ai] == false) { Vector3 rndd1 = (hitpos + Vector3.Scale(new Vector3(Random.value, Random.value, Random.value), this.AddRand) - sjc.HitSCC.SJCCTransform.position).normalized * (sjc.HitSCC.SJCCRadius * 0.96f); rndd0 = sjc.HitSCC.SJCCTransform.position + rndd1; this.rndF[i][ai] = true; } } else { rndd0 = hitpos; } //移動先座標 Vector3 hpd1 = Vector3.zero; //衝突確認 if (this.AvoidanceOn == true && sjc.HitSCC != null && sjc.CollisionRadius.Length > jn + 1) { hpd1 = this.HitTest(sjc.HitSCC.SJCCTransform.position, sjc.JointObj[jn + 1].transform.position, sjc.HitSCC.SJCCRadius, sjc.CollisionRadius[jn + 1]); } else { hpd1 = rndd0; } //移動抵抗 if (this.oldPos != null && this.oldPos[i] != null && this.oldPos[i][ai] != Vector3.zero) { hpd1 = Vector3.Lerp(hpd1, this.oldPos[i][ai], this.Friction); } if (this.WorldPos == false && hitobj != null) { //子にする sjc.FixedTarget[ai].transform.parent = hitobj.transform; //ローカル Vector3 hitLpos = hitobj.transform.InverseTransformPoint(hpd1); sjc.FixedTarget[ai].transform.localPosition = hitLpos; } else { //ワールド sjc.FixedTarget[ai].transform.position = hpd1; } //座標記憶 if (this.oldPos[i][ai] != hpd1) { this.oldPos[i][ai] = hpd1; } } //衝突なし if (this.hitF != null && this.hitF.Length > i && this.hitF[i] != null && this.hitF[i].Length > ai) { int hcn = 0; if (sjc != null && sjc.HitSCC != null) { hcn++; } //範囲外確認(衝突後用) if (this.hitF[i][ai] == true && sjc != null && sjc.HitSCC != null) { float cjl = -1f; if (sjc.JointObj[jn] != null) { cjl = (sjc.HitSCC.SJCCTransform.position - sjc.JointObj[jn].transform.position).magnitude; } if (sjc.CollisionRadius.Length > jn) { float rld = sjc.HitSCC.SJCCRadius + sjc.CollisionRadius[jn]; if (cjl != -1f && cjl > rld * 1.5f) { if (this.RangeOutOn == true && ikrf == false) { hcn = 0; } if (this.RangeOutOn == false) { hcn = 0; } } } } if (hcn == 0) { if (sjc.IKRangeOn[ai] == false) { sjc.IKRangeOn[ai] = true; //範囲IK起動 } this.BaseReturnSet(sjc, i, ai); //ベース位置に移動 this.hitF[i][ai] = false; //SJ側外部操作(初期化 sjc.HitSCC = null; if (sjc.HitPosition.Length > jn) { sjc.HitPosition[jn] = Vector3.zero; } } } } } } } } } }
private void SJListSet() { //Registration of automatic array if (this.SmoothJointObj != null) { bool sef = false; //Change confirmation of SmoothJointObj int sjc = 0; for (int ic = 0; ic < this.SmoothJointObj.Length; ic++) { if (this.SmoothJointObj[ic] != null) { sjc++; } } if (this.sjlCount != this.SmoothJointObj.Length) { this.Init(); } else { if (sjc != this.SmoothJointObj.Length) { this.Init(); } //Edit SJ name list set if (this.autoName == null) { this.autoName = new string[this.SmoothJointObj.Length]; } else { if (this.autoName.Length != this.SmoothJointObj.Length) { this.Init(); } } //List to make sure that your have been modified for (int ic = 0; ic < this.SmoothJointObj.Length; ic++) { if (this.SmoothJointObj[ic] != null) { if (this.autoName[ic] != this.SmoothJointObj[ic].name) { sef = false; } else { sef = true; } } } //Initialization After being edited to the user if (sef == false) { this.Init(); } if (sef == true) { //Sure which it has been edited if (this.SJList.Count != this.listCount && this.editName == "") { this.editName = "SJList"; } if (this.SJName.Count != this.nameCount && this.editName == "") { this.editName = "SJName"; } if (this.SJEditOn.Count != this.editOnCount && this.editName == "") { this.editName = "SJEditOn"; } switch (this.editName) { case "SJList": this.SJName.Clear(); this.SJEditOn.Clear(); for (int i = 0; i < this.SJList.Count; i++) { if (this.SJList[i] != null) { if (this.SJList[i].RootObj != null) { this.SJName.Add(this.SJList[i].RootObj.name); } else { if (this.SJList[i].JointObj[0] != null) { this.SJName.Add(this.SJList[i].JointObj[0].name); } else { this.SJName.Add("not found"); Debug.Log("Please set it up: SmoothJoint"); } } } this.SJEditOn.Add(true); } this.editName = ""; this.listCount = this.SJList.Count; this.nameCount = this.SJName.Count; this.editOnCount = this.SJEditOn.Count; break; case "SJName": SmoothJoint[] sja = new SmoothJoint[this.SJName.Count]; for (int i = 0; i < this.SJName.Count; i++) { for (int ia = 0; ia < this.SJList.Count; ia++) { if (this.SJList[ia] != null) { if (this.SJName[i] == this.SJList[ia].RootObj.name) { sja[i] = this.SJList[ia]; } } } } this.SJList.Clear(); this.SJList.AddRange(sja); this.SJEditOn.Clear(); for (int ib = 0; ib < this.SJList.Count; ib++) { this.SJEditOn.Add(true); } this.editName = ""; this.nameCount = this.SJName.Count; this.listCount = this.SJList.Count; this.editOnCount = this.SJEditOn.Count; break; case "SJEditOn": this.SJEditOn.Clear(); for (int i = 0; i < this.SJList.Count; i++) { this.SJEditOn.Add(true); } this.editName = ""; this.editOnCount = this.SJEditOn.Count; this.listCount = this.SJList.Count; this.nameCount = this.SJName.Count; break; } } } this.sjlCount = sjc; this.sjlOld = this.SJList.Count; Debug.Log("SmoothJoint= " + sjc); } else { Debug.Log("Please set it up: SmoothJointObj & SJAutoSetOn"); } }
private void SJListSet() { //自動配列読み込み if (this.SmoothJointObj != null) { bool sef = false; //SmoothJointObj変更確認 int sjc = 0; for (int ic = 0; ic < this.SmoothJointObj.Length; ic++) { if (this.SmoothJointObj[ic] != null) { sjc++; } } if (this.sjlCount != this.SmoothJointObj.Length) { this.Init(); } else { if (sjc != this.SmoothJointObj.Length) { this.Init(); } //編集SJ名リスト設定 if (this.autoName == null) { this.autoName = new string[this.SmoothJointObj.Length]; } else { if (this.autoName.Length != this.SmoothJointObj.Length) { this.Init(); } } //リストが改変されてるか確認 for (int ic = 0; ic < this.SmoothJointObj.Length; ic++) { if (this.SmoothJointObj[ic] != null) { if (this.autoName[ic] != this.SmoothJointObj[ic].name) { sef = false; } else { sef = true; } } } //ユーザーに編集されていたら初期化 if (sef == false) { this.Init(); } if (sef == true) { //どれが編集されたか確認 if (this.SJList.Count != this.listCount && this.editName == "") { this.editName = "SJList"; } if (this.SJName.Count != this.nameCount && this.editName == "") { this.editName = "SJName"; } if (this.SJEditOn.Count != this.editOnCount && this.editName == "") { this.editName = "SJEditOn"; } switch (this.editName) { case "SJList": this.SJName.Clear(); this.SJEditOn.Clear(); for (int i = 0; i < this.SJList.Count; i++) { if (this.SJList[i] != null) { if (this.SJList[i].RootObj != null) { this.SJName.Add(this.SJList[i].RootObj.name); } else { if (this.SJList[i].JointObj[0] != null) { this.SJName.Add(this.SJList[i].JointObj[0].name); } else { this.SJName.Add("not found"); Debug.Log("Please set it up: SmoothJoint"); } } } this.SJEditOn.Add(true); } this.editName = ""; this.listCount = this.SJList.Count; this.nameCount = this.SJName.Count; this.editOnCount = this.SJEditOn.Count; break; case "SJName": SmoothJoint[] sja = new SmoothJoint[this.SJName.Count]; for (int i = 0; i < this.SJName.Count; i++) { for (int ia = 0; ia < this.SJList.Count; ia++) { if (this.SJList[ia] != null) { if (this.SJName[i] == this.SJList[ia].RootObj.name) { sja[i] = this.SJList[ia]; } } } } this.SJList.Clear(); this.SJList.AddRange(sja); this.SJEditOn.Clear(); for (int ib = 0; ib < this.SJList.Count; ib++) { this.SJEditOn.Add(true); } this.editName = ""; this.nameCount = this.SJName.Count; this.listCount = this.SJList.Count; this.editOnCount = this.SJEditOn.Count; break; case "SJEditOn": this.SJEditOn.Clear(); for (int i = 0; i < this.SJList.Count; i++) { this.SJEditOn.Add(true); } this.editName = ""; this.editOnCount = this.SJEditOn.Count; this.listCount = this.SJList.Count; this.nameCount = this.SJName.Count; break; } } } this.sjlCount = sjc; this.sjlOld = this.SJList.Count; Debug.Log("SmoothJoint= " + sjc); } else { Debug.Log("Please set it up: SmoothJointObj & SJAutoSetOn"); } }
private void confirmation() { //Confirmation if (this.SJList != null && this.SJList.Count > 0 && this.Catch != null) { for (int i = 0; i < this.SJList.Count; i++) { SmoothJoint sjc = this.SJList[i]; //Confirm the presence of IK if (sjc != null && sjc.FixedJointNo != null && sjc.FixedTarget != null && this.Catch[i] != null) { for (int ai = 0; ai < sjc.FixedJointNo.Length; ai++) { int jn = sjc.FixedJointNo[ai] - 1; //Check the running of IK bool ikrf = false; if (sjc.RangeHitIK != null && sjc.RangeHitIK.Length > ai) { ikrf = sjc.RangeHitIK[ai]; } if (this.RangeOutOn == true && ikrf == false) //Outside the range of IK { this.Catch[i][ai] = false; } //Collision confirmation if (sjc.FixedTarget.Length > ai && sjc.HitPosition != null && sjc.HitPosition.Length > jn) { Vector3 hitpos = sjc.HitPosition[jn]; if (this.basePos != null && this.basePos.Length > i) { bool hpf = false; if (this.RangeOutOn == true && hitpos != Vector3.zero) { hpf = true; } if (this.RangeOutOn == false && hitpos != Vector3.zero && this.Catch[i][ai] == false) { hpf = true; } //In collision if (hpf == true) { this.Catch[i][ai] = true; sjc.IKRangeOn[ai] = false; //Pause range IK if (this.hitF != null && this.hitF.Length > i && this.hitF[i] != null && this.hitF[i].Length > ai) { this.hitF[i][ai] = true; } GameObject hitobj = null; if (sjc.HitSCC != null && sjc.HitSCC.SJCCTransform.parent.gameObject != null) { hitobj = sjc.HitSCC.SJCCTransform.parent.gameObject; } //random number Vector3 rndd0 = Vector3.zero; if (this.AddRandom == true && sjc.HitSCC != null && this.rndF != null && this.rndF.Length > i && this.rndF[i] != null && this.rndF[i].Length > ai) { if (this.rndF[i][ai] == false) { Vector3 rndd1 = (hitpos + Vector3.Scale(new Vector3(Random.value, Random.value, Random.value), this.AddRand) - sjc.HitSCC.SJCCTransform.position).normalized * (sjc.HitSCC.SJCCRadius * 0.96f); rndd0 = sjc.HitSCC.SJCCTransform.position + rndd1; this.rndF[i][ai] = true; } } else { rndd0 = hitpos; } //Previous coordinates moving Vector3 hpd1 = Vector3.zero; //Confirmation of collision if (this.AvoidanceOn == true && sjc.HitSCC != null && sjc.CollisionRadius.Length > jn + 1) { hpd1 = this.HitTest(sjc.HitSCC.SJCCTransform.position, sjc.JointObj[jn + 1].transform.position, sjc.HitSCC.SJCCRadius, sjc.CollisionRadius[jn + 1]); } else { hpd1 = rndd0; } //Resistance of movement if (this.oldPos != null && this.oldPos[i] != null && this.oldPos[i][ai] != Vector3.zero) { hpd1 = Vector3.Lerp(hpd1, this.oldPos[i][ai], this.Friction); } if (this.WorldPos == false && hitobj != null) { //To child sjc.FixedTarget[ai].transform.parent = hitobj.transform; //local Vector3 hitLpos = hitobj.transform.InverseTransformPoint(hpd1); sjc.FixedTarget[ai].transform.localPosition = hitLpos; } else { //world sjc.FixedTarget[ai].transform.position = hpd1; } //Storage of coordinates if (this.oldPos[i][ai] != hpd1) { this.oldPos[i][ai] = hpd1; } } //No collision if (this.hitF != null && this.hitF.Length > i && this.hitF[i] != null && this.hitF[i].Length > ai) { int hcn = 0; if (sjc != null && sjc.HitSCC != null) { hcn++; } //Check out of range (for after collision) if (this.hitF[i][ai] == true && sjc != null && sjc.HitSCC != null) { float cjl = -1f; if (sjc.JointObj[jn] != null) { cjl = (sjc.HitSCC.SJCCTransform.position - sjc.JointObj[jn].transform.position).magnitude; } if (sjc.CollisionRadius.Length > jn) { float rld = sjc.HitSCC.SJCCRadius + sjc.CollisionRadius[jn]; if (cjl != -1f && cjl > rld * 1.5f) { if (this.RangeOutOn == true && ikrf == false) { hcn = 0; } if (this.RangeOutOn == false) { hcn = 0; } } } } if (hcn == 0) { if (sjc.IKRangeOn[ai] == false) { sjc.IKRangeOn[ai] = true; //Start range IK } this.BaseReturnSet(sjc, i, ai); //It moved to the base position this.hitF[i][ai] = false; //SJ side external operation (initialization sjc.HitSCC = null; if (sjc.HitPosition.Length > jn) { sjc.HitPosition[jn] = Vector3.zero; } } } } } } } } } }