我试图将侦听器添加到Ross XPression项目中的场景中。我在XPression Developer中使用了音序器。当我按下' +'我在键盘上选择一个场景时键盘上的按钮我希望能够将某些内容写入控制台 这是控制台的输出:
scene.Name == Opener
scene.AnimControllerCount == 2
animController.Name == AnimController1
animController.Name == Rotate
这是我的代码:
private xpEngine engine;
private xpProject project;
private xpScene scene;
private xpAnimController animController1;
private xpAnimController animController2;
public MainWindow()
{
InitializeComponent();
engine = new xpEngine();
project = engine.ActiveProject;
if (project.GetSceneByName("Opener",out scene))
{
Console.WriteLine("scene.Name == " + scene.Name);
scene.OnSceneState += Scene_OnSceneState;
scene.SceneDirector.OnSceneDirectorState += SceneDirector_OnSceneDirectorState;
Console.WriteLine("scene.AnimControllerCount == " + scene.AnimControllerCount);
if (scene.GetAnimController(0, out animController1))
{
Console.WriteLine("animController.Name == " + animController1.Name);
animController1.OnStateChange += AnimController_OnStateChange;
}
if (scene.GetAnimController(1, out animController2))
{
Console.WriteLine("animController.Name == " + animController2.Name);
animController2.OnStateChange += AnimController_OnStateChange;
}
}
}
private void SceneDirector_OnSceneDirectorState(xpSceneDirector Director, SceneDirectorState State)
{
Console.WriteLine("Director: " + Director.Name + " State: " + State);
}
private void Scene_OnSceneState(xpScene Scene, int State)
{
Console.WriteLine("Scene: " + Scene.Name + " State: " + State);
}
private void AnimController_OnStateChange(xpAnimController Controller, PlayState State)
{
Console.WriteLine("Controller: " + Controller.Name + " State: " + State);
}
音序器本身会制作场景的副本,所以我无法想出办法。从输出中可以看出,事件不会被触发。这是为什么?我将不胜感激任何帮助。
答案 0 :(得分:0)
我使用的是旧版本的XPression API(v6.0)。更新到版本6.1后,我能够使用新的xpOutputFrameBuffer对象:OnSceneState事件。我现在能够在输出中监听场景状态:
using System;
using System.Windows;
using XPression;
namespace mynamespace
{
public partial class MainWindow : Window
{
private xpEngine engine;
private xpOutputFrameBuffer outputFrameBuffer;
public MainWindow()
{
InitializeComponent();
engine = new xpEngine();
if (engine.GetOutputFrameBuffer(0, out outputFrameBuffer))
{
outputFrameBuffer.OnSceneState += OutputFrameBuffer_OnSceneState;
}
}
private void OutputFrameBuffer_OnSceneState(xpScene Scene, int State)
{
Console.WriteLine("Scene: " + Scene.Name + " State: " + State);
}
}
}
输出:
Scene: Opener State: 0
Scene: Opener State: 1