12.10 进度 基本完成
This commit is contained in:
@@ -15,7 +15,7 @@ namespace Continentis.MainGame.Commands
|
||||
private readonly Animator animator;
|
||||
private bool waitForFinish;
|
||||
private float overrideDuration;
|
||||
private string stateName;
|
||||
private string animationName;
|
||||
private int layer;
|
||||
|
||||
//在动画的normalizedTime执行函数
|
||||
@@ -23,13 +23,14 @@ namespace Continentis.MainGame.Commands
|
||||
private float clipScaledLength => clip.length / animator.speed;
|
||||
private Dictionary<float, Action> animationActions;
|
||||
|
||||
public Cmd_PlayAnimation(CombatCharacterViewBase characterView, string stateName,
|
||||
bool waitForFinish = false, float overrideDuration = -1, int layer = 0) : base(null)
|
||||
public Cmd_PlayAnimation(CombatCharacterViewBase characterView, string animationName,
|
||||
bool waitForFinish = true, float overrideDuration = -1, int layer = 0) : base(null)
|
||||
{
|
||||
this.characterView = characterView;
|
||||
this.animator = characterView.animator;
|
||||
this.stateName = stateName;
|
||||
this.clip = characterView.animationClips[stateName];
|
||||
this.animationName = animationName;
|
||||
this.clip = null;
|
||||
characterView.animations.TryGetValue(animationName, out clip);
|
||||
this.waitForFinish = waitForFinish;
|
||||
this.overrideDuration = overrideDuration;
|
||||
this.layer = layer;
|
||||
@@ -63,25 +64,27 @@ namespace Continentis.MainGame.Commands
|
||||
|
||||
protected override IObservable<Unit> OnExecute(CommandContext outerContext)
|
||||
{
|
||||
if (animator == null)
|
||||
if (animator == null || clip == null || string.IsNullOrEmpty(animationName))
|
||||
{
|
||||
Debug.LogWarning("Animator or stateName is null or empty.");
|
||||
return Observable.Return(Unit.Default);
|
||||
}
|
||||
|
||||
if (!animator.HasState(layer, Animator.StringToHash(stateName)))
|
||||
|
||||
string finalAnimationName = animationName;
|
||||
if (!characterView.animations.ContainsKey(animationName))
|
||||
{
|
||||
if (!animator.HasState(layer, Animator.StringToHash("Default")))
|
||||
{
|
||||
Debug.LogWarning($"Animator does not have state: {stateName}, and Default state is also missing.");
|
||||
return Observable.Return(Unit.Default);
|
||||
}
|
||||
|
||||
stateName = "Default"; // Fallback to Default state
|
||||
Debug.Log($"Animator does not have state: {stateName}. Falling back to Default state.");
|
||||
finalAnimationName = "Action";
|
||||
}
|
||||
|
||||
animator.CrossFade(stateName, 0f, layer, 0f);
|
||||
if (characterView.animations.TryGetValue(finalAnimationName, out clip))
|
||||
{
|
||||
characterView.animatorPlus2D.Play(clip);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"Animation clip not found for state: {finalAnimationName}");
|
||||
return Observable.Return(Unit.Default);
|
||||
}
|
||||
|
||||
//监听动画进度以执行函数,独立Observable
|
||||
if (animationActions.Count > 0)
|
||||
@@ -102,7 +105,7 @@ namespace Continentis.MainGame.Commands
|
||||
|
||||
if (waitForFinish)
|
||||
{
|
||||
float animationDuration = overrideDuration >= 0 ? overrideDuration : characterView.animationClips[stateName].length;
|
||||
float animationDuration = overrideDuration >= 0 ? overrideDuration / animator.speed : clipScaledLength;
|
||||
return Observable.Timer(TimeSpan.FromSeconds(animationDuration)).AsUnitObservable();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -47,6 +47,11 @@ namespace Continentis.MainGame.Commands
|
||||
return Observable.Return(Unit.Default);
|
||||
}
|
||||
|
||||
return base.OnExecute(outerContext);
|
||||
}
|
||||
|
||||
protected override IObservable<Unit> CoreExecute(CommandContext outerContext)
|
||||
{
|
||||
if (useTargetPosition)
|
||||
{
|
||||
if (selfContext.context["Target"] is CharacterBase character)
|
||||
|
||||
@@ -68,6 +68,11 @@ namespace Continentis.MainGame.Commands
|
||||
return Observable.Return(Unit.Default);
|
||||
}
|
||||
|
||||
return base.OnExecute(outerContext);
|
||||
}
|
||||
|
||||
protected override IObservable<Unit> CoreExecute(CommandContext outerContext)
|
||||
{
|
||||
if (useTargetPosition)
|
||||
{
|
||||
if (selfContext.context["Target"] is CharacterBase character)
|
||||
|
||||
Reference in New Issue
Block a user