// Start is called before the first frame update void Start() { PushableScript = GetComponent <PushableScript>(); PushableScript.OnPushing += OnPushing; TileMovingObjectScript.MoveableMoving += TileMovingObjectScript_MoveableMoving; MoveScript = GetComponent <TileMovingObjectScript>(); MoveScript.CanMoveOverWorldReservedTiles = true; soundEffects = GetComponent <SoundLoader>(); }
void Awake() { Instance = this; foreach (SoundOverride so in OverrideSounds) { Sounds.Add(so.SoundName, so.Sound); } }
public void PlayShootAnimation() { if (animIdx < weaponTypes [weaponIdx].attackSprites.Length) { SetWeaponSprite(weaponTypes [weaponIdx].attackSprites [animIdx]); // Muzzle if (animIdx < weaponTypes [weaponIdx].muzzleSprites.Length && !string.IsNullOrEmpty(weaponTypes [weaponIdx].muzzleSprites [animIdx])) { Texture t = TextureLoader.Instance.GetSpriteTexture(weaponTypes [weaponIdx].muzzleSprites [animIdx]); weaponTypes [weaponIdx].muzzleImage.texture = t; weaponTypes [weaponIdx].muzzleImage.gameObject.SetActive(true); } else if (weaponTypes[weaponIdx].muzzleImage != null) { weaponTypes [weaponIdx].muzzleImage.gameObject.SetActive(false); } // Audio if (animIdx < weaponTypes [weaponIdx].audioFrames.Length) { if (!string.IsNullOrEmpty(weaponTypes [weaponIdx].audioFrames [animIdx])) { AudioClip clip = SoundLoader.LoadSound(weaponTypes [weaponIdx].audioFrames [animIdx]); audioSource.PlayOneShot(clip); } } if (animIdx == weaponTypes [weaponIdx].attackIdx) { if (weaponTypes [weaponIdx].ammoType != AmmoType.UNLM) { SetAmmo(weaponTypes[weaponIdx].name, GetAmmo(weaponTypes[weaponIdx].name) - 1); guiManager.SetAmmo(GetAmmo(weaponTypes[weaponIdx].name)); } switch (weaponTypes[weaponIdx].attackType) { case AttackType.MeleeOneShot: TryHitRaycast(1.5f, weaponTypes[weaponIdx].damage); break; case AttackType.RaycastOneShot: TryHitRaycast(Mathf.Infinity, weaponTypes[weaponIdx].damage); break; } } animIdx++; Invoke("PlayShootAnimation", AnimationUpdateTick); } else { animIdx = 0; SetWeaponSprite(weaponTypes [weaponIdx].idleSprite); } }
//////////////// private void UpdateStyleSlider(int sndType) { switch (sndType) { case 2: this.StyleSliderElem.SetRange(0f, (float)SoundLoader.SoundCount(SoundType.Item)); //125f break; case 3: this.StyleSliderElem.SetRange(1f, (float)SoundLoader.SoundCount(SoundType.NPCHit)); //57f break; case 4: this.StyleSliderElem.SetRange(0f, (float)SoundLoader.SoundCount(SoundType.NPCKilled)); //62f break; case 14: this.StyleSliderElem.SetRange(0f, 0f); //Main.soundInstanceZombie break; case 15: this.StyleSliderElem.SetRange(0f, (float)Main.soundInstanceRoar.Length - 1f); //2f break; case 19: this.StyleSliderElem.SetRange(0f, (float)Main.soundInstanceSplash.Length - 1f); //1f break; case 28: this.StyleSliderElem.SetRange(0f, (float)Main.soundInstanceMech.Length - 1f); //0f break; case 29: case 32: this.StyleSliderElem.SetRange(0f, (float)Main.soundInstanceZombie.Length - 1f); //105f break; case 34: case 35: this.StyleSliderElem.SetRange(0f, 50f); break; case 36: case 39: this.StyleSliderElem.SetRange(0f, (float)Main.soundInstanceDrip.Length - 1f); //2f break; case 50: this.StyleSliderElem.SetRange(0f, (float)SoundLoader.SoundCount(SoundType.Custom)); break; default: this.StyleSliderElem.SetRange(-1f, -1f); break; } }
void Start() { Sprite = GetComponent <Image>(); Debug.Assert(ImageCheck != null); Debug.Assert(Icon1 != null); Debug.Assert(Icon2 != null); Debug.Assert(Txt != null); HoverSound = SoundLoader.LoadSound("ui_menumove"); }
public override void Impact() { foreach (var target in GetImpactArea().SelectMany(x => x.Contents)) { var actions = new List <ActionWrapper>(); actions.Add(new ActionEnemyHit(Curio, target, SoundLoader.AddSound("content/sound/sinister.wav")).InSlot(ActionSlot.Active)); actions.Apply(target); } Curio.Destroy(); }
public void PlayGuardSound() { if (guardType == blockingType.reflect) { SoundEngine.PlaySound(SoundLoader.GetLegacySoundSlot(Mod, "Sounds/keybladeBlocking")); } else if (guardType == blockingType.normal || guardType == blockingType.reversal) { SoundEngine.PlaySound(SoundID.Item1.SoundId, x: (int)Player.Center.X, y: (int)Player.Center.Y, volumeScale: 3); } }
// Start is called before the first frame update void Start() { BlockComponent = GetComponent <DataBlockComponent>(); TileMovingObjectScript.MoveableMoved += Jetstream_SpongebobPlayerPositionChanged; var child = Render = transform.GetChild(0).gameObject; var component = child.AddComponent <DataBlockComponent>(); component.DataBlock = BlockComponent.DataBlock; child.AddComponent <TextureLoader>(); soundEffects = GetComponent <SoundLoader>(); soundEffects.ExclusiveSoundMode = true; }
/// <summary> /// 清除缓存 /// </summary> public void ClearCache() { foreach (var item in this.mySoundClipCache) { string audioBundlePath = SoundLoader.GetAudioAssetPath(item.Key); UnloadAsset(audioBundlePath); if (item.Value != null) { GameObject.Destroy(item.Value); } cullingActive = false; } this.mySoundClipCache.Clear(); }
// Update is called once per frame void Update() { if (MovementScript == null) { return; } if (!MovementScript.IsMoving && CanMove) { bool blockMotion = false; switch (Direction) { case StinkyFile.SRotation.NORTH: blockMotion = !MovementScript.WalkToTile(MovementScript.TileX, MovementScript.TileY - 1); break; case StinkyFile.SRotation.SOUTH: blockMotion = !MovementScript.WalkToTile(MovementScript.TileX, MovementScript.TileY + 1); break; case StinkyFile.SRotation.EAST: blockMotion = !MovementScript.WalkToTile(MovementScript.TileX + 1, MovementScript.TileY); break; case StinkyFile.SRotation.WEST: blockMotion = !MovementScript.WalkToTile(MovementScript.TileX - 1, MovementScript.TileY); break; } if (blockMotion) { IsDestoryed = true; CanMove = false; GetComponent <Renderer>().enabled = false; // make invisible } } if (timeSinceDestroyed > timeUntilDelete) { Destroy(gameObject); } else if (IsDestoryed) { if (!effectPlayed) { particleSystem?.Play(); SoundLoader.Play("teleport.wav", true); effectPlayed = true; } timeSinceDestroyed += Time.deltaTime; } }
void Start() { RawImage image = GetComponent <RawImage>(); Debug.Assert(image != null); MapMat = image.materialForRendering; Debug.Assert(MapMat != null); CPSelectSound = SoundLoader.LoadSound("ui_menumove"); // TODO: Load texture from "MapTexture" property specified in PhxCommandpost class Texture2D cpTexture = TextureLoader.Instance.ImportUITexture("hud_flag_icon"); MapMat.SetTexture("_CPTex", cpTexture); if (SCENE.MapTexture != null) { Debug.Assert(SCENE.MapTexture.width == SCENE.MapTexture.height); MapMat.SetTexture("_MapTex", SCENE.MapTexture); } RectTransform rt = transform as RectTransform; MapMat.SetVector("_SpriteSize", new Vector4(rt.sizeDelta.x, rt.sizeDelta.y)); if (Mode == PhxUIMapMode.StaticClickable) { for (int i = 0; i < CPButtons.Length; ++i) { CPButtons[i] = Instantiate(CPButtonPrefab, transform); CPButtons[i].gameObject.SetActive(false); RectTransform t = CPButtons[i].transform as RectTransform; t.sizeDelta = new Vector2(cpTexture.width, cpTexture.height); int idx = i; Button btn = CPButtons[i].GetComponent <Button>(); btn.onClick.AddListener(() => { PhxCommandpost cp = CommandPosts[idx]; if (cp.Team == MATCH.Player.Team) { SelectCP(idx); } }); } } }
private void Hit(ICurio target) { var world = Origin.GetWorld(); var actions = new List <ActionWrapper>(); actions.Add(new ActionEnemyHit(Origin, target, SoundLoader.AddSound("content/sound/stab.wav")).InSlot(ActionSlot.Active)); actions.Apply(target); /*target.GetFlashHelper()?.AddFlash(ColorMatrix.Flat(Color.White), 20); * target.GetShakeHelper()?.AddShakeRandom(3, LerpHelper.QuadraticOut, 30); * new TimeFade(world, 0, LerpHelper.QuadraticIn, 50); * var alive = target.GetBehavior<BehaviorAlive>(); * if (alive != null) * { * alive.TakeDamage(1); * }*/ }
public override void Init() { Transform hpHolo = transform.Find(string.Format("{0}/hp_hologram", C.Name)); if (hpHolo != null) { GameObject holoPrefab = Resources.Load <GameObject>("cp_holo"); GameObject holo = Instantiate(holoPrefab, hpHolo); HoloRay = holo.GetComponent <LineRenderer>(); Light = holo.GetComponentInChildren <HDAdditionalLightData>(); HoloWidthStart = HoloRay.startWidth; HoloWidthEnd = HoloRay.endWidth; HoloAlpha = HoloRay.material.GetColor("_UnlitColor").a; LightIntensity = Light.intensity; } AudioAmbient = gameObject.AddComponent <AudioSource>(); AudioAmbient.spatialBlend = 1.0f; AudioAmbient.clip = SoundLoader.LoadSound("com_blg_commandpost2"); AudioAmbient.pitch = 1.0f; AudioAmbient.volume = 0.5f; AudioAmbient.rolloffMode = AudioRolloffMode.Linear; AudioAmbient.minDistance = 2.0f; AudioAmbient.maxDistance = 30.0f; AudioAmbient.Play(); AudioCapture = gameObject.AddComponent <AudioSource>(); AudioCapture.spatialBlend = 1.0f; AudioCapture.loop = true; AudioCapture.pitch = 1.0f; AudioCapture.volume = 0.8f; AudioCapture.rolloffMode = AudioRolloffMode.Linear; AudioCapture.minDistance = 2.0f; AudioCapture.maxDistance = 30.0f; AudioAction = gameObject.AddComponent <AudioSource>(); AudioAction.spatialBlend = 1.0f; AudioAction.loop = false; AudioAction.pitch = 1.1f; AudioAction.volume = 0.5f; AudioAction.rolloffMode = AudioRolloffMode.Linear; AudioAction.minDistance = 2.0f; AudioAction.maxDistance = 30.0f; }
public void Tick(SceneGame scene) { var exploded = ExplosionTime.Done; var active = Origin.GetActionHolder(ActionSlot.Active); var passive = Origin.GetActionHolder(ActionSlot.Passive); ExplosionTime += scene.TimeModCurrent; if (ExplosionTime.Done) { if (!exploded) { SkillUtil.CreateSpatter(scene, Target.GetVisualTarget(), 7, Vector2.Zero, 2, Random); new TimeFade(scene, 0.05f, LerpHelper.ExponentialIn, 40); for (float angle = 0; angle <= MathHelper.TwoPi; angle += MathHelper.TwoPi * 0.02f) { var particle = new ExplosionParticle(scene, SpriteLoader.Instance.AddSprite("content/effect_explosion"), Target.GetVisualTarget() + Util.AngleToVector(angle) * 8, Random.Next(5, 15)) { Angle = angle + Random.NextFloat(-0.3f, +0.3f), Color = Color.White, DrawPass = DrawPass.EffectAdditive, }; particle.Size.Set(Random.NextFloat(1.0f, 1.5f)); } var actions = new List <ActionWrapper>(); actions.Add(new ActionGib(Origin, Target, Score, SoundLoader.AddSound("content/sound/big_splat.wav")).InSlot(ActionSlot.Active)); actions.Apply(Target); var actionsOrigin = new List <ActionWrapper>() { new ActionKeepMoving(Origin).InSlot(ActionSlot.Active), }; actionsOrigin.Apply(Origin); } Time += scene.TimeModCurrent; } else { active.CurrentActions.RemoveAll(x => x is ActionKeepMoving); } }
void Start() { Debug.Assert(Left != null); Debug.Assert(Center != null); Debug.Assert(Right != null); if (!string.IsNullOrEmpty(LocalizePath)) { Text.text = ENV.GetLocalized(LocalizePath); } Left.texture = TextureLoader.Instance.ImportUITexture("bf2_buttons_botleft"); Center.texture = TextureLoader.Instance.ImportUITexture("bf2_buttons_items_center"); Right.texture = TextureLoader.Instance.ImportUITexture("bf2_buttons_botright"); HoverSound = SoundLoader.LoadSound("ui_menumove"); ClickSound = SoundLoader.LoadSound("ui_planetzoom"); }
public override void Kill(int timeLeft) { Main.PlaySound(SoundLoader.customSoundType, projectile.position, SoundLoader.GetSoundSlot(SoundType.Custom, "Sounds/Custom/Wind2")); for (int i = 0; i < 9; i++) { } { if (Main.rand.Next(3) == 0) { Dust.NewDust(projectile.position, projectile.width, projectile.height, mod.DustType("ShortSparkle"), projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f); } else if (Main.rand.Next(3) == 0) { Dust.NewDust(projectile.position, projectile.width, projectile.height, DustID.AncientLight, projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f); } } Projectile.NewProjectile(projectile.position.X + projectile.velocity.X, projectile.position.Y + projectile.velocity.Y, projectile.velocity.X * 0.001f, 0, mod.ProjectileType("WindFieldBlast"), projectile.damage / 2, projectile.knockBack / 3, projectile.owner); }
public void TryUse() { Ray ray = new Ray(transform.position, weaponManager.transform.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit, 2, -1)) { PokeableLinedef lc = hit.collider.gameObject.GetComponent <PokeableLinedef> (); if (lc != null) { lc.Poke(gameObject); } else { oofAudio.PlayOneShot(SoundLoader.LoadSound("DSOOF")); } } }
private static void SoundLoaderPatch(On.SoundLoader.orig_LoadSounds orig, SoundLoader self) { orig(self); Stream manifestResourceStream; manifestResourceStream = typeof(Main).Assembly.GetManifestResourceStream("PrimitiveArmory.resources.sfx.Sounds.txt"); byte[] array = new byte[manifestResourceStream.Length]; manifestResourceStream.Read(array, 0, (int)manifestResourceStream.Length); string[] list = Regex.Split(System.Text.Encoding.Default.GetString(array, 0, (int)manifestResourceStream.Length), "\n"); foreach (string str in list) { Debug.Log(str); } }
public static void KillAllPlayers() { var targetPlayer = GameObject.Find("Spongebob"); if (targetPlayer != null) { var animator = targetPlayer.GetComponentInChildren <Animator>(); animator.enabled = true; animator.Play("Die"); } targetPlayer = GameObject.Find("Patrick"); if (targetPlayer != null) { var animator = targetPlayer.GetComponentInChildren <Animator>(); animator.enabled = true; animator.Play("Die"); } SoundLoader.Play("sb-death.wav", true); dying = true; }
/// <summary> /// 初始化 /// </summary> protected virtual void Init() { //音频扬声器模式; //API修改(AudioSettings.driverCapabilities;在IOS上无声音) (修改前:AudioSettings.speakerMode = AudioSettings.driverCapabilities) by邓成 AudioConfiguration confuguration = AudioSettings.GetConfiguration(); confuguration.speakerMode = AudioSettings.driverCapabilities; AudioSettings.Reset(confuguration); //初始化播放源组件 if (mySoundLoader != null) { GameObject.DestroyImmediate(mySoundLoader); mySoundLoader = null; } GameObject loaderObj = new GameObject("SoundLoader"); loaderObj.transform.parent = GameCenter.instance.transform; loaderObj.transform.localPosition = Vector3.zero; loaderObj.transform.localEulerAngles = Vector3.zero; loaderObj.transform.localScale = Vector3.one; mySoundLoader = loaderObj.AddComponent <SoundLoader>(); if (mySoundPlayer != null) { GameObject.DestroyImmediate(mySoundPlayer); mySoundPlayer = null; } GameObject playerObj = new GameObject("SoundPlayer"); playerObj.transform.parent = GameCenter.instance.transform; playerObj.transform.localPosition = Vector3.zero; playerObj.transform.localEulerAngles = Vector3.zero; playerObj.transform.localScale = Vector3.one; mySoundPlayer = playerObj.AddComponent <SoundPlayer>(); mySoundPlayer.Init(mySoundLoader); preLoadSound(); GameCenter.systemSettingMng.OnUpdate += OnUpdateSystemSettings; }
// Start is called before the first frame update void Start() { Debug.Assert(TopBarLeft != null); Debug.Assert(TopBarCenter != null); Debug.Assert(TopBarRight != null); Debug.Assert(HeaderText != null); Debug.Assert(DetailBox != null); Debug.Assert(DetailText != null); TopBarLeft.texture = TextureLoader.Instance.ImportUITexture("bf2_buttons_topleft"); TopBarCenter.texture = TextureLoader.Instance.ImportUITexture("bf2_buttons_title_center"); TopBarRight.texture = TextureLoader.Instance.ImportUITexture("bf2_buttons_topright"); // kinda hacky, since Unity doesn't allow to change a sprites texture on the fly, but well... Texture2D boxTexSrc = TextureLoader.Instance.ImportUITexture("border_3_pieces"); Texture2D boxTexDst = DetailBox.sprite.texture; boxTexDst.SetPixels32(boxTexSrc.GetPixels32()); boxTexDst.Apply(); Sound = SoundLoader.LoadSound("ui_menumove"); }
static public void Main() { AllocConsole(); ILogger logger = new NLogLoggerProvider().CreateLogger(nameof(DropAssets)); using (_game = new GlyphGame(logger, x => _rawContentLibrary = new RawContentLibrary(x, logger, ContentPath, CachePath))) { _form = (Form)Control.FromHandle(_game.Window.Handle); _form.AllowDrop = true; _form.DragOver += OnDragOver; _form.DragDrop += OnDragDrop; GlyphEngine engine = _game.Engine; GlyphObject root = engine.Root; root.Add <SceneNode>(); engine.InteractionManager.Root.Add(root.Add <InteractiveRoot>().Interactive); var freeCamera = root.Add <FreeCamera>(); freeCamera.View = engine.RootView; freeCamera.Client = _game; var scene = root.Add <GlyphObject>(); scene.Add <SceneNode>().RootNode(); _spriteLoader = scene.Add <SpriteLoader>(); scene.Add <SpriteRenderer>(); _soundLoader = scene.Add <SoundLoader>(); _soundEmitter = scene.Add <SoundEmitter>(); scene.Add <SoundListener>(); _songPlayer = scene.Add <SongPlayer>(); _game.Run(); } }
private void Awake() { audioSource = GetComponent <AudioSource> (); foreach (SoundInput si in sounds) { if (soundDict.ContainsKey(si.name)) { Debug.LogError("Tried to Add Duplicate Sound ID: " + si.name); continue; } else if (si.soundIds.Length > 0) { AudioClip[] clips = new AudioClip[si.soundIds.Length]; for (int i = 0; i < si.soundIds.Length; i++) { clips[i] = SoundLoader.LoadSound(si.soundIds[i]); } soundDict.Add(si.name, clips); continue; } Debug.LogError("No IDs supplied for Sound: " + si.name); } }
public SoundLooper(Mod mod, string name, SoundType type = SoundType.Custom) { _mod = mod; int style = _mod.GetSoundSlot(type, name); _mod.Logger.Debug($"Sound looper {name} being created. Style: {style}"); if (style < 0 || style >= SoundLoader.SoundCount(type)) { _mod.Logger.Warn($"Couldn't create SoundLooper object properly! style: {style} name: {name} type: {type}"); return; } try { _instance = (SoundEffectInstance)((Array)typeof(SoundLoader).GetField("customSoundInstances", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null)).GetValue(style); } catch (Exception e) { _mod.Logger.Error($"Couldn't create SoundLooper object properly! Exception: {e}"); return; } }
public void OnAction(EventAction e) { var hits = e.Actions.GetEffectsTargetting <IWeaponHit>(Curio).ToList(); var alive = Curio.GetBehavior <BehaviorAlive>(); foreach (var hit in hits) { if (hit is ActionEnemyHit) { continue; } if (hit is ActionStabHit stab) { e.Actions.Add(new ActionHitVisual(hit.Origin, hit.Target, SoundLoader.AddSound("content/sound/stab.wav")).InSlot(ActionSlot.Active)); e.Actions.Add(new ActionStabStuck(hit.Origin, hit.Target).InSlot(ActionSlot.Active)); } else { //Crickets } } }
/// <summary> /// 添加到缓存 /// </summary> public void AddCache(string _soundName) { if (_soundName == "0" || _soundName == string.Empty) { return; } if (this.mySoundClipCache.ContainsKey(_soundName)) { if (this.mySoundClipCache[_soundName] == null) { mySoundClipCache.Remove(_soundName); } else { return; } } AudioLoader audioLoader = new AudioLoader(); string audioBundlePath = SoundLoader.GetAudioAssetPath(_soundName); audioLoader.kName = _soundName; RequestAsyncLoad(audioBundlePath, _soundName, audioLoader); }
// Start is called before the first frame update void Start() { if (!TryGetComponent(out BlockComponent)) { var component = GetComponentInParent <DataBlockComponent>(); Position = new Vector2Int(component.WorldTileX, component.WorldTileY); BlockComponent = component; SoundLoader loader = gameObject.AddComponent <SoundLoader>(); loader.LoadAll(BlockComponent.DataBlock); } else { Position = new Vector2Int(BlockComponent.WorldTileX, BlockComponent.WorldTileY); GUID = BlockComponent.DataBlock.GUID; } var allowMovement = GetComponent <AllowTileMovement>(); if (allowMovement != null) { allowMovement.AllowMovement = true; } TileMovingObjectScript.MoveableMoved += Jetstream_SpongebobPlayerPositionChanged; TileMovingObjectScript.MoveableMoving += TileMovingObjectScript_MoveableMoving; }
public override bool?UseItem(Player player) { FargoPlayer modPlayer = player.GetFargoPlayer(); modPlayer.BattleCry = !modPlayer.BattleCry; string text = "Spawn rates " + (modPlayer.BattleCry ? "increased!" : "decreased!"); if (Main.netMode == NetmodeID.SinglePlayer) { Main.NewText(text, new Color(175, 75, 255)); } else if (Main.netMode == NetmodeID.Server) { ChatHelper.BroadcastChatMessage(NetworkText.FromLiteral(text), new Color(175, 75, 255)); } if (!Main.dedServ) { SoundEngine.PlaySound(SoundLoader.GetLegacySoundSlot(Mod, "Sounds/Horn").WithVolume(1f), player.Center); } return(true); }
public static void PlaySound(object soundType, int x, int y, object sound, bool stop = true, bool newInstance = true, float?overrideVolume = null, float?overridePitch = null) { if (Main.netMode == 2 || Main.dedServ || Main.soundVolume == 0f) { return; } Rectangle screenRect = new Rectangle((int)(Main.screenPosition.X - Main.screenWidth * 2), (int)(Main.screenPosition.Y - Main.screenHeight * 2), Main.screenWidth * 5, Main.screenHeight * 5); Rectangle locRect = new Rectangle(x, y, 1, 1); bool usePan = locRect.Intersects(screenRect); if ((x == -1 && y == -1) || usePan) { SoundEffect soundEffect = null; float pitch = 0f; int soundID = -1; SoundEffect[] soundArray = null; SoundEffectInstance[] soundInstanceArray = null; int soundType2 = (soundType is int?(int)soundType : 0); if (soundType is SoundType) { switch ((SoundType)soundType) { case SoundType.Custom: soundType2 = -1; break; case SoundType.Item: soundType2 = 2; break; case SoundType.NPCHit: soundType2 = 3; break; case SoundType.NPCKilled: soundType2 = 4; break; default: soundType2 = 0; break; } } switch (soundType2) { case -1: soundID = SoundLoader.GetSoundSlot(SoundType.Custom, (string)sound); if (soundField == null) { soundField = typeof(SoundLoader).GetField("customSounds", BindingFlags.NonPublic | BindingFlags.Static); } if (soundInstanceField == null) { soundInstanceField = typeof(SoundLoader).GetField("customSoundInstances", BindingFlags.NonPublic | BindingFlags.Static); } soundArray = (SoundEffect[])soundField.GetValue(null); // SoundLoader.customSounds[soundID]; soundInstanceArray = (SoundEffectInstance[])soundInstanceField.GetValue(null); break; case 2: if (sound is string) { soundID = SoundLoader.GetSoundSlot(SoundType.Item, (string)sound); } else { soundID = (int)sound; } soundArray = Main.soundItem; soundInstanceArray = Main.soundInstanceItem; pitch = Main.rand.Next(-6, 7) * 0.01f; break; case 3: if (sound is string) { soundID = SoundLoader.GetSoundSlot(SoundType.NPCHit, (string)sound); } else { soundID = (int)sound; } soundArray = Main.soundNPCHit; soundInstanceArray = Main.soundInstanceNPCHit; pitch = Main.rand.Next(-10, 11) * 0.01f; break; case 4: if (sound is string) { soundID = SoundLoader.GetSoundSlot(SoundType.NPCKilled, (string)sound); } else { soundID = (int)sound; } soundArray = Main.soundNPCKilled; soundInstanceArray = Main.soundInstanceNPCKilled; pitch = Main.rand.Next(-10, 11) * 0.01f; break; default: return; } //TODO: FIX SOUND VOLUME/PAN soundEffect = soundArray[soundID]; if (stop && soundID != -1 && soundInstanceArray[soundID] != null) { soundInstanceArray[soundID].Stop(); } float soundPan = 0f; float soundVol = 1f; if (usePan) { Vector2 vector = new Vector2(Main.screenPosition.X + Main.screenWidth * 0.5f, Main.screenPosition.Y + Main.screenHeight * 0.5f); float absX = Math.Abs(x - vector.X); float absY = Math.Abs(y - vector.Y); float absSQ = (float)Math.Sqrt(absX * absX + absY * absY); soundPan = (x - vector.X) / (Main.screenWidth * 0.5f); soundVol = 1f - absSQ / (Main.screenWidth * 1.5f); } SoundEffectInstance soundInstance = (newInstance ? soundEffect.CreateInstance() : (soundInstanceArray[soundID].State == SoundState.Playing ? soundInstanceArray[soundID] : soundEffect.CreateInstance())); soundInstance.Volume = Math.Max(0f, Math.Min(1f, (overrideVolume != null ? (float)overrideVolume : soundVol) * Main.soundVolume)); soundInstance.Pitch = (overridePitch != null ? (float)overridePitch : pitch); soundInstance.Pan = Math.Max(-1f, Math.Min(1f, soundPan)); Main.PlaySoundInstance(soundInstance); soundInstanceArray[soundID] = soundInstance; switch (soundType2) { case -1: soundField.SetValue(null, soundArray); soundInstanceField.SetValue(null, soundInstanceArray); break; case 2: Main.soundItem = soundArray; Main.soundInstanceItem = soundInstanceArray; break; case 3: Main.soundNPCHit = soundArray; Main.soundInstanceNPCHit = soundInstanceArray; break; case 4: Main.soundNPCKilled = soundArray; Main.soundInstanceNPCKilled = soundInstanceArray; break; default: return; } } //OLD CODE //Main.PlaySound(soundEffect, x, y, newInstance, null, Single.NaN, overrideVolume == null ? Single.NaN : (float)overrideVolume, pitch); /*if (soundType == 100) { soundType = 3; if (overridePitch == null) { overridePitch = 0f; } } * if (Main.dedServ || Main.soundVolume <= 0f) { return; } * Microsoft.Xna.Framework.Audio.SoundEffect sound = null; * Microsoft.Xna.Framework.Audio.SoundEffectInstance instance = null; * float volume = 1f; * float pan = 0f; * float pitch = 0f; * bool canPlay = false; * if (x == -1 || y == -1) { canPlay = true; }else * { * if (WorldGen.gen || Main.netMode == 2) { return; } * Rectangle value = new Rectangle((int)(Main.screenPosition.X - (float)(Main.screenWidth * 2)), (int)(Main.screenPosition.Y - (float)(Main.screenHeight * 2)), Main.screenWidth * 5, Main.screenHeight * 5); * Rectangle rectangle = new Rectangle(x, y, 1, 1); * Vector2 vector = new Vector2(Main.screenPosition.X + (float)Main.screenWidth * 0.5f, Main.screenPosition.Y + (float)Main.screenHeight * 0.5f); * canPlay = rectangle.Intersects(value); * if (canPlay) * { * pan = ((float)x - vector.X) / ((float)Main.screenWidth * 0.5f); * float distX = Math.Abs((float)x - vector.X); * float distY = Math.Abs((float)y - vector.Y); * float dist = (float)Math.Sqrt((double)(distX * distX + distY * distY)); * volume = 1f - dist / ((float)Main.screenWidth * 1.5f); * } * } * pan = Math.Max(-1, Math.Min(1, pan)); * if (volume > 1f) { volume = 1f; } * if (volume > 0f && canPlay) * { * switch (soundType) * { * case 2: * instance = Main.soundInstanceItem[soundID]; * sound = Main.soundItem[soundID]; * pitch = (float)Main.rand.Next(-6, 7) * 0.01f; * break; * case 3: * instance = Main.soundInstanceNPCHit[soundID]; * sound = Main.soundNPCHit[soundID]; * pitch = (float)Main.rand.Next(-10, 11) * 0.01f; * break; * case 4: * instance = Main.soundInstanceNPCKilled[soundID]; * sound = Main.soundNPCKilled[soundID]; * pitch = (float)Main.rand.Next(-10, 11) * 0.01f; * break; * default: break; * } * if (sound == null) { return; } * if (overridePitch != null) { pitch = (float)overridePitch; } * if (overrideVolume != null) { volume = (float)overrideVolume; } * volume *= Main.soundVolume; * if (stop && instance != null) { instance.Stop(); } * if (newInstance || instance == null || instance.State == Microsoft.Xna.Framework.Audio.SoundState.Stopped) * { * newInstance = true; * switch (soundType) * { * case 2: instance = Main.soundInstanceItem[soundID] = sound.CreateInstance(); break; * case 3: instance = Main.soundInstanceNPCHit[soundID] = sound.CreateInstance(); break; * case 4: instance = Main.soundInstanceNPCKilled[soundID] = sound.CreateInstance(); break; * default: break; * } * } * instance.Volume = volume; * instance.Pan = pan; * instance.Pitch = pitch; * if (stop || newInstance) { instance.Play(); } * }*/ }
//public MicrophoneInput microphoneInput; // Use this for initialization void Start() { player = this as Player; rigidBody = this.GetComponent<Rigidbody2D> (); networkView = this.GetComponent<NetworkView> (); currentPos = player.transform.position; playerID = NetworkManager.nextPlayerID (); playerType = PlayerType.DUDE; animator = this.gameObject.GetComponent<Animator>(); soundLoader = GameObject.Find("Audio Source").GetComponent<SoundLoader>(); // microphoneInput = GameObject.Find("Audio Source").GetComponent<MicrophoneInput>(); foreach (Transform child in this.transform) { if(child.name == "PlayerFoot") { playerFoot = child.gameObject; } if(child.name == "FBSpwnPNT") { FBSWNPOINTGO = child.gameObject; } } }
/// <summary> /// /// </summary> /// <param name="loader"></param> public static void SetSoundLoader(SoundLoader loader) { soundLoader = loader; }