让新场景的孩子们(Get Children of New Scene)
我有一个
GameManager
脚本,它管理加载场景,在场景中放置角色,从游戏对象中读取地图信息等等。GameManager
脚本设置为DontDestroyOnLoad
。我试图弄清楚如何在加载新场景后从
GameManager
访问我的新场景中的对象。 我正在使用SceneManager.sceneLoaded
事件来运行我的“场景初始化”代码。 这是事件处理程序:void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode) { // I want to access GameObjects within the newly loaded scene here // // SceneManager.GetActiveScene().GetRootGameObjects() returns // System.ArgumentException: the scene is not loaded // I want to do something like this foreach (MapFeature mapFeature in rootObject.GetComponentsInChildren<MapFeature>()) { // Do something } }
我想获得新场景的根级
GetComponentInChildren
,然后在该根对象上使用GetComponentInChildren
,以便动态地抓取场景中的各种组件并将它们存储在GameManager
。 但是,SceneManager.GetActiveScene().GetRootGameObjects()
返回System.ArgumentException: the scene is not loaded
如何在
GameManager
从新加载的场景中获取对象? 如果有一个比获得新场景的根对象更好的方法并使用它来获取它的孩子,我会全神贯注。I have a
GameManager
script which manages loading scenes, putting characters in the scene, reading map information from game objects, and so on. TheGameManager
script is set toDontDestroyOnLoad
.I'm trying to figure out how to access objects within my new scene from
GameManager
after a new scene loads. I'm using theSceneManager.sceneLoaded
event to run my "scene initialization" code. Here's the event handler:void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode) { // I want to access GameObjects within the newly loaded scene here // // SceneManager.GetActiveScene().GetRootGameObjects() returns // System.ArgumentException: the scene is not loaded // I want to do something like this foreach (MapFeature mapFeature in rootObject.GetComponentsInChildren<MapFeature>()) { // Do something } }
I'm want to get the root level
GameObject
of the new scene, and then useGetComponentInChildren
on that root object in order to dynamically grab various components in the scene and store them inGameManager
. However,SceneManager.GetActiveScene().GetRootGameObjects()
returnsSystem.ArgumentException: the scene is not loaded
How do I get objects from my newly loaded scene within my
GameManager
? If there's a better method than getting the new scene's root object and using that to get its children, I'm all ears.
原文:
最满意答案
communicate
返回一个元组所以你可以在运行中解压缩它(就像你的第一个版本一样):
stdout, stderr = p.communicate()
或者您可以按原样获取元组(就像您修改后的代码一样):
stdout = p.communicate() # tuple with 'stdout' and 'stderr'
我想放弃
stderr
,你可以写:stdout = p.communicate()[0]
communicate
returns a tupleSo you can either unpack it on-the-fly (like in your first version):
stdout, stderr = p.communicate()
or you can get the tuple as-is (like is your modified code):
stdout = p.communicate() # tuple with 'stdout' and 'stderr'
I you want to drop
stderr
, you can write:stdout = p.communicate()[0]
相关问答
更多-
在测试输出时,我已经使用此片段将cout调用重定向到stringstream。 希望它可能引发一些想法。 我以前从未使用过googletest。 // This can be an ofstream as well or any other ostream std::stringstream buffer; // Save cout's buffer here std::streambuf *sbuf = std::cout.rdbuf(); // Redirect cout to our string ...
-
这是众所周知的,因为它在手册中 。 在stderr上报告消息很常见,因为消息与stdout输出上的常规输出分离。 将几个工具与管道组合时,这很有用。 在这种情况下,当常规输出和诊断消息混在一起时会很糟糕。 It's well known, because it's in the manual. Reporting messages on stderr is common, because messages are separated from regular output on stdout. This i ...
-
是的,您可以将其重定向到std::stringstream : std::stringstream buffer; std::streambuf * old = std::cout.rdbuf(buffer.rdbuf()); std::cout << "Bla" << std::endl; std::string text = buffer.str(); // text will now contain "Bla\n" 您可以使用简单的保护类来确保缓冲区总是被重置: struct cout_redi ...
-
作为生成stdout和stderr的测试,我们使用下面的代码: { echo out; echo err >&2; } 以下代码演示了如何将stdout和stderr发送到管道中的下一个步骤,同时还将stderr发送到终端: $ { echo out; echo err >&2; } 2> >(tee /dev/stderr) | cat >f err $ cat f out err 怎么运行的 2> 这将stderr重定向到随后的(伪)文件。 >(tee /dev/stderr) 这是进程替换以及它作 ...
-
lisp:捕获stdout和stderr,将其存储在单独的变量中(lisp: capture stdout and stderr, store it in separate variables)[2023-07-11]
您可以使用let将流绑定到输出字符串流。 例如: (defun print-stuff (x y) (format t "standard output ~a" x) (format *error-output* "error output ~a" y) (+ x y)) (defun capture (x y) (let ((*standard-output* (make-string-output-stream)) (*error-output* (make-strin ... -
好吧,通过一些谷歌搜索和黑客攻击,我得到了我想要的东西: /subsystem=logging/console-handler=JUST-PRINT:add(formatter="%s%E%n") /subsystem=logging/logger=stderr:add(use-parent-handlers="false", handlers=[JUST-PRINT]) /subsystem=logging/logger=stdout:add(use-parent-handlers="false", ha ...
-
如何在java中获取输出流的名称(即stderr或stdout)?(How to get name of output stream (i.e, stderr, or stdout) in java?)[2023-11-25]
尝试这个: public void printStreamName(OutputStream stream) { String streamName = "Other"; if(stream instanceof PrintStream) { streamName = stream == System.err ? "System.err" : (stream == System.out ? "System.out" : "Other"); } System ... -
子进程基本上就像在终端中运行该命令一样。 所以你正在做的是运行notepad some_file.txt ,它只是在记事本中打开一个文件,但它不会向标准输出发送任何内容。 如果您运行一个将某些内容写入标准输出的命令,那么您将拥有一个非空的stdout1。 例如,如果您使用的是* nix系统,请尝试使用ls ,如果是Windows,请尝试使用dir 。 Subprocess is basically as if you run that command in the terminal. So what you ...
-
communicate返回一个元组 所以你可以在运行中解压缩它(就像你的第一个版本一样): stdout, stderr = p.communicate() 或者您可以按原样获取元组(就像您修改后的代码一样): stdout = p.communicate() # tuple with 'stdout' and 'stderr' 我想放弃stderr ,你可以写: stdout = p.communicate()[0] communicate returns a tuple So you can ei ...
-
这不会捕获stderr的结果。 results_Test = subprocess.Popen( HYDRA_TEST_COMMAND, stdout=subprocess.PIPE, shell=True) 因为stderr没有被重定向,只有stdout ,你的程序将无法读取它。 您的两个选择是将stderr和stdout混合到一个流中,或者单独捕获它们。 如果要将stderr和stdout合并为一个流, results_Test = subprocess.Popen( ...