Răsfoiți Sursa

Bugfix: Animation no longer runs when editor is in stopped mode

BearishSun 8 ani în urmă
părinte
comite
b6754b366b

+ 6 - 9
Source/BansheeCore/Components/BsCAnimation.cpp

@@ -19,6 +19,8 @@ namespace bs
 	{
 		mNotifyFlags = TCF_Transform;
 		setFlag(ComponentFlag::AlwaysRun, true);
+
+		setName("Animation");
 	}
 
 	CAnimation::CAnimation(const HSceneObject& parent)
@@ -167,13 +169,7 @@ namespace bs
 				{
 					AABox bounds = mBounds;
 
-					Matrix4 parentTfrm;
-					if (SO()->getParent() != nullptr)
-						parentTfrm = SO()->getParent()->getWorldMatrix();
-					else
-						parentTfrm = Matrix4::IDENTITY;
-
-					bounds.transformAffine(parentTfrm); 
+					bounds.transformAffine(SO()->getWorldMatrix()); 
 					mInternal->setBounds(bounds);
 				}
 			}
@@ -233,8 +229,9 @@ namespace bs
 			destroyInternal();
 			mPreviewMode = false;
 		}
-
-		restoreInternal(false);
+		
+		if(SceneManager::instance().isRunning())
+			restoreInternal(false);
 	}
 
 	void CAnimation::update()

+ 1 - 1
Source/BansheeCore/Components/BsCAnimation.h

@@ -187,7 +187,7 @@ namespace bs
 
 		/**
 		 * Rebuilds internal curve -> property mapping about the currently playing animation clip. This mapping allows the
-		 * animation component to know which property to assign which values from an animation curve. This Should be called
+		 * animation component to know which property to assign which values from an animation curve. This should be called
 		 * whenever playback for a new clip starts, or when clip curves change.
 		 */
 		BS_SCRIPT_EXPORT(in:true)

+ 20 - 5
Source/BansheeCore/Scene/BsSceneManager.cpp

@@ -194,11 +194,27 @@ namespace bs
 		if (mComponentState == state)
 			return;
 
+		ComponentState oldState = mComponentState;
+
+		// Make sure to change the state before calling any callbacks, so callbacks can query the state
+		mComponentState = state;
+
 		// Wake up all components with onInitialize/onEnable events if moving to running or paused state
 		if(state == ComponentState::Running || state == ComponentState::Paused)
 		{
-			if(mComponentState == ComponentState::Stopped)
+			if(oldState == ComponentState::Stopped)
 			{
+				// Disable, and then re-enable components that have an AlwaysRun flag
+				for(auto& entry : mActiveComponents)
+				{
+					if (entry->sceneObject()->getActive())
+					{
+						entry->onDisabled();
+						entry->onEnabled();
+					}
+					
+				}
+
 				// Trigger enable on all components that don't have AlwaysRun flag (at this point those will be all
 				// inactive components that have active scene object parents)
 				for(auto& entry : mInactiveComponents)
@@ -264,10 +280,11 @@ namespace bs
 					HComponent component = mActiveComponents[i];
 
 					bool alwaysRun = component->hasFlag(ComponentFlag::AlwaysRun);
-					if (alwaysRun)
-						continue;
 
 					component->onDisabled();
+
+					if(alwaysRun)
+						component->onEnabled();
 				}
 			}
 
@@ -289,8 +306,6 @@ namespace bs
 				component->setSceneManagerId(encodeComponentId(inactiveIdx, InactiveList));
 			}
 		}
-
-		mComponentState = state;
 	}
 
 	void SceneManager::_notifyComponentCreated(const HComponent& component, bool parentActive)

+ 6 - 6
Source/MBansheeEngine/Animation/Animation.cs

@@ -109,7 +109,7 @@ namespace BansheeEngine
         /// 
         ///                    Path element prefixed with ":" signify names of components. If a path doesn't have a
         ///                    component element, it is assumed the field is relative to the scene object itself (only 
-        ///                    "Translation", "Rotation" and "Scale" fields are supported in such case). Only one component
+        ///                    "Position", "Rotation" and "Scale" fields are supported in such case). Only one component
         ///                    path element per path is allowed.
         /// 
         ///                    Path entries with no prefix are considered regular script object fields. Each path must have
@@ -123,12 +123,12 @@ namespace BansheeEngine
         ///                    <paramref name="suffix"/>.
         /// 
         ///                    Path examples:
-        ///                     :MyComponent/myInt (path to myInt variable on a component attached to this object)
-        ///                     :MyComponent/myArray[0] (path to first element of myArray on the same component)
+        ///                     :MyComponent/myInt (path to myInt variable on a component attached to the root object)
+        ///                     :MyComponent/myArray[0] (path to first element of myArray on the same component as above)
         ///                     !childSO/:MyComponent/myInt (path to myInt variable on a child scene object)
-        ///                     !childSO/Translation (path to the scene object translation)
-        ///                     :MyComponent/myVector.z (path to the z component of myVector on this object)
-        ///                    </param>
+        ///                     !childSO/Position (path to the scene object position)
+        ///                     :MyComponent/myVector.z (path to the z component of myVector on the root object)
+        /// </param>
         /// <param name="suffix">Suffix of the last field entry, if it has any. Contains the suffix separator ".".</param>
         /// <returns>If found, property object you can use for setting and getting the value from the property, otherwise 
         ///          null.</returns>