Преглед изворни кода

Fixes issues with drag and dropping an object in the Library Window to its starting location
Fixed an issue with saving an already existing scene

BearishSun пре 10 година
родитељ
комит
500686a813

+ 1 - 1
BansheeEditor/Source/BsProjectLibrary.cpp

@@ -628,7 +628,7 @@ namespace BansheeEngine
 		if (!mResourceManifest->uuidToFilePath(resource.getUUID(), filePath))
 			return;
 
-		Resources::instance().save(resource, filePath, false);
+		Resources::instance().save(resource, filePath, true);
 	}
 
 	void ProjectLibrary::createFolderEntry(const Path& path)

+ 1 - 1
MBansheeEditor/EditorApplication.cs

@@ -232,7 +232,7 @@ namespace BansheeEditor
                     // TODO - If path points to an existing non-scene asset or folder I should delete it otherwise
                     //        Internal_SaveScene will silently fail.
 
-                    scenePath = ".prefab";
+                    scenePath += ".prefab";
 
                     SaveScene(scenePath);
                     LoadScene(scenePath);

+ 14 - 3
MBansheeEditor/Library/LibraryUtility.cs

@@ -99,15 +99,26 @@ namespace BansheeEditor
         public static string GetUniquePath(string path)
         {
             string extension = Path.GetExtension(path);
-            string pathNoExtension = path;
+            string pathClean = path;
             if (!String.IsNullOrEmpty(extension))
-                pathNoExtension = path.Remove(path.Length - extension.Length);
+                pathClean = path.Remove(path.Length - extension.Length);
 
             int idx = 0;
+            int separatorIdx = pathClean.LastIndexOf('_');
+            if (separatorIdx != -1)
+            {
+                string numberString = pathClean.Substring(separatorIdx + 1, pathClean.Length - (separatorIdx + 1));
+                if (int.TryParse(numberString, out idx))
+                {
+                    pathClean = pathClean.Substring(0, separatorIdx);
+                    idx++;
+                }
+            }
+           
             string destination = path;
             while (ProjectLibrary.Exists(destination))
             {
-                destination = pathNoExtension + "_" + idx + extension;
+                destination = pathClean + "_" + idx + extension;
                 idx++;
             }
 

+ 8 - 5
MBansheeEditor/Library/LibraryWindow.cs

@@ -1302,21 +1302,24 @@ namespace BansheeEditor
                     string pathTail = PathEx.GetTail(absolutePath);
                     string destination = Path.Combine(destinationFolder, pathTail);
 
-                    bool doCopy = !ProjectLibrary.Exists(path);
+                    if (PathEx.Compare(absolutePath, destination))
+                        continue;
+
+                    bool doCopy = !ProjectLibrary.Exists(absolutePath);
 
                     if (Directory.Exists(path))
                     {
                         if (doCopy)
-                            DirectoryEx.Copy(path, LibraryUtility.GetUniquePath(destination));
+                            DirectoryEx.Copy(absolutePath, LibraryUtility.GetUniquePath(destination));
                         else
-                            DirectoryEx.Move(path, LibraryUtility.GetUniquePath(destination));
+                            DirectoryEx.Move(absolutePath, LibraryUtility.GetUniquePath(destination));
                     }
                     else if (File.Exists(path))
                     {
                         if (doCopy)
-                            FileEx.Copy(path, LibraryUtility.GetUniquePath(destination));
+                            FileEx.Copy(absolutePath, LibraryUtility.GetUniquePath(destination));
                         else
-                            FileEx.Move(path, LibraryUtility.GetUniquePath(destination));
+                            ProjectLibrary.Move(absolutePath, LibraryUtility.GetUniquePath(destination));
                     }
 
                     ProjectLibrary.Refresh();

+ 12 - 5
SBansheeEngine/Source/BsScriptResourceManager.cpp

@@ -59,10 +59,17 @@ namespace BansheeEngine
 	template<class RetType, class InType>
 	void ScriptResourceManager::getScriptResource(const ResourceHandle<InType>& resourceHandle, RetType** out, bool create)
 	{
-		*out = static_cast<RetType*>(getScriptResource(resourceHandle.getUUID()));
+		String uuid = resourceHandle.getUUID();
 
-		if (*out == nullptr && create)
-			createScriptResource(resourceHandle, out);
+		if (!uuid.empty())
+		{
+			*out = static_cast<RetType*>(getScriptResource(uuid));
+
+			if (*out == nullptr && create)
+				createScriptResource(resourceHandle, out);
+		}
+		else
+			*out = nullptr;
 	}
 
 	template<>
@@ -191,8 +198,8 @@ namespace BansheeEngine
 
 	ScriptResourceBase* ScriptResourceManager::getScriptResource(const String& uuid)
 	{
-		if(uuid == "")
-			BS_EXCEPT(InvalidParametersException, "Provided resource handle has an undefined resource UUID.");
+		if (uuid == "")
+			return nullptr;
 
 		auto findIter = mScriptResources.find(uuid);
 		if(findIter != mScriptResources.end())

+ 11 - 3
SBansheeEngine/Source/BsScriptScene.cpp

@@ -43,10 +43,18 @@ namespace BansheeEngine
 			root->destroy();
 		}
 
-		ScriptPrefab* scriptPrefab;
-		ScriptResourceManager::instance().getScriptResource(prefab, &scriptPrefab, true);
+		if (prefab != nullptr)
+		{
+			ScriptPrefab* scriptPrefab;
+			ScriptResourceManager::instance().getScriptResource(prefab, &scriptPrefab, true);
 
-		return scriptPrefab->getManagedInstance();
+			return scriptPrefab->getManagedInstance();
+		}
+		else
+		{
+			LOGERR("Failed loading scene at path: \"" + nativePath.toString() + "\"");
+			return nullptr;
+		}
 	}
 
 	void ScriptScene::internal_ClearScene()