Skip to content

Commit 0bf5867

Browse files
committed
move update event back to FbxPrefab
This is where Probuilder expects the event to be, and should not get called outside the editor anyway. Also, look for FbxPrefab in the dll instead of the C# file in FbxPrefabAutoUpdater Compile FbxPrefabInspector into the dll as well.
1 parent a7fd1b6 commit 0bf5867

File tree

4 files changed

+42
-36
lines changed

4 files changed

+42
-36
lines changed

Assets/FbxExporters/Editor/FbxPrefabAutoUpdater.cs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static string FindFbxPrefabAssetPath()
3030
var allGuids = AssetDatabase.FindAssets("FbxPrefab t:MonoScript");
3131
foreach(var guid in allGuids) {
3232
var path = AssetDatabase.GUIDToAssetPath(guid);
33-
if (path.EndsWith("/FbxPrefab.cs")) {
33+
if (path.EndsWith ("/UnityFbxPrefab.dll")) {
3434
return path;
3535
}
3636
}
@@ -1040,9 +1040,7 @@ void CompareAndUpdate()
10401040
var updatedObjects = updates.ImplementUpdates(fbxPrefabInstance);
10411041

10421042
// Tell listeners about it. They're free to make adjustments now.
1043-
if (OnUpdate != null) {
1044-
OnUpdate(fbxPrefabInstance, updatedObjects);
1045-
}
1043+
FbxPrefab.CallOnUpdate (fbxPrefabInstance, updatedObjects);
10461044

10471045
// Update the representation of the history to match the new fbx.
10481046
var newFbxRep = new FbxRepresentation(m_fbxPrefab.FbxModel.transform);
@@ -1143,33 +1141,6 @@ public void SetSourceModel(GameObject fbxModel) {
11431141
CompareAndUpdate();
11441142
}
11451143
}
1146-
1147-
//////////////////////////////////////////////////////////////////////////
1148-
// Event handling for updates.
1149-
1150-
/// <summary>
1151-
/// Handler for an OnUpdate event.
1152-
///
1153-
/// The update is performed on a temporary instance, which, shortly after
1154-
/// this handler is invoked, will be applied to the prefab.
1155-
///
1156-
/// The event handler can make changes to any objects in the hierarchy rooted
1157-
/// by the updatedInstance. Those changes will be applied to the prefab.
1158-
///
1159-
/// The updatedObjects include all objects in the temporary instance
1160-
/// that were:
1161-
/// - created, or
1162-
/// - changed parent, or
1163-
/// - had a component that was created, destroyed, or updated.
1164-
/// There is no notification for entire objects that were destroyed.
1165-
/// </summary>
1166-
public delegate void HandleUpdate(FbxPrefab updatedInstance, IEnumerable<GameObject> updatedObjects);
1167-
1168-
/// <summary>
1169-
/// OnUpdate is raised once when an FbxPrefab gets updated, after all the changes
1170-
/// have been done.
1171-
/// </summary>
1172-
public static event HandleUpdate OnUpdate;
11731144
}
11741145
}
11751146
}

Assets/FbxExporters/Editor/UnitTests/FbxPrefabTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ public UpdateListener(GameObject prefabToAttachTo) {
3030
m_prefabToAttachTo = prefabToAttachTo;
3131
Updated = new List<string>();
3232
NumUpdates = 0;
33-
FbxPrefabAutoUpdater.FbxPrefabUtility.OnUpdate += OnUpdate;
33+
FbxPrefab.OnUpdate += OnUpdate;
3434
}
3535

3636
~UpdateListener() {
37-
FbxPrefabAutoUpdater.FbxPrefabUtility.OnUpdate -= OnUpdate;
37+
FbxPrefab.OnUpdate -= OnUpdate;
3838
}
3939

4040
public void Dispose() {
41-
FbxPrefabAutoUpdater.FbxPrefabUtility.OnUpdate -= OnUpdate;
41+
FbxPrefab.OnUpdate -= OnUpdate;
4242
}
4343

4444
void OnUpdate(FbxPrefab prefabInstance, IEnumerable<GameObject> updated)

Assets/FbxExporters/FbxPrefab.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,38 @@ public bool AutoUpdate {
6565
m_autoUpdate = value;
6666
}
6767
}
68+
69+
//////////////////////////////////////////////////////////////////////////
70+
// Event handling for updates.
71+
72+
/// <summary>
73+
/// Handler for an OnUpdate event.
74+
///
75+
/// The update is performed on a temporary instance, which, shortly after
76+
/// this handler is invoked, will be applied to the prefab.
77+
///
78+
/// The event handler can make changes to any objects in the hierarchy rooted
79+
/// by the updatedInstance. Those changes will be applied to the prefab.
80+
///
81+
/// The updatedObjects include all objects in the temporary instance
82+
/// that were:
83+
/// - created, or
84+
/// - changed parent, or
85+
/// - had a component that was created, destroyed, or updated.
86+
/// There is no notification for entire objects that were destroyed.
87+
/// </summary>
88+
public delegate void HandleUpdate(FbxPrefab updatedInstance, IEnumerable<GameObject> updatedObjects);
89+
90+
/// <summary>
91+
/// OnUpdate is raised once when an FbxPrefab gets updated, after all the changes
92+
/// have been done.
93+
/// </summary>
94+
public static event HandleUpdate OnUpdate;
95+
96+
public static void CallOnUpdate(FbxPrefab instance, IEnumerable<GameObject> updatedObjects){
97+
if (OnUpdate != null) {
98+
OnUpdate (instance, updatedObjects);
99+
}
100+
}
68101
}
69102
}

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
120120
COMMAND ${CMAKE_COMMAND} -E make_directory ${CLASS_LIBRARY_DEST}
121121
)
122122

123-
set(RUNTIME_CLASS_LIBRARY_NAME "UnityFbxExporter.dll")
123+
set(RUNTIME_CLASS_LIBRARY_NAME "UnityFbxPrefab.dll")
124124
fbxexporters_compile_csharp(OUTPUT ${CLASS_LIBRARY_DEST}/${RUNTIME_CLASS_LIBRARY_NAME}
125125
EXTRA_ARGS
126126
"/target:library"
@@ -146,6 +146,7 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
146146
"${CMAKE_SOURCE_DIR}/Assets/FbxExporters/Editor/FbxExportSettings.cs"
147147
"${CMAKE_SOURCE_DIR}/Assets/FbxExporters/Editor/InstallIntegration.cs"
148148
"${CMAKE_SOURCE_DIR}/Assets/FbxExporters/Editor/FbxPrefabAutoUpdater.cs"
149+
"${CMAKE_SOURCE_DIR}/Assets/FbxExporters/Editor/FbxPrefabInspector.cs"
149150
"${CMAKE_SOURCE_DIR}/Assets/FbxExporters/Editor/ConvertToModel.cs"
150151
REFERENCES
151152
"${CSHARP_MSCORLIB_LIBRARY}"
@@ -203,7 +204,8 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release")
203204
PATTERN "Editor/ReviewLastSavedModel.cs" EXCLUDE
204205
PATTERN "Editor/EditorRotate.cs" EXCLUDE
205206
PATTERN "Editor/FbxPrefabAutoUpdater.cs" EXCLUDE
206-
PATTERN "Editor/ConvertToModel.cs" EXCLUDE)
207+
PATTERN "Editor/ConvertToModel.cs" EXCLUDE
208+
PATTERN "Editor/FbxPrefabInspector.cs" EXCLUDE)
207209
install(FILES ${CLASS_LIBRARY_DEST}/${EDITOR_CLASS_LIBRARY_NAME} DESTINATION FbxExporters/Editor)
208210
install(FILES ${CLASS_LIBRARY_DEST}/${RUNTIME_CLASS_LIBRARY_NAME} DESTINATION FbxExporters)
209211
else()

0 commit comments

Comments
 (0)