Skip to content

Commit 9656bc2

Browse files
committed
Update HelloUSD and Separated out + updated ExportMeshWithAnimation sample project
1 parent bbd2308 commit 9656bc2

35 files changed

+1595
-247
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.IO;
3+
using System.Runtime.CompilerServices;
4+
using UnityEditor;
5+
using UnityEngine;
6+
7+
namespace Unity.Formats.USD
8+
{
9+
public static class SampleUtils
10+
{
11+
/// <summary>
12+
/// Utils functions for the package Samples
13+
/// </summary>
14+
15+
private static EditorWindow GetConsoleWindow()
16+
{
17+
var editorWindowTypes = TypeCache.GetTypesDerivedFrom<EditorWindow>();
18+
foreach (var type in editorWindowTypes)
19+
{
20+
if (type.Name == "ConsoleWindow")
21+
{
22+
return EditorWindow.GetWindow(type);
23+
}
24+
}
25+
26+
throw new System.Exception("Error could not find ConsoleWindow type");
27+
}
28+
29+
public static void FocusConsoleWindow()
30+
{
31+
var consoleWindow = GetConsoleWindow();
32+
consoleWindow.Focus();
33+
}
34+
}
35+
}

package/com.unity.formats.usd/Editor/Utils/SampleUtils.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/com.unity.formats.usd/Samples/ExportMesh/Editor/ExportMeshExampleEditor.cs

Lines changed: 0 additions & 55 deletions
This file was deleted.

TestProject/Usd-Development/Assets/Resources.meta renamed to package/com.unity.formats.usd/Samples/ExportMeshWithAnimation.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2017 Google Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using UnityEngine;
16+
using UnityEditor;
17+
using System.IO;
18+
19+
namespace Unity.Formats.USD.Examples
20+
{
21+
[CustomEditor(typeof(ExportMeshWithAnimationExample))]
22+
public class ExportMeshExampleEditor : Editor
23+
{
24+
public override void OnInspectorGUI()
25+
{
26+
DrawDefaultInspector();
27+
28+
ExportMeshWithAnimationExample script = (ExportMeshWithAnimationExample)target;
29+
30+
if (!EditorApplication.isPlaying)
31+
{
32+
if (GUILayout.Button("Play Scene to Start Animation"))
33+
{
34+
EditorApplication.isPlaying = true;
35+
}
36+
}
37+
else
38+
{
39+
if (script.IsFinishedRecording)
40+
{
41+
if (GUILayout.Button("Recording Complete - Stop Scene"))
42+
{
43+
EditorApplication.isPlaying = false;
44+
Debug.Log($"<color=#00FF00>Open the <b>'Assets' Folder</b> in your Unity 'Project' Window to see your newly exported USD file <{script.m_newUsdFileName}></color>");
45+
SampleUtils.FocusConsoleWindow();
46+
}
47+
}
48+
49+
else
50+
{
51+
if (script.IsRecording)
52+
{
53+
GUI.backgroundColor = Color.white;
54+
var labelStyle = new GUIStyle() { fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleCenter };
55+
labelStyle.normal.textColor = Color.white;
56+
GUILayout.Label("Recording...", labelStyle);
57+
}
58+
else
59+
{
60+
GUI.backgroundColor = Color.red;
61+
if (GUILayout.Button("Record Animation"))
62+
{
63+
EditorApplication.isPaused = false;
64+
script.StartRecording();
65+
}
66+
}
67+
}
68+
}
69+
70+
}
71+
}
72+
}

package/com.unity.formats.usd/Samples/ExportMesh/Explode.cs renamed to package/com.unity.formats.usd/Samples/ExportMeshWithAnimation/Explode.cs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,25 @@ namespace USD.NET.Examples
1818
{
1919
public class Explode : MonoBehaviour
2020
{
21-
public int m_explodeTime = 10;
21+
public float m_explodeTime = 10;
2222
public Transform m_effectRoot;
2323
public float m_force = 1;
2424
public float m_radius = 1;
2525

26-
private bool m_active = true;
27-
28-
void Start()
29-
{
30-
}
26+
private float currTime;
3127

3228
void Update()
3329
{
34-
if (!m_active)
35-
{
36-
return;
37-
}
30+
currTime += Time.deltaTime;
3831

39-
if (Time.time < m_explodeTime)
32+
if (currTime > m_explodeTime)
4033
{
41-
return;
42-
}
34+
currTime = 0;
4335

44-
m_active = false;
45-
foreach (Rigidbody rb in m_effectRoot.GetComponentsInChildren<Rigidbody>())
46-
{
47-
rb.AddExplosionForce(m_force, transform.position, m_radius);
36+
foreach (Rigidbody rb in m_effectRoot.GetComponentsInChildren<Rigidbody>())
37+
{
38+
rb.AddExplosionForce(m_force, transform.position, m_radius);
39+
}
4840
}
4941
}
5042
}

0 commit comments

Comments
 (0)