123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- public class TBodyHit
- {
- public TBodyHit()
- {
- this.spherelist = new List<THitSphere>();
- }
- public void SetSphere(Transform t, string SaveName)
- {
- this.tRoot = t;
- this.MakeList(t, "ROOT", t);
- Debug.Log("BodyHit=" + this.spherelist.Count);
- string text = "G_Assets/_DAT/hitcheck";
- if (!Directory.Exists(text))
- {
- Directory.CreateDirectory(text);
- }
- BinaryWriter binaryWriter = new BinaryWriter(File.Create(text + "/" + SaveName + ".hitcheck"));
- int count = this.spherelist.Count;
- binaryWriter.Write("HitCheck");
- binaryWriter.Write(count);
- for (int i = 0; i < count; i++)
- {
- binaryWriter.Write(this.spherelist[i].type);
- binaryWriter.Write(this.spherelist[i].len);
- this.spherelist[i].len_ = this.spherelist[i].len;
- binaryWriter.Write(this.spherelist[i].lenxlen);
- this.spherelist[i].lenxlen_ = this.spherelist[i].lenxlen;
- binaryWriter.Write(this.spherelist[i].t.name);
- binaryWriter.Write(this.spherelist[i].t.parent.name);
- binaryWriter.Write(this.spherelist[i].t.localPosition.x);
- binaryWriter.Write(this.spherelist[i].t.localPosition.y);
- binaryWriter.Write(this.spherelist[i].t.localPosition.z);
- binaryWriter.Write(this.spherelist[i].SKRT);
- binaryWriter.Write(this.spherelist[i].RL);
- }
- binaryWriter.Close();
- }
- public void ScaleMune(string t, float fac)
- {
- if (t == "HARA")
- {
- this.HARA_FUTO = fac;
- }
- if (t == "MOMO")
- {
- this.MOMO_FUTO = fac;
- }
- if (t == "KOSHI_SCL")
- {
- this.KOSHI_SCL = fac;
- }
- if (t == "KOSHI_SVAL")
- {
- this.KOSHI_SVAL = fac;
- }
- if (t == "MUNE")
- {
- for (int i = 0; i < this.spherelist.Count; i++)
- {
- if (this.spherelist[i].SKRT == 99)
- {
- this.spherelist[i].len = this.spherelist[i].len_ * fac;
- this.spherelist[i].lenxlen = this.spherelist[i].len * this.spherelist[i].len;
- }
- }
- }
- }
- public void LoadSphereFromFile(Transform t, string FileName, string tag)
- {
- this.tRoot = t;
- this.BodySkinTAG = tag;
- MemoryStream input = null;
- using (AFileBase afileBase = GameUty.FileOpen(FileName, null))
- {
- input = new MemoryStream(afileBase.ReadAll());
- }
- BinaryReader binaryReader = new BinaryReader(input);
- if (binaryReader.ReadString() != "HitCheck")
- {
- binaryReader.Close();
- Debug.LogError("HitCheck header error!");
- return;
- }
- int num = binaryReader.ReadInt32();
- for (int i = 0; i < num; i++)
- {
- THitSphere thitSphere = new THitSphere();
- thitSphere.type = binaryReader.ReadInt32();
- thitSphere.len = binaryReader.ReadSingle();
- thitSphere.lenxlen = binaryReader.ReadSingle();
- thitSphere.lenxlen = thitSphere.len * thitSphere.len;
- thitSphere.lenxlen_ = thitSphere.lenxlen;
- thitSphere.len_ = thitSphere.len;
- thitSphere.name = binaryReader.ReadString();
- thitSphere.pname = binaryReader.ReadString();
- thitSphere.vs.x = binaryReader.ReadSingle();
- thitSphere.vs.y = binaryReader.ReadSingle();
- thitSphere.vs.z = binaryReader.ReadSingle();
- thitSphere.SKRT = binaryReader.ReadInt32();
- thitSphere.RL = binaryReader.ReadInt32();
- if (thitSphere.RL != -1 && thitSphere.SKRT == 1)
- {
- this.skrt_L1 = i;
- }
- if (thitSphere.RL != -1 && thitSphere.SKRT == 2)
- {
- this.skrt_L2 = i;
- }
- if (thitSphere.RL != -1 && thitSphere.SKRT == 3)
- {
- this.skrt_L3 = i;
- }
- if (thitSphere.RL == -1 && thitSphere.SKRT == 1)
- {
- this.skrt_R1 = i;
- }
- if (thitSphere.RL == -1 && thitSphere.SKRT == 2)
- {
- this.skrt_R2 = i;
- }
- if (thitSphere.RL == -1 && thitSphere.SKRT == 3)
- {
- this.skrt_R3 = i;
- }
- if (tag == THp.check_BONE)
- {
- Debug.LogWarning(string.Concat(new string[]
- {
- thitSphere.pname,
- ":",
- thitSphere.name,
- " : cnt=",
- this.SearchCountObj(thitSphere.pname, this.tRoot, 0).ToString()
- }));
- }
- thitSphere.t = this.SearchObj(thitSphere.pname, this.tRoot);
- if (thitSphere.t == null)
- {
- Debug.LogError("Hit sphere t=null " + thitSphere.pname);
- }
- this.spherelist.Add(thitSphere);
- if (tag == THp.check_BONE)
- {
- GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(GameObject.Find("SphereHIT"), Vector3.one * 0.3f, Quaternion.identity);
- float num2 = 1f;
- gameObject.transform.localScale = new Vector3(thitSphere.len / num2, thitSphere.len / num2, thitSphere.len / num2);
- gameObject.transform.localPosition = thitSphere.vs;
- gameObject.transform.parent = thitSphere.t;
- gameObject.transform.localPosition = thitSphere.vs;
- if (thitSphere.pname == "Mune_L")
- {
- }
- if (thitSphere.RL != 0)
- {
- gameObject.name = "SphereHIT_L";
- }
- else
- {
- gameObject.name = "SphereHIT_R";
- }
- thitSphere.tPtr = gameObject.transform;
- }
- }
- if (GameMain.Instance.VRMode && Application.isPlaying && FileName.ToLower() != "ik.hitcheck")
- {
- this.OvrAddHitSphere();
- }
- }
- private void OvrAddHitSphere()
- {
- string[] array = new string[]
- {
- "Sphere_HandHitL_",
- "Sphere_HandHitR_"
- };
- for (int i = 0; i < array.Length; i++)
- {
- THitSphere thitSphere = new THitSphere();
- thitSphere.type = 0;
- thitSphere.len = 0.1f;
- thitSphere.lenxlen = 0.01f;
- thitSphere.lenxlen = thitSphere.len * thitSphere.len;
- thitSphere.lenxlen_ = thitSphere.lenxlen;
- thitSphere.len_ = thitSphere.len;
- thitSphere.name = array[i];
- thitSphere.pname = "Bip01";
- thitSphere.vs.x = 0f;
- thitSphere.vs.y = -10000f;
- thitSphere.vs.z = 0f;
- thitSphere.SKRT = 0;
- thitSphere.RL = 1;
- thitSphere.t = this.SearchObj(thitSphere.pname, this.tRoot);
- if (thitSphere.t == null)
- {
- Debug.LogError("Hit sphere t=null " + thitSphere.pname);
- }
- this.spherelist.Add(thitSphere);
- if (i == 0)
- {
- this.m_listHandHitL.Add(thitSphere);
- }
- else
- {
- this.m_listHandHitR.Add(thitSphere);
- }
- }
- array = new string[]
- {
- "Sphere_HandHitLeapL_",
- "Sphere_HandHitLeapR_"
- };
- for (int j = 0; j < array.Length; j++)
- {
- THitSphere thitSphere2 = new THitSphere();
- thitSphere2.type = 0;
- thitSphere2.len = 0.1f;
- thitSphere2.lenxlen = 0.01f;
- thitSphere2.lenxlen = thitSphere2.len * thitSphere2.len;
- thitSphere2.lenxlen_ = thitSphere2.lenxlen;
- thitSphere2.len_ = thitSphere2.len;
- thitSphere2.name = array[j];
- thitSphere2.pname = "Bip01";
- thitSphere2.vs.x = 0f;
- thitSphere2.vs.y = -10000f;
- thitSphere2.vs.z = 0f;
- thitSphere2.SKRT = 0;
- thitSphere2.RL = 1;
- thitSphere2.t = this.SearchObj(thitSphere2.pname, this.tRoot);
- if (thitSphere2.t == null)
- {
- Debug.LogError("Hit sphere t=null " + thitSphere2.pname);
- }
- this.spherelist.Add(thitSphere2);
- if (j == 0)
- {
- this.m_HandHitLeapL = thitSphere2;
- }
- else
- {
- this.m_HandHitLeapR = thitSphere2;
- }
- }
- }
- private Transform SearchObj(string name, Transform t)
- {
- string name2 = t.name;
- if (name2.Contains("_IA_"))
- {
- return null;
- }
- if (name2 == name)
- {
- return t;
- }
- for (int i = 0; i < t.childCount; i++)
- {
- Transform transform = this.SearchObj(name, t.GetChild(i));
- if (transform != null)
- {
- return transform;
- }
- }
- return null;
- }
- private int SearchCountObj(string name, Transform t, int cnt = 0)
- {
- string name2 = t.name;
- if (name2.Contains("_IA_"))
- {
- return 0;
- }
- if (name2 == name)
- {
- cnt++;
- }
- for (int i = 0; i < t.childCount; i++)
- {
- cnt += this.SearchCountObj(name, t.GetChild(i), cnt);
- }
- return cnt;
- }
- private void MakeList(Transform t, string oyax, Transform root)
- {
- if (t.name.Contains("Sphere") || t.name.Contains("_SKRT_"))
- {
- string name = t.parent.name;
- THitSphere thitSphere = new THitSphere();
- thitSphere.t = t;
- thitSphere.len = t.localScale.x * 0.5f;
- thitSphere.lenxlen = thitSphere.len * thitSphere.len;
- thitSphere.SKRT = 0;
- if (t.name.Contains("_1_"))
- {
- thitSphere.SKRT = 1;
- }
- if (t.name.Contains("_2_"))
- {
- thitSphere.SKRT = 2;
- }
- if (t.name.Contains("_3_"))
- {
- thitSphere.SKRT = 3;
- }
- if (t.name.Contains("_MUNE_"))
- {
- thitSphere.SKRT = 99;
- }
- if (t.name.Contains("_UDE_"))
- {
- thitSphere.SKRT = 98;
- }
- if (t.name.Contains("_HARA_"))
- {
- thitSphere.SKRT = 97;
- }
- if (t.name.Contains("_MOMO_"))
- {
- thitSphere.SKRT = 96;
- }
- thitSphere.RL = 1;
- thitSphere.type = 0;
- if (t.parent.name == "Bip01 Head")
- {
- thitSphere.type = 1;
- }
- this.spherelist.Add(thitSphere);
- if (name.Contains("R") || t.name.Contains("_R_"))
- {
- Transform transform;
- if (t.name.Contains("_R_"))
- {
- transform = t.parent;
- }
- else
- {
- string text = string.Empty;
- int length = name.Length;
- for (int i = 0; i < length; i++)
- {
- char c = name[i];
- if (c == 'R')
- {
- c = 'L';
- }
- text += c.ToString();
- }
- transform = this.SearchObj(text, this.tRoot);
- }
- if (transform != null)
- {
- Transform transform2 = UnityEngine.Object.Instantiate<Transform>(t);
- if (transform2.name.Contains("_R_"))
- {
- transform2.name = "hit_copy";
- }
- THitSphere thitSphere2 = new THitSphere();
- thitSphere2.t = transform2;
- thitSphere2.SKRT = thitSphere.SKRT;
- thitSphere.RL = -1;
- transform2.position = new Vector3(root.position.x * 2f - t.position.x, t.position.y, t.position.z);
- transform2.parent = transform;
- thitSphere2.len = transform2.localScale.x * 0.5f;
- thitSphere2.lenxlen = thitSphere.len * thitSphere.len;
- thitSphere2.type = 0;
- this.spherelist.Add(thitSphere2);
- }
- }
- }
- List<Transform> list = new List<Transform>();
- for (int j = 0; j < t.childCount; j++)
- {
- list.Add(t.GetChild(j));
- }
- for (int k = 0; k < list.Count; k++)
- {
- this.MakeList(list[k], t.name, root);
- }
- }
- public void PreUpdate()
- {
- for (int i = 0; i < this.spherelist.Count; i++)
- {
- this.spherelist[i].wv_old = this.spherelist[i].wv;
- Vector3 wv = this.spherelist[i].t.TransformPoint(this.spherelist[i].vs);
- this.spherelist[i].wv = wv;
- if (this.spherelist[i].tPtr != null)
- {
- this.spherelist[i].len = this.spherelist[i].tPtr.localScale.x;
- this.spherelist[i].lenxlen = this.spherelist[i].len * this.spherelist[i].len;
- this.spherelist[i].tPtr.rotation = Quaternion.identity;
- this.spherelist[i].wv = this.spherelist[i].tPtr.position;
- }
- }
- }
- public bool SphereCheck(Vector3 v)
- {
- for (int i = 0; i < this.spherelist.Count; i++)
- {
- Vector3 wv = this.spherelist[i].wv;
- if ((v - wv).sqrMagnitude < this.spherelist[i].lenxlen)
- {
- return true;
- }
- }
- return false;
- }
- public bool SphereMove(ref Vector3 v, ref Vector3 g, Vector3 v_old)
- {
- bool result = false;
- for (int i = 0; i < this.spherelist.Count; i++)
- {
- Vector3 wv = this.spherelist[i].wv;
- if ((v - wv).sqrMagnitude < this.spherelist[i].lenxlen)
- {
- Vector3 normalized = (v_old - this.spherelist[i].wv_old).normalized;
- Vector3 a = wv + normalized * this.spherelist[i].len;
- v = a * 0.5f + v * 0.5f;
- if (this.spherelist[i].type == 0)
- {
- g *= 1f - Mathf.Abs(Vector3.Dot(normalized, g.normalized));
- g.y = 0f;
- }
- else
- {
- g.x *= 0.1f;
- g.y *= 0.95f;
- g.z *= 0.1f;
- }
- result = true;
- }
- }
- return result;
- }
- public bool SphereMove_skrt(ref Vector3 v, ref Vector3 g)
- {
- bool result = false;
- Vector3 a = Vector3.zero;
- float num = 0f;
- float num2 = 0f;
- for (int i = 0; i < this.spherelist.Count; i++)
- {
- Vector3 wv = this.spherelist[i].wv;
- Vector3 a2 = v - wv;
- float num3 = this.spherelist[i].len * (1f + _TS.TestVal3 * 2f);
- if (this.spherelist[i].SKRT == 96)
- {
- num3 *= this.SkirtFT;
- }
- if (a2.sqrMagnitude < num3 * num3)
- {
- float magnitude = a2.magnitude;
- a2 /= magnitude;
- float num4 = 1f - magnitude / num3;
- num2 += num4;
- num += num4;
- a += a2 * this.spherelist[i].len * num4;
- result = true;
- }
- }
- this.MST = num;
- if (num2 > 0.8f)
- {
- num2 = 0.8f;
- }
- g *= 1f - num2;
- if (num > 0.5f)
- {
- num -= 0.5f;
- this.MST_v = a * num;
- v += this.MST_v;
- }
- else
- {
- this.MST_v = Vector3.zero;
- }
- return result;
- }
- public bool SphereMove_skrtVSHOT(ref Vector3 v, ref Vector3 g, Vector3 vshot)
- {
- bool result = false;
- Vector3 a = Vector3.zero;
- float num = 0f;
- float num2 = 0f;
- for (int i = 0; i < this.spherelist.Count; i++)
- {
- Vector3 wv = this.spherelist[i].wv;
- Vector3 vector = v - wv;
- float num3 = this.spherelist[i].len * (1f + _TS.TestVal3 * 2f);
- if (vector.sqrMagnitude < num3 * num3)
- {
- float magnitude = vector.magnitude;
- float num4 = 1f - magnitude / num3;
- num2 += num4;
- num += num4;
- a += vshot * this.spherelist[i].len * num4;
- result = true;
- }
- }
- if (num2 > 0.8f)
- {
- num2 = 0.8f;
- }
- g *= 1f - num2;
- if (num > 0.5f)
- {
- num -= 0.5f;
- v += a * num;
- }
- return result;
- }
- public bool SphereMove_hair(ref Vector3 v, ref Vector3 g, Vector3 v2)
- {
- bool result = false;
- Vector3 a = Vector3.zero;
- float num = 0f;
- float num2 = 0f;
- for (int i = 0; i < this.spherelist.Count; i++)
- {
- Vector3 wv = this.spherelist[i].wv;
- Vector3 vector = v - wv;
- if (vector.sqrMagnitude < this.spherelist[i].lenxlen)
- {
- float magnitude = vector.magnitude;
- vector /= magnitude;
- float num3 = 1f - magnitude / this.spherelist[i].len;
- num3 *= num3;
- num2 += num3;
- a += vector;
- num += num3 * this.spherelist[i].len;
- result = true;
- }
- }
- if (num2 > 0.8f)
- {
- num2 = 0.8f;
- }
- g *= 1f - num2;
- a.Normalize();
- v += a * num;
- return result;
- }
- public bool SphereMove_hair2(ref Vector3 v, ref Vector3 g, Vector3 v_old)
- {
- bool result = false;
- Vector3 a = Vector3.zero;
- Vector3 a2 = Vector3.zero;
- float num = 0f;
- float num2 = 0f;
- for (int i = 0; i < this.spherelist.Count; i++)
- {
- Vector3 wv = this.spherelist[i].wv;
- Vector3 a3 = v - wv;
- float num3 = this.spherelist[i].len * (1f + _TS.TestVal2 * 2f);
- if (a3.sqrMagnitude < num3 * num3)
- {
- float magnitude = a3.magnitude;
- a3 /= magnitude;
- float num4 = 1f - magnitude / num3;
- num2 += num4;
- num += num4;
- a += a3 * this.spherelist[i].len * num4;
- Vector3 a4 = this.spherelist[i].wv - this.spherelist[i].wv_old;
- a2 += a4 * num4;
- result = true;
- }
- }
- num2 *= _TS.TestVal;
- if (num2 > 0.8f)
- {
- num2 = 0.8f;
- }
- g *= 1f - num2;
- if (num > 0.5f)
- {
- num -= 0.5f;
- v += a * num;
- }
- return result;
- }
- public float RotOffset;
- public List<THitSphere> spherelist;
- public Transform tRoot;
- public int skrt_R1;
- public int skrt_R2;
- public int skrt_R3;
- public int skrt_L1;
- public int skrt_L2;
- public int skrt_L3;
- public float MOMO_FUTO = 1f;
- public float HARA_FUTO;
- public float KOSHI_SCL = 1f;
- public float KOSHI_SVAL = 0.5f;
- public string BodySkinTAG;
- public List<THitSphere> m_listHandHitL = new List<THitSphere>();
- public List<THitSphere> m_listHandHitR = new List<THitSphere>();
- public THitSphere m_HandHitLeapL;
- public THitSphere m_HandHitLeapR;
- public float SkirtFT = 1f;
- public float MST;
- public Vector3 MST_v;
- }
|