Browse Source

Merged hjmediastudios/master. Adds removeOnCompletion functionality to AnimationController.

Lasse Öörni 10 years ago
parent
commit
29b178914c

+ 14 - 1
Source/Urho3D/Graphics/AnimationController.cpp

@@ -127,7 +127,7 @@ void AnimationController::Update(float timeStep)
             }
 
             // Remove if weight zero and target weight zero
-            if (state->GetWeight() == 0.0f && (targetWeight == 0.0f || fadeTime == 0.0f))
+            if (state->GetWeight() == 0.0f && (targetWeight == 0.0f || fadeTime == 0.0f) && i->removeOnCompletion_)
                 remove = true;
         }
 
@@ -362,6 +362,19 @@ bool AnimationController::SetWeight(const String& name, float weight)
     return true;
 }
 
+bool AnimationController::SetRemoveOnCompletion(const String& name, bool removeOnCompletion)
+{
+    unsigned index;
+    AnimationState* state;
+    FindAnimation(name, index, state);
+    if (index == M_MAX_UNSIGNED || !state)
+        return false;
+
+    animations_[index].removeOnCompletion_ = removeOnCompletion;
+    MarkNetworkUpdate();
+    return true;    
+}
+
 bool AnimationController::SetLooped(const String& name, bool enable)
 {
     AnimationState* state = GetAnimationState(name);

+ 6 - 1
Source/Urho3D/Graphics/AnimationController.h

@@ -47,7 +47,8 @@ struct AnimationControl
         setTime_(0),
         setWeight_(0),
         setTimeRev_(0),
-        setWeightRev_(0)
+        setWeightRev_(0),
+        removeOnCompletion_(true)
     {
     }
 
@@ -75,6 +76,8 @@ struct AnimationControl
     unsigned char setTimeRev_;
     /// Set weight command revision.
     unsigned char setWeightRev_;
+    /// Sets whether this should automatically be removed when it finishes playing.
+    bool removeOnCompletion_;
 };
 
 /// %Component that drives an AnimatedModel's animations.
@@ -124,6 +127,8 @@ public:
     bool SetSpeed(const String& name, float speed);
     /// Set animation autofade at end (non-looped animations only.) Zero time disables. Return true on success.
     bool SetAutoFade(const String& name, float fadeOutTime);
+    /// Set whether an animation auto-removes on completion
+    bool SetRemoveOnCompletion(const String& name, bool removeOnCompletion);
 
     /// Return whether an animation is active. Note that non-looping animations that are being clamped at the end also return true.
     bool IsPlaying(const String& name) const;

+ 2 - 0
Source/Urho3D/Script/GraphicsAPI.cpp

@@ -1195,6 +1195,8 @@ static void RegisterAnimationController(asIScriptEngine* engine)
     engine->RegisterObjectMethod("AnimationController", "float GetFadeTarget(const String&in) const", asMETHOD(AnimationController, GetFadeTarget), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationController", "AnimationState@+ GetAnimationState(const String&in) const", asMETHODPR(AnimationController, GetAnimationState, (const String&) const, AnimationState*), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationController", "AnimationState@+ GetAnimationState(StringHash) const", asMETHODPR(AnimationController, GetAnimationState, (StringHash) const, AnimationState*), asCALL_THISCALL);
+    engine->RegisterObjectMethod("AnimationController", "bool SetRemoveOnCompletion(const String&in, bool)", asMETHOD(AnimationController, SetRemoveOnCompletion), asCALL_THISCALL);
+
 }
 
 static void RegisterBillboardSet(asIScriptEngine* engine)