using UnityEngine; namespace UMA { /// /// Auxillary slot which adds a CapsuleCollider and Rigidbody to a newly created character. /// public class CapsuleColliderSlotScript : MonoBehaviour { public bool overrideMass = false; public bool overrideConstraints = false; public bool overrideDimensions = true; public void OnDnaApplied(UMAData umaData) { var rigid = umaData.gameObject.GetComponent(); if (rigid == null) { rigid = umaData.gameObject.AddComponent(); rigid.constraints = RigidbodyConstraints.FreezeRotation; rigid.mass = umaData.characterMass; } if ( overrideConstraints) { rigid.constraints = RigidbodyConstraints.FreezeRotation; } if (overrideMass) { rigid.mass = umaData.characterMass; } CapsuleCollider capsule = umaData.gameObject.GetComponent(); BoxCollider box = umaData.gameObject.GetComponent(); if(umaData.umaRecipe.raceData.umaTarget == RaceData.UMATarget.Humanoid) { if (capsule == null) { capsule = umaData.gameObject.AddComponent(); } if( box != null ) { Destroy(box); } if (overrideDimensions) { capsule.radius = umaData.characterRadius; capsule.height = umaData.characterHeight; capsule.center = new Vector3(0, capsule.height / 2, 0); } } else { if (box == null) { box = umaData.gameObject.AddComponent(); } if(capsule != null) { Destroy(capsule); } //with skycar this capsule collider makes no sense so we need the bounds to figure out what the size of the box collider should be //we will assume that renderer 0 is the base renderer var umaRenderer = umaData.GetRenderer(0); if (umaRenderer != null) { if (overrideDimensions) { box.size = umaRenderer.bounds.size; box.center = umaRenderer.bounds.center; } } } } } }