Skip to content

Commit 63f7d0b

Browse files
vkoveclassond
authored andcommitted
Uni 48541 fix fbx exporter fdg warnings pass 2 (#423)
* move delegate definitions out of ModelExporter * use functions instead of property for ToExport - this is because properties should not return arrays as they are not write-protected * FbxExportSettings: add properties for public variables - didn't change the naming of any of the variables, only the property names are new. THis is to ensure backwards compatibility with older FbxExportSettings.asset files * move delegate definitions out of ModelExporter * use functions instead of property for ToExport - this is because properties should not return arrays as they are not write-protected * FbxExportSettings: add properties for public variables - didn't change the naming of any of the variables, only the property names are new. THis is to ensure backwards compatibility with older FbxExportSettings.asset files * change public FbxExportSettings variables into properties * replace curves property with getter/setter - properties cannot return arrays * fix permission warning when calling a process - set SecurityPermission attribute - TODO: confirm what the flag should be, currently flag allows calling unmanaged code * move FbxPrefabUtility and FbxRepresentation so they aren't nested - also make functions using "ref" internal * add FbxPrefabUtility reflection class for unit tests - to fix the tests that use functions that have now been made internal * fix failing unit test
1 parent 4645d4a commit 63f7d0b

19 files changed

+1956
-1603
lines changed

Assets/com.unity.formats.fbx.tests/ExporterTestBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,14 @@ public virtual void Term ()
209209
EditorApplication.update += DeleteOnNextUpdate;
210210

211211
// Put back the initial setting for the auto-updater toggle
212-
ExportSettings.instance.autoUpdaterEnabled = isAutoUpdaterOn;
212+
ExportSettings.instance.AutoUpdaterEnabled = isAutoUpdaterOn;
213213
}
214214

215215
[SetUp]
216216
public virtual void Init()
217217
{
218-
isAutoUpdaterOn = ExportSettings.instance.autoUpdaterEnabled;
219-
ExportSettings.instance.autoUpdaterEnabled = true;
218+
isAutoUpdaterOn = ExportSettings.instance.AutoUpdaterEnabled;
219+
ExportSettings.instance.AutoUpdaterEnabled = true;
220220
}
221221

222222

Assets/com.unity.formats.fbx.tests/FbxExporterReflection.cs

Lines changed: 106 additions & 74 deletions
Large diffs are not rendered by default.

Assets/com.unity.formats.fbx.tests/FbxPrefabAutoUpdaterTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public override void Init ()
3030
// Instantiate the fbx and create a prefab from it.
3131
// Delete the object right away (don't even wait for term).
3232
var fbxInstance = PrefabUtility.InstantiatePrefab (m_fbx) as GameObject;
33-
new FbxPrefabAutoUpdater.FbxPrefabUtility (fbxInstance.AddComponent<FbxPrefab> ()).SetSourceModel (m_fbx);
33+
new FbxPrefabUtility (fbxInstance.AddComponent<FbxPrefab> ()).SetSourceModel (m_fbx);
3434
m_prefabPath = GetRandomPrefabAssetPath ();
3535
m_prefab = PrefabUtility.CreatePrefab (m_prefabPath, fbxInstance);
3636
AssetDatabase.Refresh ();
@@ -176,7 +176,7 @@ public void TestNameMapping()
176176
fbxPrefabScript.NameMapping.Add(stringpair);
177177

178178

179-
FbxPrefabAutoUpdater.FbxPrefabUtility fbxPrefabUtility = new FbxPrefabAutoUpdater.FbxPrefabUtility(fbxPrefabScript);
179+
FbxPrefabUtility fbxPrefabUtility = new FbxPrefabUtility(fbxPrefabScript);
180180

181181
Assert.IsTrue(fbxPrefabUtility.GetUnityObjectName("SphereFBX") == stringpair.UnityObjectName);
182182
Assert.IsTrue(fbxPrefabUtility.GetFBXObjectName("Sphere") == stringpair.FBXObjectName);
@@ -240,8 +240,8 @@ public override void Init()
240240
{
241241
base.Init();
242242
// Save the initial setting for the auto updater toggle and disable it for the unit test
243-
isAutoUpdaterOn = ExportSettings.instance.autoUpdaterEnabled;
244-
ExportSettings.instance.autoUpdaterEnabled = false;
243+
isAutoUpdaterOn = ExportSettings.instance.AutoUpdaterEnabled;
244+
ExportSettings.instance.AutoUpdaterEnabled = false;
245245
FbxPrefabAutoUpdater.runningUnitTest = true;
246246
}
247247

