Unity命令行-executeMethod和logFile不起作用?

时间:2019-02-19 03:49:33

标签: unity3d

我正在尝试使用Unity Command Line自变量,并试图简单地编写一个写入文件的编辑器功能。如果我从Unity内部运行该函数,则可以正常运行,并且可以成功查看文件的内容,但是当我尝试从命令提示符处调用该函数时,它在控制台中不会给出任何错误消息(甚至如果我将函数的名称更改为不存在的名称,它也不会引起任何错误..因此,如果可能的话,获得错误stdout也很酷)。这是我的基本统一类(在统一内部调用时有效):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.Networking;
using System.IO;

public class CobysBundleBuilder {
    public static void CobyBuildIt() {
        var path = "Assets/test.txt";
        StreamWriter writer = new StreamWriter(path, true);
        writer.WriteLine("Hi there!");
        writer.Close();
        Debug.Log("ASDFGG");
        MonoBehaviour.print("wow");
    }
}

这是我从命令行调用的命令,我什至看不到创建的日志文件:

C:\"Program Files"\Unity\Hub\Editor\2019.1.0b1\Editor\Unity.exe -batchmode -quit -projectPath C:\Users\me\OneDrive\Documents\"totally empty"\"New Unity Project" -executeMethod CobysBundleBuilder.CobyBuildIt -logFile C:\Users\me\OneDrive\Desktop

首先,没有写入到我的资产文件夹(test.txt)中的所需文件(就像从Unity中调用时一样),并且日志文件也没有出现在我的桌面。

我缺少基本的东西吗?我只是想测试Unity命令行参数,并获得一些基本的功能。

谢谢,如果有人知道如何解决它。

P.S。

还有可能projectPath参数可能不起作用,因为当我不带-batchmode和-quit调用命令时,它只会打开包含所有项目列表的unity hub,但不会打开特定项目作为参数通过。

编辑: 我尝试将脚本放在我的Assets / Editor文件夹中,并检查了AppData中的Editor.Log文件,这就是它的意思(我更改了功能BTW):

LICENSE SYSTEM [2019219 0:41:36] Next license update check is after 2018-08-28T23:32:35


LICENSE SYSTEM [2019219 0:41:36] 00342-20100-00000-AAOEM != 00342-20108-34498-AAOEM

Built from '2019.1/staging' branch; Version is '2019.1.0b1 (83b3ba1f99df) revision 8631226'; Using compiler version '191627012'
OS: 'Windows 10  (10.0.0) 64bit' Language: 'en' Physical Memory: 11743 MB
BatchMode: 1, IsHumanControllingUs: 0, StartBugReporterOnCrash: 0, Is64bit: 1, IsPro: 0
[Package Manager] Server::Start -- Port 54964 was selected

 COMMAND LINE ARGUMENTS:
C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Unity
-batchmode
-quit
-projectPath
C:\Users\me\OneDrive\Documents\totally empty
-executeMethod
MyScript.MyMethod
Successfully changed project path to: C:\Users\me\OneDrive\Documents\totally empty
C:/Users/me/OneDrive/Documents/totally empty
Using Asset Import Pipeline V1.
DisplayProgressbar: Unity Package Manager
Loading GUID <-> Path mappings...0.000110 seconds
Loading Asset Database...0.016790 seconds
AssetDatabase consistency checks...0.049615 seconds
[Package Manager] Done resolving packages in 0.74s seconds
[Package Manager] Registering 38 packages:
[Package Manager]  * Package :  com.unity.ads@2.0.8
    (location: C:\Users\me\OneDrive\Documents\totally empty\Library\PackageCache\com.unity.ads@2.0.8)
[Package Manager]  * Package :  com.unity.analytics@3.2.2
    (location: C:\Users\me\OneDrive\Documents\totally empty\Library\PackageCache\com.unity.analytics@3.2.2)
[Package Manager]  * Package :  com.unity.collab-proxy@1.2.15
    (location: C:\Users\me\OneDrive\Documents\totally empty\Library\PackageCache\com.unity.collab-proxy@1.2.15)
[Package Manager]  * Package :  com.unity.package-manager-ui@2.1.1
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.package-manager-ui)
[Package Manager]  * Package :  com.unity.purchasing@2.0.1
    (location: C:\Users\me\OneDrive\Documents\totally empty\Library\PackageCache\com.unity.purchasing@2.0.1)
