Skip to content

Instantly share code, notes, and snippets.

@tinnvec
Last active January 6, 2017 14:39
Show Gist options
  • Select an option

  • Save tinnvec/9320e0f33cb55a5a56fcba526ec5c0cd to your computer and use it in GitHub Desktop.

Select an option

Save tinnvec/9320e0f33cb55a5a56fcba526ec5c0cd to your computer and use it in GitHub Desktop.
Creates json of cardid to sound file names and delays
#!/usr/bin/env python3.4
import re
import json
import unitypack
from unitypack.environment import UnityEnvironment
def loadUnityBundle(filename, env):
f = open(filename, "rb")
ret = unitypack.load(f, env)
f.close()
return ret
cardSounds = {}
spellSounds = {}
def addCardSound(cardid, path, sndType):
path = path.lower()
if spellSounds.get(path):
cardSounds[cardid][sndType].append(spellSounds[path])
env = UnityEnvironment()
bSpells = loadUnityBundle("spells0.unity3d", env)
bCards = loadUnityBundle("cards0.unity3d", env)
loadUnityBundle("sounds0.unity3d", env)
loadUnityBundle("shared.unity3d", env)
for asset in bSpells.assets:
for id, obj in asset.objects.items():
try:
if not obj.type == "AssetBundle":
continue
o = obj.read()
for path, ob in o["m_Container"]:
asset = ob["asset"].resolve()
component = asset.component[1][1].resolve()
if not hasattr(component, "get"):
continue
if not component.get("m_CardSoundData"):
continue
soundData = component["m_CardSoundData"]
if not soundData.get("m_AudioSource"):
continue
delaySec = soundData["m_DelaySec"]
audioSource = soundData["m_AudioSource"].resolve()
if not audioSource._obj.get("m_audioClip"):
continue
audioClip = audioSource._obj["m_audioClip"].resolve()
path = re.sub("\.prefab$", "", path)
spellSounds[path] = { "name": audioClip.name, "delay": delaySec }
except KeyError:
continue
for asset in bCards.assets:
for id, obj in asset.objects.items():
if obj.type == "GameObject":
o = obj.read()
cardid = o.name
carddef = o.component[1][1].resolve()
attackSounds = carddef["m_AttackEffectDef"]["m_SoundSpellPaths"]
deathSounds = carddef["m_DeathEffectDef"]["m_SoundSpellPaths"]
playSounds = carddef["m_PlayEffectDef"]["m_SoundSpellPaths"]
triggerSounds = carddef["m_TriggerEffectDefs"]
if len(triggerSounds) > 0:
triggerSounds = triggerSounds[0]["m_SoundSpellPaths"]
if len(attackSounds) > 0 or len(deathSounds) > 0 or len(playSounds) > 0 or len(triggerSounds) > 0:
cardSounds[cardid] = { "attack": [], "death": [], "play": [], "trigger": [] }
for path in attackSounds:
addCardSound(cardid, path, "attack")
for path in deathSounds:
addCardSound(cardid, path, "death")
for path in playSounds:
addCardSound(cardid, path, "play")
for path in triggerSounds:
addCardSound(cardid, path, "trigger")
fo = open("cardSounds.json", "w")
fo.write(json.dumps(cardSounds))
fo.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment