/// <summary> /// 播放实体音效(根据实体的职业) /// </summary> /// <param name="entity"></param> /// <param name="action"></param> public void OnHitYelling(EntityParent entity, int action) { AudioSource ownerSource = entity.audioSource; if (null == ownerSource) { return; } int ownerVocation = (int)entity.Vocation;//主角职业 ActionSoundData data = ActionSoundData.dataMap.FirstOrDefault(t => t.Value.vocation == ownerVocation && t.Value.action == action).Value; if (null == data) { return; } int sum = 0; foreach (var soundMessage in data.sound) { sum += soundMessage.Value; } int soundID = -1; int temp = RandomHelper.GetRandomInt(0, sum); foreach (var soundMessage in data.sound) { if (temp < soundMessage.Value) { soundID = soundMessage.Key; break; } temp -= soundMessage.Value; } if (soundID == -1) { return; } if (entity is EntityMyself) { MyselfLogicPlaySound(ownerSource, soundID); } else { } }
protected static void OnHitYelling(EntityParent entity, int action) { AudioSource ownerSource = entity.audioSource; if (ownerSource == null) { return; } int ownerVocation = (int)entity.vocation; if (entity is EntityMonster) { ownerVocation = (int)((entity as EntityMonster).MonsterData.id); } else if (entity is EntityMercenary) { ownerVocation = (int)((entity as EntityMercenary).MonsterData.id); } else if (entity is EntityDummy) { ownerVocation = (int)((entity as EntityDummy).MonsterData.id); } ActionSoundData data = ActionSoundData.dataMap.FirstOrDefault(t => t.Value.vocation == ownerVocation && t.Value.action == action).Value; if (data == null) { return; } int sum = 0; foreach (var soundMessage in data.sound) { sum += soundMessage.Value; } int soundID = -1; int temp = RandomHelper.GetRandomInt(0, sum); foreach (var soundMessage in data.sound) { if (temp < soundMessage.Value) { soundID = soundMessage.Key; break; } temp -= soundMessage.Value; } if (soundID == -1) { return; } if (entity is EntityMyself) { MyselfLogicPlaySound(ownerSource, soundID); } else { LogicPlaySound(ownerSource, soundID); } }