在 Unrealscript 中,如何为类中的资源配置值并设置组件的属性?
我有一个声音提示,每当玩家执行特定操作时我都会播放该声音提示。我已经让它运行得很好,但我想让所使用的资源来自配置文件而不是硬编码。
因此,我向我的类添加了一个名为 MonsterNoiseSoundCue 的属性,如下所示:
var config SoundCue MonsterNoiseSoundCue;
然后在 DefaultProperties 部分中,我将以下内容添加到我创建的对象中,然后将其添加到我的 pawn 的组件集合中。
Begin Object Class=AudioComponent Name=MonsterActivatedSound1
bAutoPlay=false
SoundCue=MonsterNoiseSoundCue// This variable is a configured value. SoundCue'CastleAudio.UI.UI_StopTouchToMove_Cue'
End Object
Components.Add(MonsterActivatedSound1);
MonsterActivatedSound = MonsterActivatedSound1;
由于某种原因,它不会构建说“不允许将‘配置’与对象变量一起使用。”有谁知道另一种方法来解决这个问题?
I have a sound cue that I want played whenever the player does a specific action. I've got it playing fine and everything but I want to make the resource that is used come from a configuration file instead of being hard coded.
So I added a property to my class called MonsterNoiseSoundCue as follows:
var config SoundCue MonsterNoiseSoundCue;
Then in the DefaultProperties section I added the following to the object I create which then then added to the components collection of my pawn.
Begin Object Class=AudioComponent Name=MonsterActivatedSound1
bAutoPlay=false
SoundCue=MonsterNoiseSoundCue// This variable is a configured value. SoundCue'CastleAudio.UI.UI_StopTouchToMove_Cue'
End Object
Components.Add(MonsterActivatedSound1);
MonsterActivatedSound = MonsterActivatedSound1;
For some reason it doesn't build saying "Not allowed to use 'config' with object variable." Does anyone know of another way to approach this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
“不允许将‘配置’与对象变量一起使用。”消息是 UnrealEngine 3 中的更改。
我现在无法测试,而且我是 UT2004 脚本编写者,但我会尝试这样做:
在您的 PreBeginPlay 函数(或类似函数)中,使用它来获取提示:
您应该在如果声音提示不存在则记录。
That "Not allowed to use 'config' with object variable." message was a change in UnrealEngine 3.
I cannot test right now and I'm a UT2004 scripter, but I would try this:
In your PreBeginPlay function (or similar), use this to get the cue:
You should get a warning in the log if the sound cue doesn't exist.
你用什么函数来播放声音?
PlaySound 将动态创建一个 AudioComponent,因此您不需要在 defaultproperties 部分中有一个组件。
然后当你的行动发生时:
What function are you using to play the sound?
PlaySound will create an AudioComponent on the fly so you shouldn't need to have a component in the defaultproperties section.
Then when your action happens:
要动态创建组件的实例,请使用 UnrealScript new 运算符并调用 actor 的 AttachComponent 方法将新组件附加到 actor。
要分离并释放之前附加的组件,请使用 actor 的 DetachComponent 方法。
http://wiki.beyondunreal.com/UE3:AudioComponent_(UDK)
To dynamically create an instance of a component, use the UnrealScript new operator and call the actor's AttachComponent method to attach the new component to the actor.'
To detach and free the component which you attached earlier, use the actor's DetachComponent method.
http://wiki.beyondunreal.com/UE3:AudioComponent_(UDK)