在 Unrealscript 中,如何为类中的资源配置值并设置组件的属性?

发布于 2024-10-15 20:14:51 字数 680 浏览 6 评论 0原文

我有一个声音提示,每当玩家执行特定操作时我都会播放该声音提示。我已经让它运行得很好,但我想让所使用的资源来自配置文件而不是硬编码。

因此,我向我的类添加了一个名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

输什么也不输骨气 2024-10-22 20:14:51

“不允许将‘配置’与对象变量一起使用。”消息是 UnrealEngine 3 中的更改。

我现在无法测试,而且我是 UT2004 脚本编写者,但我会尝试这样做:

var SoundCue MonsterNoiseSoundCue;
var config string MonsterNoiseSoundCueName;

在您的 PreBeginPlay 函数(或类似函数)中,使用它来获取提示:

MonsterNoiseSoundCue = SoundCue(DynamicLoadObject(MonsterNoiseSoundCueName, class'SoundCue'));

您应该在如果声音提示不存在则记录。

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:

var SoundCue MonsterNoiseSoundCue;
var config string MonsterNoiseSoundCueName;

In your PreBeginPlay function (or similar), use this to get the cue:

MonsterNoiseSoundCue = SoundCue(DynamicLoadObject(MonsterNoiseSoundCueName, class'SoundCue'));

You should get a warning in the log if the sound cue doesn't exist.

中二柚 2024-10-22 20:14:51

你用什么函数来播放声音?

PlaySound 将动态创建一个 AudioComponent,因此您不需要在 defaultproperties 部分中有一个组件。

var config SoundCue MonsterNoiseSoundCue;

然后当你的行动发生时:

function OnMonsterAction()
{
    PlaySound(MonsterNoiseSoundCue);
}

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.

var config SoundCue MonsterNoiseSoundCue;

Then when your action happens:

function OnMonsterAction()
{
    PlaySound(MonsterNoiseSoundCue);
}
∞觅青森が 2024-10-22 20:14:51

要动态创建组件的实例,请使用 UnrealScript new 运算符并调用 actor 的 AttachComponent 方法将新组件附加到 actor。

simulated event PostBeginPlay()
{
    local AudioComponent AudioComponent;
    Super.PostBeginPlay();

    AudioComponent = new(self)
    AudioComponent.SoundCue = Cue;//var(audio) SoundCue Cue
    AudioComponent.bAutoPlay=true;
    AttachComponent(AudioComponent); // Attach copm. to actor's copm. array 
    // .....
}

要分离并释放之前附加的组件,请使用 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.'

simulated event PostBeginPlay()
{
    local AudioComponent AudioComponent;
    Super.PostBeginPlay();

    AudioComponent = new(self)
    AudioComponent.SoundCue = Cue;//var(audio) SoundCue Cue
    AudioComponent.bAutoPlay=true;
    AttachComponent(AudioComponent); // Attach copm. to actor's copm. array 
    // .....
}

To detach and free the component which you attached earlier, use the actor's DetachComponent method.

http://wiki.beyondunreal.com/UE3:AudioComponent_(UDK)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文