-
Notifications
You must be signed in to change notification settings - Fork 80
[Draft][USDU-331] Make package samples more user friendly #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 32 commits
c4b7a8b
464ea5b
7af60ed
20dc1c7
4236bd0
2d14b87
bb60d3e
fa6e626
c354a2a
8ec4518
8f76aee
24392f2
8399af7
bbd2308
9656bc2
5bc6608
7eff80c
786ea4b
9891944
e02a734
9588f2c
92da6e3
33e3782
be78943
721337d
5d5827b
fcba3e5
e9f8a52
fba3a79
b446bff
94483f0
04d33ab
eddf389
149d34f
8891a7b
5f6ce5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| using System; | ||
| using System.IO; | ||
| using System.Runtime.CompilerServices; | ||
| using UnityEditor; | ||
| using UnityEngine; | ||
|
|
||
| namespace Unity.Formats.USD | ||
| { | ||
| public static class SampleUtils | ||
| { | ||
| /// <summary> | ||
| /// Utils functions for the package Samples | ||
| /// </summary> | ||
|
|
||
| public static string SampleArtifactDirectory => Path.Combine(Application.dataPath, "Samples"); | ||
| public static string SampleArtifactRelativeDirectory => "Assets/Samples"; | ||
|
|
||
| private static EditorWindow GetConsoleWindow() | ||
| { | ||
| var editorWindowTypes = TypeCache.GetTypesDerivedFrom<EditorWindow>(); | ||
| foreach (var type in editorWindowTypes) | ||
| { | ||
| if (type.Name == "ConsoleWindow") | ||
| { | ||
| return EditorWindow.GetWindow(type); | ||
| } | ||
| } | ||
|
|
||
| throw new System.Exception("Error could not find ConsoleWindow type"); | ||
| } | ||
|
|
||
| public static void FocusConsoleWindow() | ||
| { | ||
| #if UNITY_EDITOR | ||
| var consoleWindow = GetConsoleWindow(); | ||
| consoleWindow.Focus(); | ||
| #endif | ||
| } | ||
|
|
||
| public struct TextColor | ||
| { | ||
| public const string Red = "#FF2D2D"; | ||
| public const string Green = "#00FF00"; | ||
| public const string Blue = "#338DFF"; | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // Copyright 2017 Google Inc. All rights reserved. | ||
| // Copyright 2023 Unity Technologies. All rights reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
|
|
@@ -12,8 +12,8 @@ | |
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| using UnityEngine; | ||
| using UnityEditor; | ||
| using UnityEngine; | ||
|
|
||
| namespace Unity.Formats.USD.Examples | ||
| { | ||
|
|
@@ -25,30 +25,80 @@ public override void OnInspectorGUI() | |
| DrawDefaultInspector(); | ||
|
|
||
| ExportMeshExample script = (ExportMeshExample)target; | ||
| if (script.IsRecording) | ||
|
|
||
| var labelStyle = new GUIStyle() { fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleLeft, wordWrap = true }; | ||
| labelStyle.normal.textColor = Color.white; | ||
|
|
||
| GUILayout.Label($"\nFor Exporting as <.{script.FileExtension}>, follow these step(s):", labelStyle); | ||
|
|
||
| if (GUILayout.Button("1. Initialize USD Package")) | ||
| { | ||
| var oldBg = GUI.backgroundColor; | ||
| GUI.backgroundColor = Color.white; | ||
| if (GUILayout.Button("Stop")) | ||
| { | ||
| script.StopRecording(); | ||
| EditorApplication.isPaused = true; | ||
| } | ||
|
|
||
| GUI.backgroundColor = oldBg; | ||
| script.InitUSD(); | ||
| } | ||
| else | ||
|
|
||
| switch (script.FileExtension) | ||
| { | ||
| var oldBg = GUI.backgroundColor; | ||
| GUI.backgroundColor = Color.red; | ||
| if (GUILayout.Button("Record")) | ||
| { | ||
| EditorApplication.isPaused = false; | ||
| //EditorApplication.isPlaying = true; | ||
| script.StartRecording(); | ||
| } | ||
|
|
||
| GUI.backgroundColor = oldBg; | ||
| case ExportMeshExample.UsdFileExtension.usd: | ||
| case ExportMeshExample.UsdFileExtension.usda: | ||
| case ExportMeshExample.UsdFileExtension.usdc: | ||
| { | ||
| if (GUILayout.Button("2. Create New USD Scene")) | ||
| { | ||
| SampleUtils.FocusConsoleWindow(); | ||
|
|
||
| script.CreateNewUsdScene(); | ||
| Debug.Log($"<color={SampleUtils.TextColor.Green}>Created USD file: <b><{script.m_newUsdFileName}.{script.FileExtension}></b> under project <b>'{SampleUtils.SampleArtifactRelativeDirectory}'</b> folder</color>"); | ||
| } | ||
|
|
||
| if (GUILayout.Button("3. Set up Export Context")) | ||
| { | ||
| SampleUtils.FocusConsoleWindow(); | ||
|
|
||
| script.SetUpExportContext(); | ||
| } | ||
|
|
||
| if (GUILayout.Button("3. Set up Export Context")) | ||
lee-aandrew marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| SampleUtils.FocusConsoleWindow(); | ||
|
|
||
| script.SetUpExportContext(); | ||
| } | ||
|
|
||
| if (GUILayout.Button("4. Export")) | ||
| { | ||
| SampleUtils.FocusConsoleWindow(); | ||
|
|
||
| script.Export(); | ||
| } | ||
|
|
||
| if (GUILayout.Button("5. Save Scene")) | ||
| { | ||
| SampleUtils.FocusConsoleWindow(); | ||
|
|
||
| script.SaveScene(); | ||
| AssetDatabase.Refresh(); | ||
| Debug.Log($"<color={SampleUtils.TextColor.Green}>Exported details of <b><{script.m_exportRoot.name}></b> into <b><{script.m_newUsdFileName}.{script.FileExtension}></b></color>"); | ||
| } | ||
|
|
||
| if (GUILayout.Button("6. Close Scene")) | ||
| { | ||
| script.CloseScene(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see a reason to do the Save and Close steps seperately- I think they should be combined into one step to reduce clicks. |
||
| } | ||
| break; | ||
| } | ||
|
|
||
| case ExportMeshExample.UsdFileExtension.usdz: | ||
| { | ||
| if (GUILayout.Button("2. Export GameObject as USDZ")) | ||
| { | ||
| SampleUtils.FocusConsoleWindow(); | ||
| Debug.Log("For USDZ Export the sample will utilize the <b>UsdzExporter.cs</b> script"); | ||
| script.ExportAsUsdz(); | ||
| AssetDatabase.Refresh(); | ||
| Debug.Log($"<color={SampleUtils.TextColor.Green}>Exported details of <b><{script.m_exportRoot.name}></b> into <b><{script.m_newUsdFileName}.usdz></b></color>"); | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.