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

Custom animation clip save/load functional

BearishSun пре 9 година
родитељ
комит
b457b55f91

+ 1 - 1
Source/BansheeCore/Source/BsAnimationClip.cpp

@@ -96,7 +96,7 @@ namespace BansheeEngine
 
 	HAnimationClip AnimationClip::create(bool isAdditive)
 	{
-		return static_resource_cast<AnimationClip>(gResources()._createResourceHandle(_createPtr(nullptr, isAdditive)));
+		return static_resource_cast<AnimationClip>(gResources()._createResourceHandle(_createPtr(bs_shared_ptr_new<AnimationCurves>(), isAdditive)));
 	}
 
 	HAnimationClip AnimationClip::create(const SPtr<AnimationCurves>& curves, bool isAdditive, UINT32 sampleRate)

+ 6 - 0
Source/BansheeEditor/Source/BsProjectLibrary.cpp

@@ -827,6 +827,12 @@ namespace BansheeEngine
 			return;
 
 		Path filePath = uuidToPath(resource.getUUID());
+		if(filePath.isEmpty())
+		{
+			LOGWRN("Trying to save a resource that hasn't been registered with the project library. Call ProjectLibrary::create first.");
+			return;
+		}
+
 		filePath.makeAbsolute(getResourcesFolder());
 
 		Resources::instance().save(resource, filePath, true);

+ 14 - 14
Source/MBansheeEditor/Windows/AnimationWindow.cs

@@ -2,6 +2,7 @@
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Text;
 using BansheeEngine;
 
@@ -235,25 +236,24 @@ namespace BansheeEditor
                     {
                         if (type == DialogBox.ResultType.Yes)
                         {
-                            string[] clipSavePaths;
-                            if (BrowseDialog.OpenFile(ProjectLibrary.ResourceFolder, "", false, out clipSavePaths))
+                            string clipSavePath;
+                            if (BrowseDialog.SaveFile(ProjectLibrary.ResourceFolder, "*.asset", out clipSavePath))
                             {
-                                if (clipSavePaths.Length > 0)
-                                {
-                                    AnimationClip newClip = new AnimationClip();
+                                clipSavePath = Path.ChangeExtension(clipSavePath, ".asset");
 
-                                    ProjectLibrary.Create(newClip, clipSavePaths[0]);
-                                    LoadAnimClip(newClip);
+                                AnimationClip newClip = new AnimationClip();
 
-                                    Animation animation = selectedSO.GetComponent<Animation>();
-                                    if (animation == null)
-                                        animation = selectedSO.AddComponent<Animation>();
+                                ProjectLibrary.Create(newClip, clipSavePath);
+                                LoadAnimClip(newClip);
 
-                                    animation.DefaultClip = newClip;
-                                    EditorApplication.SetSceneDirty();
+                                Animation animation = selectedSO.GetComponent<Animation>();
+                                if (animation == null)
+                                    animation = selectedSO.AddComponent<Animation>();
 
-                                    openPropertyWindow();
-                                }
+                                animation.DefaultClip = newClip;
+                                EditorApplication.SetSceneDirty();
+
+                                openPropertyWindow();
                             }
                         }
                     });