public virtual void StartRagdoll() { foreach (EffectData effectData in EffectData) { GlobalBloodEffectDecalSystem.CreateEffect(effectData); } foreach (DecalData decalData in DecalData) { GlobalBloodEffectDecalSystem.CreateBloodDecal(RagdollCenter.position, decalData); } foreach (RagdollJointData JointData in RagdollJointDataArray) { if (JointData.Detach) { JointData.Joint.transform.parent = null; } if (JointData.DestoryJoint) { CharacterJoint joint = JointData.Joint.GetComponent <CharacterJoint> (); Destroy(joint); } if (JointData.JointGameObjectInitialActive == false) { JointData.Joint.gameObject.SetActive(false); } if (JointData.RandomRotation) { JointData.Joint.gameObject.transform.rotation = Random.rotation; } if (JointData.TurnOnRigibody) { JointData.Joint.isKinematic = false; JointData.Joint.useGravity = true; } if (JointData.CreateForce == false) { continue; } else { StartCoroutine("AddForce", JointData); } } if (DestroyAfterStartRagdoll == true && AutoDestory == true) { Invoke("DestoryRagdoll", LifeTime); } foreach (GameEvent e in StartRagdollEvents) { LevelManager.OnGameEvent(e, this); } }
public virtual IEnumerator Die(DamageParameter DamageParameter) { //Basic death processing. unit.IsDead = true; //stop and remove AI foreach (AI _ai in GetComponents <AI>()) { _ai.StopAI(); Destroy(_ai); } //stop and remove navigator foreach (Navigator nav in GetComponents <Navigator>()) { nav.StopAllCoroutines(); Destroy(nav); } if (animation != null) { animation.Stop(); } //Handle DeathData: //1. Find the suitable DeathData: DeathData deathData = null; if (unit.DeathDataDict.ContainsKey(DamageParameter.damageForm)) { IList <DeathData> DeathDataList = unit.DeathDataDict[DamageParameter.damageForm]; deathData = Util.RandomFromList(DeathDataList); } else { //if no DeathData matched to the DamageForm in DamageParameter,use the DamageForm.Common deathData = Util.RandomFromList <DeathData>(unit.DeathDataDict[DamageForm.Common]); } if (deathData.DestoryCharacterController && controller != null) { controller.enabled = false; } //Create effect data if (deathData.EffectDataName != null && deathData.EffectDataName.Length > 0) { foreach (string effectDataName in deathData.EffectDataName) { EffectData effectData = unit.EffectDataDict[effectDataName]; GlobalBloodEffectDecalSystem.CreateEffect(effectData); } } //Create blood decal: if (deathData.DecalDataName != null && deathData.DecalDataName.Length > 0) { foreach (string decalName in deathData.DecalDataName) { DecalData DecalData = unit.DecalDataDict[decalName]; GlobalBloodEffectDecalSystem.CreateBloodDecal(transform.position + controller.center, DecalData); } } //Play audio: if (deathData.AudioDataName != null && deathData.AudioDataName.Length > 0) { foreach (string audioDataName in deathData.AudioDataName) { GetComponent <AudioController>()._PlayAudio(audioDataName); } } if (deathData.UseDieReplacement) { if (deathData.ReplaceAfterAnimationFinish) { animation.CrossFade(deathData.AnimationName); yield return(new WaitForSeconds(animation[deathData.AnimationName].length)); } else if (deathData.ReplaceAfterSeconds > 0) { animation.CrossFade(deathData.AnimationName); yield return(new WaitForSeconds(deathData.ReplaceAfterSeconds)); } GameObject DieReplacement = (GameObject)Object.Instantiate(deathData.DieReplacement, transform.position, transform.rotation); if (deathData.CopyChildrenTransformToDieReplacement) { Util.CopyTransform(transform, DieReplacement.transform); } //if deathData.ReplaceOldObjectInSpawnedList is true, means this object has a replacement in SpawnedList. if (deathData.ReplaceOldObjectInSpawnedList) { // the Spawner must not be null, when ReplaceOldObjectInSpawnedList is true if (unit.Spawner != null) { unit.Spawner.ReplaceSpawnedWithNewObject(this.gameObject, DieReplacement); } else { Debug.LogError(string.Format("Unit:{0} hsa no Spawner", unit.gameObject.name)); } } Destroy(gameObject); } else { animation.Play(deathData.AnimationName); if (deathData.DestoryGameObject) { Destroy(gameObject, deathData.DestoryLagTime); } } }
public virtual IEnumerator ProcessReceiveDamageData(ReceiveDamageData receiveDamageData) { bool CanHaltAI = false; if (this.unit.receiveDamageStatus == UnitReceiveDamageStatus.vulnerableButNotReactToDamage || this.unit.receiveDamageStatus == UnitReceiveDamageStatus.invincible) { CanHaltAI = false; } #region if the unit is defined with ApplyDamageCondition, update the condition data. else { if (this.ApplyDamagerConditionArray != null && ApplyDamagerConditionArray.Length > 0) { foreach (ApplyDamagerCondition applyDamageCondition in ApplyDamagerConditionArray) { if (applyDamageCondition.IsApplyDamageConditionMatch()) { CanHaltAI = true; continue; } } } else { CanHaltAI = true; } } #endregion //Create effect data if (receiveDamageData.EffectDataName != null && receiveDamageData.EffectDataName.Length > 0) { foreach (string effectDataName in receiveDamageData.EffectDataName) { EffectData effectData = unit.EffectDataDict[effectDataName]; GlobalBloodEffectDecalSystem.CreateEffect(effectData); } } //Create blood decal: if (receiveDamageData.DecalDataName != null && receiveDamageData.DecalDataName.Length > 0) { foreach (string decalName in receiveDamageData.DecalDataName) { DecalData DecalData = unit.DecalDataDict[decalName]; GlobalBloodEffectDecalSystem.CreateBloodDecal(transform.position + controller.center, DecalData); } } //Play audio: if (receiveDamageData.AudioDataName != null && receiveDamageData.AudioDataName.Length > 0) { foreach (string audioName in receiveDamageData.AudioDataName) { GetComponent <AudioController>()._PlayAudio(audioName); } } //Halt AI if set true, stop all animation, and play the receive damage animation if (receiveDamageData.HaltAI && CanHaltAI) { animation.Stop(); animation.Rewind(); animation.CrossFade(receiveDamageData.AnimationName); SendMessage("HaltUnit", animation[receiveDamageData.AnimationName].length); yield return(new WaitForSeconds(animation[receiveDamageData.AnimationName].length)); } }