[Package Manager]  * Package :  com.unity.textmeshpro@1.3.0
    (location: C:\Users\me\OneDrive\Documents\totally empty\Library\PackageCache\com.unity.textmeshpro@1.3.0)
[Package Manager]  * Package :  com.unity.timeline@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.timeline)
[Package Manager]  * Package :  com.unity.xr.legacyinputhelpers@1.0.0
    (location: C:\Users\me\OneDrive\Documents\totally empty\Library\PackageCache\com.unity.xr.legacyinputhelpers@1.0.0)
[Package Manager]  * Package :  com.unity.modules.ai@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.ai)
[Package Manager]  * Package :  com.unity.modules.animation@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.animation)
[Package Manager]  * Package :  com.unity.modules.assetbundle@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.assetbundle)
[Package Manager]  * Package :  com.unity.modules.audio@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.audio)
[Package Manager]  * Package :  com.unity.modules.cloth@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.cloth)
[Package Manager]  * Package :  com.unity.modules.director@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.director)
[Package Manager]  * Package :  com.unity.modules.imageconversion@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.imageconversion)
[Package Manager]  * Package :  com.unity.modules.imgui@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.imgui)
[Package Manager]  * Package :  com.unity.modules.jsonserialize@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.jsonserialize)
[Package Manager]  * Package :  com.unity.modules.particlesystem@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.particlesystem)
[Package Manager]  * Package :  com.unity.modules.physics@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.physics)
[Package Manager]  * Package :  com.unity.modules.physics2d@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.physics2d)
[Package Manager]  * Package :  com.unity.modules.screencapture@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.screencapture)
[Package Manager]  * Package :  com.unity.modules.terrain@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.terrain)
[Package Manager]  * Package :  com.unity.modules.terrainphysics@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.terrainphysics)
[Package Manager]  * Package :  com.unity.modules.tilemap@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.tilemap)
[Package Manager]  * Package :  com.unity.modules.ui@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.ui)
[Package Manager]  * Package :  com.unity.modules.uielements@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.uielements)
[Package Manager]  * Package :  com.unity.modules.umbra@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.umbra)
[Package Manager]  * Package :  com.unity.modules.unityanalytics@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.unityanalytics)
[Package Manager]  * Package :  com.unity.modules.unitywebrequest@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.unitywebrequest)
[Package Manager]  * Package :  com.unity.modules.unitywebrequestassetbundle@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.unitywebrequestassetbundle)
[Package Manager]  * Package :  com.unity.modules.unitywebrequestaudio@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.unitywebrequestaudio)
[Package Manager]  * Package :  com.unity.modules.unitywebrequesttexture@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.unitywebrequesttexture)
[Package Manager]  * Package :  com.unity.modules.unitywebrequestwww@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.unitywebrequestwww)
[Package Manager]  * Package :  com.unity.modules.vehicles@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.vehicles)
[Package Manager]  * Package :  com.unity.modules.video@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.video)
[Package Manager]  * Package :  com.unity.modules.vr@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.vr)
[Package Manager]  * Package :  com.unity.modules.wind@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.wind)
[Package Manager]  * Package :  com.unity.modules.xr@1.0.0
    (location: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.modules.xr)
[Package Manager] Done registering packages in 0.01s seconds
Refreshing native plugins compatible for Editor in 18.94 ms, found 2 plugins.
Preloading 0 native plugins for Editor in 0.00 ms.
Initialize engine version: 2019.1.0b1 (83b3ba1f99df)
GfxDevice: creating device client; threaded=0
Direct3D:
    Version:  Direct3D 11.0 [level 11.1]
    Renderer: AMD Radeon(TM) R7 Graphics (ID=0x9874)
    Vendor:   
    VRAM:     3433 MB
    Driver:   22.19.180.513
