public virtual IEnumerator AddForce(RagdollJointData JointData) { if (JointData.CreateForceDelay > 0) { yield return new WaitForSeconds(JointData.CreateForceDelay); } //Activate the game object (if not) if (JointData.Joint.gameObject.activeInHierarchy == false) { JointData.Joint.gameObject.SetActive(true); } Vector3 ForceDirection = JointData.ForceRandomDirection ? Util.RandomVector (JointData.ForceRandomDirectionFrom, JointData.ForceRandomDirectionTo) : JointData.ForceDirection; if (JointData.IsGlobalDirection == false) { ForceDirection = transform.TransformDirection (ForceDirection); } Vector3 Force = ForceDirection.normalized * Random.Range (JointData.MinForceMagnitude, JointData.MaxForceMagnitude); JointData.Joint.AddForce (Force, JointData.forceMode); }
/// <summary> /// Copies the RagdollJoint data, EffectData from to. /// </summary> public static void CopyRagdollData(Ragdoll _from, Ragdoll to) { IList <RagdollJointData> jointDataList = new List <RagdollJointData> (); foreach (RagdollJointData jointData in _from.RagdollJointDataArray) { RagdollJointData cloned = jointData.GetClone(); jointDataList.Add(cloned); } to.RagdollJointDataArray = jointDataList.ToArray(); IList <EffectData> effectDataList = new List <EffectData> (); foreach (EffectData effectData in _from.EffectData) { EffectData cloned = effectData.GetClone(); effectDataList.Add(cloned); } to.EffectData = effectDataList.ToArray(); }
/// <summary> /// Gets a clone of this RagdollJointData. The Joint object is null and need to be assigned other way. /// </summary> public RagdollJointData GetClone() { RagdollJointData ragdollJointData = new RagdollJointData(); ragdollJointData.Name = this.Name; ragdollJointData.CreateForce = this.CreateForce; ragdollJointData.Detach = this.Detach; ragdollJointData.DestoryJoint = this.DestoryJoint; ragdollJointData.CreateForceDelay = this.CreateForceDelay; ragdollJointData.ForceRandomDirection = this.ForceRandomDirection; ragdollJointData.IsGlobalDirection = this.IsGlobalDirection; ragdollJointData.ForceDirection = this.ForceDirection; ragdollJointData.ForceRandomDirectionFrom = this.ForceRandomDirectionFrom; ragdollJointData.ForceRandomDirectionTo = this.ForceRandomDirectionTo; ragdollJointData.MinForceMagnitude = this.MinForceMagnitude; ragdollJointData.MaxForceMagnitude = this.MaxForceMagnitude; ragdollJointData.SelfcontrolDestruction = this.SelfcontrolDestruction; ragdollJointData.SelfDestructionTime = this.SelfDestructionTime; ragdollJointData.JointGameObjectInitialActive = this.JointGameObjectInitialActive; ragdollJointData.TurnOnRigibody = this.TurnOnRigibody; return(ragdollJointData); }
public virtual IEnumerator AddForce(RagdollJointData JointData) { if (JointData.CreateForceDelay > 0) { yield return(new WaitForSeconds(JointData.CreateForceDelay)); } //Activate the game object (if not) if (JointData.Joint.gameObject.activeInHierarchy == false) { JointData.Joint.gameObject.SetActive(true); } Vector3 ForceDirection = JointData.ForceRandomDirection ? Util.RandomVector(JointData.ForceRandomDirectionFrom, JointData.ForceRandomDirectionTo) : JointData.ForceDirection; if (JointData.IsGlobalDirection == false) { ForceDirection = transform.TransformDirection(ForceDirection); } Vector3 Force = ForceDirection.normalized * Random.Range(JointData.MinForceMagnitude, JointData.MaxForceMagnitude); JointData.Joint.AddForce(Force, JointData.forceMode); }
public virtual void EditRagdollJointData() { EnableEditRagdollData = EditorGUILayout.BeginToggleGroup("---Edit RagdollJointData", EnableEditRagdollData); if (EnableEditRagdollData) { if (GUILayout.Button("Add RagdollJointData")) { RagdollJointData RagdollJointData = new RagdollJointData(); IList <RagdollJointData> l = selectedRagdoll.RagdollJointDataArray.ToList <RagdollJointData> (); l.Add(RagdollJointData); selectedRagdoll.RagdollJointDataArray = l.ToArray <RagdollJointData> (); } for (int i = 0; i < selectedRagdoll.RagdollJointDataArray.Length; i++) { RagdollJointData _RagdollJointData = selectedRagdoll.RagdollJointDataArray[i]; EditorGUILayout.LabelField("---------------- Edit RagdollJointData:" + _RagdollJointData.Name + "--------"); _RagdollJointData.Name = EditorGUILayout.TextField(new GUIContent("Name", ""), _RagdollJointData.Name); _RagdollJointData.Joint = (Rigidbody)EditorGUILayout.ObjectField(new GUIContent("Joint", "关节对象"), _RagdollJointData.Joint, typeof(Rigidbody)); _RagdollJointData.JointGameObjectInitialActive = EditorGUILayout.Toggle(new GUIContent("Initial active:", "If false, the gameobject will be deactivate when ragdoll created"), _RagdollJointData.JointGameObjectInitialActive); _RagdollJointData.Detach = EditorGUILayout.Toggle(new GUIContent("Detach joint?", "Detach this joint object from parent?"), _RagdollJointData.Detach); _RagdollJointData.SelfcontrolDestruction = EditorGUILayout.Toggle(new GUIContent("Self control destruction?", "The joint control its destruction itself?"), _RagdollJointData.SelfcontrolDestruction); if (_RagdollJointData.SelfcontrolDestruction) { _RagdollJointData.SelfDestructionTime = EditorGUILayout.FloatField("Self destuction time:", _RagdollJointData.SelfDestructionTime); } _RagdollJointData.DestoryJoint = EditorGUILayout.Toggle(new GUIContent("Destory joint?", "销毁ChracterJoint组件?"), _RagdollJointData.DestoryJoint); _RagdollJointData.CreateForce = EditorGUILayout.Toggle(new GUIContent("Create force?", "Use force?"), _RagdollJointData.CreateForce); if (_RagdollJointData.CreateForce) { _RagdollJointData.forceMode = (ForceMode)EditorGUILayout.EnumPopup("Force mode:", _RagdollJointData.forceMode); _RagdollJointData.CreateForceDelay = EditorGUILayout.FloatField(new GUIContent("Create force delay", ""), _RagdollJointData.CreateForceDelay); _RagdollJointData.MinForceMagnitude = EditorGUILayout.FloatField(new GUIContent("Min force:", ""), _RagdollJointData.MinForceMagnitude); _RagdollJointData.MaxForceMagnitude = EditorGUILayout.FloatField(new GUIContent("Max force:", ""), _RagdollJointData.MaxForceMagnitude); _RagdollJointData.IsGlobalDirection = EditorGUILayout.Toggle(new GUIContent("Global direction?", ""), _RagdollJointData.IsGlobalDirection); _RagdollJointData.ForceRandomDirection = EditorGUILayout.Toggle(new GUIContent("Create force at random direction?", ""), _RagdollJointData.ForceRandomDirection); if (_RagdollJointData.ForceRandomDirection) { _RagdollJointData.ForceRandomDirectionFrom = EditorGUILayout.Vector3Field("Force random direction from:", _RagdollJointData.ForceRandomDirectionFrom); _RagdollJointData.ForceRandomDirectionTo = EditorGUILayout.Vector3Field("Force random direction to:", _RagdollJointData.ForceRandomDirectionTo); } else { _RagdollJointData.ForceDirection = EditorGUILayout.Vector3Field("Force direction:", _RagdollJointData.ForceDirection); } } _RagdollJointData.RandomRotation = EditorGUILayout.Toggle(new GUIContent("Randomize rotation?", ""), _RagdollJointData.RandomRotation); if (GUILayout.Button("Delete RagdollJointData:" + _RagdollJointData.Name)) { IList <RagdollJointData> l = selectedRagdoll.RagdollJointDataArray.ToList <RagdollJointData> (); l.Remove(_RagdollJointData); selectedRagdoll.RagdollJointDataArray = l.ToArray <RagdollJointData> (); } } } }
public virtual void EditRagdollJointData() { EnableEditRagdollData = EditorGUILayout.BeginToggleGroup ("---Edit RagdollJointData", EnableEditRagdollData); if (EnableEditRagdollData) { if (GUILayout.Button ("Add RagdollJointData")) { RagdollJointData RagdollJointData = new RagdollJointData (); IList<RagdollJointData> l = selectedRagdoll.RagdollJointDataArray.ToList<RagdollJointData> (); l.Add (RagdollJointData); selectedRagdoll.RagdollJointDataArray = l.ToArray<RagdollJointData> (); } for (int i = 0; i < selectedRagdoll.RagdollJointDataArray.Length; i++) { RagdollJointData _RagdollJointData = selectedRagdoll.RagdollJointDataArray[i]; EditorGUILayout.LabelField("---------------- Edit RagdollJointData:" + _RagdollJointData.Name + "--------"); _RagdollJointData.Name = EditorGUILayout.TextField (new GUIContent ("Name", ""), _RagdollJointData.Name); _RagdollJointData.Joint = (Rigidbody)EditorGUILayout.ObjectField(new GUIContent("Joint","关节对象"), _RagdollJointData.Joint, typeof(Rigidbody)); _RagdollJointData.JointGameObjectInitialActive = EditorGUILayout.Toggle(new GUIContent("Initial active:","If false, the gameobject will be deactivate when ragdoll created"), _RagdollJointData.JointGameObjectInitialActive); _RagdollJointData.Detach = EditorGUILayout.Toggle(new GUIContent ("Detach joint?", "Detach this joint object from parent?"), _RagdollJointData.Detach); _RagdollJointData.SelfcontrolDestruction = EditorGUILayout.Toggle(new GUIContent ("Self control destruction?", "The joint control its destruction itself?"), _RagdollJointData.SelfcontrolDestruction); if(_RagdollJointData.SelfcontrolDestruction) { _RagdollJointData.SelfDestructionTime = EditorGUILayout.FloatField("Self destuction time:", _RagdollJointData.SelfDestructionTime); } _RagdollJointData.DestoryJoint = EditorGUILayout.Toggle(new GUIContent ("Destory joint?", "销毁ChracterJoint组件?"), _RagdollJointData.DestoryJoint); _RagdollJointData.CreateForce = EditorGUILayout.Toggle(new GUIContent ("Create force?", "Use force?"), _RagdollJointData.CreateForce); if(_RagdollJointData.CreateForce) { _RagdollJointData.forceMode = (ForceMode)EditorGUILayout.EnumPopup("Force mode:" , _RagdollJointData.forceMode); _RagdollJointData.CreateForceDelay = EditorGUILayout.FloatField(new GUIContent("Create force delay",""), _RagdollJointData.CreateForceDelay); _RagdollJointData.MinForceMagnitude = EditorGUILayout.FloatField(new GUIContent("Min force:",""), _RagdollJointData.MinForceMagnitude); _RagdollJointData.MaxForceMagnitude = EditorGUILayout.FloatField(new GUIContent("Max force:",""), _RagdollJointData.MaxForceMagnitude); _RagdollJointData.IsGlobalDirection = EditorGUILayout.Toggle(new GUIContent ("Global direction?", ""), _RagdollJointData.IsGlobalDirection); _RagdollJointData.ForceRandomDirection = EditorGUILayout.Toggle(new GUIContent ("Create force at random direction?", ""), _RagdollJointData.ForceRandomDirection); if(_RagdollJointData.ForceRandomDirection) { _RagdollJointData.ForceRandomDirectionFrom = EditorGUILayout.Vector3Field("Force random direction from:",_RagdollJointData.ForceRandomDirectionFrom); _RagdollJointData.ForceRandomDirectionTo = EditorGUILayout.Vector3Field("Force random direction to:",_RagdollJointData.ForceRandomDirectionTo); } else { _RagdollJointData.ForceDirection = EditorGUILayout.Vector3Field("Force direction:",_RagdollJointData.ForceDirection); } } _RagdollJointData.RandomRotation = EditorGUILayout.Toggle(new GUIContent ("Randomize rotation?", ""), _RagdollJointData.RandomRotation); if (GUILayout.Button ("Delete RagdollJointData:" + _RagdollJointData.Name)) { IList<RagdollJointData> l = selectedRagdoll.RagdollJointDataArray.ToList<RagdollJointData> (); l.Remove (_RagdollJointData); selectedRagdoll.RagdollJointDataArray = l.ToArray<RagdollJointData> (); } } } }
/// <summary> /// Gets a clone of this RagdollJointData. The Joint object is null and need to be assigned other way. /// </summary> public RagdollJointData GetClone() { RagdollJointData ragdollJointData = new RagdollJointData (); ragdollJointData.Name = this.Name; ragdollJointData.CreateForce = this.CreateForce; ragdollJointData.Detach = this.Detach; ragdollJointData.DestoryJoint = this.DestoryJoint; ragdollJointData.CreateForceDelay = this.CreateForceDelay; ragdollJointData.ForceRandomDirection = this.ForceRandomDirection; ragdollJointData.IsGlobalDirection = this.IsGlobalDirection; ragdollJointData.ForceDirection = this.ForceDirection; ragdollJointData.ForceRandomDirectionFrom = this.ForceRandomDirectionFrom; ragdollJointData.ForceRandomDirectionTo = this.ForceRandomDirectionTo; ragdollJointData.MinForceMagnitude = this.MinForceMagnitude; ragdollJointData.MaxForceMagnitude = this.MaxForceMagnitude; ragdollJointData.SelfcontrolDestruction = this.SelfcontrolDestruction; ragdollJointData.SelfDestructionTime = this.SelfDestructionTime; ragdollJointData.JointGameObjectInitialActive = this.JointGameObjectInitialActive; ragdollJointData.TurnOnRigibody = this.TurnOnRigibody; return ragdollJointData; }