protected virtual void Awake() { this.collider = this.GetComponent <Collider>(); this.rigidbody = this.GetComponent <Rigidbody>(); this.initialDrag = this.rigidbody.drag; this.initialAngularDrag = this.rigidbody.angularDrag; if (this.calculateDensity) { float objectVolume = MathfUtils.CalculateVolume_Mesh(this.GetComponent <MeshFilter>().mesh, this.transform); this.density = this.rigidbody.mass / objectVolume; } }
protected virtual void Awake() { this.collider = this.GetComponent <Collider>(); this.rigidbody = this.GetComponent <Rigidbody>(); this.initialDrag = this.rigidbody.drag; this.initialAngularDrag = this.rigidbody.angularDrag; if (this.calculateDensity) { //通过碰撞体计算 通过mesh计算 //MeshCollider collider = this.GetComponent<MeshCollider>(); //if (collider == null || collider.sharedMesh == null) // return; //Mesh mesh0 = collider.sharedMesh; //float collisonVolume = MathfUtils.CalculateVolume_Mesh(mesh0, this.transform); float objectVolume = MathfUtils.CalculateVolume_Mesh(this.GetComponent <MeshFilter>().mesh, this.transform); this.density = this.rigidbody.mass / objectVolume; } }