@@ -340,7 +340,7 @@ public void RemappingTest()
340340
public void stopTest()
341341
{
342342
// Put back the initial setting for the auto-updater toggle
343-
ExportSettings.instance.autoUpdaterEnabled = isAutoUpdaterOn;
343+
ExportSettings.instance.AutoUpdaterEnabled = isAutoUpdaterOn;
344344
FbxPrefabAutoUpdater.runningUnitTest = false;
345345
}
346346
}
@@ -401,7 +401,7 @@ public void ExpensivePerformanceTest ()
401401
var instance = CreateGameObject("prefab_" + i);
402402
Assert.IsTrue(instance);
403403
var fbxPrefab = instance.AddComponent<FbxPrefab>();
404-
new FbxPrefabAutoUpdater.FbxPrefabUtility(fbxPrefab).SetSourceModel(fbxFiles[i]);
404+
new FbxPrefabUtility(fbxPrefab).SetSourceModel(fbxFiles[i]);
405405
PrefabUtility.CreatePrefab(GetRandomPrefabAssetPath(), fbxFiles[i]);
406406
}
407407
Debug.Log("Created prefabs in " + stopwatch.ElapsedMilliseconds);

Assets/com.unity.formats.fbx.tests/FbxPrefabTest.cs

Lines changed: 55 additions & 55 deletions
Large diffs are not rendered by default.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
using UnityEngine;
5+
6+
namespace UnityEditor.Formats.Fbx.Exporter.UnitTests
7+
{
8+
/// <summary>
9+
// This class allows accessing the FbxPrefabUtility methods that this
10+
// unit test needs to validate
11+
/// </summary>
12+
public class FbxPrefabUtilityReflection
13+
{
14+
public static void Initialize<T>(ref T item) where T : new()
15+
{
16+
object[] args = new object[] { item };
17+
Invoke.InvokeStaticGenericMethod<FbxPrefabUtility>("Initialize", ref args, typeof(T));
18+
item = (T)args[0];
19+
}
20+
21+
public static void Add<TKey, TValue>(ref Dictionary<TKey, TValue> thedict, TKey key, TValue value)
22+
{
23+
object[] args = new object[] { thedict, key, value };
24+
Invoke.InvokeStaticGenericMethod<FbxPrefabUtility>("Add", ref args, typeof(TKey), typeof(TValue));
25+
thedict = (Dictionary<TKey,TValue>)args[0];
26+
}
27+
28+
public static void Append<T>(ref List<T> thelist, T item)
29+
{
30+
object[] args = new object[] { thelist, item };
31+
Invoke.InvokeStaticGenericMethodOverload<FbxPrefabUtility>("Append", ref args, typeof(T));
32+
thelist = (List<T>)args[0];
33+
}
34+
35+
public static void Append<TKey, TValue>(ref Dictionary<TKey, List<TValue>> thedict, TKey key, TValue item)
36+
{
37+
object[] args = new object[] { thedict, key, item };
38+
Invoke.InvokeStaticGenericMethodOverload<FbxPrefabUtility>(
39+
"Append",
40+
ref args,
41+
typeof(TKey), typeof(TValue)
42+
);
43+
thedict = (Dictionary<TKey, List<TValue>>)args[0];
44+
}
45+
46+
public static void Append<TKey1, TKey2, TValue>(ref Dictionary<TKey1, Dictionary<TKey2, List<TValue>>> thedict, TKey1 key1, TKey2 key2, TValue item)
47+
{
48+
object[] args = new object[] { thedict, key1, key2, item };
49+
Invoke.InvokeStaticGenericMethodOverload<FbxPrefabUtility>(
50+
"Append",
51+
ref args,
52+
typeof(TKey1), typeof(TKey2), typeof(TValue)
53+
);
54+
thedict = (Dictionary<TKey1, Dictionary<TKey2, List<TValue>>>)args[0];
55+
}
56+
}
57+
58+
public class FbxRepresentationReflection
59+
{
60+
public static bool Consume(char expected, string json, ref int index, bool required = true)
61+
{
62+
object[] args = new object[] { expected, json, index, required };
63+
try
64+
{
65+
var result = (bool)Invoke.InvokeStaticMethod<FbxRepresentation>("Consume", ref args);
66+
return result;
67+
}
68+
finally
69+
{
70+
// adding this in the finally in case an exception is raised.
71+
// This is because when calling the function normally, if an exception is raised after
72+
// setting the ref param, then the ref param will still be set.
73+
// Want to have the same functionality here.
74+
index = (int)args[2];
75+
}
76+
}
77+
78+
public static string ReadString(string json, ref int index)
79+
{
80+
object[] args = new object[] { json, index };
81+
try
82+
{
83+
var result = (string)Invoke.InvokeStaticMethod<FbxRepresentation>("ReadString", ref args);
84+
return result;
85+
}
86+
finally
87+
{
88+
// adding this in the finally in case an exception is raised.
89+
// This is because when calling the function normally, if an exception is raised after
90+
// setting the ref param, then the ref param will still be set.
91+
// Want to have the same functionality here.
92+
index = (int)args[1];
93+
}
94+
}
95+
}
96+
}