Launched and connected shader compiler UnityShaderCompiler.exe after 0.14 seconds
[EnlightenBakeManager] m_Clear = false;
WARNING: Shader Unsupported: 'AR/TangoARRender' - Pass '' has no vertex shader
WARNING: Shader Unsupported: 'AR/TangoARRender' - Setting to default shader.
WARNING: Shader Unsupported: 'Hidden/VideoDecodeOSX' - Pass 'Flip_RGBARect_To_RGBA' has no vertex shader
WARNING: Shader Unsupported: 'Hidden/VideoDecodeOSX' - Setting to default shader.
WARNING: Shader Unsupported: 'Hidden/VideoDecodeAndroid' - Pass 'RGBAExternal_To_RGBA' has no vertex shader
WARNING: Shader Unsupported: 'Hidden/VideoDecodeAndroid' - Setting to default shader.
WARNING: Shader Unsupported: 'Hidden/VideoDecodeML' - Pass 'RGBAExternal_To_RGBA' has no vertex shader
WARNING: Shader Unsupported: 'Hidden/VideoDecodeML' - Setting to default shader.
Initialize mono
Mono path[0] = 'C:/Program Files/Unity/Hub/Editor/2019.1.0b1/Editor/Data/Managed'
Mono path[1] = 'C:/Program Files/Unity/Hub/Editor/2019.1.0b1/Editor/Data/MonoBleedingEdge/lib/mono/unityjit'
Mono config path = 'C:/Program Files/Unity/Hub/Editor/2019.1.0b1/Editor/Data/MonoBleedingEdge/etc'
Using monoOptions --debugger-agent=transport=dt_socket,embedding=1,server=y,suspend=n,address=0.0.0.0:56428
Begin MonoManager ReloadAssembly
Refreshing native plugins compatible for Editor in 0.97 ms, found 3 plugins.
Initializing Extension Manager v2019.1.0 for Unity v2019.1.0b1
Registering precompiled unity dll's ...
Register platform support module: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\PlaybackEngines\windowsstandalonesupport/UnityEditor.WindowsStandalone.Extensions.dll
Register platform support module: C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Data\PlaybackEngines\WebGLSupport/UnityEditor.WebGL.Extensions.dll
Registered in 0.005863 seconds.
Registering platform support modules:
Registered platform support modules in: 0.2405032s.
Native extension for WindowsStandalone target not found
Native extension for WebGL target not found
Refreshing native plugins compatible for Editor in 0.59 ms, found 3 plugins.
Preloading 1 native plugins for Editor in 3.16 ms.
Mono: successfully reloaded assembly
- Completed reload, in  3.308 seconds
Registering precompiled user dll's ...
Registered in 0.082678 seconds.
Platform modules already initialized, skipping
Begin MonoManager ReloadAssembly

我的新C#代码几乎相同,但是无论如何都在这里:

using UnityEngine;
using UnityEditor;
using System.IO;
public class MyScript {

    public static void MyMethod () {
        var path = "Assets/test.txt";
        StreamWriter writer = new StreamWriter(path, true);
        writer.WriteLine("Hi there!");
        writer.Close();
        Debug.Log ("Here you put your code");
    }
}

运行命令后,仍未创建test.txt文件。

第二次编辑:我刚刚看到一个新的答案,即日志文件确实需要是一个文件名,然后创建了日志文件!这就是它的意思:

LICENSE SYSTEM [2019219 0:45:54] Next license update check is after 2018-08-28T23:32:35


LICENSE SYSTEM [2019219 0:45:54] 00342-20100-00000-AAOEM != 00342-20108-34498-AAOEM

    Built from '2019.1/staging' branch; Version is '2019.1.0b1 (83b3ba1f99df) revision 8631226'; Using compiler version '191627012'
    OS: 'Windows 10  (10.0.0) 64bit' Language: 'en' Physical Memory: 11743 MB
    BatchMode: 1, IsHumanControllingUs: 0, StartBugReporterOnCrash: 0, Is64bit: 1, IsPro: 0
    [Package Manager] Server::Start -- Port 51774 was selected



        COMMAND LINE ARGUMENTS:
        C:\Program Files\Unity\Hub\Editor\2019.1.0b1\Editor\Unity
        -batchmode
        -quit
        -projectPath
        C:\Users\me\OneDrive\Documents\totally empty
        -executeMethod
        MyScript.MyMethod
        -logfile
        C:\Users\me\OneDrive\Desktop\wow.txt
        Successfully changed project path to: C:\Users\me\OneDrive\Documents\totally empty
        C:/Users/me/OneDrive/Documents/totally empty
        Using Asset Import Pipeline V1.
        DisplayProgressbar: Unity Package Manager
        Loading GUID <-> Path mappings...0.000149 seconds
        Loading Asset Database...0.018028 seconds
        AssetDatabase consistency checks...0.041902 seconds

所以它似乎正在打开项目,但是仍然没有创建test.txt文件,因此似乎还没有调用MyScript.MyMethod函数。

1 个答案:

答案 0 :(得分:0)

如文档所述,-logfile的参数应为文件名,并且您似乎使用目录名,这可能是原因。

https://docs.unity3d.com/2019.1/Documentation/Manual/CommandLineArguments.html