You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
5.9 KiB

using System;
using UnityEngine;
namespace MU3
{
// Token: 0x020004E0 RID: 1248
[AddComponentMenu("MU3/SwingJoint/Node", 0)]
public class SwingJoint : MonoBehaviour
{
// Token: 0x17000370 RID: 880
// (get) Token: 0x06001ED5 RID: 7893 RVA: 0x000C2DA8 File Offset: 0x000C2DA8
// (set) Token: 0x06001ED6 RID: 7894 RVA: 0x000C2DB0 File Offset: 0x000C2DB0
public Transform childNode
{
get
{
return this._childNode;
}
set
{
this._childNode = value;
}
}
// Token: 0x06001ED7 RID: 7895 RVA: 0x000C2DBC File Offset: 0x000C2DBC
public void update()
{
Quaternion rotation = this._transform.rotation;
this._transform.localRotation = this._initialLocalRotation;
Vector3 position = this._transform.position;
Quaternion rotation2 = this._transform.rotation;
float x = this._childNode.lossyScale.x;
Vector3 vector = rotation2 * this._nodeAxis * this.childPullForce + this.staticForce;
vector *= x;
vector += (this._oldChildPos - this._nowChildPos) * this.inertialForce;
Vector3 vector2 = 2f * this._nowChildPos - this._oldChildPos + vector;
vector2 = this.calcNormalizedChildPosition(ref vector2, ref position, x);
float collisionRadius = this.collisionRadius;
int num;
int num2;
SwingJointColliderInformation[] collideCandidates = this._manager.getCollideCandidates(out num, out num2, vector2, collisionRadius);
for (int i = num; i < num2; i++)
{
if (collideCandidates[i].getCollisionPointWithSphere(ref vector2, ref vector2, collisionRadius))
{
vector2 = this.calcNormalizedChildPosition(ref vector2, ref position, x);
}
}
Vector3 vector3 = this._transform.TransformDirection(this._nodeAxis);
Quaternion quaternion = Quaternion.FromToRotation(vector3, vector2 - position);
this._transform.rotation = Quaternion.Lerp(rotation, quaternion * rotation2, this._physicsRatio);
this._oldChildPos = this._nowChildPos;
this._nowChildPos = vector2;
}
// Token: 0x17000371 RID: 881
// (get) Token: 0x06001ED8 RID: 7896 RVA: 0x000C2F4C File Offset: 0x000C2F4C
private float collisionRadius
{
get
{
return ((!(this._manager != null) || !this._manager.overwriteRadius) ? this._collisionRadius : this._manager.collisionRadius) * base.transform.lossyScale.x;
}
}
// Token: 0x17000372 RID: 882
// (get) Token: 0x06001ED9 RID: 7897 RVA: 0x000C2FA4 File Offset: 0x000C2FA4
private float childPullForce
{
get
{
return (!(this._manager != null) || !this._manager.overwriteDynamic) ? this._childPullForce : this._manager.childPullForce;
}
}
// Token: 0x17000373 RID: 883
// (get) Token: 0x06001EDA RID: 7898 RVA: 0x000C2FE0 File Offset: 0x000C2FE0
private float inertialForce
{
get
{
return (!(this._manager != null) || !this._manager.overwriteDynamic) ? this._inertialForce : this._manager.inertialForce;
}
}
// Token: 0x17000374 RID: 884
// (get) Token: 0x06001EDB RID: 7899 RVA: 0x000C301C File Offset: 0x000C301C
private Vector3 staticForce
{
get
{
return (!(this._manager != null) || !this._manager.overwriteStatic) ? this._staticForce : this._manager.staticForce;
}
}
// Token: 0x06001EDC RID: 7900 RVA: 0x000C3058 File Offset: 0x000C3058
private void Awake()
{
this._transform = base.transform;
this._initialLocalRotation = this._transform.localRotation;
this._manager = this.findManager();
if (this._childNode == null && this._transform.childCount > 0)
{
this._childNode = this._transform.GetChild(0);
}
}
// Token: 0x06001EDD RID: 7901 RVA: 0x000C30C4 File Offset: 0x000C30C4
private void Start()
{
if (null != this._childNode)
{
Vector3 localPosition = this._childNode.transform.localPosition;
this._nodeAxis = localPosition.normalized;
this._nodeLength = localPosition.magnitude;
this._nowChildPos = (this._oldChildPos = this._childNode.position);
}
if (null != this._manager)
{
if (this._manager.overwriteRadius)
{
this._collisionRadius = this._manager.collisionRadius;
}
if (this._manager.overwriteDynamic)
{
this._childPullForce = this._manager.childPullForce;
this._inertialForce = this._manager.inertialForce;
}
if (this._manager.overwriteStatic)
{
this._staticForce = this._manager.staticForce;
}
}
}
// Token: 0x06001EDE RID: 7902 RVA: 0x000C31AC File Offset: 0x000C31AC
private SwingJointManager findManager()
{
SwingJointManager swingJointManager = null;
Transform transform = base.transform;
while (swingJointManager == null && transform != null)
{
swingJointManager = transform.GetComponent<SwingJointManager>();
transform = transform.parent;
}
return swingJointManager;
}
// Token: 0x06001EDF RID: 7903 RVA: 0x000C31F0 File Offset: 0x000C31F0
private Vector3 calcNormalizedChildPosition(ref Vector3 childPos, ref Vector3 position, float childLossyScale)
{
Vector3 vector = CustomMath.normalize(childPos - position);
return position + vector * this._nodeLength * childLossyScale;
}
// Token: 0x040048EB RID: 18667
public float _physicsRatio = 1f;
// Token: 0x040048EC RID: 18668
public float _collisionRadius = 0.05f;
// Token: 0x040048ED RID: 18669
public float _childPullForce = 0.01f;
// Token: 0x040048EE RID: 18670
public float _inertialForce = 0.4f;
// Token: 0x040048EF RID: 18671
public Vector3 _staticForce = new Vector3(0f, -0.0001f, 0f);
// Token: 0x040048F0 RID: 18672
private Transform _childNode;
// Token: 0x040048F1 RID: 18673
private Vector3 _nodeAxis;
// Token: 0x040048F2 RID: 18674
private float _nodeLength;
// Token: 0x040048F3 RID: 18675
private Quaternion _initialLocalRotation;
// Token: 0x040048F4 RID: 18676
private Vector3 _nowChildPos;
// Token: 0x040048F5 RID: 18677
private Vector3 _oldChildPos;
// Token: 0x040048F6 RID: 18678
private Transform _transform;
// Token: 0x040048F7 RID: 18679
private SwingJointManager _manager;
}
}