public override void OnInspectorGUI() { base.OnInspectorGUI(); serializedObject.Update(); SoundComponent t = (SoundComponent)target; EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode); { EditorGUILayout.PropertyField(m_EnablePlaySoundUpdateEvent); EditorGUILayout.PropertyField(m_EnablePlaySoundDependencyAssetEvent); EditorGUILayout.PropertyField(m_InstanceRoot); EditorGUILayout.PropertyField(m_AudioMixer); m_SoundHelperInfo.Draw(); m_SoundGroupHelperInfo.Draw(); m_SoundAgentHelperInfo.Draw(); EditorGUILayout.PropertyField(m_SoundGroups, true); } EditorGUI.EndDisabledGroup(); if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject)) { EditorGUILayout.LabelField("Sound Group Count", t.SoundGroupCount.ToString()); } serializedObject.ApplyModifiedProperties(); Repaint(); }
protected SoundComponent LoadAndPlay(string fileName, Vector3 Position, KBusAudio bus = null, float DelayTime = 0f, float Duration = -1f) { SoundComponent source = GetAudioSource3D(fileName); if (source == null) { return(null); } if (bus != null) { if (bus.Add(source) == false) { if (PushToPool != null) { PushToPool.Invoke(source.transform); } else { Destroy(source.transform.gameObject); } return(null); } else { // Please Add All CallbackFunction // Do dùng cái Pool nên sợ Add thê nhiều lần // if (_Sound.callback == null) // :: Todo // Ignore add to Pool of KAudioCompoenent source._Sound.callback = () => { bus.Remove(source); if (PushToPool != null) { PushToPool.Invoke(source.transform); } else { Destroy(source.transform.gameObject); } }; } } source.gameObject.transform.localPosition = Position; if (Duration > 0) { source.Play(DelayTime, Duration); } else { source.Play(DelayTime); } return(source); }
public static int?PlayMusic(this SoundComponent soundComponent, int musicId, object userData = null) { soundComponent.StopMusic(); IDataTable <DRMusic> dtMusic = GameEntry.DataTable.GetDataTable <DRMusic>(); if (dtMusic == null) { Log.Warning("Music data is null", musicId.ToString()); return(null); } DRMusic drMusic = dtMusic.GetDataRow(musicId); if (drMusic == null) { Log.Warning("Can not load music '{0}' from data table.", musicId.ToString()); return(null); } PlaySoundParams playSoundParams = new PlaySoundParams { Priority = 64, Loop = true, VolumeInSoundGroup = 1f, FadeInSeconds = FadeVolumeDuration, SpatialBlend = 0f, }; s_MusicSerialId = soundComponent.PlaySound(AssetUtility.GetMusicAsset(drMusic.AssetName), "Music", playSoundParams, null, userData); return(s_MusicSerialId); }
public MoonTaxi(bool isServer, string username) : base() { this.isServer = isServer; if (isServer) { server = new Server(); server.Start(); } else { client = new Client(username); client.Connect(IPAddress.Loopback, 1234); client.DataReceived += Client_DataReceived; } graphics = new GraphicsDeviceManager(this); level = new RandomLevel(new Vector2(1280, 720), 2, Environment.TickCount); graphics.PreferredBackBufferWidth = (int)level.Size.X; graphics.PreferredBackBufferHeight = (int)level.Size.Y; Content.RootDirectory = "Content"; Components.Add(sound = new SoundComponent(this)); }
public void LoadContent(ContentManager contentManager) { var entities = ComponentManager.Instance .GetEntitiesWithComponent(typeof(SpriteComponent)) .Where(entity => !(entity.Value as SpriteComponent).SpriteIsLoaded); foreach (var entity in entities) { var spriteComponent = entity.Value as SpriteComponent; if (string.IsNullOrEmpty(spriteComponent.SpriteName)) { continue; } spriteComponent.Sprite = contentManager.Load <Texture2D>(spriteComponent.SpriteName); spriteComponent.SpriteIsLoaded = true; if (spriteComponent.TileWidth == 0) { spriteComponent.TileWidth = spriteComponent.Sprite.Width; } if (spriteComponent.TileHeight == 0) { spriteComponent.TileHeight = spriteComponent.Sprite.Height; } } var soundEntities = ComponentManager.Instance.GetEntitiesWithComponent(typeof(SoundComponent)); foreach (var entity in soundEntities) { SoundComponent soundComponent = (SoundComponent)entity.Value; soundComponent.SoundEffect = contentManager.Load <SoundEffect>(soundComponent.SoundEffectName); } }
protected SoundComponent GetAudioSource3D(string fileName) { // PoolManager.Pools[POOL.POOL_AUDIO].Spawn("Audio3D").gameObject; GameObject ownerSource = GetPool("Audio3D").gameObject; // Get AudioSource SoundComponent _SoundComponent = ownerSource.GetComponent <SoundComponent>(); // Add Clip _SoundComponent._Sound.clip = LoadClip(fileName); if (_SoundComponent._Sound.clip == null) { #if UNITY_EDITOR Debug.LogError(fileName); #endif return(null); } // Add Cache if (_AudioSources3D == null) { _AudioSources3D = new List <SoundComponent>(); } if (_AudioSources3D.Contains(_SoundComponent) == false) { _AudioSources3D.Add(_SoundComponent); } //Debug.LogWarning(fileName); return(_SoundComponent); }
public override void OnInspectorGUI() { serializedObject.Update(); SoundComponent t = (SoundComponent)target; EditorGUILayout.PropertyField(m_EnablePlaySoundSuccessEvent); EditorGUILayout.PropertyField(m_EnablePlaySoundFailureEvent); EditorGUILayout.PropertyField(m_EnablePlaySoundUpdateEvent); EditorGUILayout.PropertyField(m_EnablePlaySoundDependencyAssetEvent); EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode); { EditorGUILayout.PropertyField(m_AudioMixer); EditorGUILayout.PropertyField(m_SoundGroupInfos, true); } EditorGUI.EndDisabledGroup(); if (EditorApplication.isPlaying && PrefabUtility.GetPrefabType(t.gameObject) != PrefabType.Prefab) { EditorGUILayout.LabelField("Sound Group Count", t.SoundGroupCount.ToString()); } serializedObject.ApplyModifiedProperties(); Repaint(); }
public override void OnAwake() { base.OnAwake(); m_throwable = true; // change depending on power-up MovementSpeedModifier = 1.0f; BaseThrowForce = 15.0f; MaxThrowForce = 25.0f; ThrowForce = BaseThrowForce; m_rigidBody.Friction = 100.0f; _LastCollider = null; DespawnTime = 60.0f; _BananaTimer = 0.0f; SetModels(true, false); SlipSound = gameObject.AddComponent <SoundComponent>(); SlipSound.Type = SoundComponent.SoundType.Effect; SlipSound.Clip = BananaSlipSound; SlipSound.Looping = false; SlipSound.Is3D = true; Rigidbody rb = gameObject.GetComponent <Rigidbody>(); rb.CcdMotionThreshold = 1e-7f; rb.CcdSweptSphereRadius = 0.1f; }
public static int?PlayMusic(this SoundComponent soundComponent, int musicId, object userData = null) { soundComponent.StopMusic(); s_MusicSerialId = soundComponent.PlaySound(musicId, null, userData); return(s_MusicSerialId); }
public void Execute() { foreach (Entity e in _group.GetEntities()) { SoundComponent sound = e.sound; GameObject go = sound.go; if (go == null) { sound.go = new GameObject(); AudioSource source = sound.go.AddComponent <AudioSource>(); source.volume = sound.volume; source.clip = Resources.Load <AudioClip>(sound.path); source.Play(); } else { AudioSource source = go.GetComponent <AudioSource>(); if (!source.isPlaying) { UnityEngine.Object.Destroy(go); e.isDestroyEntity = true; } } } }
void Awake() { sound = GetComponent <SoundComponent>(); _health = GetComponent <IHealth>(); ShieldActive.Value = false; CurrentHP = _health.MaxHP; scoreComponent = GetComponent <ScoreComponent>(); }
private void Collided(Entity other, Vector3 point) { if (other.Has <AircraftComponent>()) { Entity e = Entity.Instantiate(); e.Attach(new TransformComponent() { Position = point }); //e.Attach<GunBulletSmokeComponent>(); e.Attach(new LimitedLifeTimeComponent() { CountSpeed = 0.04f }); var soundComponent = new SoundComponent(BulletHitSound); soundComponent.VolumeFactor = 0.5f; e.Attach(soundComponent); soundComponent.Play(); var aircraft = other.Get <AircraftComponent>(); aircraft.Damage(Damage); if (this.ShootedByPlayer) { if (aircraft.Armor > 0) { Entity.SendMessage(Entity.Find("ui"), "notice", "Hit"); } else { Entity.SendMessage(Entity.Find("ui"), "notice", "Destroyed"); } } if (other.Name == "player") { Entity.SendMessage(Entity.Find("ui"), "notice", "Damaged"); } } else if (other.Has <GroundComponent>()) { Entity e = Entity.Instantiate(); e.Attach(new TransformComponent() { Position = point }); e.Attach <GunBulletSmokeComponent>(); e.Attach(new LimitedLifeTimeComponent() { CountSpeed = 0.04f }); var soundComponent = new SoundComponent(BulletHitSound); soundComponent.VolumeFactor = 0.5f; e.Attach(soundComponent); soundComponent.Play(); } Entity.Kill(this.Owner); }
public static void StopMusic(this SoundComponent soundComponent) { if (!s_MusicSerialId.HasValue) { return; } soundComponent.StopSound(s_MusicSerialId.Value); }
public static int?PlaySound(this SoundComponent soundComponent, EnumSound enumSound, Entity bindingEntity = null, object userData = null) { if (enumSound == EnumSound.None) { return(null); } return(soundComponent.PlaySound((int)enumSound, bindingEntity, userData)); }
public RheinwerkGame() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.IsFullScreen = false; IsMouseVisible = true; Input = new InputComponent(this); Input.UpdateOrder = 0; Components.Add(Input); Screen = new ScreenComponent(this); Screen.UpdateOrder = 1; Screen.DrawOrder = 2; Components.Add(Screen); Local = new LocalComponent(this); Local.UpdateOrder = 2; Components.Add(Local); var client = new ClientComponent(this); Client = client; client.UpdateOrder = 3; Components.Add(client); var server = new ServerComponent(this); Server = server; server.UpdateOrder = 4; Components.Add(server); Simulation = new SimulationComponent(this); Simulation.UpdateOrder = 5; Components.Add(Simulation); Scene = new SceneComponent(this); Scene.UpdateOrder = 6; Scene.DrawOrder = 0; Components.Add(Scene); Hud = new HudComponent(this); Hud.UpdateOrder = 7; Hud.DrawOrder = 1; Components.Add(Hud); Music = new MusicComponent(this); Music.UpdateOrder = 8; Components.Add(Music); Sound = new SoundComponent(this); Sound.UpdateOrder = 9; Components.Add(Sound); // Einstellungen laden Settings = Settings.LoadSettings(); }
private void PlayStompSound(float volume) { SoundComponent stomp = this.Components.Get <SoundComponent>(); if (!stomp.IsRunning) { stomp.Volume = volume; stomp.PlayPitched(0.5f); } }
public static void StopMusic(this SoundComponent soundComponent) { if (!s_MusicSerialId.HasValue) { return; } soundComponent.StopSound(s_MusicSerialId.Value, FadeVolumeDuration); s_MusicSerialId = null; }
void Start() { rigidBody = GetComponent <Rigidbody2D>(); Vector2 diagonalDirection = UnityEngine.Random.insideUnitCircle; diagonalDirection.x = diagonalDirection.x >= 0 ? 1 : -1; diagonalDirection.y = diagonalDirection.y >= 0 ? 1 : -1; rigidBody.AddForce(diagonalDirection * ballLaunchSpeed, ForceMode2D.Impulse); sc = GetComponent <SoundComponent>(); }
public SoundComponent Play(string fileName, string soundFile, Vector3 position, bool isLoop = false, float DelayTime = 0f) { SoundComponent source = LoadAndPlay(fileName, position, this.UIBus, DelayTime); if (source == null) { return(null); } return(source); }
public void UnMute(string name) { SoundComponent s = Array.Find(sounds, sound => sound.name == name); if (s == null) { Debug.LogWarning("Sound " + name + " not found."); return; } s.source.volume = 1.0f; }
public void Play(string name) { SoundComponent s = Array.Find(sounds, sound => sound.name == name); if (s == null) { Debug.LogWarning("Sound: " + name + " not found."); return; } s.source.Play(); }
public override void Start() { DisableRagdoll(); // Load the ragdoll impact sound RagdollSound = gameObject.AddComponent <SoundComponent>(); RagdollSound.Type = SoundComponent.SoundType.Effect; RagdollSound.Clip = ImpactSound; RagdollSound.Looping = false; RagdollSound.Is3D = true; identity = gameObject.GetComponent <NetworkIdentity>(); }
public static int?PlayMusic(this SoundComponent soundComponent, EnumSound enumSound, object userData = null) { if (enumSound == EnumSound.None) { return(null); } soundComponent.StopMusic(); s_MusicSerialId = soundComponent.PlaySound((int)enumSound, null, userData); return(s_MusicSerialId); }
public bool IsPlaying(string name) { bool check; SoundComponent s = Array.Find(sounds, sound => sound.name == name); if (s == null) { Debug.LogWarning("Sound " + name + " not found."); return(false); } check = s.source.isPlaying; return(check); }
/// <summary> /// 游戏框架组件初始化。 /// </summary> protected override void Awake() { base.Awake(); m_SoundMethods = CentorPivot.This.GetComponent <SoundComponent>(); if (m_SoundMethods == null) { Log.Fatal("Sound manager is invalid."); return; } m_AudioListener = gameObject.GetOrAddComponent <AudioListener>(); SceneManager.sceneLoaded += OnSceneLoaded; SceneManager.sceneUnloaded += OnSceneUnloaded; if (EventComponent.This == null) { Log.Fatal("Event component is invalid."); return; } m_SoundMethods.SetResourceManager(CentorPivot.This.GetComponent <ResourceComponent>()); SoundHelperBase soundHelper = (SoundHelperBase)CreateHelper.Create(m_SoundHelperTypeName); if (soundHelper == null) { Log.Error("Can not create sound helper."); return; } m_SoundMethods.SetSoundHelper(soundHelper); if (m_InstanceRoot == null) { m_InstanceRoot = new GameObject("Sound Instances").transform; m_InstanceRoot.SetParent(gameObject.transform); m_InstanceRoot.localScale = Vector3.one; } for (int i = 0; i < m_SoundGroups.Length; i++) { if (!AddSoundGroup(m_SoundGroups[i].Name, m_SoundGroups[i].AvoidBeingReplacedBySamePriority, m_SoundGroups[i].Mute, m_SoundGroups[i].Volume, m_SoundGroups[i].AgentHelperCount)) { Log.Warning("Add sound group '{0}' failure.", m_SoundGroups[i].Name); continue; } } }
/// <summary> /// This is main function /// </summary> /// <param name="fileName"></param> /// <param name="position"></param> /// <returns></returns> public SoundComponent PlayVoice(string fileName, Vector3 position) { SoundComponent source = GetAudioSource3D(fileName); if (source == null) { return(null); } source.gameObject.transform.localPosition = position; source.Play(); return(source); }
public override void Start() { ExplosionSound = gameObject.AddComponent <SoundComponent>(); ExplosionSound.Type = SoundComponent.SoundType.Effect; ExplosionSound.Clip = Sound; ExplosionSound.Looping = true; ExplosionSound.Is3D = true; ExplosionSound.Volume = 0.5f; // 3D options ExplosionSound.MaxDistance = 100; ExplosionSound.MinDistance = 3; ExplosionSound.SpreadAngle = 0; ExplosionSound.Play(); }
public static void NewLoopSoundFromComponent(SoundComponent comp, List <short> list) { if (null == list) { Logger.Error("GetNewSoundFromComponent failed , list is null"); return; } if (null == comp) { Logger.Error("GetNewSoundFromComponent failed , comp is null"); return; } list.Clear(); Diff(comp.LastPlayOnce, comp.PlayOnce, list); comp.LastPlayOnce = comp.PlayOnce; }
private void Awake() { sound = GetComponent <SoundComponent>(); _inputEntity = GetComponent <InputEntity>(); m_Rigidbody2D = GetComponent <Rigidbody2D>(); canDash = true; if (OnLandEvent == null) { OnLandEvent = new UnityEvent(); } if (OnCrouchEvent == null) { OnCrouchEvent = new BoolEvent(); } }
public SoundComponent Play(string fileName, string soundFile, Vector3 position, bool isLoop = false, float DelayTime = 0f) { SoundComponent source = GetAudioSource3D(fileName); if (source == null) { return(null); } source.gameObject.transform.position = position; source.gameObject.transform.localPosition = Vector3.zero; source._Sound.DelayTime = DelayTime; source.Play(); return(source); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { AggregateFactory = new AggregateFactory(this); WeaponFactory = new WeaponFactory(this); DoorFactory = new DoorFactory(this); RoomFactory = new RoomFactory(this); CollectableFactory = new CollectibleFactory(this); WallFactory = new WallFactory(this); EnemyFactory = new EnemyFactory(this); SkillEntityFactory = new SkillEntityFactory(this); NPCFactory = new NPCFactory(this); // Initialize Components PlayerComponent = new PlayerComponent(); LocalComponent = new LocalComponent(); RemoteComponent = new RemoteComponent(); PositionComponent = new PositionComponent(); MovementComponent = new MovementComponent(); MovementSpriteComponent = new MovementSpriteComponent(); SpriteComponent = new SpriteComponent(); DoorComponent = new DoorComponent(); RoomComponent = new RoomComponent(); HUDSpriteComponent = new HUDSpriteComponent(); HUDComponent = new HUDComponent(); InventoryComponent = new InventoryComponent(); InventorySpriteComponent = new InventorySpriteComponent(); ContinueNewGameScreen = new ContinueNewGameScreen(graphics, this); EquipmentComponent = new EquipmentComponent(); WeaponComponent = new WeaponComponent(); BulletComponent = new BulletComponent(); PlayerInfoComponent = new PlayerInfoComponent(); WeaponSpriteComponent = new WeaponSpriteComponent(); StatsComponent = new StatsComponent(); EnemyAIComponent = new EnemyAIComponent(); NpcAIComponent = new NpcAIComponent(); CollectibleComponent = new CollectibleComponent(); CollisionComponent = new CollisionComponent(); TriggerComponent = new TriggerComponent(); EnemyComponent = new EnemyComponent(); NPCComponent = new NPCComponent(); //QuestComponent = new QuestComponent(); LevelManager = new LevelManager(this); SpriteAnimationComponent = new SpriteAnimationComponent(); SkillProjectileComponent = new SkillProjectileComponent(); SkillAoEComponent = new SkillAoEComponent(); SkillDeployableComponent = new SkillDeployableComponent(); SoundComponent = new SoundComponent(); ActorTextComponent = new ActorTextComponent(); TurretComponent = new TurretComponent(); TrapComponent = new TrapComponent(); ExplodingDroidComponent = new ExplodingDroidComponent(); HealingStationComponent = new HealingStationComponent(); PortableShieldComponent = new PortableShieldComponent(); PortableStoreComponent = new PortableStoreComponent(); ActiveSkillComponent = new ActiveSkillComponent(); PlayerSkillInfoComponent = new PlayerSkillInfoComponent(); Quests = new List<Quest>(); #region Initialize Effect Components AgroDropComponent = new AgroDropComponent(); AgroGainComponent = new AgroGainComponent(); BuffComponent = new BuffComponent(); ChanceToSucceedComponent = new ChanceToSucceedComponent(); ChangeVisibilityComponent = new ChangeVisibilityComponent(); CoolDownComponent = new CoolDownComponent(); DamageOverTimeComponent = new DamageOverTimeComponent(); DirectDamageComponent = new DirectDamageComponent(); DirectHealComponent = new DirectHealComponent(); FearComponent = new FearComponent(); HealOverTimeComponent = new HealOverTimeComponent(); InstantEffectComponent = new InstantEffectComponent(); KnockBackComponent = new KnockBackComponent(); TargetedKnockBackComponent = new TargetedKnockBackComponent(); ReduceAgroRangeComponent = new ReduceAgroRangeComponent(); ResurrectComponent = new ResurrectComponent(); StunComponent = new StunComponent(); TimedEffectComponent = new TimedEffectComponent(); EnslaveComponent = new EnslaveComponent(); CloakComponent = new CloakComponent(); #endregion base.Initialize(); }