123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- using System;
- using UnityEngine;
- public class jiggleBone : MonoBehaviour
- {
- private void Awake()
- {
- Vector3 vector = base.transform.position + base.transform.TransformDirection(new Vector3(this.boneAxis.x * this.targetDistance, this.boneAxis.y * this.targetDistance, this.boneAxis.z * this.targetDistance));
- this.dynamicPos = vector;
- this.defQtn = base.transform.localRotation;
- if (base.transform.name == "Mune_R")
- {
- this.MuneL_y = -1f;
- }
- this.m_trParent = base.transform.parent;
- this.m_trSub = base.transform.Find(base.transform.name + "_sub");
- if (this.m_trSub == null)
- {
- NDebug.Assert("transform.name の下に" + base.transform.name + "_sub がありません。", false);
- }
- }
- public void LateUpdateSelf()
- {
- if (!base.enabled)
- {
- return;
- }
- if (0f < this.BlendValueON)
- {
- if (0.5f <= this.m_fMuneYawaraka)
- {
- float num = (this.m_fMuneYawaraka - 0.5f) / 0.5f;
- this.bMass = 0.4f + 1.1f * num;
- this.bDamping = 0.3f - 0.290000021f * num;
- this.BlendValueON2 = 1f;
- }
- else
- {
- float blendValueON = this.m_fMuneYawaraka / 0.5f;
- this.bMass = 0.4f;
- this.bDamping = 0.3f;
- this.BlendValueON2 = blendValueON;
- }
- base.transform.localRotation = this.defQtn;
- Vector3 dir = base.transform.TransformDirection(new Vector3(this.boneAxis.x * this.targetDistance, this.boneAxis.y * this.targetDistance, this.boneAxis.z * this.targetDistance));
- Vector3 vector = base.transform.TransformDirection(new Vector3(0f, 1f, 0f));
- Vector3 vector2 = base.transform.position + base.transform.TransformDirection(new Vector3(this.boneAxis.x * this.targetDistance, this.boneAxis.y * this.targetDistance, this.boneAxis.z * this.targetDistance));
- float p = 0.5f;
- float num2 = this.bStiffness[1];
- float num3 = this.bStiffness[0];
- if (this.boBRA)
- {
- num2 = this.bStiffnessBRA[1];
- num3 = this.bStiffnessBRA[0];
- p = 0.7f;
- }
- float num4 = Mathf.Pow(this.BlendValue / 1.3f, p);
- this.force.x = (vector2.x - this.dynamicPos.x) * (num2 * num4 + (1f - num4) * num3);
- this.acc.x = this.force.x / this.bMass;
- this.vel.x = this.vel.x + this.acc.x * (1f - this.bDamping);
- this.force.y = (vector2.y - this.dynamicPos.y) * (num2 * num4 + (1f - num4) * num3);
- this.force.y = this.force.y - this.bGravity / 10f;
- this.acc.y = this.force.y / this.bMass;
- this.vel.y = this.vel.y + this.acc.y * (1f - this.bDamping);
- this.force.z = (vector2.z - this.dynamicPos.z) * (num2 * num4 + (1f - num4) * num3);
- this.acc.z = this.force.z / this.bMass;
- this.vel.z = this.vel.z + this.acc.z * (1f - this.bDamping);
- if (this.m_fBackBlendValueON2 != this.BlendValueON2)
- {
- this.force = Vector3.zero;
- this.acc = Vector3.zero;
- this.vel = Vector3.zero;
- this.m_fBackBlendValueON2 = this.BlendValueON2;
- }
- if (this.boWarpInit)
- {
- this.force = Vector3.zero;
- this.acc = Vector3.zero;
- this.vel = Vector3.zero;
- vector2 = (this.dynamicPos = base.transform.position + base.transform.TransformDirection(new Vector3(this.boneAxis.x * this.targetDistance, this.boneAxis.y * this.targetDistance, this.boneAxis.z * this.targetDistance)));
- }
- Vector3 a = this.dynamicPos;
- a += this.force;
- a += this.vel;
- if (Vector3.Dot(a - base.transform.position, vector2 - base.transform.position) < this.m_fLimitRot)
- {
- this.force *= this.m_fLimitRotDecay;
- this.vel *= this.m_fLimitRotDecay;
- }
- this.dynamicPos += this.force;
- this.dynamicPos += this.vel;
- this.dynamicPos = Vector3.Slerp(vector2, this.dynamicPos, this.BlendValueON2);
- base.transform.LookAt(this.dynamicPos, vector);
- base.transform.Rotate(0f, 90f - this.MuneYori * this.BlendValue, -this.MuneUpDown * this.MuneL_y * this.BlendValue);
- Quaternion localRotation = base.transform.localRotation;
- base.transform.localRotation = Quaternion.Slerp(this.defQtn, localRotation, this.BlendValueON);
- if (this.SquashAndStretch)
- {
- float magnitude = (this.dynamicPos - vector2).magnitude;
- float x;
- if (this.boneAxis.x == 0f)
- {
- x = 1f + -magnitude * this.sideStretch;
- }
- else
- {
- x = 1f + magnitude * this.frontStretch;
- }
- float y;
- if (this.boneAxis.y == 0f)
- {
- y = 1f + -magnitude * this.sideStretch;
- }
- else
- {
- y = 1f + magnitude * this.frontStretch;
- }
- float z;
- if (this.boneAxis.z == 0f)
- {
- z = 1f + -magnitude * this.sideStretch;
- }
- else
- {
- z = 1f + magnitude * this.frontStretch;
- }
- base.transform.localScale = new Vector3(x, y, z);
- if (this.m_bEnableScaleX)
- {
- float num5 = Vector3.Dot(Vector3.up, this.m_trParent.up);
- if (this.m_fScaleDotRateLimit <= num5 && 0.7f < this.BlendValue)
- {
- this.m_fMuneScaleRate = (this.BlendValue - 0.7f) / 0.599999964f;
- this.m_fScaleX = 1f - this.m_fScaleMinus * ((num5 - this.m_fScaleDotRateLimit) / (1f - this.m_fScaleDotRateLimit)) * this.m_fMuneScaleRate * this.BlendValueON;
- }
- else
- {
- this.m_fScaleX = 1f;
- }
- base.transform.localScale = new Vector3(base.transform.localScale.x * this.m_fScaleX, base.transform.localScale.y, base.transform.localScale.z);
- }
- }
- if (this.debugMode)
- {
- Debug.DrawRay(base.transform.position, dir, Color.blue);
- Debug.DrawRay(base.transform.position, vector, Color.green);
- Debug.DrawRay(vector2, Vector3.up * 0.2f, Color.yellow);
- Debug.DrawRay(this.dynamicPos, Vector3.up * 0.2f, Color.red);
- }
- if (this.boWarpInit)
- {
- this.boWarpInit = false;
- }
- }
- else
- {
- if (0f < this.BlendValueON)
- {
- base.transform.localRotation = this.defQtn;
- }
- this.m_fBackBlendValueON2 = -1f;
- this.boWarpInit = true;
- }
- Transform parent = base.transform.parent;
- float num6 = (1f - Mathf.Abs(Vector3.Dot(parent.up, Vector3.down))) * -this.MuneL_y * 0.8f;
- num6 += this.BlendValue2 * (this.BlendValue * 0.5f);
- float num7 = this.BlendValue;
- if (num7 > 1f)
- {
- num7 = 1f;
- }
- num6 *= num7 * this.BlendValueON;
- num6 += 3.14159274f;
- this.m_trSub.localRotation = Quaternion.EulerRotation(0f, 0f, num6);
- }
- public bool debugMode;
- private Vector3 dynamicPos = default(Vector3);
- public bool boBRA = true;
- public float BlendValue;
- public float BlendValue2;
- public float BlendValueON = 1f;
- public float BlendValueON2 = 1f;
- public Vector3 boneAxis = new Vector3(-1f, 0f, 0f);
- public float targetDistance = 0.7f;
- public float[] bStiffness = new float[]
- {
- 0.22f,
- 0.055f
- };
- public float[] bStiffnessBRA = new float[]
- {
- 0.27f,
- 0.07f
- };
- public float bMass = 0.4f;
- public float bDamping = 0.3f;
- public float bGravity = 0.1f;
- private Vector3 force = default(Vector3);
- private Vector3 acc = default(Vector3);
- private Vector3 vel = default(Vector3);
- public bool SquashAndStretch = true;
- public float sideStretch = -0.2f;
- public float frontStretch = 0.3f;
- public float MuneL_y = 1f;
- public float MuneYori;
- public float MuneUpDown;
- public float MuneYori_f;
- public float MuneUpDown_f;
- private Quaternion defQtn;
- public float m_fMuneYawaraka = 0.5f;
- public float m_fLimitRot = 0.3f;
- public float m_fLimitRotDecay = 0.8f;
- public bool m_bEnableScaleX;
- public float m_fScaleX = 1f;
- public float m_fMuneScaleRate;
- public float m_fScaleDotRateLimit = 0.8f;
- public float m_fScaleMinus = 0.2f;
- private Transform m_trParent;
- private Transform m_trSub;
- public bool boWarpInit;
- private float m_fBackBlendValueON2;
- }
|