浏览代码
Merge pull request #500 from Unity-Technologies/feature/HDEditorCLI
Merge pull request #500 from Unity-Technologies/feature/HDEditorCLI
Feature/hd editor cli/Yibing-Project-2
GitHub
7 年前
当前提交
dda4fde5
共有 6 个文件被更改,包括 278 次插入 和 31 次删除
-
33ScriptableRenderPipeline/HDRenderPipeline/Editor/HDEditorUtils.cs
-
58ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
-
77ScriptableRenderPipeline/HDRenderPipeline/Editor/HDEditorCLI.cs
-
13ScriptableRenderPipeline/HDRenderPipeline/Editor/HDEditorCLI.cs.meta
-
119ScriptableRenderPipeline/HDRenderPipeline/Editor/cli.ps1
-
9ScriptableRenderPipeline/HDRenderPipeline/Editor/cli.ps1.meta
|
|||
using System; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class HDEditorCLI |
|||
{ |
|||
enum CommandLineOperation |
|||
{ |
|||
None, |
|||
ResetMaterialKeywords |
|||
} |
|||
|
|||
struct CommandLineAction |
|||
{ |
|||
internal CommandLineOperation operation; |
|||
} |
|||
|
|||
const string k_SwitchOperation = "-operation"; |
|||
|
|||
public static void Run() |
|||
{ |
|||
var args = System.Environment.GetCommandLineArgs(); |
|||
|
|||
var action = ParseCommandLine(args); |
|||
Execute(action); |
|||
} |
|||
|
|||
static void Execute(CommandLineAction action) |
|||
{ |
|||
switch (action.operation) |
|||
{ |
|||
case CommandLineOperation.ResetMaterialKeywords: |
|||
{ |
|||
Console.WriteLine("[HDEditorCLI][ResetMaterialKeywords] Starting material reset"); |
|||
|
|||
var matIds = AssetDatabase.FindAssets("t:Material"); |
|||
|
|||
for (int i = 0, length = matIds.Length; i < length; i++) |
|||
{ |
|||
var path = AssetDatabase.GUIDToAssetPath(matIds[i]); |
|||
var mat = AssetDatabase.LoadAssetAtPath<Material>(path); |
|||
|
|||
if (HDEditorUtils.ResetMaterialKeywords(mat)) |
|||
Console.WriteLine("[HDEditorCLI][ResetMaterialKeywords] " + path); |
|||
} |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
static CommandLineAction ParseCommandLine(string[] args) |
|||
{ |
|||
CommandLineAction action = new CommandLineAction(); |
|||
for (int i = 0, length = args.Length; i < length; ++i) |
|||
{ |
|||
switch (args[i]) |
|||
{ |
|||
case k_SwitchOperation: |
|||
{ |
|||
if (i + 1 < length) |
|||
{ |
|||
++i; |
|||
try |
|||
{ |
|||
action.operation = (CommandLineOperation)Enum.Parse(typeof(CommandLineOperation), args[i]); |
|||
} |
|||
catch (Exception e) { } |
|||
} |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
return action; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4baa489311168cc4ebdf3cd85ceb544a |
|||
timeCreated: 1508231097 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
# Execute the HDEditorCLI from a powsershell scripts |
|||
# UNITY_PATH environment variable must be set to the folder containing Unity.exe |
|||
|
|||
Param |
|||
( |
|||
[parameter(Mandatory=$true)] |
|||
[ValidateSet("ResetMaterialKeywords")] |
|||
[String] |
|||
$Operation |
|||
) |
|||
|
|||
function FindUnityProjectRootPath |
|||
{ |
|||
Param |
|||
( |
|||
[parameter(Mandatory=$true)] |
|||
[string] |
|||
$Path |
|||
) |
|||
|
|||
$folderName = [System.IO.Path]::GetFileNameWithoutExtension("$Path"); |
|||
$currentPath = $Path; |
|||
|
|||
while ($folderName -ne "Assets" -and -not [string]::IsNullOrEmpty("$currentPath")) |
|||
{ |
|||
$currentPath = Split-Path -Path $currentPath -Parent; |
|||
$folderName = [System.IO.Path]::GetFileNameWithoutExtension("$currentPath"); |
|||
} |
|||
|
|||
return Split-Path -Path $currentPath -Parent; |
|||
} |
|||
|
|||
function FindUnityBin |
|||
{ |
|||
return [System.IO.Path]::Combine("$env:UNITY_PATH", "Unity.exe"); |
|||
} |
|||
|
|||
function GetLogFilePath |
|||
{ |
|||
Param |
|||
( |
|||
[parameter(Mandatory=$true)] |
|||
[string] |
|||
$ProjectPath |
|||
) |
|||
|
|||
$libPath = [System.IO.Path]::Combine("$ProjectPath", "Library"); |
|||
|
|||
if (-not [System.IO.Directory]::Exists("$libPath")) |
|||
{ |
|||
[System.IO.Directory]::CreateDirectory("$libPath"); |
|||
} |
|||
|
|||
return [System.IO.Path]::Combine("$libPath", "hdcli.log"); |
|||
} |
|||
|
|||
$projectPath = FindUnityProjectRootPath $PSScriptRoot; |
|||
if ([string]::IsNullOrEmpty("$projectPath")) |
|||
{ |
|||
throw "Unity Project Path was not found" |
|||
} |
|||
|
|||
$unityPath = FindUnityBin |
|||
if (-not [System.IO.File]::Exists("$unityPath")) |
|||
{ |
|||
throw "Unity binary was not found at $unityPath"; |
|||
} |
|||
|
|||
$logFilePath = GetLogFilePath $projectPath |
|||
|
|||
$cmd = $unityPath; |
|||
$params = '-projectPath', "$projectPath", '-quit', '-batchmode', '-logFile', "$logFilePath", '-executeMethod', 'UnityEditor.Experimental.Rendering.HDPipeline.HDEditorCLI.Run', '-operation', "$Operation" |
|||
|
|||
if (Test-Path $logFilePath) |
|||
{ |
|||
Remove-Item $logFilePath |
|||
} |
|||
|
|||
Start-Process $cmd $params |
|||
|
|||
while ((Test-Path $logFilePath) -eq $false) |
|||
{ |
|||
Start-Sleep -Milliseconds 100 |
|||
} |
|||
|
|||
$readJob = Start-Job -Name Reader -Arg $logFilePath -ScriptBlock { |
|||
param($file) |
|||
|
|||
Get-Content $file -Tail 1 -Wait |
|||
} |
|||
|
|||
Write-Host "Starting Task" |
|||
|
|||
while ($true) |
|||
{ |
|||
$lines = Receive-Job -Name Reader |
|||
$theEnd = $false; |
|||
foreach ($line in $lines) |
|||
{ |
|||
if ($line.Contains("[HDEditorCLI]")) |
|||
{ |
|||
Write-Host $line; |
|||
} |
|||
if ($line.Contains("Exiting batchmode")) |
|||
{ |
|||
$theEnd = $true; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if ($theEnd) |
|||
{ break; } |
|||
|
|||
Start-Sleep -Milliseconds 500 |
|||
} |
|||
|
|||
Stop-Job $readJob |
|||
|
|||
Write-Host "Task Complete" |
|
|||
fileFormatVersion: 2 |
|||
guid: a07b31caef0cfb741b72f94fd0139c89 |
|||
timeCreated: 1508233704 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue