public void Stop(GameObject _parentGameObject) { m_looping = false; StopCoroutine(Loop(_parentGameObject)); IDictionaryEnumerator enumerator = m_childComponents.GetEnumerator(); try { while (enumerator.MoveNext()) { DictionaryEntry dictionaryEntry = (DictionaryEntry)enumerator.Current; if (dictionaryEntry.Value is AudioComponent) { AudioComponent audioComponent = dictionaryEntry.Value as AudioComponent; audioComponent.Stop(_parentGameObject); } if (dictionaryEntry.Value is AudioRandomComponent) { AudioRandomComponent audioRandomComponent = dictionaryEntry.Value as AudioRandomComponent; audioRandomComponent.Stop(_parentGameObject); } } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } }
private void unloadFabricAudio(GameObject gameObject) { AudioComponent[] componentsInChildren = gameObject.GetComponentsInChildren <AudioComponent>(includeInactive: true); int num = componentsInChildren.Length; for (int i = 0; i < num; i++) { AudioComponent audioComponent = componentsInChildren[i]; audioComponent.Stop(); audioComponent.UnloadAudio(); AudioClip audioClip = audioComponent.AudioClip; if (audioClip != null && !audioClip.UnloadAudioData()) { Log.LogError(this, "Failed to unload audio data for: " + audioClip.name); } } }
public void StopChargingShot() { ShakeComponent playerShake = Owner.FindComponent <ShakeComponent>(); if (playerShake != null) { playerShake.StopShake(); } PlayerChargedShotFx playerChargedShotCmp = Owner.FindComponent <PlayerChargedShotFx>(); if (playerChargedShotCmp != null) { playerChargedShotCmp.Stop(); } m_chargedShotTimer.Stop(); m_chargingShot = false; m_audioCmpCharge.Stop(); }
protected override void InitializeScene() { GraphicsManager.Instance.Context.UseDepth(true); _fps = new Text(GUI.Root); _fps.Dimensions = new Vector2(10000, 16); DefaultCamera.ClearColor = new Color(63, 136, 197, 255); DefaultCamera.Parent.Transform.Position2D = new Vector2(0, -46); ScaleGame(); _background = AddGameObject("Background"); TileMap map = _background.AddComponent <TileMap>(); map.TileSize = 16; map.MapData = ResourceManager.Load <Texture2D>("Textures/backgroundData.png"); map.MapData.Wrap = Texture2D.WrapMode.Repeat; map.Sprites = ResourceManager.Load <Texture2D>("Textures/background.png"); AudioComponent music = _background.AddComponent <AudioComponent>(); music.SetAudioClip(ResourceManager.Load <AudioClip>("Sounds/main.mp3")); music.Play(); _website = AddGameObject("website"); _websiteSprite = _website.AddComponent <Sprite>(); _websiteSprite.Texture = ResourceManager.Load <Texture2D>("Textures/Website0.png"); _websiteSprite.Offset = new Vector2(-_websiteSprite.Texture.Width / 2, -_websiteSprite.Texture.Height / 2); _websiteSprite.Priority = 0.1f; EmptyUIElement websiteHit = new EmptyUIElement(GUI.Root); websiteHit.Dimensions = new Vector2(200, 200) * DefaultCamera.Zoom; websiteHit.Pivot = UIDefaults.Centered; websiteHit.OnMouseUp += WebsiteClick; websiteHit.OnMouseEnter += WebsiteEnter; websiteHit.OnMouseExit += WebsiteExit; AudioComponent webAudio = _website.AddComponent <AudioComponent>(); webAudio.SetAudioClip(ResourceManager.Load <AudioClip>("Sounds/buy.mp3")); UIComponent websiteUI = _website.AddComponent <UIComponent>(); websiteUI.Setup(websiteHit, this); GameObject buyParticles = AddGameObject("Particles"); _websiteParticles = buyParticles.AddComponent <BurstParticleComponent>(); _websiteParticles.Texture = ResourceManager.Load <Texture2D>("Textures/Dollar.png"); _websiteParticles.Gravity = new Vector2(0, 5); _websiteParticles.BurstAmount = 5; _websiteParticles.OnRequestParticle += () => { Particle particle = new Particle(); particle.particleFrames = 1; particle.sourceRectangles = new Rectangle[] { new Rectangle(0, 0, 8, 8) }; particle.velocity = new Vector2(Random.NextRange(-1.0f, 1.0f), Random.NextRange(-0.5f, -1.0f)); particle.color = Color.White; particle.lifeTime = Random.NextRange(0.25f, 1.0f); particle.totalLifeTime = particle.lifeTime; particle.size = new Vector2(1, 1); return(particle); }; _websiteParticles.OnParticleUpdate += (particle) => { particle.size = new Vector2(2, 2) * (particle.lifeTime / particle.totalLifeTime); }; _debtCounter = AddGameObject("Debt counter"); _debtCounter.Transform.Position2D = new Vector2(0, 54); _debtText = _debtCounter.AddComponent <TextComponent>(); _debtText.Font = ResourceManager.Load <Font>("Fonts/8-bit.bff"); _debtText.DisplayText = GetDisplayString(debt); _debtText.Alignment = TextAlignment.Center; _debtTextShadow = _debtCounter.AddComponent <TextComponent>(); _debtTextShadow.Font = ResourceManager.Load <Font>("Fonts/8-bit.bff"); _debtTextShadow.Color = Color.Black; _debtTextShadow.Alignment = TextAlignment.Center; _debtTextShadow.DisplayText = _debtText.DisplayText; _debtTextShadow.Offset = new Vector2(2, -2); _debtPerSecondCounter = AddGameObject("DPS counter"); _debtPerSecondCounter.Transform.Position2D = new Vector2(0, 47); _debtPerSecondText = _debtPerSecondCounter.AddComponent <TextComponent>(); _debtPerSecondText.DisplayText = GetDisplayString(debt); _debtPerSecondText.Alignment = TextAlignment.Center; _debtPerSecondTextShadow = _debtPerSecondCounter.AddComponent <TextComponent>(); _debtPerSecondTextShadow.Offset = new Vector2(1, -1); _debtPerSecondTextShadow.Color = Color.Black; _debtPerSecondTextShadow.DisplayText = _debtPerSecondText.DisplayText; _debtPerSecondTextShadow.Alignment = TextAlignment.Center; _fixedCharges = new GameObject[FixedCharges.Length]; _fixedChargesGenerated = new ulong[FixedCharges.Length]; // Setup fixed charges objects. for (int i = 0; i < FixedCharges.Length; ++i) { FixedCharge fixedCharge = FixedCharges[i]; GameObject charge = AddGameObject($"Fixed charge {i}"); charge.Enabled = false; _fixedCharges[i] = charge; charge.Transform.Position = new Vector3(0, -80 - i * 20, 0.25f); Sprite chargeSprite = charge.AddComponent <Sprite>(); chargeSprite.Texture = ResourceManager.Load <Texture2D>("Textures/Charge.png"); chargeSprite.Offset = new Vector2(-chargeSprite.Texture.Width / 2, -chargeSprite.Texture.Height / 2); chargeSprite.Priority = 0.5f; EmptyUIElement chargeHit = new EmptyUIElement(GUI.Root); chargeHit.Dimensions = new Vector2(chargeSprite.Texture.Width * 2 * DefaultCamera.Zoom, chargeSprite.Texture.Height * DefaultCamera.Zoom); chargeHit.Pivot = UIDefaults.Centered; TextComponent chargeText = charge.AddComponent <TextComponent>(); chargeText.Offset = new Vector2(-60, -9); chargeText.Color = Color.Black; chargeText.DisplayText = $"???? {GetDisplayStringSmall(fixedCharge.price)}"; TextComponent chargeDebtText = charge.AddComponent <TextComponent>(); chargeDebtText.Offset = new Vector2(22, -9); chargeDebtText.Color = Color.Black; chargeDebtText.DisplayText = $"${fixedCharge.debtPerSecond.KiloFormat()}/s"; UIComponent chargeUI = charge.AddComponent <UIComponent>(); chargeUI.Setup(chargeHit, this); AudioComponent audio = charge.AddComponent <AudioComponent>(); audio.SetAudioClip(ResourceManager.Load <AudioClip>("Sounds/ka-ching.mp3")); // Setup UI events. chargeHit.OnMouseEnter += (ev) => { _popup.Transform.Position2D = charge.Transform.Position2D; _popup.Enabled = true; _popupEnabledThisFrame = true; CoroutineManager.StartCoroutine(DefaultRoutines.Linear(0.3f, (x) => { chargeSprite.Size = new Vector2(1, 1) * (1 + Easings.CircularEaseOut(x) / 4.0f); charge.Transform.Scale = new Vector3(1, 1, 1) * (1 + Easings.CircularEaseOut(x) / 4.0f); _popup.GetComponent <Sprite>().Size = new Vector2(1, 1) * (Easings.CircularEaseOut(x)); _popup.Transform.Scale = new Vector3(1, 1, 1) * (Easings.CircularEaseOut(x)); })); }; chargeHit.OnMouseStay += (ev) => { _popup.GetComponent <TextComponent>().DisplayText = $"{fixedCharge.desc}\nHave: {fixedCharge.owned} (${fixedCharge.debtPerSecond * fixedCharge.owned}/s)\nTotal: {GetDisplayStringSmall(_fixedChargesGenerated[fixedCharge.id])}"; }; chargeHit.OnMouseExit += (ev) => { if (!_popupEnabledThisFrame) { _popup.Enabled = false; } CoroutineManager.StartCoroutine(DefaultRoutines.Linear(0.3f, (x) => { chargeSprite.Size = new Vector2(1, 1) * (1 + Easings.QuadraticEaseOut(1.0f - x) / 4.0f); charge.Transform.Scale = new Vector3(1, 1, 1) * (1 + Easings.QuadraticEaseOut(1.0f - x) / 4.0f); })); }; chargeHit.OnMouseUp += (ev) => { if (debt >= fixedCharge.price) { debtPerSecond += fixedCharge.debtPerSecond; debt -= fixedCharge.price; _shownDebt = debt; _helpText.Enabled = false; fixedCharge.owned++; fixedCharge.price = (ulong)(fixedCharge.price * JMath.Pow(1.15f, fixedCharge.owned)); chargeText.DisplayText = $"{fixedCharge.name} {GetDisplayStringSmall(fixedCharge.price)}"; audio.Stop(); audio.Play(); audio.SetVolume(0.5f); } CoroutineManager.StartCoroutine(DefaultRoutines.Linear(0.3f, (x) => { chargeSprite.Size = new Vector2(1, 1) * (1 + Easings.CircularEaseOut(x) / 4.0f); charge.Transform.Scale = new Vector3(1, 1, 1) * (1 + Easings.CircularEaseOut(x) / 4.0f); })); }; } _popup = AddGameObject("Popup"); _popup.Enabled = false; Sprite popupSprite = _popup.AddComponent <Sprite>(); popupSprite.Texture = ResourceManager.Load <Texture2D>("Textures/WebsiteBuyFrame.png"); popupSprite.Offset = new Vector2(-popupSprite.Texture.Width / 2, popupSprite.Texture.Height / 64); popupSprite.Priority = 0.000001f; TextComponent popupText = _popup.AddComponent <TextComponent>(); popupText.Alignment = TextAlignment.Left; popupText.Offset = new Vector2(-50, popupSprite.Texture.Height / 1.5f); popupText.DisplayText = "All your base\nare belong to\nus."; popupText.Color = Color.Black; _timer = AddGameObject("Timer"); _timer.Transform.Position2D = new Vector2(0, -68); _timerText = _timer.AddComponent <TextComponent>(); _timerText.Alignment = TextAlignment.Center; _timerText.DisplayText = "2:30 remaining"; EmptyUIElement startelement = new EmptyUIElement(GUI.Root); startelement.Dimensions = new Vector2(80, 20) * _defaultZoom * 2; startelement.Pivot = UIDefaults.Centered; startelement.OnMouseEnter += (ev) => { CoroutineManager.StartCoroutine(DefaultRoutines.Linear(0.3f, (x) => { _exit.GetComponent <Sprite>().Size = new Vector2(1, 1) * (1 + Easings.CircularEaseOut(x) / 4.0f); })); }; startelement.OnMouseExit += (ev) => { CoroutineManager.StartCoroutine(DefaultRoutines.Linear(0.3f, (x) => { _exit.GetComponent <Sprite>().Size = new Vector2(1, 1) * (1 + Easings.QuadraticEaseOut(1.0f - x) / 4.0f); })); }; startelement.OnMouseUp += (x) => { SceneManager.SwitchToScene(new MainMenu(ResourceManager)); }; _exit = AddGameObject("Exit"); _exit.Transform.Position2D = new Vector2(0, 108); _exit.AddComponent <UIComponent>().Setup(startelement, this); Sprite exitSprite = _exit.AddComponent <Sprite>(); exitSprite.Texture = ResourceManager.Load <Texture2D>("Textures/buttons.png"); exitSprite.SourceRectangle = new Rectangle(0, 20, 128, 20); exitSprite.Offset = new Vector2(-35, -9); _helpText = AddGameObject("help").AddComponent <TextComponent>(); _helpText.DisplayText = "Exchange debt to gain\n debt automatically!"; _helpText.Alignment = TextAlignment.Center; _helpText.Parent.Transform.Position2D = new Vector2(0, -110); _helpText.Enabled = false; _exit.Enabled = false; }