浏览代码

Merge pull request #760 from LumaDigital/PrefabImportFix

A fix for prefab components not refreshing in a scene in the editor w…
JoshEngebretson 9 年之前
父节点
当前提交
ae06c0745b
共有 2 个文件被更改,包括 19 次插入9 次删除
  1. 16 9
      Source/ToolCore/Assets/PrefabImporter.cpp
  2. 3 0
      Source/ToolCore/Assets/PrefabImporter.h

+ 16 - 9
Source/ToolCore/Assets/PrefabImporter.cpp

@@ -152,15 +152,7 @@ void PrefabImporter::HandlePrefabSave(StringHash eventType, VariantMap& eventDat
     FileSystem* fs = GetSubsystem<FileSystem>();
     FileSystem* fs = GetSubsystem<FileSystem>();
     fs->Copy(asset_->GetPath(), asset_->GetCachePath());
     fs->Copy(asset_->GetPath(), asset_->GetCachePath());
 
 
-    // reload it immediately so it is ready for use
-    // TODO: The resource cache is reloading after this reload due to catching the file cache
-    ResourceCache* cache = GetSubsystem<ResourceCache>();
-    XMLFile* xmlfile = cache->GetResource<XMLFile>(asset_->GetGUID());
-    cache->ReloadResource(xmlfile);
-
-    VariantMap changedData;
-    changedData[PrefabChanged::P_GUID] = asset_->GetGUID();
-    SendEvent(E_PREFABCHANGED, changedData);
+    OnPrefabFileChanged();
 
 
 }
 }
 
 
@@ -170,9 +162,24 @@ bool PrefabImporter::Import()
 
 
     fs->Copy(asset_->GetPath(), asset_->GetCachePath());
     fs->Copy(asset_->GetPath(), asset_->GetCachePath());
 
 
+    OnPrefabFileChanged();
+
     return true;
     return true;
 }
 }
 
 
+void PrefabImporter::OnPrefabFileChanged()
+{
+    // reload it immediately so it is ready for use
+    // TODO: The resource cache is reloading after this reload due to catching the file cache
+    ResourceCache* cache = GetSubsystem<ResourceCache>();
+    XMLFile* xmlfile = cache->GetResource<XMLFile>(asset_->GetGUID());
+    cache->ReloadResource(xmlfile);
+
+    VariantMap changedData;
+    changedData[PrefabChanged::P_GUID] = asset_->GetGUID();
+    SendEvent(E_PREFABCHANGED, changedData);
+}
+
 bool PrefabImporter::LoadSettingsInternal(JSONValue& jsonRoot)
 bool PrefabImporter::LoadSettingsInternal(JSONValue& jsonRoot)
 {
 {
     if (!AssetImporter::LoadSettingsInternal(jsonRoot))
     if (!AssetImporter::LoadSettingsInternal(jsonRoot))

+ 3 - 0
Source/ToolCore/Assets/PrefabImporter.h

@@ -55,6 +55,9 @@ protected:
     virtual bool LoadSettingsInternal(JSONValue& jsonRoot);
     virtual bool LoadSettingsInternal(JSONValue& jsonRoot);
     virtual bool SaveSettingsInternal(JSONValue& jsonRoot);
     virtual bool SaveSettingsInternal(JSONValue& jsonRoot);
 
 
+    /// Handle notifying any objects that might need to update after the prefab file changes, such as ResourceCache or any scene components
+    virtual void OnPrefabFileChanged();
+
 private:
 private:
 
 
     void HandlePrefabSave(StringHash eventType, VariantMap& eventData);
     void HandlePrefabSave(StringHash eventType, VariantMap& eventData);