Assets/com.unity.formats.fbx.tests/ModelExporterTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public void TestExporterCallbacks()
288288
GameObject asset;
289289
Mesh assetMesh;
290290

291-
ModelExporter.GetMeshForComponent<FbxPrefab> prefabCallback =
291+
GetMeshForComponent<FbxPrefab> prefabCallback =
292292
(ModelExporter exporter, FbxPrefab component, FbxNode node) => {
293293
ModelExporterReflection.ExportMesh(exporter,sphereMesh, node);
294294
return true;
@@ -308,7 +308,7 @@ public void TestExporterCallbacks()
308308
// to make sure we don't pass if the previous pass didn't
309309
// actually unregister).
310310
filename = GetRandomFbxFilePath();
311-
ModelExporter.GetMeshForObject callback =
311+
GetMeshForObject callback =
312312
(ModelExporter exporter, GameObject gameObject, FbxNode node) => {
313313
if (gameObject.name == "Parent2") {
314314
ModelExporterReflection.ExportMesh(exporter,sphereMesh, node);

Assets/com.unity.formats.fbx.tests/RotationCurveTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public void TestBasics() {
2323
var animCurve = new AnimationCurve();
2424

2525
eulerCurve.SetCurve (2, animCurve);
26-
Assert.That (eulerCurve.Curves [2], Is.EqualTo (animCurve));
26+
Assert.That (eulerCurve.GetCurves()[2], Is.EqualTo (animCurve));
2727

2828
Assert.That(() => eulerCurve.SetCurve (-1, animCurve), Throws.Exception.TypeOf<System.IndexOutOfRangeException>());
2929
Assert.That(() => eulerCurve.SetCurve (3, animCurve), Throws.Exception.TypeOf<System.IndexOutOfRangeException>());
3030

3131
quaternionCurve.SetCurve (3, animCurve);
32-
Assert.That (quaternionCurve.Curves [3], Is.EqualTo (animCurve));
32+
Assert.That (quaternionCurve.GetCurves()[3], Is.EqualTo (animCurve));
3333

3434
Assert.That(() => quaternionCurve.SetCurve (-5, animCurve), Throws.Exception.TypeOf<System.IndexOutOfRangeException>());
3535
Assert.That(() => quaternionCurve.SetCurve (4, animCurve), Throws.Exception.TypeOf<System.IndexOutOfRangeException>());

Packages/com.unity.formats.fbx/Editor/Scripts/ConvertToModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static GameObject[] CreateInstantiatedModelPrefab (
108108
{
109109
var toExport = ModelExporter.RemoveRedundantObjects (unityGameObjectsToConvert);
110110

111-
if (ExportSettings.instance.showConvertToPrefabDialog)
111+
if (ExportSettings.instance.ShowConvertToPrefabDialog)
112112
{
113113
ConvertToPrefabEditorWindow.Init(toExport);
114114
return toExport.ToArray();
@@ -416,7 +416,7 @@ public static void SetupFbxPrefab(GameObject toSetUp, GameObject unityMainAsset)
416416
Object.DestroyImmediate(fbxPrefab);
417417
}
418418
fbxPrefab = toSetUp.AddComponent<FbxPrefab>();
419-
var fbxPrefabUtility = new FbxPrefabAutoUpdater.FbxPrefabUtility (fbxPrefab);
419+
var fbxPrefabUtility = new FbxPrefabUtility (fbxPrefab);
420420
fbxPrefabUtility.SetSourceModel(unityMainAsset);
421421
}
422422

Packages/com.unity.formats.fbx/Editor/Scripts/ConvertToPrefabEditorWindow.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ protected override bool DisableNameSelection
2020
{
2121
get
2222
{
23-
return (ToExport != null && ToExport.Length > 1);
23+
return (GetToExport() != null && GetToExport().Length > 1);
2424
}
2525
}
2626
protected override bool DisableTransferAnim
2727
{
2828
get
2929
{
30-
return ToExport == null || ToExport.Length > 1;
30+
return GetToExport() == null || GetToExport().Length > 1;
3131
}
3232
}
3333

@@ -41,13 +41,13 @@ public static void Init(IEnumerable<GameObject> toConvert)
4141

4242
protected void SetGameObjectsToConvert(IEnumerable<GameObject> toConvert)
4343
{
44-
ToExport = toConvert.OrderBy(go => go.name).ToArray();
44+
SetToExport(toConvert.OrderBy(go => go.name).ToArray());
4545

4646
TransferAnimationSource = null;
4747
TransferAnimationDest = null;
48-
if (ToExport.Length == 1)
48+
if (GetToExport().Length == 1)
4949
{
50-
var go = ModelExporter.GetGameObject(ToExport[0]);
50+
var go = ModelExporter.GetGameObject(GetToExport()[0]);
5151
// check if the GameObject is a model instance, use as default filename and path if it is
5252
var mainAsset = ConvertToModel.GetFbxAssetOrNull(go);
5353
if (!mainAsset)
@@ -73,7 +73,7 @@ protected void SetGameObjectsToConvert(IEnumerable<GameObject> toConvert)
7373
TransferAnimationDest = go.transform;
7474
}
7575
}
76-
else if (ToExport.Length > 1)
76+
else if (GetToExport().Length > 1)
7777
{
7878
m_prefabFileName = "(automatic)";
7979
}
@@ -93,7 +93,7 @@ protected override void OnEnable()
9393

9494
protected bool ExportSetContainsAnimation()
9595
{
96-
foreach (var obj in ToExport)
96+
foreach (var obj in GetToExport())
9797
{
9898
var go = ModelExporter.GetGameObject(obj);
9999
if (go.GetComponentInChildren<Animation>() || go.GetComponentInChildren<Animator>())
@@ -124,7 +124,7 @@ protected override bool Export()
124124
var prefabDirPath = ExportSettings.PrefabAbsoluteSavePath;
125125
var prefabPath = System.IO.Path.Combine(prefabDirPath, m_prefabFileName + ".prefab");
126126

127-
if (ToExport == null)
127+
if (GetToExport() == null)
128128
{
129129
Debug.LogError("FbxExporter: missing object for conversion");
130130
return false;
@@ -153,9 +153,9 @@ protected override bool Export()
153153
}
154154
}
155155

156-
if (ToExport.Length == 1)
156+
if (GetToExport().Length == 1)
157157
{
158-
var go = ModelExporter.GetGameObject(ToExport[0]);
158+
var go = ModelExporter.GetGameObject(GetToExport()[0]);
159159

160160
// Check if we'll be clobbering files. If so, warn the user
161161
// first and let them cancel out.
@@ -180,7 +180,7 @@ protected override bool Export()
180180
return true;
181181
}
182182

183-
foreach (var obj in ToExport)
183+
foreach (var obj in GetToExport())
184184
{
185185
// Convert, automatically choosing a file path that won't clobber any existing files.
186186
var go = ModelExporter.GetGameObject(obj);
@@ -235,7 +235,7 @@ protected override void CreateCustomUI()
235235

236236
var pathLabels = ExportSettings.GetRelativePrefabSavePaths();
237237

238-
ExportSettings.instance.selectedPrefabPath = EditorGUILayout.Popup(ExportSettings.instance.selectedPrefabPath, pathLabels, GUILayout.MinWidth(SelectableLabelMinWidth));
238+
ExportSettings.instance.SelectedPrefabPath = EditorGUILayout.Popup(ExportSettings.instance.SelectedPrefabPath, pathLabels, GUILayout.MinWidth(SelectableLabelMinWidth));
239239

240240
if (GUILayout.Button(new GUIContent("...", "Browse to a new location to save prefab to"), EditorStyles.miniButton, GUILayout.Width(BrowseButtonWidth)))
241241
{
@@ -270,9 +270,9 @@ protected override void CreateCustomUI()
270270
protected override void DoNotShowDialogUI()
271271
{
272272
EditorGUI.indentLevel--;
273-
ExportSettings.instance.showConvertToPrefabDialog = !EditorGUILayout.Toggle(
273+
ExportSettings.instance.ShowConvertToPrefabDialog = !EditorGUILayout.Toggle(
274274
new GUIContent("Don't ask me again", "Don't ask me again, use the last used paths and options instead"),
275-
!ExportSettings.instance.showConvertToPrefabDialog
275+
!ExportSettings.instance.ShowConvertToPrefabDialog
276276
);
277277
}
278278
}

0 commit comments

Comments
 (0)