public void CloneTo(Unit unit) { base.CloneTo(unit as UnitBase); //copy character controller CharacterController cc = unit.gameObject.AddComponent <CharacterController> (); cc.center = this.GetComponent <CharacterController> ().center; cc.radius = this.GetComponent <CharacterController> ().radius; cc.height = this.GetComponent <CharacterController> ().height; //copy animation foreach (AnimationState ani in this.animation) { AnimationClip clip = ani.clip; unit.animation.AddClip(clip, ani.name); } //copy idledata foreach (IdleData idleData in this.IdleData) { IdleData clone = idleData.GetClone(); unit.IdleData = Util.AddToArray <IdleData> (clone, unit.IdleData); } //copy movedata foreach (MoveData moveData in this.MoveData) { MoveData clone = moveData.GetClone(); unit.MoveData = Util.AddToArray <MoveData> (clone, unit.MoveData); } //copy attackdata foreach (AttackData attackData in this.AttackData) { AttackData clone = attackData.GetClone(); unit.AttackData = Util.AddToArray <AttackData> (clone, unit.AttackData); } //copy ReceiveDamageData foreach (ReceiveDamageData receiveDamageData in this.ReceiveDamageData) { ReceiveDamageData clone = receiveDamageData.GetClone(); unit.ReceiveDamageData = Util.AddToArray <ReceiveDamageData> (clone, unit.ReceiveDamageData); } //copy DeathData foreach (DeathData deathData in this.DeathData) { DeathData clone = deathData.GetClone(); unit.DeathData = Util.AddToArray <DeathData> (clone, unit.DeathData); } //copy AudioData foreach (AudioData audioData in this.AudioData) { AudioData clone = audioData.GetClone(); unit.AudioData = Util.AddToArray <AudioData> (clone, unit.AudioData); } //copy DecalData foreach (DecalData decalData in this.DecalData) { DecalData clone = decalData.GetClone(); unit.DecalData = Util.AddToArray <DecalData> (clone, unit.DecalData); } }
public ReceiveDamageData GetClone() { ReceiveDamageData clone = new ReceiveDamageData(); base.CloneBasic(clone); clone.ApplicableDamageForm = Util.CloneArray <DamageForm>(this.ApplicableDamageForm); clone.HaltAI = this.HaltAI; clone.EffectDataName = Util.CloneArray <string>(this.EffectDataName); clone.DecalDataName = Util.CloneArray <string>(this.DecalDataName); return(clone); }
/// <summary> /// Receives a damageParam, and performs consequential behavior - play particle, play animation..etc. /// </summary> public virtual IEnumerator DoDamage(DamageParameter damageParam) { #region Look for the suitable ReceiveDamageData //if there is no receive damage defined, quit now! if (this.unit.ReceiveDamageData.Length == 0) { yield break; } foreach (ApplyDamagerCondition applyDamageCondition in ApplyDamagerConditionArray) { applyDamageCondition.UpdateDamageInfo(damageParam); } //Get ReceiveDamageData ReceiveDamageData receiveDamageData = null; if (unit.ReceiveDamageDataDict.ContainsKey(damageParam.damageForm)) { if (unit.ReceiveDamageDataDict[damageParam.damageForm].Count == 1) { receiveDamageData = unit.ReceiveDamageDataDict[damageParam.damageForm][0]; } else //if more than one matched receive damage data is found, randomly choose one. { int RandomIndex = Random.Range(0, unit.ReceiveDamageDataDict[damageParam.damageForm].Count); receiveDamageData = unit.ReceiveDamageDataDict[damageParam.damageForm][RandomIndex]; } } //If ReceiveDamageDataDict[DamageForm.Common] = null or Count ==0, will have error! //So make sure you have assign a Common receive damage data! else { receiveDamageData = unit.ReceiveDamageDataDict[DamageForm.Common][0]; } #endregion //play receive damage animation yield return(StartCoroutine("ProcessReceiveDamageData", receiveDamageData)); }
public ReceiveDamageData GetClone() { ReceiveDamageData clone = new ReceiveDamageData(); base.CloneBasic(clone); clone.ApplicableDamageForm = Util.CloneArray<DamageForm>( this.ApplicableDamageForm ); clone.HaltAI = this.HaltAI; clone.EffectDataName = Util.CloneArray<string>(this.EffectDataName); clone.DecalDataName = Util.CloneArray<string>(this.DecalDataName); return clone; }
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)); } }
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); } }