Results 1 to 4 of 4
  1. #1
    MSgt. Shooter Person
    Join Date
    Jan 2010
    Location
    Tokyo, JAPAN
    Posts
    34

    Default SetWeaponAmbientSound()の使い方について

    お世話になっております。
    miyayukです。

    表題のSetWeaponAmbientSound()の使い方について質問させてください。

    実現したいのはLinkPlasmaのビームタイプのように
    ボタン押下時にforeverのサウンドを再生して
    ボタンを離すとサウンドが停止するような感じです。

    基本ベースはPlatformerKitで作成しており
    SPG_Weaponクラスに以下のstateを追加して
    UTBeamWeaponと同じようにサウンド部分を実装しているのですが
    実際に音が再生されない状態です。
    具体的にはBeginState / EndState部分にサウンド部分を追加しております。

    ※defaultproperties部分は省略してます
    ※SPG_PlayerPawnにSetWeaponAmbientSound部分は組み込んで おります
    ※実際はSPG_から始まる名前ではなく、ActTwoSide_から始まる名前でucファイルを作成して おります
     (分かり難くしててすみません。。)

    Code:
    /*********************************************************************************************
     * state WeaponFiring
     * This is the default Firing State.  It's performed on both the client and the server.
     *********************************************************************************************/
    
    simulated state WeaponFiring
    {
    	simulated event bool IsFiring()
    	{
    		return true;
    	}
    
    	/**
    	 * Timer event, call is set up in Weapon::TimeWeaponFiring().
    	 * The weapon is given a chance to evaluate if another shot should be fired.
    	 * This event defines the weapon's rate of fire.
    	 */
    	simulated function RefireCheckTimer()
    	{
    		// if switching to another weapon, abort firing and put down right away
    		if( bWeaponPutDown )
    		{
    			`LogInv("Weapon put down requested during fire, put it down now");
    			PutDownWeapon();
    			return;
    		}
    
    		// If weapon should keep on firing, then do not leave state and fire again.
    		if( ShouldRefire() )
    		{
    			FireAmmunition();
    			return;
    		}
    
    		// Otherwise we're done firing
    		HandleFinishedFiring();
    	}
    
    	simulated event BeginState( Name PreviousStateName )
    	{
    		local ActTwoSide_PlayerPawn POwner;
    
    		POwner = ActTwoSide_PlayerPawn(Instigator);
    		if (POwner != None)
    		{
    			POwner.SetWeaponAmbientSound(StartAltFireSound);
    		}
    
    		`LogInv("PreviousStateName:" @ PreviousStateName);
    		// Fire the first shot right away
    		FireAmmunition();
    		TimeWeaponFiring( CurrentFireMode );
    
    		//Instigator.PlaySound(EndAltFireSound);
    	}
    
    	simulated event EndState( Name NextStateName )
    	{
    		local ActTwoSide_PlayerPawn POwner;
    
    		POwner = ActTwoSide_PlayerPawn(Instigator);
    		if (POwner != None)
    		{
    			POwner.SetWeaponAmbientSound(None);
    		}
    
    		`LogInv("NextStateName:" @ NextStateName);
    		// Set weapon as not firing
    		ClearFlashCount();
    		ClearFlashLocation();
    		ClearTimer( nameof(RefireCheckTimer) );
    
    		NotifyWeaponFinishedFiring( CurrentFireMode );
    
    		//Instigator.PlaySound(None);
    
    	}
    }
    
    defaultproperties
    {
    	// Set the weapon firing states
    	FiringStatesArray(0)="WeaponFiring"
    
    	// Set the weapon to fire projectiles by default
    	WeaponFireTypes(0)=EWFT_Projectile
    }
    どこかおかしな点などわかる方いましたら返信頂けると幸いです。

  2. #2

    Default

    武器の効果音を複数同時再生するのでなければ、
    SetWeaponAmbientSound()命令ではなく、単純にPlaySound()命令でいいと 思います。

    以下の2つのコメントアウトを取り外して、再生する時の引数をStartAltFireSoundにしてみ るといいかもしれません。
    再生する時:
    //Instigator.PlaySound(EndAltFireSound);
    停止する時:
    //Instigator.PlaySound(None);

    効果音をLoopしたい場合は、UDKのコンテンツブラウザから新たにSoundCueを作っ て、
    そのサウンドキューにLoopingというノードを加えれば、ループサウンドが作れます。
    そのループサウンドを上記PlaySoundで指定すれば、いけるんじゃないかと思います。

  3. #3
    MSgt. Shooter Person
    Join Date
    Jan 2010
    Location
    Tokyo, JAPAN
    Posts
    34

    Default

    Ayaemonさん

    返信どもです

    PlaySoundですが最初はこの方法で実装しようと思っていました。
    ただ、複数再生されてしまうため他の方法がないか探していました。

    使用しているSoundCueはテスト用として、
    既存の'A_Weapon_Link.Cue.A_Weapon_Link_AltFireCue'(ルー プサウンド)を使用しているのですが、
    EndStateでInstigator.PlaySound(None);を呼んでも
    サウンドは停止せずに次のBeginStateが呼ばれ
    複数再生されているような状態となってしまいます。

    停止時に他にしないこととかあるんでしょうか。。

  4. #4
    MSgt. Shooter Person
    Join Date
    Jan 2010
    Location
    Tokyo, JAPAN
    Posts
    34

    Default

    なんとか自己解決しました。

    どうもAudioComponentの初期化処理が抜けていただけだったようです。

    以下のコードをdefaultproperties内に追加したら
    意図したようにサウンドが停止されました。

    Code:
    Begin Object Class=UTAmbientSoundComponent name=AmbientSoundComponent
    End Object
    WeaponAmbientSound=AmbientSoundComponent
    Components.Add(AmbientSoundComponent)
    まだまだUnrealScriptを理解が足りないようで
    もっとコード書いて行かなくてはなぁと思いました。


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.