//省略 前缀 卸载AB包 public static void AwayPrefixUnloadBundle(this ResourcesComponent resourcesComponent, string assetBundleName) { assetBundleName = assetBundleName.ToLower(); if (ResourcesComponent.bundlesNameDictionary.ContainsKey(assetBundleName)) { resourcesComponent.UnloadBundle(ResourcesComponent.bundlesNameDictionary[assetBundleName] + "/" + assetBundleName); } else { resourcesComponent.UnloadBundle(assetBundleName); } }
//加载声音 private async Task <SoundData> LoadSound(string soundName) { ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>(); if (!abSounds.ContainsKey(soundName) || abSounds[soundName] == null) { await resourcesComponent.LoadBundleAsync("sound.unity3d"); abSounds.Add(soundName, GameObject.Instantiate((GameObject)resourcesComponent.GetAsset("sound.unity3d", soundName)).GetComponent <SoundData>()); resourcesComponent.UnloadBundle("sound.unity3d"); } return(abSounds[soundName]); }
public static GameObject Create(Vector3 pos) { // 创建爆炸效果 ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>(); resourcesComponent.LoadBundle(AssetBundleName.Unit); GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset(AssetBundleName.Unit, PrefabName.Unit); resourcesComponent.UnloadBundle(AssetBundleName.Unit); GameObject explosion = bundleGameObject.Get <GameObject>(PrefabName.BulletBoomEffect); GameObject explosionGameObject = resourcesComponent.NewObj(PrefabType.BulletBoom, explosion); explosionGameObject.SetActive(false); explosionGameObject.transform.position = pos; // 创建爆炸音效 AudioClip audio = bundleGameObject.Get <AudioClip>(PrefabName.BulletBoomAudio); AudioSource audioSource = explosionGameObject.GetComponent <AudioSource>(); if (audioSource == null) { audioSource = explosionGameObject.AddComponent <AudioSource>(); audioSource.spatialBlend = 1; audioSource.loop = false; audioSource.clip = audio; audioSource.playOnAwake = true; audioSource.volume = GameSettingInfo.AudioVolume(); } explosionGameObject.SetActive(true); FairyGUI.Timers.inst.Add(7f, 1, (_) => { resourcesComponent.RecycleObj(PrefabType.BulletBoom, explosionGameObject); }); return(explosionGameObject); }
public static GameObject CreateTankBoomEffect(Tank tank) { ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>(); resourcesComponent.LoadBundle(AssetBundleName.Unit); GameObject unit = (GameObject)resourcesComponent.GetAsset(AssetBundleName.Unit, PrefabName.Unit); resourcesComponent.UnloadBundle(AssetBundleName.Unit); GameObject boomPrefab = unit.Get <GameObject>(PrefabName.TankBoomEffect); UnityEngine.GameObject boomEffect = resourcesComponent.NewObj(PrefabType.TankBoom, boomPrefab); boomEffect.transform.SetParent(tank.GameObject.FindComponentInChildren <Transform>("BoomEffect"), false); boomEffect.transform.localPosition = Vector3.zero; boomEffect.transform.localScale = Vector3.one * 10; return(boomEffect); }