问题
- EditorPrefs类可以修改Perforce的设置,但Unity文档中并没有解释如何实现
原因
EditorPrefs类可以修改Perforce的设置,以方便用户批量配置。相关的说明没有发布到Unity文档中,但可以在BitBucket上查询到相关信息。
解决方案
Unity内置的版本控制插件源代码可以在BitBucket上找到。
Perforce设置以及所有命令可到此处查询:
VersionControlPlugins/P4Plugin/Source/P4ConfigCommand.cpp
其中最重要的几个命令如下:
vcPerforceUsername -> string
vcPerforcePassword -> string
vcPerforceWorkspace -> string
vcPerforceServer -> string
vcPerforceHost -> string
vcSharedLogLevel -> one of these strings: "notice", "fatal" or "info'
下列脚本会在Editor启动时执行,作用是更改Perforce的设置:
using UnityEngine; using UnityEditor; [InitializeOnLoad] public class PerforceSettings { static PerforceSettings () { EditorUserSettings.SetConfigValue ("vcPerforceUsername", "myUserName"); EditorUserSettings.SetConfigValue ("vcPerforcePassword", "myPassword"); EditorUserSettings.SetConfigValue ("vcPerforceWorkspace", "myWorkspace"); EditorUserSettings.SetConfigValue ("vcPerforceServer", "10.11.12.13:1234"); EditorUserSettings.SetConfigValue ("vcPerforceHost", "Hostname"); EditorUserSettings.SetConfigValue ("vcSharedLogLevel", "info"); //"notice", "fatal" or "info"; } }
更多信息